Class NavigationComponentHelper

java.lang.Object
com.jidesoft.swing.NavigationComponentHelper

public abstract class NavigationComponentHelper extends 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 Linvalid input: '&Fs' already do it by default but the most Linvalid input: '&Fs' don't do it. This class provides some common code to make the implementation easy.
  • Constructor Details

    • NavigationComponentHelper

      public NavigationComponentHelper()
  • Method Details

    • getRowBounds

      protected abstract 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(Point p)
    • getSelectedRows

      protected abstract int[] getSelectedRows()
    • mouseMoved

      public void mouseMoved(MouseEvent e)
    • mouseExited

      public void mouseExited(MouseEvent e)
    • mousePressed

      public void mousePressed(MouseEvent e)
    • mouseReleased

      public void mouseReleased(MouseEvent e)
    • mouseClicked

      public void mouseClicked(MouseEvent e)
    • mouseEntered

      public void mouseEntered(MouseEvent e)
    • focusGained

      public void focusGained(FocusEvent e)
    • focusLost

      public void focusLost(FocusEvent e)
    • paint

      public void paint(Graphics g, JComponent c)
      Paints the rollover row and selection rows.
      Parameters:
      g - the Graphics
      c - the component
    • paintSelectedRow

      protected void paintSelectedRow(Graphics g, 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 Graphics
      c - the component
      row - the row index
    • getSelectionColor

      protected Color getSelectionColor(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(Graphics g, 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 Graphics
      c - the component
      row - the row index
    • setup

      public void setup(JComponent c)
    • repaintSelections

      public void repaintSelections(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 Point getMousePosition()