MetalTreeUIpublic class MetalTreeUI extends BasicTreeUI 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:
Angled |
A line is drawn connecting the child to the parent. For handling
of the root node refer to
{@link javax.swing.JTree#setRootVisible} and
{@link javax.swing.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 impratical 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 . |
Fields Summary |
---|
private static Color | lineColor | private static final String | LINE_STYLE | private static final String | LEG_LINE_STYLE_STRING | private static final String | HORIZ_STYLE_STRING | private static final String | NO_STYLE_STRING | private static final int | LEG_LINE_STYLE | private static final int | HORIZ_LINE_STYLE | private static final int | NO_LINE_STYLE | private int | lineStyle | private PropertyChangeListener | lineStyleListener |
Constructors Summary |
---|
public MetalTreeUI()
super();
|
Methods Summary |
---|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent x)
// Boilerplate
return new MetalTreeUI();
| protected void | decodeLineStyle(java.lang.Object lineStyleFlag)this function converts between the string passed into the client property
and the internal representation (currently and int)
if ( lineStyleFlag == null ||
lineStyleFlag.equals(LEG_LINE_STYLE_STRING)){
lineStyle = LEG_LINE_STYLE; // default case
} else {
if ( lineStyleFlag.equals(NO_STYLE_STRING) ) {
lineStyle = NO_LINE_STYLE;
} else if ( lineStyleFlag.equals(HORIZ_STYLE_STRING) ) {
lineStyle = HORIZ_LINE_STYLE;
}
}
| protected int | getHorizontalLegBuffer()
return 4;
| public void | installUI(javax.swing.JComponent c)
super.installUI( c );
lineColor = UIManager.getColor( "Tree.line" );
Object lineStyleFlag = c.getClientProperty( LINE_STYLE );
decodeLineStyle(lineStyleFlag);
c.addPropertyChangeListener(lineStyleListener);
| protected boolean | isLocationInExpandControl(int row, int rowLevel, int mouseX, int mouseY)
if(tree != null && !isLeaf(row)) {
int boxWidth;
if(getExpandedIcon() != null)
boxWidth = getExpandedIcon().getIconWidth() + 6;
else
boxWidth = 8;
Insets i = tree.getInsets();
int boxLeftX = (i != null) ? i.left : 0;
boxLeftX += (((rowLevel + depthOffset - 1) * totalChildIndent) +
getLeftChildIndent()) - boxWidth/2;
int boxRightX = boxLeftX + boxWidth;
return mouseX >= boxLeftX && mouseX <= boxRightX;
}
return false;
| public void | paint(java.awt.Graphics g, javax.swing.JComponent c)
super.paint( g, c );
// Paint the lines
if (lineStyle == HORIZ_LINE_STYLE && !largeModel) {
paintHorizontalSeparators(g,c);
}
| protected void | paintHorizontalPartOfLeg(java.awt.Graphics g, java.awt.Rectangle clipBounds, java.awt.Insets insets, java.awt.Rectangle bounds, javax.swing.tree.TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
if (lineStyle == LEG_LINE_STYLE) {
super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds,
path, row, isExpanded,
hasBeenExpanded, isLeaf);
}
| protected void | paintHorizontalSeparators(java.awt.Graphics g, javax.swing.JComponent c)
g.setColor( lineColor );
Rectangle clipBounds = g.getClipBounds();
int beginRow = getRowForPath(tree, getClosestPathForLocation
(tree, 0, clipBounds.y));
int endRow = getRowForPath(tree, getClosestPathForLocation
(tree, 0, clipBounds.y + clipBounds.height - 1));
if ( beginRow <= -1 || endRow <= -1 ) {
return;
}
for ( int i = beginRow; i <= endRow; ++i ) {
TreePath path = getPathForRow(tree, i);
if(path != null && path.getPathCount() == 2) {
Rectangle rowBounds = getPathBounds(tree,getPathForRow
(tree, i));
// Draw a line at the top
if(rowBounds != null)
g.drawLine(clipBounds.x, rowBounds.y,
clipBounds.x + clipBounds.width, rowBounds.y);
}
}
| protected void | paintVerticalPartOfLeg(java.awt.Graphics g, java.awt.Rectangle clipBounds, java.awt.Insets insets, javax.swing.tree.TreePath path)
if (lineStyle == LEG_LINE_STYLE) {
super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
}
| public void | uninstallUI(javax.swing.JComponent c)
c.removePropertyChangeListener(lineStyleListener);
super.uninstallUI(c);
|
|