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

public Class MetalTreeUI

extends BasicTreeUI
Class Inheritance
Imports
javax.swing.*, javax.swing.event.*, java.awt.*, java.awt.event.*, java.beans.*, java.io.*, java.util.*, javax.swing.plaf.*, javax.swing.tree.*, javax.swing.plaf.basic.*

The metal look and feel implementation of TreeUI.

MetalTreeUI allows for configuring how to visually render the spacing and delineation between nodes. The following hints are supported:

Descriptions of supported hints: Angled, Horizontal, and None
Hint Description
Angled A line is drawn connecting the child to the parent. For handling of the root node refer to JTree#setRootVisible and JTree#setShowsRootHandles.
Horizontal A horizontal line is drawn dividing the children of the root node.
None Do not draw any visual indication between nodes.

As it is typically impractical to obtain the TreeUI from the JTree and cast to an instance of MetalTreeUI you enable this property via the client property JTree.lineStyle. For example, to switch to Horizontal style you would do: tree.putClientProperty("JTree.lineStyle", "Horizontal");

The default is Angled.

Authors
Tom Santos, Steve Wilson (value add stuff)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
MetalTreeUI.LineListener

This class listens for changes in line style

Field Summary

Modifier and TypeField and Description
private static final int
private static final String
private static final int
private static final String
private static final String
private static Color
private int
private PropertyChangeListener
private static final int
private static final String
Inherited from javax.swing.plaf.basic.BasicTreeUI:
cellEditorcollapsedIconcreatedCellEditorcreatedRenderercurrentCellRendererdepthOffsetdrawingCacheeditingComponenteditingPatheditingRoweditorHasDifferentSizeexpandedIconlargeModellastSelectedRowleftChildIndentnodeDimensionspreferredMinSizepreferredSizerendererPanerightChildIndentstopEditingInCompleteEditingtotalChildIndenttreetreeModeltreeSelectionModeltreeStatevalidCachedPreferredSize

Constructor Summary

AccessConstructor and Description
public
MetalTreeUI()

Constructs the MetalTreeUI.

Method Summary

Modifier and TypeMethod and Description
public static ComponentUI

Returns:

the instance of the MetalTreeUI
createUI
(JComponent
a component
x
)

Hides javax.swing.plaf.basic.BasicTreeUI.createUI.

Constructs the MetalTreeUI.

protected void
decodeLineStyle(Object
a flag
lineStyleFlag
)

Converts between the string passed into the client property and the internal representation (currently and int)

protected int
getHorizontalLegBuffer()

Overrides javax.swing.plaf.basic.BasicTreeUI.getHorizontalLegBuffer.

The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default.

public void
installUI(JComponent c)

Overrides javax.swing.plaf.basic.BasicTreeUI.installUI.

Configures the specified component appropriately for the look and feel.

protected boolean

Returns:

true if a point with X coordinate mouseX and Y coordinate mouseY is in expanded control.
isLocationInExpandControl
(int
a row
row
,
int
a row level
rowLevel
,
int
X coordinate
mouseX
,
int
Y coordinate
mouseY
)

Returns true if a point with X coordinate mouseX and Y coordinate mouseY is in expanded control.

public void
paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.basic.BasicTreeUI.paint.

Paints the specified component appropriately for the look and feel.

protected void
paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)

Overrides javax.swing.plaf.basic.BasicTreeUI.paintHorizontalPartOfLeg.

Paints the horizontal part of the leg.

protected void
paintHorizontalSeparators(Graphics
an instance of Graphics
g
,
JComponent
a component
c
)

Paints the horizontal separators.

protected void
paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)

Overrides javax.swing.plaf.basic.BasicTreeUI.paintVerticalPartOfLeg.

Paints the vertical part of the leg.

public void
uninstallUI(JComponent c)

Overrides javax.swing.plaf.basic.BasicTreeUI.uninstallUI.

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

Inherited from javax.swing.plaf.basic.BasicTreeUI:
cancelEditingcheckForClickInExpandControlcompleteEditingcompleteEditingcompleteUIInstallcompleteUIUninstallconfigureLayoutCachecreateCellEditorListenercreateCellRendererPanecreateComponentListenercreateDefaultCellEditorcreateDefaultCellRenderercreateFocusListenercreateKeyListenercreateLayoutCachecreateMouseListenercreateNodeDimensionscreatePropertyChangeListenercreateSelectionModelPropertyChangeListenercreateTreeExpansionListenercreateTreeModelListenercreateTreeSelectionListenerdrawCentereddrawDashedHorizontalLinedrawDashedVerticalLineensureRowsAreVisiblegetBaselinegetBaselineResizeBehaviorgetCellEditorgetCellRenderergetClosestPathForLocationgetCollapsedIcongetDropLineRectgetEditingPathgetExpandedIcongetHashColorgetLastChildPathgetLeadSelectionRowgetLeftChildIndentgetMaximumSizegetMinimumSizegetModelgetPathBoundsgetPathForRowgetPreferredMinSizegetPreferredSizegetPreferredSizegetRightChildIndentgetRowCountgetRowForPathgetRowHeightgetRowXgetSelectionModelgetShowsRootHandlesgetVerticalLegBufferhandleExpandControlClickinstallComponentsinstallDefaultsinstallKeyboardActionsinstallListenersisDropLineisEditableisEditingisLargeModelisLeafisLocationInExpandControlisMultiSelectEventisRootVisibleisToggleEventisToggleSelectionEventpaintDropLinepaintExpandControlpaintHorizontalLinepaintRowpaintVerticalLinepathWasCollapsedpathWasExpandedprepareForUIInstallprepareForUIUninstallselectPathForEventsetCellEditorsetCellRenderersetCollapsedIconsetEditablesetExpandedIconsetHashColorsetLargeModelsetLeftChildIndentsetModelsetPreferredMinSizesetRightChildIndentsetRootVisiblesetRowHeightsetSelectionModelsetShowsRootHandlesshouldPaintExpandControlstartEditingstartEditingAtPathstopEditingtoggleExpandStateuninstallComponentsuninstallDefaultsuninstallKeyboardActionsuninstallListenersupdateCachedPreferredSizeupdateCellEditorupdateDepthOffsetupdateExpandedDescendantsupdateLayoutCacheExpandedNodesupdateLeadSelectionRowupdateRendererupdateSize

Field Detail

HORIZ_LINE_STYLEback to summary
private static final int HORIZ_LINE_STYLE
HORIZ_STYLE_STRINGback to summary
private static final String HORIZ_STYLE_STRING
LEG_LINE_STYLEback to summary
private static final int LEG_LINE_STYLE
LEG_LINE_STYLE_STRINGback to summary
private static final String LEG_LINE_STYLE_STRING
LINE_STYLEback to summary
private static final String LINE_STYLE
lineColorback to summary
private static Color lineColor
lineStyleback to summary
private int lineStyle
lineStyleListenerback to summary
private PropertyChangeListener lineStyleListener
NO_LINE_STYLEback to summary
private static final int NO_LINE_STYLE
NO_STYLE_STRINGback to summary
private static final String NO_STYLE_STRING

Constructor Detail

MetalTreeUIback to summary
public MetalTreeUI()

Constructs the MetalTreeUI.

Method Detail

createUIback to summary
public static ComponentUI createUI(JComponent x)

Hides javax.swing.plaf.basic.BasicTreeUI.createUI.

Constructs the MetalTreeUI.

Parameters
x:JComponent

a component

Returns:ComponentUI

the instance of the MetalTreeUI

decodeLineStyleback to summary
protected void decodeLineStyle(Object lineStyleFlag)

Converts between the string passed into the client property and the internal representation (currently and int)

Parameters
lineStyleFlag:Object

a flag

getHorizontalLegBufferback to summary
protected int getHorizontalLegBuffer()

Overrides javax.swing.plaf.basic.BasicTreeUI.getHorizontalLegBuffer.

Doc from javax.swing.plaf.basic.BasicTreeUI.getHorizontalLegBuffer.

The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default. This method makes the leg end before that.

installUIback to summary
public void installUI(JComponent c)

Overrides javax.swing.plaf.basic.BasicTreeUI.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.
isLocationInExpandControlback to summary
protected boolean isLocationInExpandControl(int row, int rowLevel, int mouseX, int mouseY)

Returns true if a point with X coordinate mouseX and Y coordinate mouseY is in expanded control.

Parameters
row:int

a row

rowLevel:int

a row level

mouseX:int

X coordinate

mouseY:int

Y coordinate

Returns:boolean

true if a point with X coordinate mouseX and Y coordinate mouseY is in expanded control.

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

Overrides javax.swing.plaf.basic.BasicTreeUI.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.

paintHorizontalPartOfLegback to summary
protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)

Overrides javax.swing.plaf.basic.BasicTreeUI.paintHorizontalPartOfLeg.

Doc from javax.swing.plaf.basic.BasicTreeUI.paintHorizontalPartOfLeg.

Paints the horizontal part of the leg. The receiver should NOT modify clipBounds, or insets.

Note

parentRow can be -1 if the root is not visible.

paintHorizontalSeparatorsback to summary
protected void paintHorizontalSeparators(Graphics g, JComponent c)

Paints the horizontal separators.

Parameters
g:Graphics

an instance of Graphics

c:JComponent

a component

paintVerticalPartOfLegback to summary
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)

Overrides javax.swing.plaf.basic.BasicTreeUI.paintVerticalPartOfLeg.

Doc from javax.swing.plaf.basic.BasicTreeUI.paintVerticalPartOfLeg.

Paints the vertical part of the leg. The receiver should NOT modify clipBounds, insets.

uninstallUIback to summary
public void uninstallUI(JComponent c)

Overrides javax.swing.plaf.basic.BasicTreeUI.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.
javax.swing.plaf.metal back to summary

pack-priv Class MetalTreeUI.LineListener

extends Object
implements PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener

This class listens for changes in line style

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LineListenerback to summary
pack-priv LineListener()

Method Detail

propertyChangeback to summary
public void propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.