Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / swing / tree / DefaultTreeModel.java
blob2e34a35223e0ef1bd18fc1a0741071da6bf99a3a
1 /* DefaultTreeModel.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package javax.swing.tree;
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;
47 import javax.swing.event.EventListenerList;
48 import javax.swing.event.TreeModelEvent;
49 import javax.swing.event.TreeModelListener;
51 /**
52 * DefaultTreeModel
53 * @author Andrew Selkirk
55 public class DefaultTreeModel
56 implements Serializable, TreeModel
58 static final long serialVersionUID = -2621068368932566998L;
60 /**
61 * root
63 protected TreeNode root = null;
65 /**
66 * listenerList
68 protected EventListenerList listenerList = new EventListenerList();
70 /**
71 * asksAllowsChildren
73 protected boolean asksAllowsChildren;
75 /**
76 * Constructor DefaultTreeModel
77 * @param value0 TODO
79 public DefaultTreeModel(TreeNode root)
81 setRoot(root);
84 /**
85 * Constructor DefaultTreeModel
86 * @param value0 TODO
87 * @param value1 TODO
89 public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
91 setRoot(root);
92 this.asksAllowsChildren = asksAllowsChildren;
95 /**
96 * writeObject
97 * @param value0 TODO
98 * @exception IOException TODO
100 private void writeObject(ObjectOutputStream value0) throws IOException
102 // TODO
106 * readObject
107 * @param value0 TODO
108 * @exception IOException TODO
109 * @exception ClassNotFoundException TODO
111 private void readObject(ObjectInputStream value0)
112 throws IOException, ClassNotFoundException
114 // TODO
118 * asksAllowsChildren
119 * @return boolean
121 public boolean asksAllowsChildren()
123 return asksAllowsChildren;
127 * setAsksAllowsChildren
128 * @param value0 TODO
130 public void setAsksAllowsChildren(boolean value)
132 asksAllowsChildren = value; // TODO
136 * setRoot
137 * @param value0 TODO
139 public void setRoot(TreeNode root)
141 // Sanity Check
142 if (root == null)
144 throw new IllegalArgumentException("null root");
146 // Set new root
147 this.root = root;
149 // TODO
153 * getRoot
154 * @return Object
156 public Object getRoot()
158 return root;
162 * getIndexOfChild
163 * @param value0 TODO
164 * @param value1 TODO
165 * @return int
167 public int getIndexOfChild(Object parent, Object child)
169 return 0; // TODO
173 * getChild
174 * @param value0 TODO
175 * @param value1 TODO
176 * @return Object
178 public Object getChild(Object node, int idx)
180 if (node instanceof TreeNode)
181 return ((TreeNode)node).getChildAt(idx);
182 else
183 return null;
187 * getChildCount
188 * @param value0 TODO
189 * @return int
191 public int getChildCount(Object node)
193 if (node instanceof TreeNode)
194 return ((TreeNode)node).getChildCount();
195 else
196 return 0;
200 * isLeaf
201 * @param value0 TODO
202 * @return boolean
204 public boolean isLeaf(Object node)
206 if (node instanceof TreeNode)
207 return ((TreeNode)node).isLeaf();
208 else
209 return true;
213 * reload
215 public void reload()
217 // TODO
221 * reload
222 * @param value0 TODO
224 public void reload(TreeNode value0)
226 // TODO
230 * valueForPathChanged
231 * @param value0 TODO
232 * @param value1 TODO
234 public void valueForPathChanged(TreePath value0, Object value1)
236 // TODO
240 * insertNodeInto
241 * @param value0 TODO
242 * @param value1 TODO
243 * @param value2 TODO
245 public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,
246 int value2)
248 // TODO
252 * removeNodeFromParent
253 * @param value0 TODO
255 public void removeNodeFromParent(MutableTreeNode value0)
257 // TODO
261 * nodeChanged
262 * @param value0 TODO
264 public void nodeChanged(TreeNode value0)
266 // TODO
270 * nodesWereInserted
271 * @param value0 TODO
272 * @param value1 TODO
274 public void nodesWereInserted(TreeNode value0, int[] value1)
276 // TODO
280 * nodesWereRemoved
281 * @param value0 TODO
282 * @param value1 TODO
283 * @param value2 TODO
285 public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)
287 // TODO
291 * nodesChanged
292 * @param value0 TODO
293 * @param value1 TODO
295 public void nodesChanged(TreeNode value0, int[] value1)
297 // TODO
301 * nodeStructureChanged
302 * @param value0 TODO
304 public void nodeStructureChanged(TreeNode value0)
306 // TODO
310 * getPathToRoot
311 * @param value0 TODO
312 * @return TreeNode[]
314 public TreeNode[] getPathToRoot(TreeNode value0)
316 return null; // TODO
320 * getPathToRoot
321 * @param value0 TODO
322 * @param value1 TODO
323 * @return TreeNode[]
325 protected TreeNode[] getPathToRoot(TreeNode value0, int value1)
327 return null; // TODO
331 * Registers a listere to the model.
333 * @param listener the listener to add
335 public void addTreeModelListener(TreeModelListener listener)
337 listenerList.add(TreeModelListener.class, listener);
341 * Removes a listener from the model.
343 * @param listener the listener to remove
345 public void removeTreeModelListener(TreeModelListener listener)
347 listenerList.remove(TreeModelListener.class, listener);
351 * Returns all registered <code>TreeModelListener</code> listeners.
353 * @return an array of listeners.
355 * @since 1.4
357 public TreeModelListener[] getTreeModelListeners()
359 return (TreeModelListener[]) listenerList.getListeners(TreeModelListener.class);
363 * fireTreeNodesChanged
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
370 protected void fireTreeNodesChanged(Object source, Object[] path,
371 int[] childIndices, Object[] children)
373 TreeModelEvent event =
374 new TreeModelEvent(source, path, childIndices, children);
375 TreeModelListener[] listeners = getTreeModelListeners();
377 for (int i = listeners.length - 1; i >= 0; --i)
378 listeners[i].treeNodesChanged(event);
382 * fireTreeNodesInserted
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
389 protected void fireTreeNodesInserted(Object source, Object[] path,
390 int[] childIndices, Object[] children)
392 TreeModelEvent event =
393 new TreeModelEvent(source, path, childIndices, children);
394 TreeModelListener[] listeners = getTreeModelListeners();
396 for (int i = listeners.length - 1; i >= 0; --i)
397 listeners[i].treeNodesInserted(event);
401 * fireTreeNodesRemoved
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
408 protected void fireTreeNodesRemoved(Object source, Object[] path,
409 int[] childIndices, Object[] children)
411 TreeModelEvent event =
412 new TreeModelEvent(source, path, childIndices, children);
413 TreeModelListener[] listeners = getTreeModelListeners();
415 for (int i = listeners.length - 1; i >= 0; --i)
416 listeners[i].treeNodesRemoved(event);
420 * fireTreeStructureChanged
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
427 protected void fireTreeStructureChanged(Object source, Object[] path,
428 int[] childIndices, Object[] children)
430 TreeModelEvent event =
431 new TreeModelEvent(source, path, childIndices, children);
432 TreeModelListener[] listeners = getTreeModelListeners();
434 for (int i = listeners.length - 1; i >= 0; --i)
435 listeners[i].treeStructureChanged(event);
439 * Returns the registered listeners of a given type.
441 * @param listenerType the listener type to return
443 * @return an array of listeners
445 * @since 1.3
447 public EventListener[] getListeners(Class listenerType)
449 return listenerList.getListeners(listenerType);