Package com.jidesoft.swing
Class NavigationComponentHelper
- java.lang.Object
-
- com.jidesoft.swing.NavigationComponentHelper
-
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 Summary
Constructors Constructor Description NavigationComponentHelper()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods 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)
-
-
-
Method Detail
-
getRowBounds
protected abstract java.awt.Rectangle getRowBounds(int row)
Gets the bounds of the row.- Parameters:
row
- the bounds of the specific row.- Returns:
- the bounds of the row. Or null if there is no row at all or the specified row doesn't exist.
-
rowAtPoint
protected abstract int rowAtPoint(java.awt.Point p)
-
getSelectedRows
protected abstract int[] getSelectedRows()
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
-
focusGained
public void focusGained(java.awt.event.FocusEvent e)
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
-
paint
public void paint(java.awt.Graphics g, javax.swing.JComponent c)
Paints the rollover row and selection rows.- Parameters:
g
- the Graphicsc
- the component
-
paintSelectedRow
protected void paintSelectedRow(java.awt.Graphics g, javax.swing.JComponent c, int row)
Paints the selected row. This method is called after the tree is painted. It will paint over the content of the tree. In order to not cover the content, the painting code must be semi-transparent. By default, we paint it using the selection color which can be retrieved from UIDefault "Tree.selectionBackground" but with an alpha between 70 to 100 to create a gradient effect.- Parameters:
g
- the Graphicsc
- the componentrow
- the row index
-
getSelectionColor
protected java.awt.Color getSelectionColor(javax.swing.JComponent c)
Gets the color to paint the selected rows.- Parameters:
c
- the component- Returns:
- the selection color.
- Since:
- 3.4.6
-
paintRolloverRow
protected void paintRolloverRow(java.awt.Graphics g, javax.swing.JComponent c, int row)
Paints the rollover row. This method is called after the tree is painted. It will paint over the content of the tree. In order to not cover the content, the painting code must be semi-transparent. By default, we paint it using the selection color which can be retrieved from UIDefault "Tree.selectionBackground" but with an alpha between 10 to 40 to create a gradient effect.- Parameters:
g
- the Graphicsc
- the componentrow
- the row index
-
setup
public void setup(javax.swing.JComponent c)
-
repaintSelections
public void repaintSelections(javax.swing.JComponent c)
-
getRolloverRow
public int getRolloverRow()
Gets the rollover row that currently has rollover effect.- Returns:
- the row that has the rollover effect.
-
setRolloverRow
public void setRolloverRow(int rolloverRow)
Sets the rollover row.- Parameters:
rolloverRow
- the row to show the rollover effect.
-
getMousePosition
public java.awt.Point getMousePosition()
-
-