0N/A/*
2362N/A * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing.tree;
0N/A
0N/Aimport javax.swing.event.*;
0N/A
0N/A/**
0N/A * The model used by <code>JTree</code>.
0N/A * <p>
0N/A * <code>JTree</code> and its related classes make extensive use of
0N/A * <code>TreePath</code>s for indentifying nodes in the <code>TreeModel</code>.
0N/A * If a <code>TreeModel</code> returns the same object, as compared by
0N/A * <code>equals</code>, at two different indices under the same parent
0N/A * than the resulting <code>TreePath</code> objects will be considered equal
0N/A * as well. Some implementations may assume that if two
0N/A * <code>TreePath</code>s are equal, they identify the same node. If this
0N/A * condition is not met, painting problems and other oddities may result.
0N/A * In other words, if <code>getChild</code> for a given parent returns
0N/A * the same Object (as determined by <code>equals</code>) problems may
0N/A * result, and it is recommended you avoid doing this.
0N/A * <p>
0N/A * Similarly <code>JTree</code> and its related classes place
0N/A * <code>TreePath</code>s in <code>Map</code>s. As such if
0N/A * a node is requested twice, the return values must be equal
0N/A * (using the <code>equals</code> method) and have the same
0N/A * <code>hashCode</code>.
0N/A * <p>
0N/A * For further information on tree models,
0N/A * including an example of a custom implementation,
0N/A * see <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html">How to Use Trees</a>
0N/A * in <em>The Java Tutorial.</em>
0N/A *
0N/A * @see TreePath
0N/A *
0N/A * @author Rob Davis
0N/A * @author Ray Ryan
0N/A */
0N/Apublic interface TreeModel
0N/A{
0N/A
0N/A /**
0N/A * Returns the root of the tree. Returns <code>null</code>
0N/A * only if the tree has no nodes.
0N/A *
0N/A * @return the root of the tree
0N/A */
0N/A public Object getRoot();
0N/A
0N/A
0N/A /**
0N/A * Returns the child of <code>parent</code> at index <code>index</code>
0N/A * in the parent's
0N/A * child array. <code>parent</code> must be a node previously obtained
0N/A * from this data source. This should not return <code>null</code>
0N/A * if <code>index</code>
0N/A * is a valid index for <code>parent</code> (that is <code>index >= 0 &&
0N/A * index < getChildCount(parent</code>)).
0N/A *
0N/A * @param parent a node in the tree, obtained from this data source
0N/A * @return the child of <code>parent</code> at index <code>index</code>
0N/A */
0N/A public Object getChild(Object parent, int index);
0N/A
0N/A
0N/A /**
0N/A * Returns the number of children of <code>parent</code>.
0N/A * Returns 0 if the node
0N/A * is a leaf or if it has no children. <code>parent</code> must be a node
0N/A * previously obtained from this data source.
0N/A *
0N/A * @param parent a node in the tree, obtained from this data source
0N/A * @return the number of children of the node <code>parent</code>
0N/A */
0N/A public int getChildCount(Object parent);
0N/A
0N/A
0N/A /**
0N/A * Returns <code>true</code> if <code>node</code> is a leaf.
0N/A * It is possible for this method to return <code>false</code>
0N/A * even if <code>node</code> has no children.
0N/A * A directory in a filesystem, for example,
0N/A * may contain no files; the node representing
0N/A * the directory is not a leaf, but it also has no children.
0N/A *
0N/A * @param node a node in the tree, obtained from this data source
0N/A * @return true if <code>node</code> is a leaf
0N/A */
0N/A public boolean isLeaf(Object node);
0N/A
0N/A /**
0N/A * Messaged when the user has altered the value for the item identified
0N/A * by <code>path</code> to <code>newValue</code>.
0N/A * If <code>newValue</code> signifies a truly new value
0N/A * the model should post a <code>treeNodesChanged</code> event.
0N/A *
0N/A * @param path path to the node that the user has altered
0N/A * @param newValue the new value from the TreeCellEditor
0N/A */
0N/A public void valueForPathChanged(TreePath path, Object newValue);
0N/A
0N/A /**
0N/A * Returns the index of child in parent. If either <code>parent</code>
0N/A * or <code>child</code> is <code>null</code>, returns -1.
0N/A * If either <code>parent</code> or <code>child</code> don't
0N/A * belong to this tree model, returns -1.
0N/A *
0N/A * @param parent a node in the tree, obtained from this data source
0N/A * @param child the node we are interested in
0N/A * @return the index of the child in the parent, or -1 if either
0N/A * <code>child</code> or <code>parent</code> are <code>null</code>
0N/A * or don't belong to this tree model
0N/A */
0N/A public int getIndexOfChild(Object parent, Object child);
0N/A
0N/A//
0N/A// Change Events
0N/A//
0N/A
0N/A /**
0N/A * Adds a listener for the <code>TreeModelEvent</code>
0N/A * posted after the tree changes.
0N/A *
0N/A * @param l the listener to add
0N/A * @see #removeTreeModelListener
0N/A */
0N/A void addTreeModelListener(TreeModelListener l);
0N/A
0N/A /**
0N/A * Removes a listener previously added with
0N/A * <code>addTreeModelListener</code>.
0N/A *
0N/A * @see #addTreeModelListener
0N/A * @param l the listener to remove
0N/A */
0N/A void removeTreeModelListener(TreeModelListener l);
0N/A
0N/A}