edu.umd.cfar.lamp.apploader.misc
Class EnhancedTable

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JTable
                  extended byedu.umd.cfar.lamp.apploader.misc.EnhancedTable
All Implemented Interfaces:
javax.accessibility.Accessible, javax.swing.event.CellEditorListener, java.util.EventListener, java.awt.image.ImageObserver, ListenableTable, javax.swing.event.ListSelectionListener, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener

public class EnhancedTable
extends javax.swing.JTable
implements ListenableTable

Provides a JTable with some higher-level functionality than the standard Swing version. This includes listeners for each cell (instead of having to add a mouse listener and then check what cell it is over).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
EnhancedTable()
          Create a new, empty table.
EnhancedTable(int numRows, int numColumns)
          Create a new table with the given number of columns and rows.
EnhancedTable(java.lang.Object[][] rowData, java.lang.Object[] columnNames)
          Creates a new table using the default table model cell renderers, using the given array to populate the model.
EnhancedTable(javax.swing.table.TableModel dm)
          Creates a new table from the given table model.
EnhancedTable(javax.swing.table.TableModel dm, javax.swing.table.TableColumnModel cm)
          Create a new table with the given data model and title data model.
EnhancedTable(javax.swing.table.TableModel dm, javax.swing.table.TableColumnModel cm, javax.swing.ListSelectionModel sm)
          Create a new table with the given table data, column, and selection models.
EnhancedTable(java.util.Vector rowData, java.util.Vector columnNames)
          Creates a new default table model for a new table using the given vector-of-vectors for the data and the vector-of-titles for the titles.
 
Method Summary
 void addComponentListener(java.awt.event.ComponentListener l)
          This is a total hack to handle scroll panes.
 void addTableListener(TableListener tl)
          Add a TableListener
 void doLayout()
           
 java.awt.Color getCellSelectionBackground()
           
 java.awt.Color getCellSelectionForeground()
           
 java.lang.String getColumnWidthDescription()
          Gets the description of the current set of widths, and how they were set.
 int getMinimumNaturalColumnWidth()
          Gets the minimum width that each column will be allowed to auto-resize to.
 TableListener[] getTableListeners()
          Gets all table listeners attached to the table.
 void removeComponentListener(java.awt.event.ComponentListener l)
           
 void removeTableListener(TableListener tl)
          Removes the given table listener, if it is among the ones attached.
 void resizeAllColumnsToNaturalWidth()
          Resizes all columns to the preferred width of their contents.
 void resizeAllRowsToNaturalHeight()
          Set the row heights to the maximum preferred height of each row.
 void resizeColumnToNaturalWidth(int col)
          Resizes the given column to the maximum preferred width of its cells.
 void resizeRowToNaturalHeight(int row)
          Resizes the given row to the maximum preferred height of its contents.
 void setCellSelectionBackground(java.awt.Color cellSelectionBackground)
           
 void setCellSelectionForeground(java.awt.Color cellSelectionForeground)
           
 void setColumnWidthsFromDescription(java.lang.String description)
          Deserialize the column widths.
 void setMinimumNaturalColumnWidth(int i)
          Sets the minimum allowed width for auto-resize.
 void setRowHeightToMaximumPreferredHeight()
          Sets the row heights to be the maximum preferred height of all cells.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setValueAt, sizeColumnsToFit, sizeColumnsToFit, tableChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Constructor Detail

EnhancedTable

public EnhancedTable()
Create a new, empty table.


EnhancedTable

public EnhancedTable(int numRows,
                     int numColumns)
Create a new table with the given number of columns and rows.

Parameters:
numRows - The height of the table (in cells)
numColumns - The width of the table (in cells)

EnhancedTable

public EnhancedTable(javax.swing.table.TableModel dm)
Creates a new table from the given table model.

Parameters:
dm - The data model

EnhancedTable

public EnhancedTable(java.lang.Object[][] rowData,
                     java.lang.Object[] columnNames)
Creates a new table using the default table model cell renderers, using the given array to populate the model.

Parameters:
rowData - The data items
columnNames - The titles for the columns

EnhancedTable

public EnhancedTable(java.util.Vector rowData,
                     java.util.Vector columnNames)
Creates a new default table model for a new table using the given vector-of-vectors for the data and the vector-of-titles for the titles.

Parameters:
rowData - The data, rowwise.
columnNames - The names for each column

EnhancedTable

public EnhancedTable(javax.swing.table.TableModel dm,
                     javax.swing.table.TableColumnModel cm)
Create a new table with the given data model and title data model.

Parameters:
dm - The data model for the table.
cm - The model for the columns

EnhancedTable

public EnhancedTable(javax.swing.table.TableModel dm,
                     javax.swing.table.TableColumnModel cm,
                     javax.swing.ListSelectionModel sm)
Create a new table with the given table data, column, and selection models.

Parameters:
dm - The data model
cm - The column model
sm - The selection model
Method Detail

addTableListener

public void addTableListener(TableListener tl)
Add a TableListener

Specified by:
addTableListener in interface ListenableTable
Parameters:
tl - the new listener to add.

getTableListeners

public TableListener[] getTableListeners()
Gets all table listeners attached to the table.

Specified by:
getTableListeners in interface ListenableTable
Returns:
Array of the listeners

removeTableListener

public void removeTableListener(TableListener tl)
Removes the given table listener, if it is among the ones attached.

Specified by:
removeTableListener in interface ListenableTable
Parameters:
tl - The listener to remove.

resizeAllColumnsToNaturalWidth

public void resizeAllColumnsToNaturalWidth()
Resizes all columns to the preferred width of their contents. This involves enumerating all cells in the table and checking their preferred sizes.


setRowHeightToMaximumPreferredHeight

public void setRowHeightToMaximumPreferredHeight()
Sets the row heights to be the maximum preferred height of all cells. This involves enumerating all cells in the table and checking their preferred sizes.


resizeAllRowsToNaturalHeight

public void resizeAllRowsToNaturalHeight()
Set the row heights to the maximum preferred height of each row. This may result in heterogenous row sizes, which may seem odd. For homogenous row resizing, use setRowHeightToMaximumPreferredHeight(). This involves enumerating all cells in the table and checking their preferred sizes.


resizeColumnToNaturalWidth

public void resizeColumnToNaturalWidth(int col)
Resizes the given column to the maximum preferred width of its cells.

Parameters:
col - the column to resize

resizeRowToNaturalHeight

public void resizeRowToNaturalHeight(int row)
Resizes the given row to the maximum preferred height of its contents.

Parameters:
row - the row to resize

getMinimumNaturalColumnWidth

public int getMinimumNaturalColumnWidth()
Gets the minimum width that each column will be allowed to auto-resize to.

Returns:
the minimum width auto-resize allows

setMinimumNaturalColumnWidth

public void setMinimumNaturalColumnWidth(int i)
Sets the minimum allowed width for auto-resize. Note that this only takes effect when resizeColumnToNaturalWidth is invoked.

Parameters:
i - the new minimum allowed width

getColumnWidthDescription

public java.lang.String getColumnWidthDescription()
Gets the description of the current set of widths, and how they were set. This is useful for serializing the current state.

Returns:
the widths of the columns

setColumnWidthsFromDescription

public void setColumnWidthsFromDescription(java.lang.String description)
Deserialize the column widths.

Parameters:
description - the widths

addComponentListener

public void addComponentListener(java.awt.event.ComponentListener l)
This is a total hack to handle scroll panes.

See Also:
Component.addComponentListener(java.awt.event.ComponentListener)

removeComponentListener

public void removeComponentListener(java.awt.event.ComponentListener l)
See Also:
Component.removeComponentListener(java.awt.event.ComponentListener)

doLayout

public void doLayout()
See Also:
JTable.doLayout()

getCellSelectionBackground

public java.awt.Color getCellSelectionBackground()
Returns:
Returns the cellSelectionBackground.

setCellSelectionBackground

public void setCellSelectionBackground(java.awt.Color cellSelectionBackground)
Parameters:
cellSelectionBackground - The cellSelectionBackground to set.

getCellSelectionForeground

public java.awt.Color getCellSelectionForeground()
Returns:
Returns the cellSelectionForeground.

setCellSelectionForeground

public void setCellSelectionForeground(java.awt.Color cellSelectionForeground)
Parameters:
cellSelectionForeground - The cellSelectionForeground to set.