dsto.dfc.swing.table
Class DfcTable

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 dsto.dfc.swing.table.DfcTable
All Implemented Interfaces:
CommandSource, CnpProvider, DragComponent, DragDropComponent, DropComponent, SelectionEventSource, PropertyEventSource, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable
Direct Known Subclasses:
LogMessageTable, MapTableView, StyleSheetTableView

public class DfcTable
extends JTable
implements PropertyEventSource, SelectionEventSource, CommandSource, CnpProvider, ListSelectionListener, DragDropComponent

DFC extended table component.

Version:
$Revision$
See Also:
Serialized Form

Nested Class Summary
protected static class DfcTable.RectSelection
          Represents a selection of rows, columns or a rectangular selection of cells.
 
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, 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
DfcTable()
           
DfcTable(TableModel model)
           
 
Method Summary
 void addSelectionListener(SelectionListener l)
           
 void cancelEditing()
           
 Transferable cnpCopy()
          Perform copy operation.
 Transferable cnpCut()
          Perform cut operation.
 boolean cnpPaste(Transferable transferable)
          Perform paste operation.
 void enableDragAndDrop()
           
 void enableEditCellsByClass(TableColumn column)
          Enable cell editor selection by class of value in cells of a column rather than by getColumnClass () of model.
 void enableRenderCellsByClass(TableColumn column)
          Enable cell renderer selection by class of value in cells of a column rather than by getColumnClass () of model.
 void endDrag(DragSourceDropEvent e, boolean moveData)
           
 void executeDrop(DropTargetDropEvent e)
          Execute a drop action.
 TableCellEditor getCellEditor(int row, int col)
          Override JTable's getCellEditor ().
 TableCellRenderer getCellRenderer(int row, int col)
           
 boolean getCnpCommandsEnabled()
           
 CommandView getCommandView(String viewName)
          Get the command view instance for a given view name.
 TableCellEditor getDefaultEditor(Class valueClass)
          Override JTable getDefaultEditor () to provide editor mapping via interface as well as by class.
 DfcTableModel getDfcTableModel()
           
protected  DfcTable.RectSelection getRectSelection()
          Compute a rectangular selection from the current row and column selection models and the selection mode settings for the table.
 int getSupportedDragActions()
          Return a mask of possible drag actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE.
 int getSupportedDropActions()
          Return a mask of actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE.
 void hideDragUnderFeedback()
          Remove any drag under feedback displayed by showDragUnderFeedback ().
 boolean isCnpCopyEnabled()
          True if a copy operation is possible.
 boolean isCnpCutEnabled()
          True if a cut operation is possible.
 boolean isCnpPasteEnabled(Transferable transferable)
          True if a paste operation with a given transferable is possible.
 boolean isDragOK(DragGestureEvent e)
          Return true if starting a drag in the given context is possible.
 boolean isDropOK(DropTargetDragEvent e)
          Return true if a drop in the context in a DropTargetDragEvent is possible.
 void removeSelectionListener(SelectionListener l)
           
 void scrollToBottom()
          Ensure bottom part of table is visible.
 void scrollToRow(int row)
          Ensure a given row is visible.
 void scrollToTop()
          Ensure top part of table is visible.
 void setCnpCommandsEnabled(boolean newValue)
           
 void setDefaultEditor(Class valueClass, TableCellEditor editor)
          Override JTable setDefaultEditor () to store interfaces in a separate table.
 void showDragUnderFeedback(boolean dropOK, DropTargetDragEvent e)
          Display any drag under (ie displayed under the mouse in the component) feedback.
 void sizeColumnsToFit()
          Size all columns to best fit.
 int sizeColumnToFit(TableColumn column)
          Auto size a column to the smallest width required to display all items, including the header.
 Transferable startDrag(DragGestureEvent e)
          Start a drag operation.
 void stopEditing()
           
 void tableChanged(TableModelEvent e)
          TableModelListener interface implementation only: do not invoke directly.
protected  void updateCnpEnabled()
          Update the settings of the cnpCopyEnabled and cnpCutEnabled properties.
 void valueChanged(ListSelectionEvent e)
          Override of JTable's ListSelectionModelListener interface implementation.
 
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, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, 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, 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, unconfigureEnclosingScrollPane, updateUI
 
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
 
Methods inherited from interface dsto.dfc.util.PropertyEventSource
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

DfcTable

public DfcTable()

DfcTable

public DfcTable(TableModel model)
Method Detail

enableDragAndDrop

public void enableDragAndDrop()

getDfcTableModel

public DfcTableModel getDfcTableModel()

cancelEditing

public void cancelEditing()

stopEditing

public void stopEditing()

sizeColumnsToFit

public void sizeColumnsToFit()
Size all columns to best fit. When auto resize is on, last column is not resized.

See Also:
sizeColumnToFit(javax.swing.table.TableColumn)

sizeColumnToFit

public int sizeColumnToFit(TableColumn column)
Auto size a column to the smallest width required to display all items, including the header.

Parameters:
column - The column to resize.
Returns:
The new size of the column.
See Also:
sizeColumnsToFit(), Tables.getBestColumnSize(javax.swing.JTable, javax.swing.table.TableColumn)

setCnpCommandsEnabled

public void setCnpCommandsEnabled(boolean newValue)

getCnpCommandsEnabled

public boolean getCnpCommandsEnabled()

enableRenderCellsByClass

public void enableRenderCellsByClass(TableColumn column)
Enable cell renderer selection by class of value in cells of a column rather than by getColumnClass () of model.


enableEditCellsByClass

public void enableEditCellsByClass(TableColumn column)
Enable cell editor selection by class of value in cells of a column rather than by getColumnClass () of model.


getCellEditor

public TableCellEditor getCellEditor(int row,
                                     int col)
Override JTable's getCellEditor ().

Overrides:
getCellEditor in class JTable

getCellRenderer

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

getDefaultEditor

public TableCellEditor getDefaultEditor(Class valueClass)
Override JTable getDefaultEditor () to provide editor mapping via interface as well as by class.

Overrides:
getDefaultEditor in class JTable

setDefaultEditor

public void setDefaultEditor(Class valueClass,
                             TableCellEditor editor)
Override JTable setDefaultEditor () to store interfaces in a separate table.

Overrides:
setDefaultEditor in class JTable
See Also:
getDefaultEditor(java.lang.Class)

scrollToRow

public void scrollToRow(int row)
Ensure a given row is visible.


scrollToBottom

public void scrollToBottom()
Ensure bottom part of table is visible.


scrollToTop

public void scrollToTop()
Ensure top part of table is visible.


addSelectionListener

public void addSelectionListener(SelectionListener l)
Specified by:
addSelectionListener in interface SelectionEventSource

removeSelectionListener

public void removeSelectionListener(SelectionListener l)
Specified by:
removeSelectionListener in interface SelectionEventSource

getCommandView

public CommandView getCommandView(String viewName)
Description copied from interface: CommandSource
Get the command view instance for a given view name.

Specified by:
getCommandView in interface CommandSource
Parameters:
viewName - The name of the view to be retrieved. Usually one of CommandView.MAIN_MENU_VIEW, CommandView.CONTEXT_MENU_VIEW or CommandView.TOOLBAR_VIEW, but custom views may be supported also.
Returns:
The command view instance or null if view is not defined.

isCnpCopyEnabled

public boolean isCnpCopyEnabled()
Description copied from interface: CnpProvider
True if a copy operation is possible. Implementors of this method who also implement PropertyEventSource are assumed to provide property change notification.

Specified by:
isCnpCopyEnabled in interface CnpProvider

isCnpCutEnabled

public boolean isCnpCutEnabled()
Description copied from interface: CnpProvider
True if a cut operation is possible. Implementors of this method who also implement PropertyEventSource are assumed to provide property change notification.

Specified by:
isCnpCutEnabled in interface CnpProvider

isCnpPasteEnabled

public boolean isCnpPasteEnabled(Transferable transferable)
Description copied from interface: CnpProvider
True if a paste operation with a given transferable is possible.

Specified by:
isCnpPasteEnabled in interface CnpProvider

cnpCopy

public Transferable cnpCopy()
                     throws UnsupportedOperationException,
                            CloneNotSupportedException
Description copied from interface: CnpProvider
Perform copy operation.

Specified by:
cnpCopy in interface CnpProvider
Returns:
Copied transferable or null if nothing is available to be copied (eg because there is nothing selected)
Throws:
UnsupportedOperationException - if copy operation not supported.
CloneNotSupportedException - if the data could not be cloned.

cnpCut

public Transferable cnpCut()
                    throws UnsupportedOperationException,
                           CloneNotSupportedException
Description copied from interface: CnpProvider
Perform cut operation.

Specified by:
cnpCut in interface CnpProvider
Returns:
Cut transferable or null if nothing is available to be cut (eg because there is nothing selected)
Throws:
UnsupportedOperationException - if cut operation not supported.
CloneNotSupportedException - if the data could not be cloned.

cnpPaste

public boolean cnpPaste(Transferable transferable)
                 throws UnsupportedOperationException,
                        UnsupportedFlavorException,
                        CloneNotSupportedException,
                        IOException
Description copied from interface: CnpProvider
Perform paste operation.

Specified by:
cnpPaste in interface CnpProvider
Parameters:
transferable - The data to be pasted.
Returns:
True is transferable was pasted, false if not (eg because there is no selection to define where pasted item goes).
Throws:
UnsupportedOperationException - if paste operation not supported.
UnsupportedFlavorException - if transferable does not contain a supported data flavor for pasting.
CloneNotSupportedException - if the data could not be cloned.
IOException - if IO exception occurs during data transfer.

getSupportedDragActions

public int getSupportedDragActions()
Description copied from interface: DragComponent
Return a mask of possible drag actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE. Note that the component may veto any particular drag attempt from DragComponent.isDragOK(java.awt.dnd.DragGestureEvent).

Specified by:
getSupportedDragActions in interface DragComponent

isDragOK

public boolean isDragOK(DragGestureEvent e)
Description copied from interface: DragComponent
Return true if starting a drag in the given context is possible.

Specified by:
isDragOK in interface DragComponent
Parameters:
e - The drag context.

startDrag

public Transferable startDrag(DragGestureEvent e)
Description copied from interface: DragComponent
Start a drag operation.

Specified by:
startDrag in interface DragComponent
Parameters:
e - The gesture that started the drag.
Returns:
The transferable data, or null if no data available.

endDrag

public void endDrag(DragSourceDropEvent e,
                    boolean moveData)
Specified by:
endDrag in interface DragComponent

executeDrop

public void executeDrop(DropTargetDropEvent e)
Description copied from interface: DropComponent
Execute a drop action.

Specified by:
executeDrop in interface DropComponent

getSupportedDropActions

public int getSupportedDropActions()
Description copied from interface: DropComponent
Return a mask of actions supported by this component eg DnDConstants.ACTION_COPY_OR_MOVE. Note that the component may veto any particular drop attempt from DropComponent.isDropOK(java.awt.dnd.DropTargetDragEvent).

Specified by:
getSupportedDropActions in interface DropComponent

isDropOK

public boolean isDropOK(DropTargetDragEvent e)
Description copied from interface: DropComponent
Return true if a drop in the context in a DropTargetDragEvent is possible.

Specified by:
isDropOK in interface DropComponent
Parameters:
e - The drop context.

showDragUnderFeedback

public void showDragUnderFeedback(boolean dropOK,
                                  DropTargetDragEvent e)
Description copied from interface: DropComponent
Display any drag under (ie displayed under the mouse in the component) feedback.

Specified by:
showDragUnderFeedback in interface DropComponent
Parameters:
dropOK - The value of isDropOK () when the mouse first entered the component.
e - The drop context.

hideDragUnderFeedback

public void hideDragUnderFeedback()
Description copied from interface: DropComponent
Remove any drag under feedback displayed by showDragUnderFeedback ().

Specified by:
hideDragUnderFeedback in interface DropComponent

valueChanged

public void valueChanged(ListSelectionEvent e)
Override of JTable's ListSelectionModelListener interface implementation. (do not invoke directly).

Specified by:
valueChanged in interface ListSelectionListener
Overrides:
valueChanged in class JTable
To do:
This is a bit dodgy: we are relying on JTable registering itself as a listener to both row and column selection models.

tableChanged

public void tableChanged(TableModelEvent e)
TableModelListener interface implementation only: do not invoke directly.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class JTable

updateCnpEnabled

protected final void updateCnpEnabled()
Update the settings of the cnpCopyEnabled and cnpCutEnabled properties.


getRectSelection

protected final DfcTable.RectSelection getRectSelection()
Compute a rectangular selection from the current row and column selection models and the selection mode settings for the table.



Copyright © 2008 Commonwealth of Australia