Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.table
Class GroupTableHeader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.table.JTableHeader
                  extended by com.sciapp.table.AdvancedTableHeader
                      extended by com.sciapp.table.GroupTableHeader
All Implemented Interfaces:
GroupTableColumnModelListener, VetoableTableColumnModelListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TableColumnModelListener
Direct Known Subclasses:
FilterTableHeader

public class GroupTableHeader
extends AdvancedTableHeader
implements GroupTableColumnModelListener

GroupTableHeader provides for a TableHeader that is able to group columns together.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.table.JTableHeader
JTableHeader.AccessibleJTableHeader
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  boolean allowGroupColumnReordering
          a flag that is true if group columns can be reordered with the mouse, false otherwise
protected  boolean allowGroupReordering
          boolean flag that controls the reordering of group columns.
protected  TableCellRendererFactory factory
          a factory for creating new table cell renderer components.
protected  GroupTableColumnModel groupTableColumnModel
          the group table column model
 
Fields inherited from class javax.swing.table.JTableHeader
columnModel, draggedColumn, draggedDistance, reorderingAllowed, resizingAllowed, resizingColumn, table, updateTableInRealTime
 
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
GroupTableHeader()
          Constructs a GroupTableHeader.
GroupTableHeader(TableColumnModel cm)
          Constructs a GroupTableHeader.
 
Method Summary
 void addGroupColumn(GroupTableColumn aColumn)
          Adds a group column to the header.
protected  boolean canMove(int fromIndex, int toIndex)
          Determines whether the column at fromIndex can be moved to toIndex.
 void columnAdded(TableColumnModelEvent e)
          Invoked when a column is added to the table column model.
 void columnMoved(TableColumnModelEvent e)
          Invoked when a column is repositioned.
 void columnRemoved(TableColumnModelEvent e)
          Invoked when a column is removed from the table column model.
 void columnWillBeMoved(TableColumnModelEvent e)
          Invoked whenever a table column is about to be moved.
protected  GroupTableColumnModel createDefaultGroupColumnModel()
          Creates and returns the default GroupTableColumnModel.
protected  TableCellRenderer createDefaultGroupRenderer(int level)
          Returns a default renderer at a specified level to be used when no header renderer is defined by a GroupTableColumn.
 boolean getAllowGroupColumnReordering()
          Determines whether group columns can be reordered with the mouse.
 boolean getAllowGroupReordering()
          Determines whether columns that are part of a group can be reordered with the mouse.
 TableCellRenderer getDefaultGroupRenderer(int level)
          Returns the default renderer at the specified level used when no header renderer is defined by a GroupTableColumn.
 TableCellRendererFactory getFactory()
          Returns the factory that is used to create a new table cell renderer for a group column.
 GroupTableColumn getGroupColumn(TableColumn column)
          Returns the parent group column of the specified column.
 GroupTableColumnModel getGroupColumnModel()
          Returns the group column model.
 int getGroupLevel(Component hit)
          Returns the group level of the component passed as argument.
protected  GroupTableColumn[] getPathToRoot(GroupTableColumn aNode, int depth)
          Returns the path from the root group column to this column.
 GroupTableColumn[] getPathToRoot(TableColumn tc)
          Returns the path from the root group column to this column.
protected  int getPreferredHeight(Component comp, TableColumn tableColumn, int level, int column)
          Returns the preferred height of the component that renders the specified column.
 boolean getResizingAllowed()
          Returns true if the user is allowed to resize columns by dragging between their headers, false otherwise.
 TableColumn groupColumnAtPoint(Point p)
          Returns the group column at the specified point.
 void groupColumnsInserted(GroupTableColumnModelEvent e)
          Tells listeners that group columns were added to the model.
 void groupColumnsRemoved(GroupTableColumnModelEvent e)
          Tells listeners that group columns were removed from the model.
 int groupLevelAtPoint(Point p)
          Returns the group level at the specified point.
protected  boolean handleEvent(MouseEvent e, Component comp)
          Handles a mouse event on the header.
 boolean isReorderingAllowed(int index)
          Returns true if the column at index is reorderable.
 boolean isReorderingAllowed(Point p)
          Returns true if column reordering at the specified coordinate can be initiated.
protected  Component prepareRenderer(TableCellRenderer renderer, Object value, GroupTableColumn groupColumn, int level, int column)
          Prepares the renderer by returning a suitable component.
 void removeGroupColumn(GroupTableColumn aColumn)
          Removes a group column from the model.
 void setAllowGroupColumnReordering(boolean allowGroupColumnReordering)
          Assigns a flag that controls whether group columns can be reordered with the mouse.
 void setAllowGroupReordering(boolean allowGroupReordering)
          Assigns a flag that controls whether columns that are part of a group can be reordered with the mouse.
 void setColumnModel(TableColumnModel newModel)
          Sets the column model for this table to newModel and registers for listener notifications from the new column model.
 void setDefaultGroupRenderer(TableCellRenderer renderer, int level)
          Sets the default renderer at the specified level used when no header renderer is defined by a GroupTableColumn.
 void setFactory(TableCellRendererFactory newFactory)
          Assigns a new table cell renderer factory.
 void setGroupColumnModel(GroupTableColumnModel groupModel)
          Assigns a new group column model.
 void setResizingColumn(TableColumn aColumn)
          Sets the header's resizingColumn to aColumn.
 void setTable(JTable aTable)
          Sets the table associated with this header.
 void updateUI()
          Notification from the UIManager that the look and feel (L&F) has changed. Replaces the current UI object with the latest version from the UIManager.
 
Methods inherited from class com.sciapp.table.AdvancedTableHeader
addNotify, columnWillBeAdded, columnWillBeRemoved, createDefaultColumnModel, doProcessMouseEvent, doProcessMouseMotionEvent, getComponentAtPoint, getDraggedDistance, getReorderingAllowed, getToolTipLocation, getToolTipText, initializeLocalVars, processMouseEvent, processMouseMotionEvent, setDraggedColumn
 
Methods inherited from class javax.swing.table.JTableHeader
columnAtPoint, columnMarginChanged, columnSelectionChanged, createDefaultRenderer, getAccessibleContext, getColumnModel, getDefaultRenderer, getDraggedColumn, getHeaderRect, getResizingColumn, getTable, getUI, getUIClassID, getUpdateTableInRealTime, paramString, resizeAndRepaint, setDefaultRenderer, setDraggedDistance, setReorderingAllowed, setResizingAllowed, setUI, setUpdateTableInRealTime
 
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, 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, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, doLayout, 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, addComponentListener, 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, processMouseWheelEvent, remove, removeComponentListener, 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
 

Field Detail

allowGroupReordering

protected boolean allowGroupReordering
boolean flag that controls the reordering of group columns.


groupTableColumnModel

protected GroupTableColumnModel groupTableColumnModel
the group table column model


allowGroupColumnReordering

protected boolean allowGroupColumnReordering
a flag that is true if group columns can be reordered with the mouse, false otherwise


factory

protected transient TableCellRendererFactory factory
a factory for creating new table cell renderer components.

Constructor Detail

GroupTableHeader

public GroupTableHeader()
Constructs a GroupTableHeader.


GroupTableHeader

public GroupTableHeader(TableColumnModel cm)
Constructs a GroupTableHeader.

Method Detail

addGroupColumn

public void addGroupColumn(GroupTableColumn aColumn)
Adds a group column to the header.

Parameters:
aColumn - the group column to add

canMove

protected boolean canMove(int fromIndex,
                          int toIndex)
Determines whether the column at fromIndex can be moved to toIndex. By default, this method returns true. You will need to override it in order to define conditions for which columns cannot be moved.

Overrides:
canMove in class AdvancedTableHeader
Parameters:
fromIndex - the current view index of the column being moved
toIndex - the index the column is being moved to
Returns:
true if the column can move, false otherwise

columnAdded

public void columnAdded(TableColumnModelEvent e)
Invoked when a column is added to the table column model.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
columnAdded in interface TableColumnModelListener
Overrides:
columnAdded in class JTableHeader
Parameters:
e - the event received
See Also:
TableColumnModelListener

columnMoved

public void columnMoved(TableColumnModelEvent e)
Invoked when a column is repositioned.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
columnMoved in interface TableColumnModelListener
Overrides:
columnMoved in class JTableHeader
Parameters:
e - the event received
See Also:
TableColumnModelListener

columnRemoved

public void columnRemoved(TableColumnModelEvent e)
Invoked when a column is removed from the table column model.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
columnRemoved in interface TableColumnModelListener
Overrides:
columnRemoved in class JTableHeader
Parameters:
e - the event received
See Also:
TableColumnModelListener

columnWillBeMoved

public void columnWillBeMoved(TableColumnModelEvent e)
                       throws ColumnModelVetoException
Invoked whenever a table column is about to be moved.

Specified by:
columnWillBeMoved in interface VetoableTableColumnModelListener
Overrides:
columnWillBeMoved in class AdvancedTableHeader
Parameters:
e - the event identifying the move.
Throws:
ColumnModelVetoException

createDefaultGroupColumnModel

protected GroupTableColumnModel createDefaultGroupColumnModel()
Creates and returns the default GroupTableColumnModel.

Returns:
a new instance of DefaultGroupTableColumnModel.

createDefaultGroupRenderer

protected TableCellRenderer createDefaultGroupRenderer(int level)
Returns a default renderer at a specified level to be used when no header renderer is defined by a GroupTableColumn.

Parameters:
level - the group table column's level
Returns:
the default table group column renderer

getAllowGroupColumnReordering

public boolean getAllowGroupColumnReordering()
Determines whether group columns can be reordered with the mouse. Returns true if group columns can be reordered with the mouse, false otherwise


getAllowGroupReordering

public boolean getAllowGroupReordering()
Determines whether columns that are part of a group can be reordered with the mouse. Returns true if columns that are part of a group can be reordered with the mouse, false otherwise


getDefaultGroupRenderer

public TableCellRenderer getDefaultGroupRenderer(int level)
Returns the default renderer at the specified level used when no header renderer is defined by a GroupTableColumn.

Parameters:
level - the group table column's level
Returns:
the default header renderer for group columns

getFactory

public TableCellRendererFactory getFactory()
Returns the factory that is used to create a new table cell renderer for a group column.

Returns:
the table cell renderer factory for group columns.

getGroupColumn

public GroupTableColumn getGroupColumn(TableColumn column)
Returns the parent group column of the specified column. If the column is not part of a group, null is returned.

Parameters:
column - the column being part of a group column
Returns:
the enclosing group column or null, if the column is not part of a group

getGroupColumnModel

public GroupTableColumnModel getGroupColumnModel()
Returns the group column model.

Returns:
the group column model.

getGroupLevel

public int getGroupLevel(Component hit)
Returns the group level of the component passed as argument. The component can be retrieved with the getComponentAtPoint method. If hit targets a non-group table column, this method will return -1.

Parameters:
hit - the component for which the group level is evaluated
Returns:
the component's group level

getPathToRoot

protected GroupTableColumn[] getPathToRoot(GroupTableColumn aNode,
                                           int depth)
Returns the path from the root group column to this column.

Parameters:
aNode - the column for which the path is returned
depth - the passed node's depth
Returns:
the path from the root to this column

getPathToRoot

public GroupTableColumn[] getPathToRoot(TableColumn tc)
Returns the path from the root group column to this column. The column passed as parameter is excluded from the path. If the column is not enclosed in a group, this method returns null.

Parameters:
tc - the column for which the path is returned
Returns:
the path from the root to this column

getPreferredHeight

protected int getPreferredHeight(Component comp,
                                 TableColumn tableColumn,
                                 int level,
                                 int column)
Returns the preferred height of the component that renders the specified column. By default, the preferred height of comp is returned.

Parameters:
comp - the component that renders the column
tableColumn - the column that is being rendered
level - the level of the column
column - the column being drawn
Returns:
the column's preferred height

getResizingAllowed

public boolean getResizingAllowed()
Returns true if the user is allowed to resize columns by dragging between their headers, false otherwise. The default is true. You can resize columns programmatically regardless of this setting.

Overrides:
getResizingAllowed in class JTableHeader
Returns:
the resizingAllowed property
See Also:
JTableHeader.setResizingAllowed(boolean)

groupColumnAtPoint

public TableColumn groupColumnAtPoint(Point p)
Returns the group column at the specified point. If no group column is found, this method returns the normal (non-group) column at that point. The method will return null if the point does not hit on a column.

Parameters:
p - the point for which a group column exists
Returns:
the group column at the point, or the normal non-group column if a group column is not found

groupColumnsInserted

public void groupColumnsInserted(GroupTableColumnModelEvent e)
Tells listeners that group columns were added to the model.

Specified by:
groupColumnsInserted in interface GroupTableColumnModelListener
Parameters:
e - the event that identifies the addition.

groupColumnsRemoved

public void groupColumnsRemoved(GroupTableColumnModelEvent e)
Tells listeners that group columns were removed from the model.

Specified by:
groupColumnsRemoved in interface GroupTableColumnModelListener
Parameters:
e - the event that identifies the removal

groupLevelAtPoint

public int groupLevelAtPoint(Point p)
Returns the group level at the specified point. If no group column is found, this method returns -1.

Parameters:
p - the point for which a group column exists
Returns:
the group level at the point, or -1 if a group column is not found

handleEvent

protected boolean handleEvent(MouseEvent e,
                              Component comp)
Handles a mouse event on the header. This method is called before the event is propagated to any mouse listeners.

Overrides:
handleEvent in class AdvancedTableHeader
Parameters:
e - the mouse event that triggered the method
comp - the drawn table cell component
Returns:
true, if the event should be consumed, false otherwise

isReorderingAllowed

public boolean isReorderingAllowed(int index)
Returns true if the column at index is reorderable. By default, the last dummy column in AdvancedJScrollPane cannot be reordered, nor the first column of AdvancedJTable, if this is fixed (see setFirstColumnFixed).

Overrides:
isReorderingAllowed in class AdvancedTableHeader
Parameters:
index - the index of the table column
Returns:
true if the ith element of the table's TableColumnModel can be reordered, false otherwise.

isReorderingAllowed

public boolean isReorderingAllowed(Point p)
Returns true if column reordering at the specified coordinate can be initiated. By default, this method returns true.

Overrides:
isReorderingAllowed in class AdvancedTableHeader
Parameters:
p - object containing the x and y coordinates of the mouse event
Returns:
true if column reordering at p can be initiated, false otherwise

prepareRenderer

protected Component prepareRenderer(TableCellRenderer renderer,
                                    Object value,
                                    GroupTableColumn groupColumn,
                                    int level,
                                    int column)
Prepares the renderer by returning a suitable component.

Parameters:
renderer - the renderer to return a component from
value - the value used to initialize the renderer
groupColumn - the groupColumn being drawn or null if there is no group column
level - the level of the group column
column - the column
Returns:
the component being to draw

removeGroupColumn

public void removeGroupColumn(GroupTableColumn aColumn)
Removes a group column from the model.

Parameters:
aColumn - the group column to remove

setAllowGroupColumnReordering

public void setAllowGroupColumnReordering(boolean allowGroupColumnReordering)
Assigns a flag that controls whether group columns can be reordered with the mouse.

Parameters:
allowGroupColumnReordering - true if group columns can be reordered with the mouse, false otherwise

setAllowGroupReordering

public void setAllowGroupReordering(boolean allowGroupReordering)
Assigns a flag that controls whether columns that are part of a group can be reordered with the mouse.

Parameters:
allowGroupReordering - true if columns that are part of a group can be reordered with the mouse, false otherwise

setColumnModel

public void setColumnModel(TableColumnModel newModel)
Sets the column model for this table to newModel and registers for listener notifications from the new column model.

Overrides:
setColumnModel in class AdvancedTableHeader
Parameters:
newModel - the new data source for this table
See Also:
JTableHeader.getColumnModel()

setDefaultGroupRenderer

public void setDefaultGroupRenderer(TableCellRenderer renderer,
                                    int level)
Sets the default renderer at the specified level used when no header renderer is defined by a GroupTableColumn.

Parameters:
renderer - the default header renderer for group columns
level - the group table column's level

setFactory

public void setFactory(TableCellRendererFactory newFactory)
Assigns a new table cell renderer factory.

Parameters:
newFactory - the new table cell renderer factory to assign.

setGroupColumnModel

public void setGroupColumnModel(GroupTableColumnModel groupModel)
Assigns a new group column model.

Parameters:
groupModel - the new group column model to assign.

setResizingColumn

public void setResizingColumn(TableColumn aColumn)
Sets the header's resizingColumn to aColumn.

Application code will not use this method explicitly, it is used internally by the column sizing mechanism.

Overrides:
setResizingColumn in class JTableHeader
Parameters:
aColumn - the column being resized, or null if no column is being resized

setTable

public void setTable(JTable aTable)
Sets the table associated with this header.

Overrides:
setTable in class AdvancedTableHeader
Parameters:
aTable - the new table

updateUI

public void updateUI()
Notification from the UIManager that the look and feel (L&F) has changed. Replaces the current UI object with the latest version from the UIManager.

Overrides:
updateUI in class AdvancedTableHeader
See Also:
JComponent.updateUI()

Copyright © 2005 Scientific Applications. All Rights Reserved.