1 /* DefaultTreeCellRenderer.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.tree;
41 import java.awt.Color;
42 import java.awt.Component;
43 import java.awt.Dimension;
45 import java.awt.Graphics;
46 import java.awt.Rectangle;
48 import javax.swing.Icon;
49 import javax.swing.JLabel;
50 import javax.swing.JTree;
51 import javax.swing.UIDefaults;
52 import javax.swing.UIManager;
53 import javax.swing.plaf.UIResource;
56 * DefaultTreeCellRenderer
57 * @author Andrew Selkirk
59 public class DefaultTreeCellRenderer
61 implements TreeCellRenderer
63 //-------------------------------------------------------------
64 // Variables --------------------------------------------------
65 //-------------------------------------------------------------
70 protected boolean selected;
75 protected boolean hasFocus;
78 * drawsFocusBorderAroundIcon
80 private boolean drawsFocusBorderAroundIcon;
85 protected transient Icon closedIcon;
90 protected transient Icon leafIcon;
95 protected transient Icon openIcon;
100 protected Color textSelectionColor;
103 * textNonSelectionColor
105 protected Color textNonSelectionColor;
108 * backgroundSelectionColor
110 protected Color backgroundSelectionColor;
113 * backgroundNonSelectionColor
115 protected Color backgroundNonSelectionColor;
118 * borderSelectionColor
120 protected Color borderSelectionColor;
123 //-------------------------------------------------------------
124 // Initialization ---------------------------------------------
125 //-------------------------------------------------------------
128 * Constructor DefaultTreeCellRenderer
130 public DefaultTreeCellRenderer() {
131 UIDefaults defaults = UIManager.getLookAndFeelDefaults();
133 setLeafIcon(getDefaultLeafIcon());
134 setOpenIcon(getDefaultOpenIcon());
135 setClosedIcon(getDefaultClosedIcon());
137 setTextNonSelectionColor(defaults.getColor("Tree.textForeground"));
138 setTextSelectionColor(defaults.getColor("Tree.selectionForeground"));
139 setBackgroundNonSelectionColor(defaults.getColor("Tree.textBackground"));
140 setBackgroundSelectionColor(defaults.getColor("Tree.selectionBackground"));
141 setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));
145 //-------------------------------------------------------------
146 // Methods ----------------------------------------------------
147 //-------------------------------------------------------------
153 public Icon getDefaultOpenIcon() {
154 return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");
158 * getDefaultClosedIcon
161 public Icon getDefaultClosedIcon() {
162 return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");
169 public Icon getDefaultLeafIcon() {
170 return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");
177 public void setOpenIcon(Icon i) {
185 public Icon getOpenIcon() {
193 public void setClosedIcon(Icon i) {
201 public Icon getClosedIcon() {
209 public void setLeafIcon(Icon i) {
217 public Icon getLeafIcon() {
222 * setTextSelectionColor
225 public void setTextSelectionColor(Color c) {
226 textSelectionColor = c;
230 * getTextSelectionColor
233 public Color getTextSelectionColor() {
234 return textSelectionColor;
238 * setTextNonSelectionColor
241 public void setTextNonSelectionColor(Color c) {
242 textNonSelectionColor = c;
246 * getTextNonSelectionColor
249 public Color getTextNonSelectionColor() {
250 return textNonSelectionColor;
254 * setBackgroundSelectionColor
257 public void setBackgroundSelectionColor(Color c) {
258 backgroundSelectionColor = c;
262 * getBackgroundSelectionColor
265 public Color getBackgroundSelectionColor() {
266 return backgroundSelectionColor;
270 * setBackgroundNonSelectionColor
273 public void setBackgroundNonSelectionColor(Color c) {
274 backgroundNonSelectionColor = c;
278 * getBackgroundNonSelectionColor
281 public Color getBackgroundNonSelectionColor() {
282 return backgroundNonSelectionColor;
286 * setBorderSelectionColor
289 public void setBorderSelectionColor(Color c) {
290 borderSelectionColor = c;
294 * getBorderSelectionColor
297 public Color getBorderSelectionColor() {
298 return borderSelectionColor;
305 public void setFont(Font f) {
306 if (f != null && f instanceof UIResource)
315 public void setBackground(Color c) {
316 if (c != null && c instanceof UIResource)
318 super.setBackground(c);
322 * getTreeCellRendererComponent
332 public Component getTreeCellRendererComponent(JTree tree,
339 this.selected = selected;
340 this.hasFocus = hasFocus;
343 setIcon(getLeafIcon());
345 setIcon(getOpenIcon());
347 setIcon(getClosedIcon());
349 setText(val.toString());
350 setHorizontalAlignment(LEFT);
351 setVerticalAlignment(TOP);
360 public void paint(Graphics g) {
368 public Dimension getPreferredSize() {
370 } // getPreferredSize()
375 public void validate() {
382 public void revalidate() {
394 public void repaint(long value0, int value1, int value2, int value3, int value4) {
402 public void repaint(Rectangle value0) {
412 protected void firePropertyChange(String value0, Object value1, Object value2) {
414 } // firePropertyChange()
422 public void firePropertyChange(String value0, byte value1, byte value2) {
424 } // firePropertyChange()
432 public void firePropertyChange(String value0, char value1, char value2) {
434 } // firePropertyChange()
442 public void firePropertyChange(String value0, short value1, short value2) {
444 } // firePropertyChange()
452 public void firePropertyChange(String value0, int value1, int value2) {
454 } // firePropertyChange()
462 public void firePropertyChange(String value0, long value1, long value2) {
464 } // firePropertyChange()
472 public void firePropertyChange(String value0, float value1, float value2) {
474 } // firePropertyChange()
482 public void firePropertyChange(String value0, double value1, double value2) {
484 } // firePropertyChange()
492 public void firePropertyChange(String value0, boolean value1, boolean value2) {
494 } // firePropertyChange()
497 } // DefaultTreeCellRenderer