Class DataTable

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

public class DataTable extends JTable
DataTable displays multiple TableModels in a table. The first TableModel usually contains the independent variable for the other TableModel so that the visibility of column[0] can be set to false for subsequent TableModels.
Version:
1.0
Author:
Joshua Gould, Wolfgang Christian
See Also:
  • Field Details

  • Constructor Details

    • DataTable

      public DataTable()
      Constructs a DataTable with a default data model
  • Method Details

    • unshiftName

      public static String unshiftName(String name)
      Trim "'" from name
      Parameters:
      name -
      Returns:
    • setModel

      public void setModel(TableModel dataModel)
      Called by JTable's default constructor to install the default table model, which we coerce to be an OSPDataTableModel.
      Overrides:
      setModel in class JTable
    • createTableModel

      protected DataTable.OSPDataTableModel createTableModel()
      Overridden in DataToolTable in order to use its own implementation of OSPDataTableModel
      Returns:
    • addColumnSelectionInterval

      public void addColumnSelectionInterval(int index0, int index1)
      Overrides:
      addColumnSelectionInterval in class JTable
    • init

      protected void init()
    • updateRowSelection

      protected void updateRowSelection(int firstIndex, boolean isAdjusting)
      Overridden in DataToolTable
      Parameters:
      firstIndex -
      isAdjusting -
    • addColumn

      public void addColumn(TableColumn c)
      Overrides:
      addColumn in class JTable
    • convertColumnIndexToModel

      public int convertColumnIndexToModel(int viewIndex)
      Overrides:
      convertColumnIndexToModel in class JTable
    • setMaximumFractionDigits

      public void setMaximumFractionDigits(String columnName, int maximumFractionDigits)
      Sets the maximum number of fraction digits to display in a named column
      Parameters:
      maximumFractionDigits - maximum number of fraction digits to display
      columnName - name of the column
    • setFormatPattern

      public void setFormatPattern(String columnName, String pattern)
      Sets the formatting pattern for a named column
      Parameters:
      pattern - the pattern
      columnName - name of the column
    • setUnits

      public void setUnits(String columnName, String units, String tooltip)
      Sets the units and tooltip for a named column.
      Parameters:
      columnName - name of the column
      units - the units string (may be null)
      tootip - the tooltip (may be null)
    • getFormatPattern

      public String getFormatPattern(String columnName)
      Gets the formatting pattern for a named column
      Parameters:
      columnName - name of the column
      Returns:
      the pattern
    • getFormattedColumnNames

      public String[] getFormattedColumnNames()
      Gets the names of formatted columns Added by D Brown 24 Apr 2011
      Returns:
      array of names of columns with non-null formats
    • getFormattedValueAt

      public Object getFormattedValueAt(int row, int col)
      Gets the formatted value at a given row and column. Added by D Brown 6 Oct 2010
      Parameters:
      row - the row number
      col - the column number
      Returns:
      the value formatted as displayed in the table
    • getFormatDialog

      public DataTable.NumberFormatDialog getFormatDialog(String[] names, String[] selected)
      Gets the format setter dialog.
      Parameters:
      names - the column name choices
      selected - the initially selected names
      Returns:
      the format setter dialog
    • setMaximumFractionDigits

      public void setMaximumFractionDigits(int maximumFractionDigits)
      Sets the maximum number of fraction digits to display for cells that have type Double
      Parameters:
      maximumFractionDigits - - maximum number of fraction digits to display
    • getMaximumFractionDigits

      public int getMaximumFractionDigits()
      Gets the maximum number of digits in the table.
      Returns:
      int
    • getMinimumTableWidth

      public int getMinimumTableWidth()
      Returns the minimum table width.
      Returns:
      minimum table width.
    • setLabelColumnWidth

      public void setLabelColumnWidth(int w)
      Sets the label column width
      Parameters:
      w - the width
    • resizeAndRepaint

      public void resizeAndRepaint()
      Overrides:
      resizeAndRepaint in class JTable
    • setRowNumberVisible

      public void setRowNumberVisible(boolean b)
      Sets the display row number flag. Table displays row number.
      Parameters:
      b - true<\code> if table display row number
    • setColumnVisible

      public void setColumnVisible(TableModel model, int columnIndex, boolean b)
      Sets the visibility of a column of a TableModel in the DataTable.
      Parameters:
      model - an OSPTableModel, actually
      columnIndex -
      b -
    • refreshColumnModel

      public void refreshColumnModel()
      Reset bsColVis for all elements.
    • isRowNumberVisible

      public boolean isRowNumberVisible()
      Gets the display row number flag.
      Returns:
      The rowNumberVisible value
    • getCellRenderer

      public TableCellRenderer getCellRenderer(int row, int column)
      Returns an appropriate renderer for the cell specified by this row and column. If the TableColumn for this column has a non-null renderer, returns that. If the TableColumn for this column has the same name as a name specified in the setMaximumFractionDigits method, returns the appropriate renderer. If not, finds the class of the data in this column (using getColumnClass) and returns the default renderer for this type of data.
      Overrides:
      getCellRenderer in class JTable
      Parameters:
      row - Description of Parameter
      column - Description of Parameter
      Returns:
      The cellRenderer value
    • getPrecisionRenderer

      public TableCellRenderer getPrecisionRenderer(String columnName)
      Gets the precision renderer, if any, for a given columnn name. Added by D Brown Dec 2010
      Parameters:
      columnName - the name
      Returns:
      the PrecisionRenderer, or null if none
    • setRefreshDelay

      public void setRefreshDelay(int delay)
      Deprecated.
      Sets the delay time for table refresh timer. Only called by TableTrackView dispose
      Parameters:
      delay - the delay in millisecond
    • dispose

      public void dispose()
      Clear the table and stop refreshing. Only called by TableTrackView dispose.
      Parameters:
      delay - the delay in millisecond
    • refreshTable

      public void refreshTable()
    • refreshTable

      public void refreshTable(int mode)
      Refresh the data in the DataTable, as well as other changes to the table, such as row number visibility. Changes to the TableModels displayed in the table will not be visible until this method is called.
    • refreshTableNow

      protected void refreshTableNow(int mode)
      Performs the action for the refresh timer and refreshTable() method by refreshing the data in the DataTable.
      Parameters:
      cause - allows more nuanced refresh
    • add

      public void add(TableModel tableModel)
      Add a TableModel object to the table model list.
      Parameters:
      tableModel -
    • remove

      public void remove(TableModel tableModel)
      Remove a TableModel object from the table model list.
      Parameters:
      tableModel -
    • clear

      public void clear()
      Remove all TableModels from the table model list.
    • sort

      public void sort(int col)
    • setModelColumnOrder

      public void setModelColumnOrder(int[] modelColumns)
      from DataToolTable Sets the model column order -- for DataToolTab Loader only
      Parameters:
      modelColumns - array of model column numbers in view column order
    • getModelColumnOrder

      public int[] getModelColumnOrder()
      Gets the model column order. -- for DataToolTab Loader
      Returns:
      array of model column numbers in view column order
    • createDefaultColumnsFromModel

      @Deprecated public void createDefaultColumnsFromModel()
      Deprecated.
      This method, called by Jtable.tableChanged(TableModelEvent), is never called, because we have set autoCreateColumnsFromModel false. All updating is handled exclusively by DataTableColumnModel.updateColumnModel().
      Overrides:
      createDefaultColumnsFromModel in class JTable
    • getSortedRow

      public int getSortedRow(int i)
    • resetSort

      public void resetSort()
    • getRowCount

      public int getRowCount()
      Overrides:
      getRowCount in class JTable
    • refreshTable

      protected void refreshTable(int mode, boolean resortAndReselect)
    • selectTableRowsBS

      public void selectTableRowsBS(BitSet rows, int nRows)
      A standard method using BitSet blocks; reduces the number of calls to addRowSelectionInterval.
      Parameters:
      rows -
      nRows -
    • selectTableColsBS

      public void selectTableColsBS(BitSet cols)
      A standard method using BitSet blocks; reduces the number of calls to addColumnSelectionInterval.
      Parameters:
      cols -
    • setSelectedColumnsFromModelBS

      public void setSelectedColumnsFromModelBS()
    • updateColumnModel

      public void updateColumnModel()
    • getSelectedModelRows

      protected int[] getSelectedModelRows()
      Gets the selected model rows in ascending order.
      Returns:
      the selected rows
    • getViewRow

      protected int getViewRow(int modelRow)
      Converts a model row index (i.e., displayed in the "row" column) to the corresponding table row number.
      Parameters:
      modelRow - the table row
      Returns:
      the model row
    • selectModelRows

      public void selectModelRows(int[] modelRows)
      Sets the selected model rows.
      Parameters:
      modelRows - the model rows to select
    • selectModelRowsBS

      public void selectModelRowsBS(BitSet rows)
    • haveSelectedRows

      protected boolean haveSelectedRows()
    • getSelectedModelRowsBS

      public BitSet getSelectedModelRowsBS()
    • setSelectedModelRowsBS

      public void setSelectedModelRowsBS(BitSet rows)
    • getModelRow

      protected int getModelRow(int i)
    • scrollRowToVisible

      public void scrollRowToVisible(int row)
    • scrollColumnToVisible

      public void scrollColumnToVisible(int col)
    • getData

      public StringBuffer getData(boolean asFormatted)
      Gets the data selected by the user in this datatable. This method is modified from the org.opensourcephysics.display.DataTableFrame getSelectedData method.
      Parameters:
      asFormatted - true to retain table formatting
      Returns:
      a StringBuffer containing the data.
    • copyTable

      public void copyTable(boolean asFormatted, String header)
      Copies data from this table to the system clipboard.
      Parameters:
      asFormatted - true to retain table formatting
      header - the table header
    • findLastAddedModelIndex

      protected int findLastAddedModelIndex(StringBuffer names)
      subclass should return the modelIndex of the first column name (comma-quoted key) not found in names and, if that exists, add that key to name in case this needs to be run more than once.
      Parameters:
      names - a simple comma-quoted listing of known column names
      Returns:
      the modelIndex and append to names the new comma-quoted name found