org.opensourcephysics.display
Class DataTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by org.opensourcephysics.display.DataTable
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CellEditorListener, javax.swing.event.ListSelectionListener, javax.swing.event.RowSorterListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable
Direct Known Subclasses:
DataToolTable

public class DataTable
extends javax.swing.JTable
implements java.awt.event.ActionListener

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:
Serialized Form

Nested Class Summary
 class DataTable.NumberFormatDialog
           
 
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.DropLocation, javax.swing.JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static java.lang.String rowName
           
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DataTable()
          Constructs a DatTable with a default data model
DataTable(DataTableModel model)
          Constructs a DatTable with the specified data model
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          Performs the action for the refresh timer by refreshing the data in the DataTable.
 void add(javax.swing.table.TableModel tableModel)
          Add a TableModel object to the table model list.
 void clear()
          Remove all TableModels from the table model list.
 javax.swing.table.TableCellRenderer getCellRenderer(int row, int column)
          Returns an appropriate renderer for the cell specified by this row and column.
 DataTable.NumberFormatDialog getFormatDialog(java.lang.String[] names, java.lang.String[] selected)
          Gets the format setter dialog.
 java.lang.String getFormatPattern(java.lang.String columnName)
          Gets the formatting pattern for a named column
 java.lang.String[] getFormattedColumnNames()
          Gets the names of formatted columns Added by D Brown 24 Apr 2011
 java.lang.Object getFormattedValueAt(int row, int col)
          Gets the formatted value at a given row and column.
 int getMaximumFractionDigits()
          Gets the maximum number of digits in the table.
 javax.swing.table.TableCellRenderer getPrecisionRenderer(java.lang.String columnName)
          Gets the precision renderer, if any, for a given columnn name.
 int getSortedColumn()
          Gets the sorted column.
 boolean isRowNumberVisible()
          Gets the display row number flag.
 void refreshTable()
          Refresh the data in the DataTable, as well as other changes to the table, such as row number visibility.
 void remove(javax.swing.table.TableModel tableModel)
          Remove a TableModel object from the table model list.
 void setColumnVisible(javax.swing.table.TableModel tableModel, int columnIndex, boolean b)
          Sets the visibility of a column of a TableModel in the DataTable.
 void setFormatPattern(java.lang.String columnName, java.lang.String pattern)
          Sets the formatting pattern for a named column
 void setMaximumFractionDigits(int maximumFractionDigits)
          Sets the maximum number of fraction digits to display for cells that have type Double
 void setMaximumFractionDigits(java.lang.String columnName, int maximumFractionDigits)
          Sets the maximum number of fraction digits to display in a named column
 void setModel(DataTableModel _model)
          Sets the model for this data table;
 void setRefreshDelay(int delay)
          Sets the delay time for table refresh timer.
 void setRowNumberVisible(boolean _rowNumberVisible)
          Sets the display row number flag.
 void setStride(javax.swing.table.TableModel tableModel, int stride)
          Sets the stride of a TableModel in the DataTable.
 void setUnits(java.lang.String columnName, java.lang.String units, java.lang.String tooltip)
          Sets the units and tooltip for a named column.
 void sort(int col)
          Sorts the table using the given column.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnsFromModel, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, prepareEditor, prepareRenderer, print, print, print, print, print, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, tableChanged, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rowName

public static java.lang.String rowName
Constructor Detail

DataTable

public DataTable()
Constructs a DatTable with a default data model


DataTable

public DataTable(DataTableModel model)
Constructs a DatTable with the specified data model

Parameters:
model - data model
Method Detail

setMaximumFractionDigits

public void setMaximumFractionDigits(java.lang.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(java.lang.String columnName,
                             java.lang.String pattern)
Sets the formatting pattern for a named column

Parameters:
pattern - the pattern
columnName - name of the column

setUnits

public void setUnits(java.lang.String columnName,
                     java.lang.String units,
                     java.lang.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 java.lang.String getFormatPattern(java.lang.String columnName)
Gets the formatting pattern for a named column

Parameters:
columnName - name of the column
Returns:
the pattern

getFormattedColumnNames

public java.lang.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 java.lang.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(java.lang.String[] names,
                                                    java.lang.String[] selected)
Gets the format setter dialog.

Parameters:
names - the column name choices
selected - the initially selected names
Returns:
the format setter dialog

sort

public void sort(int col)
Sorts the table using the given column.

Parameters:
col - int

getSortedColumn

public int getSortedColumn()
Gets the sorted column. Added by D Brown 2010-10-24.

Returns:
the

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

setRowNumberVisible

public void setRowNumberVisible(boolean _rowNumberVisible)
Sets the display row number flag. Table displays row number.

Parameters:
_rowNumberVisible - true<\code> if table display row number

setModel

public void setModel(DataTableModel _model)
Sets the model for this data table;

Parameters:
_model -

setStride

public void setStride(javax.swing.table.TableModel tableModel,
                      int stride)
Sets the stride of a TableModel in the DataTable.

Parameters:
tableModel -
stride -

setColumnVisible

public void setColumnVisible(javax.swing.table.TableModel tableModel,
                             int columnIndex,
                             boolean b)
Sets the visibility of a column of a TableModel in the DataTable.

Parameters:
tableModel -
columnIndex -
b -

isRowNumberVisible

public boolean isRowNumberVisible()
Gets the display row number flag.

Returns:
The rowNumberVisible value

getCellRenderer

public javax.swing.table.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 javax.swing.JTable
Parameters:
row - Description of Parameter
column - Description of Parameter
Returns:
The cellRenderer value

getPrecisionRenderer

public javax.swing.table.TableCellRenderer getPrecisionRenderer(java.lang.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)
Sets the delay time for table refresh timer.

Parameters:
delay - the delay in millisecond

refreshTable

public void refreshTable()
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.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Performs the action for the refresh timer by refreshing the data in the DataTable.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
evt -

add

public void add(javax.swing.table.TableModel tableModel)
Add a TableModel object to the table model list.

Parameters:
tableModel -

remove

public void remove(javax.swing.table.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.