APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.basic

public Class BasicTableHeaderUI

extends TableHeaderUI
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.synth.SynthTableHeaderUI
Imports
java.awt.*, java.awt.event.*, java.util.*, javax.swing.*, javax.swing.event.*, javax.swing.plaf.*, javax.swing.table.*, sun.swing.*

BasicTableHeaderUI implementation
Authors
Alan Chung, Philip Milne

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public class
BasicTableHeaderUI.MouseInputHandler

This class should be treated as a "protected" inner class.

Field Summary

Modifier and TypeField and Description
private static FocusListener
protected JTableHeader
header

The JTableHeader that is delegating the painting to this UI.

protected MouseInputListener
mouseInputListener

Listeners that are attached to the JTable

protected CellRendererPane
rendererPane

The instance of CellRendererPane.

private static Cursor
private int
private int

Constructor Summary

AccessConstructor and Description
public
BasicTableHeaderUI()

Constructs a BasicTableHeaderUI.

Method Summary

Modifier and TypeMethod and Description
private static boolean
private int
changeColumnWidth(TableColumn resizingColumn, JTableHeader th, int oldWidth, int newWidth)

private Dimension
createHeaderSize(long width)

protected MouseInputListener

Returns:

the mouse listener for the JTableHeader
createMouseInputListener
()

Creates the mouse listener for the JTableHeader.

public static ComponentUI

Returns:

a new instance of BasicTableHeaderUI
createUI
(JComponent
a component.
h
)

Hides javax.swing.plaf.ComponentUI.createUI.

Returns a new instance of BasicTableHeaderUI.

public int
getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.ComponentUI.getBaseline.

Returns the baseline.

private int
private Component
getHeaderRenderer(int columnIndex)

public Dimension
getMaximumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

Return the maximum size of the header.

public Dimension
getMinimumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

Return the minimum size of the header.

public Dimension
getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

Return the preferred size of the header.

protected int

Returns:

the index of the current rollover column
getRolloverColumn
()

Returns the index of the column header over which the mouse currently is.

private int
protected void
installDefaults()

Initializes JTableHeader properties such as font, foreground, and background.

protected void
installKeyboardActions()

Register all keyboard actions on the JTableHeader.

protected void
installListeners()

Attaches listeners to the JTableHeader.

public void
installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Configures the specified component appropriately for the look and feel.

pack-priv static void
loadActionMap(LazyActionMap map)

Populates TableHeader's actions.

public void
paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Paints the specified component appropriately for the look and feel.

private void
paintCell(Graphics g, Rectangle cellRect, int columnIndex)

protected void
rolloverColumnUpdated(int
the index of the previous rollover column or -1 if the mouse was not over a column
oldColumn
,
int
the index of the new rollover column or -1 if the mouse is not over a column
newColumn
)

This method gets called every time when a rollover column in the table header is updated.

private void
scrollToColumn(int col)

Used by selectColumn to scroll horizontally, if necessary, to ensure that the newly selected column is visible.

pack-priv void
selectColumn(int newColIndex)

Selects the specified column in the table header.

pack-priv void
selectColumn(int newColIndex, boolean doScroll)

private int
selectNextColumn(boolean doIt)

private int
selectPreviousColumn(boolean doIt)

protected void
uninstallDefaults()

Uninstalls default properties

protected void
uninstallKeyboardActions()

Unregisters default key actions.

protected void
uninstallListeners()

Unregisters listeners.

public void
uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Reverses configuration which was done on the specified component during installUI.

private void
private int

Field Detail

focusListenerback to summary
private static FocusListener focusListener
mouseInputListenerback to summary
protected MouseInputListener mouseInputListener

Listeners that are attached to the JTable

rendererPaneback to summary
protected CellRendererPane rendererPane

The instance of CellRendererPane.

resizeCursorback to summary
private static Cursor resizeCursor
rolloverColumnback to summary
private int rolloverColumn
selectedColumnIndexback to summary
private int selectedColumnIndex

Constructor Detail

BasicTableHeaderUIback to summary
public BasicTableHeaderUI()

Constructs a BasicTableHeaderUI.

Method Detail

canResizeback to summary
private static boolean canResize(TableColumn column, JTableHeader header)
changeColumnWidthback to summary
private int changeColumnWidth(TableColumn resizingColumn, JTableHeader th, int oldWidth, int newWidth)
createHeaderSizeback to summary
private Dimension createHeaderSize(long width)
createMouseInputListenerback to summary
protected MouseInputListener createMouseInputListener()

Creates the mouse listener for the JTableHeader.

Returns:MouseInputListener

the mouse listener for the JTableHeader

createUIback to summary
public static ComponentUI createUI(JComponent h)

Hides javax.swing.plaf.ComponentUI.createUI.

Returns a new instance of BasicTableHeaderUI.

Parameters
h:JComponent

a component.

Returns:ComponentUI

a new instance of BasicTableHeaderUI

getBaselineback to summary
public int getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.ComponentUI.getBaseline.

Returns the baseline.

Exceptions
NullPointerException:
if c is null
IllegalArgumentException:
if width or height is < 0
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getHeaderHeightback to summary
private int getHeaderHeight()
getHeaderRendererback to summary
private Component getHeaderRenderer(int columnIndex)
getMaximumSizeback to summary
public Dimension getMaximumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

Return the maximum size of the header. The maximum width is the sum of the maximum widths of each column (plus inter-cell spacing).

getMinimumSizeback to summary
public Dimension getMinimumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

Return the minimum size of the header. The minimum width is the sum of the minimum widths of each column (plus inter-cell spacing).

getPreferredSizeback to summary
public Dimension getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

Return the preferred size of the header. The preferred height is the maximum of the preferred heights of all of the components provided by the header renderers. The preferred width is the sum of the preferred widths of each column (plus inter-cell spacing).

getRolloverColumnback to summary
protected int getRolloverColumn()

Returns the index of the column header over which the mouse currently is. When the mouse is not over the table header, -1 is returned.

Returns:int

the index of the current rollover column

Since
1.6
See Also
rolloverColumnUpdated(int, int)
getSelectedColumnIndexback to summary
private int getSelectedColumnIndex()
installDefaultsback to summary
protected void installDefaults()

Initializes JTableHeader properties such as font, foreground, and background. The font, foreground, and background properties are only set if their current value is either null or a UIResource, other properties are set if the current value is null.

See Also
installUI
installKeyboardActionsback to summary
protected void installKeyboardActions()

Register all keyboard actions on the JTableHeader.

installListenersback to summary
protected void installListeners()

Attaches listeners to the JTableHeader.

installUIback to summary
public void installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Doc from javax.swing.plaf.ComponentUI.installUI.

Configures the specified component appropriately for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:

  1. Install default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.
loadActionMapback to summary
pack-priv static void loadActionMap(LazyActionMap map)

Populates TableHeader's actions.

paintback to summary
public void paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Doc from javax.swing.plaf.ComponentUI.paint.

Paints the specified component appropriately for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.

paintCellback to summary
private void paintCell(Graphics g, Rectangle cellRect, int columnIndex)
rolloverColumnUpdatedback to summary
protected void rolloverColumnUpdated(int oldColumn, int newColumn)

This method gets called every time when a rollover column in the table header is updated. Every look and feel that supports a rollover effect in a table header should override this method and repaint the header.

Parameters
oldColumn:int

the index of the previous rollover column or -1 if the mouse was not over a column

newColumn:int

the index of the new rollover column or -1 if the mouse is not over a column

Since
1.6
See Also
getRolloverColumn(), JTableHeader#getHeaderRect(int)
scrollToColumnback to summary
private void scrollToColumn(int col)

Used by selectColumn to scroll horizontally, if necessary, to ensure that the newly selected column is visible.

selectColumnback to summary
pack-priv void selectColumn(int newColIndex)

Selects the specified column in the table header. Repaints the affected header cells and makes sure the newly selected one is visible.

selectColumnback to summary
pack-priv void selectColumn(int newColIndex, boolean doScroll)
selectNextColumnback to summary
private int selectNextColumn(boolean doIt)
selectPreviousColumnback to summary
private int selectPreviousColumn(boolean doIt)
uninstallDefaultsback to summary
protected void uninstallDefaults()

Uninstalls default properties

uninstallKeyboardActionsback to summary
protected void uninstallKeyboardActions()

Unregisters default key actions.

uninstallListenersback to summary
protected void uninstallListeners()

Unregisters listeners.

uninstallUIback to summary
public void uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Doc from javax.swing.plaf.ComponentUI.uninstallUI.

Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:

  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.
updateRolloverColumnback to summary
private void updateRolloverColumn(MouseEvent e)
viewIndexForColumnback to summary
private int viewIndexForColumn(TableColumn aColumn)
javax.swing.plaf.basic back to summary

private Class BasicTableHeaderUI.Actions

extends UIAction
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
accept(Object sender)

Overrides sun.swing.UIAction.accept.

Overrides default javax.swing.Action.accept.

Subclasses that need to conditionalize the enabled state should override this.

public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

private boolean
maybeMoveColumn(boolean leftArrow, JTableHeader th, BasicTableHeaderUI ui, boolean doIt)

private void
moveColumn(boolean leftArrow, JTableHeader th, BasicTableHeaderUI ui)

private void
resize(boolean leftArrow, JTableHeader th, BasicTableHeaderUI ui)

Inherited from sun.swing.UIAction:
addPropertyChangeListenergetNamegetValueisEnabledputValueremovePropertyChangeListenersetEnabled

Field Detail

FOCUS_TABLEback to summary
public static final String FOCUS_TABLE
MOVE_COLUMN_LEFTback to summary
public static final String MOVE_COLUMN_LEFT
MOVE_COLUMN_RIGHTback to summary
public static final String MOVE_COLUMN_RIGHT
RESIZE_LEFTback to summary
public static final String RESIZE_LEFT
RESIZE_RIGHTback to summary
public static final String RESIZE_RIGHT
SELECT_COLUMN_TO_LEFTback to summary
public static final String SELECT_COLUMN_TO_LEFT
SELECT_COLUMN_TO_RIGHTback to summary
public static final String SELECT_COLUMN_TO_RIGHT
TOGGLE_SORT_ORDERback to summary
public static final String TOGGLE_SORT_ORDER

Constructor Detail

Actionsback to summary
public Actions(String name)

Method Detail

acceptback to summary
public boolean accept(Object sender)

Overrides sun.swing.UIAction.accept.

Overrides default javax.swing.Action.accept.

Doc from sun.swing.UIAction.accept.

Subclasses that need to conditionalize the enabled state should override this. Be aware that sender may be null.

Annotations
@Override
actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

maybeMoveColumnback to summary
private boolean maybeMoveColumn(boolean leftArrow, JTableHeader th, BasicTableHeaderUI ui, boolean doIt)
moveColumnback to summary
private void moveColumn(boolean leftArrow, JTableHeader th, BasicTableHeaderUI ui)
resizeback to summary
private void resize(boolean leftArrow, JTableHeader th, BasicTableHeaderUI ui)
javax.swing.plaf.basic back to summary

public Class BasicTableHeaderUI.MouseInputHandler

extends Object
implements MouseInputListener
Class Inheritance
All Implemented Interfaces
javax.swing.event.MouseInputListener, java.awt.event.MouseMotionListener, java.util.EventListener, java.awt.event.MouseListener

This class should be treated as a "protected" inner class. Instantiate it only within subclasses of BasicTableHeaderUI.

Field Summary

Modifier and TypeField and Description
private int
private Cursor

Constructor Summary

AccessConstructor and Description
public
MouseInputHandler()

Constructs a MouseInputHandler.

Method Summary

Modifier and TypeMethod and Description
private TableColumn
private TableColumn
getResizingColumn(Point p, int column)

public void
mouseClicked(MouseEvent e)

Implements java.awt.event.MouseListener.mouseClicked.

Invoked when the mouse button has been clicked (pressed and released) on a component.

public void
mouseDragged(MouseEvent e)

Implements java.awt.event.MouseMotionListener.mouseDragged.

Invoked when a mouse button is pressed on a component and then dragged.

public void
mouseEntered(MouseEvent e)

Implements java.awt.event.MouseListener.mouseEntered.

Invoked when the mouse enters a component.

public void
mouseExited(MouseEvent e)

Implements java.awt.event.MouseListener.mouseExited.

Invoked when the mouse exits a component.

public void
mouseMoved(MouseEvent e)

Implements java.awt.event.MouseMotionListener.mouseMoved.

Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.

public void
mousePressed(MouseEvent e)

Implements java.awt.event.MouseListener.mousePressed.

Invoked when a mouse button has been pressed on a component.

public void
mouseReleased(MouseEvent e)

Implements java.awt.event.MouseListener.mouseReleased.

Invoked when a mouse button has been released on a component.

private void
setDraggedDistance(int draggedDistance, int column)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mouseXOffsetback to summary
private int mouseXOffset
otherCursorback to summary
private Cursor otherCursor

Constructor Detail

MouseInputHandlerback to summary
public MouseInputHandler()

Constructs a MouseInputHandler.

Method Detail

getResizingColumnback to summary
private TableColumn getResizingColumn(Point p)
getResizingColumnback to summary
private TableColumn getResizingColumn(Point p, int column)
mouseClickedback to summary
public void mouseClicked(MouseEvent e)

Implements java.awt.event.MouseListener.mouseClicked.

Doc from java.awt.event.MouseListener.mouseClicked.

Invoked when the mouse button has been clicked (pressed and released) on a component.

mouseDraggedback to summary
public void mouseDragged(MouseEvent e)

Implements java.awt.event.MouseMotionListener.mouseDragged.

Doc from java.awt.event.MouseMotionListener.mouseDragged.

Invoked when a mouse button is pressed on a component and then dragged. MOUSE_DRAGGED events will continue to be delivered to the component where the drag originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).

Due to platform-dependent Drag&Drop implementations, MOUSE_DRAGGED events may not be delivered during a native Drag&Drop operation.

mouseEnteredback to summary
public void mouseEntered(MouseEvent e)

Implements java.awt.event.MouseListener.mouseEntered.

Doc from java.awt.event.MouseListener.mouseEntered.

Invoked when the mouse enters a component.

mouseExitedback to summary
public void mouseExited(MouseEvent e)

Implements java.awt.event.MouseListener.mouseExited.

Doc from java.awt.event.MouseListener.mouseExited.

Invoked when the mouse exits a component.

mouseMovedback to summary
public void mouseMoved(MouseEvent e)

Implements java.awt.event.MouseMotionListener.mouseMoved.

Doc from java.awt.event.MouseMotionListener.mouseMoved.

Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.

mousePressedback to summary
public void mousePressed(MouseEvent e)

Implements java.awt.event.MouseListener.mousePressed.

Doc from java.awt.event.MouseListener.mousePressed.

Invoked when a mouse button has been pressed on a component.

mouseReleasedback to summary
public void mouseReleased(MouseEvent e)

Implements java.awt.event.MouseListener.mouseReleased.

Doc from java.awt.event.MouseListener.mouseReleased.

Invoked when a mouse button has been released on a component.

setDraggedDistanceback to summary
private void setDraggedDistance(int draggedDistance, int column)
swapCursorback to summary
private void swapCursor()