Class GTable

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable
Direct Known Subclasses:
FVTable, GhidraTable

public class GTable extends JTable
A sub-class of JTable that provides navigation and auto-lookup. By default, both of these features are disabled.

Auto-lookup is only supported on one column and must be specified using the setAutoLookupColumn() method.

Auto-lookup allows a user to begin typing the first few letters of a desired row. The table will attempt to locate the first row that contains the letters typed up to that point. There is an 800ms timeout between typed letters, at which point the list of typed letters will be flushed.

Auto-lookup is much faster if the underlying table model implements SortedTableModel, because a binary search can used to locate the desired row. A linear search is used if the model is not sorted.

Other features provided:

  • Column hiding/showing
  • Multi-column sorting
  • Column settings
  • Column state saving (visibility, size, positioning, sort values)
  • Selection management (saving/restoring selection when used with a filter panel)
See Also:
  • Constructor Details

    • GTable

      public GTable()
      Constructs a new GTable
    • GTable

      public GTable(TableModel dm)
      Constructs a new GTable using the specified table model.
      Parameters:
      dm - the table model
  • Method Details

    • setUI

      public void setUI(TableUI ui)
      Overrides:
      setUI in class JTable
    • setVisibleRowCount

      public void setVisibleRowCount(int visibleRowCount)
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
      Overrides:
      getPreferredScrollableViewportSize in class JTable
    • tableChanged

      public void tableChanged(TableModelEvent e)
      Specified by:
      tableChanged in interface TableModelListener
      Overrides:
      tableChanged in class JTable
    • selectRow

      public void selectRow(int row)
      Selects the given row. This is a convenience method for JTable.setRowSelectionInterval(int, int).
      Parameters:
      row - The row to select
    • selectRow

      public boolean selectRow(MouseEvent event)
      Selects the row under the given mouse point. This method is useful when the user triggers a popup mouse action and you would like to have the table select that row if it is not already selected. This allows you to guarantee that there is always a selection when the user triggers a popup menu.
      Parameters:
      event - The event that triggered the popup menu
      Returns:
      true if the row is selected or was already selected.
    • createDefaultColumnModel

      protected TableColumnModel createDefaultColumnModel()
      Overrides:
      createDefaultColumnModel in class JTable
    • createAutoLookup

      protected AutoLookup createAutoLookup()
      Allows subclasses to change the type of AutoLookup created by this table
      Returns:
      the auto lookup
    • setColumnModel

      public void setColumnModel(TableColumnModel columnModel)
      Overrides:
      setColumnModel in class JTable
    • setSelectionModel

      public void setSelectionModel(ListSelectionModel newModel)
      Overrides:
      setSelectionModel in class JTable
    • setModel

      public void setModel(TableModel dataModel)
      Overrides:
      setModel in class JTable
    • createSelectionManager

      protected <T> SelectionManager createSelectionManager()
    • getSelectionManager

      public SelectionManager getSelectionManager()
      Returns the SelectionManager in use by this GTable. null is returned if the user has installed their own ListSelectionModel.
      Returns:
      the selection manager
    • notifyTableChanged

      public void notifyTableChanged(TableModelEvent event)
      A method that allows clients to signal to this GTable and its internals that the table model has changed. Usually, tableChanged(TableModelEvent) is called, but clients alter the table, but do not do so through the model. In this case, they need a way to signal to the table that the model has been updated.
      Parameters:
      event - the event for the change
    • dispose

      public void dispose()
      Call this when the table will no longer be used
    • setAutoLookupTimeout

      public void setAutoLookupTimeout(long timeout)
      Sets the delay between keystrokes after which each keystroke is considered a new lookup
      Parameters:
      timeout - the timeout
      See Also:
    • getAutoLookup

      protected AutoLookup getAutoLookup()
    • setAutoLookupColumn

      public void setAutoLookupColumn(int lookupColumn)
      Sets the column in which auto-lookup will be enabled.

      Note: calling this method with a valid column index will disable key binding support of actions. See setActionsEnabled(boolean). Passing an invalid column index will disable the auto-lookup feature.

      Parameters:
      lookupColumn - the column in which auto-lookup will be enabled
    • setActionsEnabled

      public void setActionsEnabled(boolean b)
      Enables the keyboard actions to pass through this table and up the component hierarchy. Specifically, passing true to this method allows unmodified keystrokes to work in the tool when this table is focused. Modified keystrokes, like Ctrl-C, will work at all times. Finally, if true is passed to this method, then the auto lookup feature is disabled.

      The default state is for actions to be disabled.

      Parameters:
      b - true allows keyboard actions to pass up the component hierarchy.
    • areActionsEnabled

      public boolean areActionsEnabled()
      Returns true if key strokes are used to trigger actions.

      This method has a relationship with setAutoLookupColumn(int). If this method returns true, then the auto-lookup feature is disabled. If this method returns false, then the auto-lookup may or may not be enabled.

      Returns:
      true if key strokes are used to trigger actions
      See Also:
    • setAccessibleNamePrefix

      public void setAccessibleNamePrefix(String namePrefix)
      Sets an accessible name on the GTable such that screen readers will properly describe them.

      This prefix should be the base name that describes the type of items in the table. This method will then append the necessary information to property name the table.

      Parameters:
      namePrefix - the accessible name prefix to assign to the filter component. For example if the table contains fruits, then "Fruits" would be an appropriate prefix name.
    • setAutoEditEnabled

      public void setAutoEditEnabled(boolean allowAutoEdit)
      Enables or disables auto-edit. When enabled, the user can start typing to trigger an edit of an editable table cell.
      Parameters:
      allowAutoEdit - true for auto-editing
    • installEditKeyBinding

      protected void installEditKeyBinding()
    • setRowHeight

      public void setRowHeight(int height)
      Overrides:
      setRowHeight in class JTable
    • columnAdded

      public void columnAdded(TableColumnModelEvent e)
      Specified by:
      columnAdded in interface TableColumnModelListener
      Overrides:
      columnAdded in class JTable
    • columnRemoved

      public void columnRemoved(TableColumnModelEvent e)
      Specified by:
      columnRemoved in interface TableColumnModelListener
      Overrides:
      columnRemoved in class JTable
    • getConfigurableColumnTableModel

      public ConfigurableColumnTableModel getConfigurableColumnTableModel()
      Returns the underlying ConfigurableColumnTableModel if one is in-use
      Returns:
      the underlying ConfigurableColumnTableModel if one is in-use
    • getUnwrappedTableModel

      protected TableModel getUnwrappedTableModel()
      Unrolls the current model by checking if the current model is inside of a wrapper table model.
      Returns:
      this class's table model, unwrapped as needed
    • processKeyBinding

      protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
      Overrides:
      processKeyBinding in class JTable
    • getDefaultRenderer

      public TableCellRenderer getDefaultRenderer(Class<?> columnClass)
      Overrides:
      getDefaultRenderer in class JTable
    • wrapDefaultTableCellRenderer

      protected TableCellRenderer wrapDefaultTableCellRenderer(TableCellRenderer renderer, Class<?> columnClass)
    • initDefaultRenderers

      protected void initDefaultRenderers()
      Installs the default TableCellRenderers for known Ghidra table cell data classes. Subclasses can override this method to add additional types or to change the default associations.
    • createDefaultColumnsFromModel

      public void createDefaultColumnsFromModel()
      Overrides:
      createDefaultColumnsFromModel in class JTable
    • getToolTipText

      public String getToolTipText(MouseEvent e)
      Overrides:
      getToolTipText in class JTable
    • setHTMLRenderingEnabled

      public void setHTMLRenderingEnabled(boolean enable)
      Enables and disables the rendering of HTML content in this table. If enabled, this table will:
      • Wrap tooltip text content with an <html> tag so that it is possible for the content to be formatted in a manner that is easier for the user read, and
      • Enable any default GTableCellRenderer instances to render HTML content, which they do not do by default.

      HTML rendering is disabled by default.

      Parameters:
      enable - true to enable HTML rendering; false to disable it
    • setPreferenceKey

      public void setPreferenceKey(String preferenceKey)
      Sets the key for saving and restoring column configuration state. Use this if you have multiple instances of a table and you want different column settings for each instance.
      Parameters:
      preferenceKey - the unique string to use a key for this instance.
    • getPreferenceKey

      public String getPreferenceKey()
      Returns:
      the preference key
      See Also:
    • savePreferences

      public void savePreferences()
      Signals that the preferences of this table (visible columns, sort order, etc.) should be saved. Most clients never need to call this method, as changes are saved for free when the user manipulates columns. However, sometimes the client can change the state of the columns programmatically, which is not guaranteed to get saved; for example, setting the sort state of a sorted table model programmatically will not get saved.
    • setUserSortingEnabled

      public void setUserSortingEnabled(boolean enabled)
      Allows for the disabling of the user's ability to sort an instance of AbstractSortedTableModel by clicking the table's headers. The default setting is enabled.
      Parameters:
      enabled - true to enable; false to disable
    • setColumnHeaderPopupEnabled

      public void setColumnHeaderPopupEnabled(boolean enabled)
    • isColumnHeaderPopupEnabled

      public boolean isColumnHeaderPopupEnabled()
    • getTableColumnPopupMenu

      public JPopupMenu getTableColumnPopupMenu(int columnIndex)
    • getCellRenderer

      public TableCellRenderer getCellRenderer(int row, int col)
      Overrides:
      getCellRenderer in class JTable
    • getCellRendererOverride

      public final TableCellRenderer getCellRendererOverride(int row, int col)
      Performs custom work to locate renderers for special table model types. This method allows clients to bypass the getCellRenderer(int, int), which is sometimes overridden by subclasses to return a hard-coded renderer. In that case, some clients still want a way to perform normal cell renderer lookup.
      Parameters:
      row - the row
      col - the column
      Returns:
      the cell renderer
    • getHeaderRendererOverride

      public final TableCellRenderer getHeaderRendererOverride(int col)
      Performs custom work to locate header renderers for special table model types. The headers are located and installed at the time the table's model is set.
      Parameters:
      col - the column
      Returns:
      the header cell renderer
    • editCellAt

      public boolean editCellAt(int row, int column, EventObject e)
      If you just begin typing into an editable cell in a JTable, then the cell editor will be displayed. However, the editor component will not have a focus. This method has been overridden to request focus on the editor component.
      Overrides:
      editCellAt in class JTable
      See Also:
    • requestTableEditorFocus

      public void requestTableEditorFocus()
    • scrollToSelectedRow

      public void scrollToSelectedRow()
    • getValueAt

      public Object getValueAt(int row, int column)
      Overrides:
      getValueAt in class JTable
    • supportsPopupActions

      protected boolean supportsPopupActions()
      A method that subclasses can override to signal that they wish not to have this table's built-in popup actions. Subclasses will almost never need to override this method.
      Returns:
      true if popup actions are supported
    • createSharedActions

      public static void createSharedActions(Tool tool, ToolActions toolActions, String owner)