public abstract class NavigationComponentHelper
extends java.lang.Object
NavigationComponentHelper
is a helper class to implement on JTree, JList and JTable (or JIDE table
subclasses) so they can be used for the navigation purpose. In order to make the component suitable for the
navigation, we want the selection effect to be easily noticeable and covers the row (instead of just one cell or one
node in the case of JTable and JTree respectively). We also want to have rollover effect the mouse is over a row.
Further more, the selection should have different color when the component is focused so that when multiple
navigation components are used, we can tell which one is active. Some L&Fs already do it by default but the most L&Fs
don't do it. This class provides some common code to make the implementation easy.Constructor | Description |
---|---|
NavigationComponentHelper() |
Modifier and Type | Method | Description |
---|---|---|
void |
focusGained(java.awt.event.FocusEvent e) |
|
void |
focusLost(java.awt.event.FocusEvent e) |
|
java.awt.Point |
getMousePosition() |
|
int |
getRolloverRow() |
Gets the rollover row that currently has rollover effect.
|
protected abstract java.awt.Rectangle |
getRowBounds(int row) |
Gets the bounds of the row.
|
protected abstract int[] |
getSelectedRows() |
|
protected java.awt.Color |
getSelectionColor(javax.swing.JComponent c) |
Gets the color to paint the selected rows.
|
void |
mouseClicked(java.awt.event.MouseEvent e) |
|
void |
mouseEntered(java.awt.event.MouseEvent e) |
|
void |
mouseExited(java.awt.event.MouseEvent e) |
|
void |
mouseMoved(java.awt.event.MouseEvent e) |
|
void |
mousePressed(java.awt.event.MouseEvent e) |
|
void |
mouseReleased(java.awt.event.MouseEvent e) |
|
void |
paint(java.awt.Graphics g,
javax.swing.JComponent c) |
Paints the rollover row and selection rows.
|
protected void |
paintRolloverRow(java.awt.Graphics g,
javax.swing.JComponent c,
int row) |
Paints the rollover row.
|
protected void |
paintSelectedRow(java.awt.Graphics g,
javax.swing.JComponent c,
int row) |
Paints the selected row.
|
void |
repaintSelections(javax.swing.JComponent c) |
|
protected abstract int |
rowAtPoint(java.awt.Point p) |
|
void |
setRolloverRow(int rolloverRow) |
Sets the rollover row.
|
void |
setup(javax.swing.JComponent c) |
protected abstract java.awt.Rectangle getRowBounds(int row)
row
- the bounds of the specific row.protected abstract int rowAtPoint(java.awt.Point p)
protected abstract int[] getSelectedRows()
public void mouseMoved(java.awt.event.MouseEvent e)
public void mouseExited(java.awt.event.MouseEvent e)
public void mousePressed(java.awt.event.MouseEvent e)
public void mouseReleased(java.awt.event.MouseEvent e)
public void mouseClicked(java.awt.event.MouseEvent e)
public void mouseEntered(java.awt.event.MouseEvent e)
public void focusGained(java.awt.event.FocusEvent e)
public void focusLost(java.awt.event.FocusEvent e)
public void paint(java.awt.Graphics g, javax.swing.JComponent c)
g
- the Graphicsc
- the componentprotected void paintSelectedRow(java.awt.Graphics g, javax.swing.JComponent c, int row)
g
- the Graphicsc
- the componentrow
- the row indexprotected java.awt.Color getSelectionColor(javax.swing.JComponent c)
c
- the componentprotected void paintRolloverRow(java.awt.Graphics g, javax.swing.JComponent c, int row)
g
- the Graphicsc
- the componentrow
- the row indexpublic void setup(javax.swing.JComponent c)
public void repaintSelections(javax.swing.JComponent c)
public int getRolloverRow()
public void setRolloverRow(int rolloverRow)
rolloverRow
- the row to show the rollover effect.public java.awt.Point getMousePosition()