1/*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package javax.swing.tree;
26
27import java.awt.Component;
28import javax.swing.JTree;
29
30/**
31 * Defines the requirements for an object that displays a tree node.
32 * See <a
33 href="http://docs.oracle.com/javase/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 * @author Rob Davis
39 * @author Ray Ryan
40 * @author Scott Violet
41 */
42public interface TreeCellRenderer {
43
44    /**
45     * Sets the value of the current tree cell to <code>value</code>.
46     * If <code>selected</code> is true, the cell will be drawn as if
47     * selected. If <code>expanded</code> is true the node is currently
48     * expanded and if <code>leaf</code> is true the node represents a
49     * leaf and if <code>hasFocus</code> is true the node currently has
50     * focus. <code>tree</code> is the <code>JTree</code> the receiver is being
51     * configured for.  Returns the <code>Component</code> that the renderer
52     * uses to draw the value.
53     * <p>
54     * The <code>TreeCellRenderer</code> is also responsible for rendering the
55     * the cell representing the tree's current DnD drop location if
56     * it has one. If this renderer cares about rendering
57     * the DnD drop location, it should query the tree directly to
58     * see if the given row represents the drop location:
59     * <pre>
60     *     JTree.DropLocation dropLocation = tree.getDropLocation();
61     *     if (dropLocation != null
62     *             &amp;&amp; dropLocation.getChildIndex() == -1
63     *             &amp;&amp; tree.getRowForPath(dropLocation.getPath()) == row) {
64     *
65     *         // this row represents the current drop location
66     *         // so render it specially, perhaps with a different color
67     *     }
68     * </pre>
69     *
70     * @param tree      the receiver is being configured for
71     * @param value     the value to render
72     * @param selected  whether node is selected
73     * @param expanded  whether node is expanded
74     * @param leaf      whether node is a lead node
75     * @param row       row index
76     * @param hasFocus  whether node has focus
77     * @return          the {@code Component} that the renderer uses to draw the value
78     */
79    Component getTreeCellRendererComponent(JTree tree, Object value,
80                                   boolean selected, boolean expanded,
81                                   boolean leaf, int row, boolean hasFocus);
82
83}
84