/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Displays an entry in a tree.
* <code>DefaultTreeCellRenderer</code> is not opaque and
* unless you subclass paint you should not change this.
* See <a
href="http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html">How to Use Trees</a>
* in <em>The Java Tutorial</em>
* for examples of customizing node display using this class.
* <p>
* The set of icons and colors used by {@code DefaultTreeCellRenderer}
* can be configured using the various setter methods. The value for
* each property is initialized from the defaults table. When the
* look and feel changes ({@code updateUI} is invoked), any properties
* that have a value of type {@code UIResource} are refreshed from the
* defaults table. The following table lists the mapping between
* {@code DefaultTreeCellRenderer} property and defaults table key:
* <table border="1" cellpadding="1" cellspacing="0"
* valign="top" >
* <tr valign="top" align="left">
* <th bgcolor="#CCCCFF" align="left">Property:
* <th bgcolor="#CCCCFF" align="left">Key:
* <tr><td>"leafIcon"<td>"Tree.leafIcon"
* <tr><td>"closedIcon"<td>"Tree.closedIcon"
* <tr><td>"openIcon"<td>"Tree.openIcon"
* <tr><td>"textSelectionColor"<td>"Tree.selectionForeground"
* <tr><td>"textNonSelectionColor"<td>"Tree.textForeground"
* <tr><td>"backgroundSelectionColor"<td>"Tree.selectionBackground"
* <tr><td>"backgroundNonSelectionColor"<td>"Tree.textBackground"
* <tr><td>"borderSelectionColor"<td>"Tree.selectionBorderColor"
* </table>
* <p>
* <strong><a name="override">Implementation Note:</a></strong>
* This class overrides
* <code>invalidate</code>,
* <code>validate</code>,
* <code>revalidate</code>,
* <code>repaint</code>,
* and
* <code>firePropertyChange</code>
* solely to improve performance.
* If not overridden, these frequently called methods would execute code paths
* that are unnecessary for the default tree cell renderer.
* If you write your own renderer,
* take care to weigh the benefits and
* drawbacks of overriding these methods.
*
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Rob Davis
* @author Ray Ryan
* @author Scott Violet
*/
{
/** Last tree the renderer was painted in. */
/** Is the value currently selected. */
protected boolean selected;
/** True if has focus. */
protected boolean hasFocus;
/** True if draws focus border around icon as well. */
private boolean drawsFocusBorderAroundIcon;
/** If true, a dashed line is drawn as the focus indicator. */
private boolean drawDashedFocusIndicator;
// If drawDashedFocusIndicator is true, the following are used.
/**
* Background color of the tree.
*/
/**
* Color to draw the focus indicator in, determined from the background.
* color.
*/
// Icons
/** Icon used to show non-leaf nodes that aren't expanded. */
/** Icon used to show leaf nodes. */
/** Icon used to show non-leaf nodes that are expanded. */
// Colors
/** Color to use for the foreground for selected nodes. */
/** Color to use for the foreground for non-selected nodes. */
/** Color to use for the background when a node is selected. */
/** Color to use for the background when the node isn't selected. */
/** Color to use for the focus indicator when the node has focus. */
private boolean isDropCell;
private boolean fillBackground = true;
/**
* Set to true after the constructor has run.
*/
private boolean inited;
/**
* Creates a {@code DefaultTreeCellRenderer}. Icons and text color are
* determined from the {@code UIManager}.
*/
public DefaultTreeCellRenderer() {
inited = true;
}
/**
* {@inheritDoc}
*
* @since 1.7
*/
public void updateUI() {
super.updateUI();
// To avoid invoking new methods from the constructor, the
// inited field is first checked. If inited is false, the constructor
// has not run and there is no point in checking the value. As
// all look and feels have a non-null value for these properties,
// a null value means the developer has specifically set it to
// null. As such, if the value is null, this does not reset the
// value.
}
}
}
}
}
}
if (!inited ||
(getBackgroundNonSelectionColor() instanceof UIResource)) {
}
}
this, ui, "Tree.drawsFocusBorderAroundIcon", false);
this, ui, "Tree.drawDashedFocusIndicator", false);
}
setName("Tree.cellRenderer");
}
/**
* Returns the default icon, for the current laf, that is used to
* represent non-leaf nodes that are expanded.
*/
}
/**
* Returns the default icon, for the current laf, that is used to
* represent non-leaf nodes that are not expanded.
*/
}
/**
* Returns the default icon, for the current laf, that is used to
* represent leaf nodes.
*/
}
/**
* Sets the icon used to represent non-leaf nodes that are expanded.
*/
}
/**
* Returns the icon used to represent non-leaf nodes that are expanded.
*/
return openIcon;
}
/**
* Sets the icon used to represent non-leaf nodes that are not expanded.
*/
}
/**
* Returns the icon used to represent non-leaf nodes that are not
* expanded.
*/
return closedIcon;
}
/**
* Sets the icon used to represent leaf nodes.
*/
}
/**
* Returns the icon used to represent leaf nodes.
*/
return leafIcon;
}
/**
* Sets the color the text is drawn with when the node is selected.
*/
}
/**
* Returns the color the text is drawn with when the node is selected.
*/
return textSelectionColor;
}
/**
* Sets the color the text is drawn with when the node isn't selected.
*/
}
/**
* Returns the color the text is drawn with when the node isn't selected.
*/
return textNonSelectionColor;
}
/**
* Sets the color to use for the background if node is selected.
*/
}
/**
* Returns the color to use for the background if node is selected.
*/
return backgroundSelectionColor;
}
/**
* Sets the background color to be used for non selected nodes.
*/
}
/**
* Returns the background color to be used for non selected nodes.
*/
return backgroundNonSelectionColor;
}
/**
* Sets the color to use for the border.
*/
}
/**
* Returns the color the border is drawn.
*/
return borderSelectionColor;
}
/**
* Subclassed to map <code>FontUIResource</code>s to null. If
* <code>font</code> is null, or a <code>FontUIResource</code>, this
* has the effect of letting the font of the JTree show
* through. On the other hand, if <code>font</code> is non-null, and not
* a <code>FontUIResource</code>, the font becomes <code>font</code>.
*/
if(font instanceof FontUIResource)
}
/**
* Gets the font of this component.
* @return this component's font; if a font has not been set
* for this component, the font of its parent is returned
*/
// Strive to return a non-null value, otherwise the html support
// will typically pick up the wrong font in certain situations.
}
return font;
}
/**
* Subclassed to map <code>ColorUIResource</code>s to null. If
* <code>color</code> is null, or a <code>ColorUIResource</code>, this
* has the effect of letting the background color of the JTree show
* through. On the other hand, if <code>color</code> is non-null, and not
* a <code>ColorUIResource</code>, the background becomes
* <code>color</code>.
*/
if(color instanceof ColorUIResource)
super.setBackground(color);
}
/**
* Configures the renderer based on the passed in components.
* The value is set from messaging the tree with
* <code>convertValueToText</code>, which ultimately invokes
* <code>toString</code> on <code>value</code>.
* The foreground color is set based on the selection and the icon
* is set based on the <code>leaf</code> and <code>expanded</code>
* parameters.
*/
boolean sel,
boolean expanded,
boolean hasFocus) {
isDropCell = false;
if (dropLocation != null
} else {
fg = getTextSelectionColor();
}
isDropCell = true;
} else if (sel) {
fg = getTextSelectionColor();
} else {
}
if (leaf) {
icon = getLeafIcon();
} else if (expanded) {
icon = getOpenIcon();
} else {
icon = getClosedIcon();
}
setEnabled(false);
} else {
setEnabled(true);
}
return this;
}
/**
* Paints the value. The background is filled based on selected.
*/
if (isDropCell) {
}
} else if (selected) {
} else {
bColor = getBackground();
}
}
int imageOffset = -1;
imageOffset = getLabelStart();
if(getComponentOrientation().isLeftToRight()) {
getHeight());
} else {
getHeight());
}
}
if (hasFocus) {
if (drawsFocusBorderAroundIcon) {
imageOffset = 0;
}
else if (imageOffset == -1) {
imageOffset = getLabelStart();
}
if(getComponentOrientation().isLeftToRight()) {
} else {
}
}
super.paint(g);
}
}
if (treeBGColor != notColor) {
}
g.setColor(focusBGColor);
BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
}
}
private int getLabelStart() {
}
return 0;
}
/**
* Overrides <code>JComponent.getPreferredSize</code> to
* return slightly wider preferred size value.
*/
if(retDimension != null)
return retDimension;
}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
public void validate() {}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*
* @since 1.5
*/
public void invalidate() {}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
public void revalidate() {}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*
* @since 1.5
*/
public void repaint() {}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
// Strings get interned...
if (propertyName == "text"
}
}
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
/**
* Overridden for performance reasons.
* See the <a href="#override">Implementation Note</a>
* for more information.
*/
}