gate.swing
Class XJTable

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 gate.swing.XJTable
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable
Direct Known Subclasses:
FeaturesSchemaEditor, JTreeTable, ResourceParametersEditor

public class XJTable
extends JTable

A "smarter" JTable. Features include:

It uses a custom made model that stands between the table model set by the user and the GUI component. This middle model is responsible for sorting the rows.

See Also:
Serialized Form

Nested Class Summary
protected  class XJTable.ColumnData
           
protected  class XJTable.HeaderMouseListener
           
protected  class XJTable.SortingModel
          Handles translations between an indexed data source and a permutation of itself (like the translations between the rows in sorted table and the rows in the actual unsorted model).
 
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
protected  boolean ascending
          is the current sort order ascending (or descending)?
protected  List<XJTable.ColumnData> columnData
          A list of XJTable.ColumnData objects.
protected  ObjectComparator defaultComparator
           
protected  XJTable.HeaderMouseListener headerMouseListener
           
protected  List<TableColumn> hiddenColumns
          Contains the hidden columns in no particular order.
protected  boolean sortable
          Should this table be sortable.
protected  int sortedColumn
          The column currently being sorted.
protected  XJTable.SortingModel sortingModel
           
 
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
XJTable()
           
XJTable(TableModel model)
           
 
Method Summary
protected  void calculatePreferredSize()
           
 void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
           
 void columnMarginChanged(ChangeEvent e)
          Overridden to fix //http://bugs.sun.com/bugdatabase/view_bug.do?
 void columnMoved(TableColumnModelEvent e)
          Overridden to fix //http://bugs.sun.com/bugdatabase/view_bug.do?
 void doLayout()
           
 Dimension getPreferredScrollableViewportSize()
           
 Dimension getPreferredSize()
           
 boolean getScrollableTracksViewportHeight()
          Track parent viewport's size if it's larger than the current preferred height of the table (causes empty tables to fill in the whole area of a JScrollPane).
 boolean getScrollableTracksViewportWidth()
          Overridden to ignore requests for this table to track the width of its containing viewport in cases where the viewport is narrower than the minimum size of the table.
 int getSortedColumn()
           
 int getTableRow(int modelRow)
          Get the row in the table for a row in the model.
 void hideColumn(int columnIndex)
          Hide a column.
 boolean isAscending()
           
 boolean isColumnHidden(int columnIndex)
          Gets the hidden state for a column
 boolean isEditCellAsSoonAsFocus()
          Returns the state for editing a cell as soon as it gets the focus.
 boolean isEnableHidingColumns()
          Returns the state for hiding a column.
 boolean isSortable()
           
 boolean isTabSkipUneditableCell()
          Returns the state for enabling tab key to skip uneditable cells.
protected  void newColumns()
          Called when the columns have changed.
 int rowAtPoint(Point point)
           
 int rowModelToView(int modelRow)
          Converts a row number from the model co-ordinates system to the view's.
 int rowViewToModel(int viewRow)
          Converts a row number from the view co-ordinates system to the model's.
 void setAscending(boolean ascending)
           
 void setComparator(int column, Comparator comparator)
          Sets the custom comparator to be used for a particular column.
 void setEditCellAsSoonAsFocus(boolean editCellAsSoonAsFocus)
          Set the possibility for a cell to be in editing mode as soon as it gets the focus.
 void setEnableHidingColumns(boolean enableHidingColumns)
          Set the possibility for the user to hide/show a column by right-clicking on a column header.
 void setModel(TableModel dataModel)
           
 void setSortable(boolean sortable)
           
 void setSortedColumn(int sortColumn)
           
 void setTableHeader(JTableHeader newTableHeader)
           
 void setTabSkipUneditableCell(boolean tabSkipUneditableCell)
          Set the possibility for the tab key to skip uneditable cells.
 void showColumn(int columnIndex, int insertionIndex)
          Show a column.
 void tableChanged(TableModelEvent e)
          Overridden for efficiency reasons (provides a better calculation of the dirty region).
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, 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, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, 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, 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

sortingModel

protected XJTable.SortingModel sortingModel

defaultComparator

protected ObjectComparator defaultComparator

sortedColumn

protected int sortedColumn
The column currently being sorted.


ascending

protected boolean ascending
is the current sort order ascending (or descending)?


sortable

protected boolean sortable
Should this table be sortable.


columnData

protected List<XJTable.ColumnData> columnData
A list of XJTable.ColumnData objects.


headerMouseListener

protected XJTable.HeaderMouseListener headerMouseListener

hiddenColumns

protected List<TableColumn> hiddenColumns
Contains the hidden columns in no particular order.

Constructor Detail

XJTable

public XJTable()

XJTable

public XJTable(TableModel model)
Method Detail

setModel

public void setModel(TableModel dataModel)
Overrides:
setModel in class JTable

newColumns

protected void newColumns()
Called when the columns have changed.


setTableHeader

public void setTableHeader(JTableHeader newTableHeader)
Overrides:
setTableHeader in class JTable

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Overrides:
getPreferredScrollableViewportSize in class JTable

calculatePreferredSize

protected void calculatePreferredSize()

doLayout

public void doLayout()
Overrides:
doLayout in class JTable

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Overridden to ignore requests for this table to track the width of its containing viewport in cases where the viewport is narrower than the minimum size of the table. Where the viewport is at least as wide as the minimum size of the table, we will allow the table to resize with the viewport, but when it gets too small we stop tracking, which allows the horizontal scrollbar to appear.

Specified by:
getScrollableTracksViewportWidth in interface Scrollable
Overrides:
getScrollableTracksViewportWidth in class JTable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Track parent viewport's size if it's larger than the current preferred height of the table (causes empty tables to fill in the whole area of a JScrollPane).

Specified by:
getScrollableTracksViewportHeight in interface Scrollable
Overrides:
getScrollableTracksViewportHeight in class JTable
Returns:
true if the preferred height of the table is smaller than the viewport.

rowModelToView

public int rowModelToView(int modelRow)
Converts a row number from the model co-ordinates system to the view's.

Parameters:
modelRow - the row number in the model
Returns:
the corresponding row number in the view.
See Also:
rowViewToModel(int)

isAscending

public boolean isAscending()
Returns:
Returns the ascending.

isColumnHidden

public boolean isColumnHidden(int columnIndex)
Gets the hidden state for a column

Parameters:
columnIndex - index of the column in the table model
Returns:
hidden state for a column

hideColumn

public void hideColumn(int columnIndex)
Hide a column. Do nothing if already hidden.

Parameters:
columnIndex - index of the column in the table model

showColumn

public void showColumn(int columnIndex,
                       int insertionIndex)
Show a column. Do nothing if already shown.

Parameters:
columnIndex - index of the column in the table model
insertionIndex - index of the view where the colum will be inserted

setAscending

public void setAscending(boolean ascending)
Parameters:
ascending - The ascending to set. True by default.

rowViewToModel

public int rowViewToModel(int viewRow)
Converts a row number from the view co-ordinates system to the model's.

Parameters:
viewRow - the row number in the view.
Returns:
the corresponding row number in the model.
See Also:
rowModelToView(int)

setEnableHidingColumns

public void setEnableHidingColumns(boolean enableHidingColumns)
Set the possibility for the user to hide/show a column by right-clicking on a column header. False by default.

Parameters:
enableHidingColumns - true if and only if the columns can be hidden.

isEnableHidingColumns

public boolean isEnableHidingColumns()
Returns the state for hiding a column.

Returns:
true if and only if the columns can be hidden.

isEditCellAsSoonAsFocus

public boolean isEditCellAsSoonAsFocus()
Returns the state for editing a cell as soon as it gets the focus.

Returns:
true if and only if a cell get in editing mode when it receives the focus.

setEditCellAsSoonAsFocus

public void setEditCellAsSoonAsFocus(boolean editCellAsSoonAsFocus)
Set the possibility for a cell to be in editing mode as soon as it gets the focus. False by default.

Parameters:
editCellAsSoonAsFocus - true if and only if a cell get in editing mode when it receives the focus.

isTabSkipUneditableCell

public boolean isTabSkipUneditableCell()
Returns the state for enabling tab key to skip uneditable cells.

Returns:
true if and only if the tab key skip uneditable cells.

setTabSkipUneditableCell

public void setTabSkipUneditableCell(boolean tabSkipUneditableCell)
Set the possibility for the tab key to skip uneditable cells. False by default.

Parameters:
tabSkipUneditableCell - true if and only if the tab key skip uneditable cells.

setComparator

public void setComparator(int column,
                          Comparator comparator)
Sets the custom comparator to be used for a particular column. Columns that don't have a custom comparator will be sorted using the natural order.

Parameters:
column - the column index.
comparator - the comparator to be used.

isSortable

public boolean isSortable()
Returns:
Returns the sortable.

setSortable

public void setSortable(boolean sortable)
Parameters:
sortable - The sortable to set. True by default.

getSortedColumn

public int getSortedColumn()
Returns:
Returns the sortColumn.

setSortedColumn

public void setSortedColumn(int sortColumn)
Parameters:
sortColumn - The sortColumn to set. None (-1) by default.

getTableRow

public int getTableRow(int modelRow)
Get the row in the table for a row in the model.

Parameters:
modelRow - row in the model
Returns:
row in the table view

changeSelection

public void changeSelection(int rowIndex,
                            int columnIndex,
                            boolean toggle,
                            boolean extend)
Overrides:
changeSelection in class JTable

rowAtPoint

public int rowAtPoint(Point point)
Overrides:
rowAtPoint in class JTable

tableChanged

public void tableChanged(TableModelEvent e)
Overridden for efficiency reasons (provides a better calculation of the dirty region). See this page for a more complete discussion.

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

columnMoved

public void columnMoved(TableColumnModelEvent e)
Overridden to fix //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4330950:

Specified by:
columnMoved in interface TableColumnModelListener
Overrides:
columnMoved in class JTable

columnMarginChanged

public void columnMarginChanged(ChangeEvent e)
Overridden to fix //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4330950:

Specified by:
columnMarginChanged in interface TableColumnModelListener
Overrides:
columnMarginChanged in class JTable