01 /*
02 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25 package javax.swing.tree;
26
27 import java.awt.Component;
28 import javax.swing.JTree;
29
30 /**
31 * Defines the requirements for an object that displays a tree node.
32 * See <a
33 href="http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html">How to Use Trees</a>
34 * in <em>The Java Tutorial</em>
35 * for an example of implementing a tree cell renderer
36 * that displays custom icons.
37 *
38 * @version 1.30 05/05/07
39 * @author Rob Davis
40 * @author Ray Ryan
41 * @author Scott Violet
42 */
43 public interface TreeCellRenderer {
44
45 /**
46 * Sets the value of the current tree cell to <code>value</code>.
47 * If <code>selected</code> is true, the cell will be drawn as if
48 * selected. If <code>expanded</code> is true the node is currently
49 * expanded and if <code>leaf</code> is true the node represents a
50 * leaf and if <code>hasFocus</code> is true the node currently has
51 * focus. <code>tree</code> is the <code>JTree</code> the receiver is being
52 * configured for. Returns the <code>Component</code> that the renderer
53 * uses to draw the value.
54 * <p>
55 * The <code>TreeCellRenderer</code> is also responsible for rendering the
56 * the cell representing the tree's current DnD drop location if
57 * it has one. If this renderer cares about rendering
58 * the DnD drop location, it should query the tree directly to
59 * see if the given row represents the drop location:
60 * <pre>
61 * JTree.DropLocation dropLocation = tree.getDropLocation();
62 * if (dropLocation != null
63 * && dropLocation.getChildIndex() == -1
64 * && tree.getRowForPath(dropLocation.getPath()) == row) {
65 *
66 * // this row represents the current drop location
67 * // so render it specially, perhaps with a different color
68 * }
69 * </pre>
70 *
71 * @return the <code>Component</code> that the renderer uses to draw the value
72 */
73 Component getTreeCellRendererComponent(JTree tree, Object value,
74 boolean selected, boolean expanded, boolean leaf, int row,
75 boolean hasFocus);
76
77 }
|