OSDN Git Service

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