home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / TreeModel.java < prev    next >
Text File  |  1998-11-09  |  4KB  |  113 lines

  1. /*
  2.  * @(#)TreeModel.java    1.10 98/01/11
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package javax.awt.swing.tree;
  21.  
  22. import javax.awt.swing.event.TreeModelListener;
  23.  
  24. /**
  25.  * The interface that defines a suitable data model for a JTree. 
  26.  * 
  27.  * @version 1.10 01/11/98
  28.  * @author Rob Davis
  29.  * @author Ray Ryan
  30.  */
  31. public interface TreeModel
  32. {
  33.  
  34.     /**
  35.      * Returns the root of the tree.  Returns null only if the tree has
  36.      * no nodes.
  37.      *
  38.      * @return  the root of the tree
  39.      */
  40.     public Object getRoot();
  41.  
  42.  
  43.     /**
  44.      * Returns the child of <I>parent</I> at index <I>index</I> in the parent's
  45.      * child array.  <I>parent</I> must be a node previously obtained from
  46.      * this data source.
  47.      *
  48.      * @param   parent  a node in the tree, obtained from this data source
  49.      * @return  the child of <I>parent</I> at index <I>index</I>
  50.      */
  51.     public Object getChild(Object parent, int index);
  52.  
  53.  
  54.     /**
  55.      * Returns the number of children of <I>parent</I>.  Returns 0 if the node
  56.      * is a leaf or if it has no children.  <I>parent</I> must be a node
  57.      * previously obtained from this data source.
  58.      *
  59.      * @param   parent  a node in the tree, obtained from this data source
  60.      * @return  the number of children of the node <I>parent</I>
  61.      */
  62.     public int getChildCount(Object parent);
  63.  
  64.  
  65.     /**
  66.      * Returns true if <I>node</I> is a leaf.  It is possible for this method
  67.      * to return false even if <I>node</I> has no children.  A directory in a
  68.      * filesystem, for example, may contain no files; the node representing
  69.      * the directory is not a leaf, but it also has no children.
  70.      *
  71.      * @param   node    a node in the tree, obtained from this data source
  72.      * @return  true if <I>node</I> is a leaf
  73.      */
  74.     public boolean isLeaf(Object node);
  75.  
  76.     /**
  77.       * Messaged when the user has altered the value for the item identified
  78.       * by <I>path</I> to <I>newValue</I>.  If <I>newValue</I> signifies
  79.       * a truly new value the model should post a treeNodesChanged
  80.       * event.
  81.       *
  82.       * @param path path to the node that the user has altered.
  83.       * @param newValue the new value from the TreeCellEditor.
  84.       */
  85.     public void valueForPathChanged(TreePath path, Object newValue);
  86.  
  87.     /**
  88.      * Returns the index of child in parent.
  89.      */
  90.     public int getIndexOfChild(Object parent, Object child);
  91.  
  92. //
  93. //  Change Events
  94. //
  95.  
  96.     /**
  97.      * Adds a listener for the TreeModelEvent posted after the tree changes.
  98.      *
  99.      * @see     #removeTreeModelListener
  100.      * @param   l       the listener to add
  101.      */
  102.     void addTreeModelListener(TreeModelListener l);
  103.  
  104.     /**
  105.      * Removes a listener previously added with <B>addTreeModelListener()</B>.
  106.      *
  107.      * @see     #addTreeModelListener
  108.      * @param   l       the listener to remove
  109.      */  
  110.     void removeTreeModelListener(TreeModelListener l);
  111.  
  112. }
  113.