/[classpath]/classpath/javax/swing/tree/DefaultTreeModel.java
ViewVC logotype

Diff of /classpath/javax/swing/tree/DefaultTreeModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3.2.3 by gnu_andrew, Tue Aug 2 20:12:39 2005 UTC revision 1.3.2.4 by gnu_andrew, Tue Aug 16 16:22:38 2005 UTC
# Line 1  Line 1 
1  /* DefaultTreeModel.java --  /* DefaultTreeModel.java --
2     Copyright (C) 2002, 2004  Free Software Foundation, Inc.     Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
6  GNU Classpath is free software; you can redistribute it and/or modify  GNU Classpath is free software; you can redistribute it and/or modify
# Line 10  any later version. Line 10  any later version.
10    
11  GNU Classpath is distributed in the hope that it will be useful, but  GNU Classpath is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.  General Public License for more details.
15    
16  You should have received a copy of the GNU General Public License  You should have received a copy of the GNU General Public License
17  along with GNU Classpath; see the file COPYING.  If not, write to the  along with GNU Classpath; see the file COPYING. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA.  02110-1301 USA.
20    
21  Linking this library statically or dynamically with other modules is  Linking this library statically or dynamically with other modules is
22  making a combined work based on this library.  Thus, the terms and  making a combined work based on this library. Thus, the terms and
23  conditions of the GNU General Public License cover the whole  conditions of the GNU General Public License cover the whole
24  combination.  combination.
25    
# Line 29  executable, regardless of the license te Line 29  executable, regardless of the license te
29  modules, and to copy and distribute the resulting executable under  modules, and to copy and distribute the resulting executable under
30  terms of your choice, provided that you also meet, for each linked  terms of your choice, provided that you also meet, for each linked
31  independent module, the terms and conditions of the license of that  independent module, the terms and conditions of the license of that
32  module.  An independent module is a module which is not derived from  module. An independent module is a module which is not derived from
33  or based on this library.  If you modify this library, you may extend  or based on this library. If you modify this library, you may extend
34  this exception to your version of the library, but you are not  this exception to your version of the library, but you are not
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so. If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
   
38  package javax.swing.tree;  package javax.swing.tree;
39    
40  import java.io.IOException;  import java.io.IOException;
# Line 51  import javax.swing.tree.DefaultMutableTr Line 50  import javax.swing.tree.DefaultMutableTr
50    
51  /**  /**
52   * DefaultTreeModel   * DefaultTreeModel
53     *
54   * @author Andrew Selkirk   * @author Andrew Selkirk
55   */   */
56  public class DefaultTreeModel  public class DefaultTreeModel
57                  implements Serializable, TreeModel      implements Serializable, TreeModel
58  {  {
59          static final long serialVersionUID = -2621068368932566998L;    static final long serialVersionUID = -2621068368932566998L;
60    
61          /**    /**
62           * root     * root
63           */     */
64          protected TreeNode root = null;    protected TreeNode root = null;
65    
66          /**    /**
67           * listenerList     * listenerList
68           */     */
69          protected EventListenerList listenerList = new EventListenerList();    protected EventListenerList listenerList = new EventListenerList();
70    
71          /**    /**
72           * asksAllowsChildren     * asksAllowsChildren
73           */     */
74          protected boolean asksAllowsChildren;    protected boolean asksAllowsChildren;
75    
76          /**    /**
77           * Constructor DefaultTreeModel     * Constructor DefaultTreeModel
78           * @param root the tree root.     *
79           */     * @param root the tree root.
80          public DefaultTreeModel(TreeNode root)     */
81          {    public DefaultTreeModel(TreeNode root)
82                  if (root == null)    {
83                          root = new DefaultMutableTreeNode();      if (root == null)
84                  setRoot(root);        root = new DefaultMutableTreeNode();
85          }      setRoot(root);
86      }
87          /**  
88           * Constructor DefaultTreeModel    /**
89           * @param root the tree root.     * Constructor DefaultTreeModel
90           * @param asksAllowsChildren TODO     *
91           */     * @param root the tree root.
92          public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)     * @param asksAllowsChildren TODO
93          {     */
94                  setRoot(root);    public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
95                  this.asksAllowsChildren = asksAllowsChildren;    {
96          }      setRoot(root);
97        this.asksAllowsChildren = asksAllowsChildren;
98          /**    }
99           * writeObject  
100           * @param obj the object.    /**
101           * @exception IOException TODO     * writeObject
102           */     *
103          private void writeObject(ObjectOutputStream obj) throws IOException     * @param obj the object.
104          {     * @exception IOException TODO
105                  // TODO     */
106          }    private void writeObject(ObjectOutputStream obj) throws IOException
107      {
108          /**      // TODO
109           * readObject    }
110           * @param value0 TODO  
111           * @exception IOException TODO    /**
112           * @exception ClassNotFoundException TODO     * readObject
113           */     *
114          private void readObject(ObjectInputStream value0) throws IOException,     * @param value0 TODO
115                          ClassNotFoundException     * @exception IOException TODO
116          {     * @exception ClassNotFoundException TODO
117                  // TODO     */
118          }    private void readObject(ObjectInputStream value0) throws IOException,
119          ClassNotFoundException
120          /**    {
121           * asksAllowsChildren      // TODO
122           * @return boolean    }
123           */  
124          public boolean asksAllowsChildren()    /**
125          {     * asksAllowsChildren
126                  return asksAllowsChildren;     *
127          }     * @return boolean
128       */
129          /**    public boolean asksAllowsChildren()
130           * setAsksAllowsChildren    {
131           * @param value TODO      return asksAllowsChildren;
132           */    }
133          public void setAsksAllowsChildren(boolean value)  
134          {    /**
135                  asksAllowsChildren = value; // TODO     * setAsksAllowsChildren
136          }     *
137       * @param value TODO
138          /**     */
139           * setRoot    public void setAsksAllowsChildren(boolean value)
140           * @param root the root node.    {
141           */      asksAllowsChildren = value; // TODO
142          public void setRoot(TreeNode root)    }
143          {  
144                  // Sanity Check    /**
145                  if (root == null)     * setRoot
146                  {     *
147                          throw new IllegalArgumentException("null root");     * @param root the root node.
148                  }     */
149                  // Set new root    public void setRoot(TreeNode root)
150                  this.root = root;    {
151        // Sanity Check
152                  // TODO      if (root == null)
153          }      {
154          throw new IllegalArgumentException("null root");
155          /**      }
156           * getRoot      // Set new root
157           * @return Object      this.root = root;
158           */  
159          public Object getRoot()      // TODO
160          {    }
161                  return root;  
162          }    /**
163       * getRoot
164          /**     *
165           * getIndexOfChild     * @return Object
166           * @param parent TODO     */
167           * @param child TODO    public Object getRoot()
168           * @return int    {
169           */      return root;
170          public int getIndexOfChild(Object parent, Object child)    }
171          {  
172                  return 0; // TODO    /**
173          }     * getIndexOfChild
174       *
175          /**     * @param parent TODO
176           * getChild     * @param child TODO
177           * @param node TODO     * @return int
178           * @param idx TODO     */
179           * @return Object    public int getIndexOfChild(Object parent, Object child)
180           */    {
181          public Object getChild(Object node, int idx)      for (int i = 0; i < getChildCount(parent); i++)
182          {      {
183                  if (node instanceof TreeNode)        if (getChild(parent, i).equals(child))
184                          return ((TreeNode) node).getChildAt(idx);          return i;
185                  else      }
186                          return null;      return -1;
187          }    }
188    
189          /**    /**
190           * getChildCount     * getChild
191           * @param node TODO     *
192           * @return int     * @param node TODO
193           */     * @param idx TODO
194          public int getChildCount(Object node)     * @return Object
195          {     */
196                  if (node instanceof TreeNode)    public Object getChild(Object node, int idx)
197                          return ((TreeNode) node).getChildCount();    {
198                  else      if (node instanceof TreeNode)
199                          return 0;        return ((TreeNode) node).getChildAt(idx);
200          }      else
201          return null;
202          /**    }
203           * isLeaf  
204           * @param node TODO    /**
205           * @return boolean     * getChildCount
206           */     *
207          public boolean isLeaf(Object node)     * @param node TODO
208          {     * @return int
209                  if (node instanceof TreeNode)     */
210                          return ((TreeNode) node).isLeaf();    public int getChildCount(Object node)
211                  else    {
212                          return true;      if (node instanceof TreeNode)
213          }        return ((TreeNode) node).getChildCount();
214        else
215          /**        return 0;
216           * reload    }
217           */  
218          public void reload()    /**
219          {     * isLeaf
220                  // TODO     *
221          }     * @param node TODO
222       * @return boolean
223          /**     */
224           * reload    public boolean isLeaf(Object node)
225           * @param value0 TODO    {
226           */      if (node instanceof TreeNode)
227          public void reload(TreeNode value0)        return ((TreeNode) node).isLeaf();
228          {      else
229                  // TODO        return true;
230          }    }
231    
232          /**    /**
233           * valueForPathChanged     * reload
234           * @param value0 TODO     */
235           * @param value1 TODO    public void reload()
236           */    {
237          public void valueForPathChanged(TreePath value0, Object value1)      // TODO
238          {    }
239                  // TODO  
240          }    /**
241       * reload
242          /**     *
243           * insertNodeInto     * @param value0 TODO
244           * @param value0 TODO     */
245           * @param value1 TODO    public void reload(TreeNode value0)
246           * @param value2 TODO    {
247           */      // TODO
248          public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,    }
249                          int value2)  
250          {    /**
251                  // TODO     * valueForPathChanged
252          }     *
253       * @param value0 TODO
254          /**     * @param value1 TODO
255           * removeNodeFromParent     */
256           * @param value0 TODO    public void valueForPathChanged(TreePath value0, Object value1)
257           */    {
258          public void removeNodeFromParent(MutableTreeNode value0)      // TODO
259          {    }
260                  // TODO  
261          }    /**
262       * insertNodeInto
263          /**     *
264           * nodeChanged     * @param value0 TODO
265           * @param value0 TODO     * @param value1 TODO
266           */     * @param value2 TODO
267          public void nodeChanged(TreeNode value0)     */
268          {    public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,
269                  // TODO        int value2)
270          }    {
271        // TODO
272          /**    }
273           * nodesWereInserted  
274           * @param value0 TODO    /**
275           * @param value1 TODO     * removeNodeFromParent
276           */     *
277          public void nodesWereInserted(TreeNode value0, int[] value1)     * @param value0 TODO
278          {     */
279                  // TODO    public void removeNodeFromParent(MutableTreeNode value0)
280          }    {
281        // TODO
282          /**    }
283           * nodesWereRemoved  
284           * @param value0 TODO    /**
285           * @param value1 TODO     * nodeChanged
286           * @param value2 TODO     *
287           */     * @param value0 TODO
288          public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)     */
289          {    public void nodeChanged(TreeNode value0)
290                  // TODO    {
291          }      // TODO
292      }
293          /**  
294           * nodesChanged    /**
295           * @param value0 TODO     * nodesWereInserted
296           * @param value1 TODO     *
297           */     * @param value0 TODO
298          public void nodesChanged(TreeNode value0, int[] value1)     * @param value1 TODO
299          {     */
300                  // TODO    public void nodesWereInserted(TreeNode value0, int[] value1)
301          }    {
302        // TODO
303          /**    }
304           * nodeStructureChanged  
305           * @param value0 TODO    /**
306           */     * nodesWereRemoved
307          public void nodeStructureChanged(TreeNode value0)     *
308          {     * @param value0 TODO
309                  // TODO     * @param value1 TODO
310          }     * @param value2 TODO
311       */
312          /**    public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)
313           * getPathToRoot    {
314           * @param value0 TODO      // TODO
315           * @return TreeNode[]    }
316           */  
317          public TreeNode[] getPathToRoot(TreeNode value0)    /**
318          {     * nodesChanged
319                  return null; // TODO     *
320          }     * @param value0 TODO
321       * @param value1 TODO
322          /**     */
323           * getPathToRoot    public void nodesChanged(TreeNode value0, int[] value1)
324           * @param value0 TODO    {
325           * @param value1 TODO      // TODO
326           * @return TreeNode[]    }
327           */  
328          protected TreeNode[] getPathToRoot(TreeNode value0, int value1)    /**
329          {     * nodeStructureChanged
330                  return null; // TODO     *
331          }     * @param value0 TODO
332       */
333          /**    public void nodeStructureChanged(TreeNode value0)
334           * Registers a listere to the model.    {
335           *      // TODO
336           * @param listener the listener to add    }
337           */  
338          public void addTreeModelListener(TreeModelListener listener)    /**
339          {     * getPathToRoot
340                  listenerList.add(TreeModelListener.class, listener);     *
341          }     * @param value0 TODO
342       * @return TreeNode[]
343          /**     */
344           * Removes a listener from the model.    public TreeNode[] getPathToRoot(TreeNode value0)
345           *    {
346           * @param listener the listener to remove      return null; // TODO
347           */    }
348          public void removeTreeModelListener(TreeModelListener listener)  
349          {    /**
350                  listenerList.remove(TreeModelListener.class, listener);     * getPathToRoot
351          }     *
352       * @param value0 TODO
353          /**     * @param value1 TODO
354           * Returns all registered <code>TreeModelListener</code> listeners.     * @return TreeNode[]
355           *     */
356           * @return an array of listeners.    protected TreeNode[] getPathToRoot(TreeNode value0, int value1)
357           *    {
358           * @since 1.4      return null; // TODO
359           */    }
360          public TreeModelListener[] getTreeModelListeners()  
361          {    /**
362                  return (TreeModelListener[]) listenerList     * Registers a listere to the model.
363                                  .getListeners(TreeModelListener.class);     *
364          }     * @param listener the listener to add
365       */
366          /**    public void addTreeModelListener(TreeModelListener listener)
367           * fireTreeNodesChanged    {
368           *      listenerList.add(TreeModelListener.class, listener);
369           * @param source the node being changed    }
370           * @param path the path to the root node  
371           * @param childIndices the indices of the changed elements    /**
372           * @param children the changed elements     * Removes a listener from the model.
373           */     *
374          protected void fireTreeNodesChanged(Object source, Object[] path,     * @param listener the listener to remove
375                          int[] childIndices, Object[] children)     */
376          {    public void removeTreeModelListener(TreeModelListener listener)
377                  TreeModelEvent event = new TreeModelEvent(source, path, childIndices,    {
378                                  children);      listenerList.remove(TreeModelListener.class, listener);
379                  TreeModelListener[] listeners = getTreeModelListeners();    }
380    
381                  for (int i = listeners.length - 1; i >= 0; --i)    /**
382                          listeners[i].treeNodesChanged(event);     * Returns all registered <code>TreeModelListener</code> listeners.
383          }     *
384       * @return an array of listeners.
385          /**     *
386           * fireTreeNodesInserted     * @since 1.4
387           *     */
388           * @param source the node where new nodes got inserted    public TreeModelListener[] getTreeModelListeners()
389           * @param path the path to the root node    {
390           * @param childIndices the indices of the new elements      return (TreeModelListener[]) listenerList
391           * @param children the new elements          .getListeners(TreeModelListener.class);
392           */    }
393          protected void fireTreeNodesInserted(Object source, Object[] path,  
394                          int[] childIndices, Object[] children)    /**
395          {     * fireTreeNodesChanged
396                  TreeModelEvent event = new TreeModelEvent(source, path, childIndices,     *
397                                  children);     * @param source the node being changed
398                  TreeModelListener[] listeners = getTreeModelListeners();     * @param path the path to the root node
399       * @param childIndices the indices of the changed elements
400                  for (int i = listeners.length - 1; i >= 0; --i)     * @param children the changed elements
401                          listeners[i].treeNodesInserted(event);     */
402          }    protected void fireTreeNodesChanged(Object source, Object[] path,
403          int[] childIndices, Object[] children)
404          /**    {
405           * fireTreeNodesRemoved      TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
406           *          children);
407           * @param source the node where nodes got removed-      TreeModelListener[] listeners = getTreeModelListeners();
408           * @param path the path to the root node  
409           * @param childIndices the indices of the removed elements      for (int i = listeners.length - 1; i >= 0; --i)
410           * @param children the removed elements        listeners[i].treeNodesChanged(event);
411           */    }
412          protected void fireTreeNodesRemoved(Object source, Object[] path,  
413                          int[] childIndices, Object[] children)    /**
414          {     * fireTreeNodesInserted
415                  TreeModelEvent event = new TreeModelEvent(source, path, childIndices,     *
416                                  children);     * @param source the node where new nodes got inserted
417                  TreeModelListener[] listeners = getTreeModelListeners();     * @param path the path to the root node
418       * @param childIndices the indices of the new elements
419                  for (int i = listeners.length - 1; i >= 0; --i)     * @param children the new elements
420                          listeners[i].treeNodesRemoved(event);     */
421          }    protected void fireTreeNodesInserted(Object source, Object[] path,
422          int[] childIndices, Object[] children)
423          /**    {
424           * fireTreeStructureChanged      TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
425           *          children);
426           * @param source the node where the model has changed      TreeModelListener[] listeners = getTreeModelListeners();
427           * @param path the path to the root node  
428           * @param childIndices the indices of the affected elements      for (int i = listeners.length - 1; i >= 0; --i)
429           * @param children the affected elements        listeners[i].treeNodesInserted(event);
430           */    }
431          protected void fireTreeStructureChanged(Object source, Object[] path,  
432                          int[] childIndices, Object[] children)    /**
433          {     * fireTreeNodesRemoved
434                  TreeModelEvent event = new TreeModelEvent(source, path, childIndices,     *
435                                  children);     * @param source the node where nodes got removed-
436                  TreeModelListener[] listeners = getTreeModelListeners();     * @param path the path to the root node
437       * @param childIndices the indices of the removed elements
438                  for (int i = listeners.length - 1; i >= 0; --i)     * @param children the removed elements
439                          listeners[i].treeStructureChanged(event);     */
440          }    protected void fireTreeNodesRemoved(Object source, Object[] path,
441          int[] childIndices, Object[] children)
442          /**    {
443           * Returns the registered listeners of a given type.      TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
444           *          children);
445           * @param listenerType the listener type to return      TreeModelListener[] listeners = getTreeModelListeners();
446           *  
447           * @return an array of listeners      for (int i = listeners.length - 1; i >= 0; --i)
448           *        listeners[i].treeNodesRemoved(event);
449           * @since 1.3    }
450           */  
451          public EventListener[] getListeners(Class listenerType)    /**
452          {     * fireTreeStructureChanged
453                  return listenerList.getListeners(listenerType);     *
454          }     * @param source the node where the model has changed
455       * @param path the path to the root node
456       * @param childIndices the indices of the affected elements
457       * @param children the affected elements
458       */
459      protected void fireTreeStructureChanged(Object source, Object[] path,
460          int[] childIndices, Object[] children)
461      {
462        TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
463            children);
464        TreeModelListener[] listeners = getTreeModelListeners();
465    
466        for (int i = listeners.length - 1; i >= 0; --i)
467          listeners[i].treeStructureChanged(event);
468      }
469    
470      /**
471       * Returns the registered listeners of a given type.
472       *
473       * @param listenerType the listener type to return
474       *
475       * @return an array of listeners
476       *
477       * @since 1.3
478       */
479      public EventListener[] getListeners(Class listenerType)
480      {
481        return listenerList.getListeners(listenerType);
482      }
483  }  }

Legend:
Removed from v.1.3.2.3  
changed lines
  Added in v.1.3.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26