Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.table
Class AdvancedTableHeader

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
All Implemented Interfaces:
VetoableTableColumnModelListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TableColumnModelListener
Direct Known Subclasses:
GroupTableHeader

public class AdvancedTableHeader
extends JTableHeader
implements VetoableTableColumnModelListener

This is the object which manages the header of AdvancedJTable. This class does not let users reorder table columns when dragging them with the right mouse button pressed. It also disallows the reordering of the last dummy column (if that one exists).

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
 
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
AdvancedTableHeader()
          Constructs an AdvancedTableHeader.
AdvancedTableHeader(TableColumnModel cm)
          Constructs an AdvancedTableHeader which is initialized with cm as the column model.
 
Method Summary
 void addNotify()
          Notifies this component that it now has a parent component.
protected  boolean canMove(int fromIndex, int toIndex)
          Determines whether the column at fromIndex can be moved to toIndex.
 void columnWillBeAdded(TableColumnModelEvent e)
          Invoked whenever a table column is about to be added.
 void columnWillBeMoved(TableColumnModelEvent e)
          Invoked whenever a table column is about to be moved.
 void columnWillBeRemoved(TableColumnModelEvent e)
          Invoked whenever a table column is about to be removed.
protected  TableColumnModel createDefaultColumnModel()
          Creates a new instance of DefaultVetoableColumnModel.
protected  void doProcessMouseEvent(MouseEvent e)
          Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.
protected  void doProcessMouseMotionEvent(MouseEvent e)
          Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.
 Component getComponentAtPoint(Point p)
          Returns the component that is painted on the header at the point p.
 int getDraggedDistance()
          Returns the column's horizontal distance from its original position, if and only if, a drag is in process.
 boolean getReorderingAllowed()
          Returns true if the user is allowed to rearrange columns by dragging their headers, false otherwise.
 Point getToolTipLocation(MouseEvent event)
          Returns the tooltip location in this component's coordinate system.
 String getToolTipText(MouseEvent event)
          Allows the renderer's tips to be used if there is text set.
protected  boolean handleEvent(MouseEvent e, Component comp)
          Handles a mouse event on the header.
protected  void initializeLocalVars()
          Initializes the local variables and properties with default values.
 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  void processMouseEvent(MouseEvent e)
          This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows.
protected  void processMouseMotionEvent(MouseEvent e)
          This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows.
 void setColumnModel(TableColumnModel newModel)
          Sets the column model for this table to newModel and registers for listener notifications from the new column model.
 void setDraggedColumn(TableColumn col)
          Sets the header's draggedColumn 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.
 
Methods inherited from class javax.swing.table.JTableHeader
columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, createDefaultRenderer, getAccessibleContext, getColumnModel, getDefaultRenderer, getDraggedColumn, getHeaderRect, getResizingAllowed, getResizingColumn, getTable, getUI, getUIClassID, getUpdateTableInRealTime, paramString, resizeAndRepaint, setDefaultRenderer, setDraggedDistance, setReorderingAllowed, setResizingAllowed, setResizingColumn, 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
 

Constructor Detail

AdvancedTableHeader

public AdvancedTableHeader()
Constructs an AdvancedTableHeader.


AdvancedTableHeader

public AdvancedTableHeader(TableColumnModel cm)
Constructs an AdvancedTableHeader which is initialized with cm as the column model.

Method Detail

addNotify

public void addNotify()
Notifies this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with KeyboardAction event listeners.

Overrides:
addNotify in class JComponent
See Also:
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

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.

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

columnWillBeAdded

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

Specified by:
columnWillBeAdded in interface VetoableTableColumnModelListener
Parameters:
e - the event identifying the addition.
Throws:
ColumnModelVetoException

columnWillBeMoved

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

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

columnWillBeRemoved

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

Specified by:
columnWillBeRemoved in interface VetoableTableColumnModelListener
Parameters:
e - the event identifying the removal.
Throws:
ColumnModelVetoException

createDefaultColumnModel

protected TableColumnModel createDefaultColumnModel()
Creates a new instance of DefaultVetoableColumnModel.

Returns the default column model object which is a DefaultTableColumnModel. A subclass can override this method to return a different column model object

Overrides:
createDefaultColumnModel in class JTableHeader
Returns:
the default column model object

doProcessMouseEvent

protected void doProcessMouseEvent(MouseEvent e)
Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.

Parameters:
e - the 'converted' mouse event

doProcessMouseMotionEvent

protected void doProcessMouseMotionEvent(MouseEvent e)
Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.

Parameters:
e - the 'converted' mouse event

getComponentAtPoint

public Component getComponentAtPoint(Point p)
Returns the component that is painted on the header at the point p. If the component is a container, this method will return the child at that point.

Parameters:
p - a point in the header's frame of reference
Returns:
the component being painted at the specified point

getDraggedDistance

public int getDraggedDistance()
Returns the column's horizontal distance from its original position, if and only if, a drag is in process. Otherwise, the the return value is meaningless.

Overrides:
getDraggedDistance in class JTableHeader
Returns:
the column's horizontal distance from its original position, if a drag is in process, otherwise the return value is meaningless
See Also:
JTableHeader.getDraggedColumn()

getReorderingAllowed

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

Overrides:
getReorderingAllowed in class JTableHeader
Returns:
the reorderingAllowed property
See Also:
JTableHeader.setReorderingAllowed(boolean)

getToolTipLocation

public Point getToolTipLocation(MouseEvent event)
Returns the tooltip location in this component's coordinate system. If null is returned, Swing will choose a location. The default implementation returns null.

Overrides:
getToolTipLocation in class JComponent
Parameters:
event - the MouseEvent that caused the ToolTipManager to show the tooltip
Returns:
always returns null

getToolTipText

public String getToolTipText(MouseEvent event)
Allows the renderer's tips to be used if there is text set.

Overrides:
getToolTipText in class JTableHeader
Parameters:
event - the location of the event identifies the proper renderer and, therefore, the proper tip
Returns:
the tool tip for this component

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.

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

initializeLocalVars

protected void initializeLocalVars()
Initializes the local variables and properties with default values. Used by the constructor methods.

Overrides:
initializeLocalVars in class JTableHeader

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).

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.

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

processMouseEvent

protected void processMouseEvent(MouseEvent e)
This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows. The doProcessMouseEvent method is then called.

Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.

This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Overrides:
processMouseEvent in class Component
Parameters:
e - the mouse event
See Also:
MouseEvent, MouseListener, Component.addMouseListener(java.awt.event.MouseListener), Component.enableEvents(long)

processMouseMotionEvent

protected void processMouseMotionEvent(MouseEvent e)
This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows. The doProcessMouseMotionEvent method is then called.

Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.

Overrides:
processMouseMotionEvent in class JComponent
Parameters:
e - the MouseEvent
See Also:
MouseEvent

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 JTableHeader
Parameters:
newModel - the new data source for this table
See Also:
JTableHeader.getColumnModel()

setDraggedColumn

public void setDraggedColumn(TableColumn col)
Sets the header's draggedColumn to aColumn.

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

Overrides:
setDraggedColumn in class JTableHeader
Parameters:
col - the column being dragged, or null if no column is being dragged

setTable

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

Overrides:
setTable in class JTableHeader
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 JTableHeader
See Also:
JComponent.updateUI()

Copyright © 2005 Scientific Applications. All Rights Reserved.