Class GTrable<T>

Type Parameters:
T - The row object type
All Implemented Interfaces:
GTrableModeRowlListener, ImageObserver, MenuContainer, Serializable, Scrollable

public class GTrable<T> extends JComponent implements Scrollable, GTrableModeRowlListener
Component that combines the display of a tree and a table. Data is presented in columns like a table, but rows can have child rows like a tree which are displayed indented in the first column.

A GTrable uses two different models: a row model and a column model. The row model contains row objects that contains the data to be displayed on a given row. The column model specifies how to display the data in the row object as a series of column values.

The row model also provides information about the parent child relationship of rows. If the model reports that a row can be expanded, an expand control is show on that row. If the row is then expanded, the model will then report additional rows immediately below the parent row, pushing any existing rows further down (i.e. all rows below the row being opened have their row indexes increased by the number of rows added.)

See Also:
  • Constructor Details

    • GTrable

      public GTrable(GTrableRowModel<T> rowModel, GTrableColumnModel<T> columnModel)
      Constructor
      Parameters:
      rowModel - the model that provides the row data.
      columnModel - the model the provides the column information for displaying the data stored in the row data.
  • Method Details

    • setRowModel

      public void setRowModel(GTrableRowModel<T> newRowModel)
      Sets a new row model.
      Parameters:
      newRowModel - the new row model to use
    • setColumnModel

      public void setColumnModel(GTrableColumnModel<T> columnModel)
      Sets a new column model.
      Parameters:
      columnModel - the new column model to use
    • setPreferredVisibleRowCount

      public void setPreferredVisibleRowCount(int minVisibleRows, int maxVisibleRows)
      Sets the preferred number of visible rows to be displayed in the scrollable area.
      Parameters:
      minVisibleRows - the minimum number of visible rows.
      maxVisibleRows - the maximum number of visible rows.
    • addCellClickedListener

      public void addCellClickedListener(GTrableCellClickedListener listener)
      Adds a listener to be notified if the user clicks on a cell in the GTrable.
      Parameters:
      listener - the listener to be notified
    • removeCellClickedListener

      public void removeCellClickedListener(GTrableCellClickedListener listener)
      Removes a cell clicked listener.
      Parameters:
      listener - the listener to be removed
    • addSelectedRowConsumer

      public void addSelectedRowConsumer(Consumer<Integer> consumer)
      Adds a consumer to be notified when the selected row changes.
      Parameters:
      consumer - the consumer to be notified when the selected row changes
    • removeSelectedRowConsumer

      public void removeSelectedRowConsumer(Consumer<Integer> consumer)
      Removes the consumer to be notified when the selected row changes.
      Parameters:
      consumer - the consumer to be removed
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • getVisibleRows

      public Range getVisibleRows()
      Returns the range of visible row indices..
      Returns:
      the range of visible row indices.
    • getSelectedRow

      public int getSelectedRow()
      Returns the currently selected row or -1 if not row is selected..
      Returns:
      the currently selected row or -1 if not row is selected.
    • setSelectedRow

      public void setSelectedRow(int rowIndex)
      Sets the selected row to the given row index
      Parameters:
      rowIndex - the row index to select
    • clearSelectedRow

      public void clearSelectedRow()
      Deselects any selected row
    • getSelectionForeground

      public Color getSelectionForeground()
      Returns the selection foreground color.
      Returns:
      the selection foreground color
    • getSelectionBackground

      public Color getSelectionBackground()
      Returns the selection background color.
      Returns:
      the selection background color
    • getRowHeight

      public int getRowHeight()
      Returns the height of a row in the trable..
      Returns:
      the height of a row in the trable.
    • getRowOffcut

      public int getRowOffcut()
      Returns the amount the view is scrolled such that the first line is not fully visible..
      Returns:
      the amount the view is scrolled such that the first line is not fully visible.
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
      Specified by:
      getScrollableUnitIncrement in interface Scrollable
    • getScrollableBlockIncrement

      public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
      Specified by:
      getScrollableBlockIncrement in interface Scrollable
    • getScrollableTracksViewportWidth

      public boolean getScrollableTracksViewportWidth()
      Specified by:
      getScrollableTracksViewportWidth in interface Scrollable
    • getScrollableTracksViewportHeight

      public boolean getScrollableTracksViewportHeight()
      Specified by:
      getScrollableTracksViewportHeight in interface Scrollable
    • expandRow

      public void expandRow(int rowIndex)
      Expands the row at the given index.
      Parameters:
      rowIndex - the index of the row to expand
    • collapseRow

      public void collapseRow(int rowIndex)
      Collapse the row (remove any of its descendants) at the given row index.
      Parameters:
      rowIndex - the index of the row to collapse
    • expandRowRecursively

      public void expandRowRecursively(int rowIndex)
      Fully expands the given row and all its descendants.
      Parameters:
      rowIndex - the index of the row to fully expand
    • expandAll

      public void expandAll()
      Expands all rows fully.
    • collapseAll

      public void collapseAll()
      Collapses all rows.
    • scrollToSelectedRow

      public void scrollToSelectedRow()
      Scrolls the view to make the currently selected row visible.
    • trableChanged

      public void trableChanged()
      Description copied from interface: GTrableModeRowlListener
      Notification that the row model changed
      Specified by:
      trableChanged in interface GTrableModeRowlListener
    • setBounds

      public void setBounds(int x, int y, int width, int height)
      Overrides:
      setBounds in class Component
    • getRow

      public int getRow(Point p)