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
protected static class DataTable.DefaultDataTableModel
           
 class DataTable.NumberFormatDialog
           
protected static class DataTable.RowNumberRenderer
           
 
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable, 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.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  SortDecorator decorator
           
protected  DataTable.NumberFormatDialog formatDialog
           
protected  int labelColumnWidth
           
protected  java.util.HashMap<java.lang.String,org.opensourcephysics.display.DataTable.PrecisionRenderer> renderersByColumnName
           
static java.lang.String rowName
           
protected  DataTable.RowNumberRenderer rowNumberRenderer
           
 
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, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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.util.ArrayList<java.lang.String> names, java.lang.String selected)
          Gets the format setter for a named column
 java.lang.String getFormatPattern(java.lang.String columnName)
          Gets the formatting pattern for a named column
 int getMaximumFractionDigits()
          Gets the maximum number of digits in the table.
 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 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, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, 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, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, 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, unconfigureEnclosingScrollPane, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rowName

public static java.lang.String rowName

decorator

protected final SortDecorator decorator

renderersByColumnName

protected java.util.HashMap<java.lang.String,org.opensourcephysics.display.DataTable.PrecisionRenderer> renderersByColumnName

rowNumberRenderer

protected DataTable.RowNumberRenderer rowNumberRenderer

labelColumnWidth

protected int labelColumnWidth

formatDialog

protected DataTable.NumberFormatDialog formatDialog
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

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

getFormatDialog

public DataTable.NumberFormatDialog getFormatDialog(java.util.ArrayList<java.lang.String> names,
                                                    java.lang.String selected)
Gets the format setter for a named column

Parameters:
columnName - name of the column
Returns:
the format setter dialog

sort

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

Parameters:
col - int

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

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.