jdk/src/java.desktop/share/classes/javax/swing/tree/TreeModel.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 24495 jdk/src/share/classes/javax/swing/tree/TreeModel.java@a5c854a00679
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The model used by <code>JTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <code>JTree</code> and its related classes make extensive use of
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20455
diff changeset
    33
 * <code>TreePath</code>s for identifying nodes in the <code>TreeModel</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * If a <code>TreeModel</code> returns the same object, as compared by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>equals</code>, at two different indices under the same parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * than the resulting <code>TreePath</code> objects will be considered equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * as well. Some implementations may assume that if two
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>TreePath</code>s are equal, they identify the same node. If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * condition is not met, painting problems and other oddities may result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * In other words, if <code>getChild</code> for a given parent returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * the same Object (as determined by <code>equals</code>) problems may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * result, and it is recommended you avoid doing this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Similarly <code>JTree</code> and its related classes place
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>TreePath</code>s in <code>Map</code>s.  As such if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a node is requested twice, the return values must be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * (using the <code>equals</code> method) and have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>hashCode</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * For further information on tree models,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * including an example of a custom implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * see <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    53
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see TreePath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Rob Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Ray Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public interface TreeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Returns the root of the tree.  Returns <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * only if the tree has no nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @return  the root of the tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public Object getRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Returns the child of <code>parent</code> at index <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * in the parent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * child array.  <code>parent</code> must be a node previously obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * from this data source. This should not return <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * if <code>index</code>
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    79
     * is a valid index for <code>parent</code> (that is <code>index &gt;= 0 &amp;&amp;
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    80
     * index &lt; getChildCount(parent</code>)).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
24495
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 23010
diff changeset
    82
     * @param parent    a node in the tree, obtained from this data source
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 23010
diff changeset
    83
     * @param index     index of child to be returned
a5c854a00679 8042089: Fix doclint warnings from javax.swing.tree and javax.swing.undo packages
yan
parents: 23010
diff changeset
    84
     * @return          the child of {@code parent} at index {@code index}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public Object getChild(Object parent, int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Returns the number of children of <code>parent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Returns 0 if the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * is a leaf or if it has no children.  <code>parent</code> must be a node
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * previously obtained from this data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param   parent  a node in the tree, obtained from this data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @return  the number of children of the node <code>parent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public int getChildCount(Object parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Returns <code>true</code> if <code>node</code> is a leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * It is possible for this method to return <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * even if <code>node</code> has no children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * A directory in a filesystem, for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * may contain no files; the node representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * the directory is not a leaf, but it also has no children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param   node  a node in the tree, obtained from this data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return  true if <code>node</code> is a leaf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public boolean isLeaf(Object node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      * Messaged when the user has altered the value for the item identified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      * by <code>path</code> to <code>newValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      * If <code>newValue</code> signifies a truly new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      * the model should post a <code>treeNodesChanged</code> event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      * @param path path to the node that the user has altered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      * @param newValue the new value from the TreeCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void valueForPathChanged(TreePath path, Object newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Returns the index of child in parent.  If either <code>parent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * or <code>child</code> is <code>null</code>, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * If either <code>parent</code> or <code>child</code> don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * belong to this tree model, returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param parent a node in the tree, obtained from this data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param child the node we are interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the index of the child in the parent, or -1 if either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *    <code>child</code> or <code>parent</code> are <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *    or don't belong to this tree model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public int getIndexOfChild(Object parent, Object child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
//  Change Events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Adds a listener for the <code>TreeModelEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * posted after the tree changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param   l       the listener to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see     #removeTreeModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    void addTreeModelListener(TreeModelListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Removes a listener previously added with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <code>addTreeModelListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see     #addTreeModelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param   l       the listener to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void removeTreeModelListener(TreeModelListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}