GNU Classpath (0.17) | ||
Frames | No Frames |
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., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 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: import javax.swing.tree.DefaultMutableTreeNode; 51: 52: /** 53: * DefaultTreeModel 54: * @author Andrew Selkirk 55: */ 56: public class DefaultTreeModel 57: implements Serializable, TreeModel 58: { 59: static final long serialVersionUID = -2621068368932566998L; 60: 61: /** 62: * root 63: */ 64: protected TreeNode root = null; 65: 66: /** 67: * listenerList 68: */ 69: protected EventListenerList listenerList = new EventListenerList(); 70: 71: /** 72: * asksAllowsChildren 73: */ 74: protected boolean asksAllowsChildren; 75: 76: /** 77: * Constructor DefaultTreeModel 78: * @param value0 TODO 79: */ 80: public DefaultTreeModel(TreeNode root) 81: { 82: if (root == null) 83: root = new DefaultMutableTreeNode(); 84: setRoot(root); 85: } 86: 87: /** 88: * Constructor DefaultTreeModel 89: * @param value0 TODO 90: * @param value1 TODO 91: */ 92: public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) 93: { 94: setRoot(root); 95: this.asksAllowsChildren = asksAllowsChildren; 96: } 97: 98: /** 99: * writeObject 100: * @param value0 TODO 101: * @exception IOException TODO 102: */ 103: private void writeObject(ObjectOutputStream value0) throws IOException 104: { 105: // TODO 106: } 107: 108: /** 109: * readObject 110: * @param value0 TODO 111: * @exception IOException TODO 112: * @exception ClassNotFoundException TODO 113: */ 114: private void readObject(ObjectInputStream value0) throws IOException, 115: ClassNotFoundException 116: { 117: // TODO 118: } 119: 120: /** 121: * asksAllowsChildren 122: * @return boolean 123: */ 124: public boolean asksAllowsChildren() 125: { 126: return asksAllowsChildren; 127: } 128: 129: /** 130: * setAsksAllowsChildren 131: * @param value0 TODO 132: */ 133: public void setAsksAllowsChildren(boolean value) 134: { 135: asksAllowsChildren = value; // TODO 136: } 137: 138: /** 139: * setRoot 140: * @param value0 TODO 141: */ 142: public void setRoot(TreeNode root) 143: { 144: // Sanity Check 145: if (root == null) 146: { 147: throw new IllegalArgumentException("null root"); 148: } 149: // Set new root 150: this.root = root; 151: 152: // TODO 153: } 154: 155: /** 156: * getRoot 157: * @return Object 158: */ 159: public Object getRoot() 160: { 161: return root; 162: } 163: 164: /** 165: * getIndexOfChild 166: * @param value0 TODO 167: * @param value1 TODO 168: * @return int 169: */ 170: public int getIndexOfChild(Object parent, Object child) 171: { 172: return 0; // TODO 173: } 174: 175: /** 176: * getChild 177: * @param value0 TODO 178: * @param value1 TODO 179: * @return Object 180: */ 181: public Object getChild(Object node, int idx) 182: { 183: if (node instanceof TreeNode) 184: return ((TreeNode) node).getChildAt(idx); 185: else 186: return null; 187: } 188: 189: /** 190: * getChildCount 191: * @param value0 TODO 192: * @return int 193: */ 194: public int getChildCount(Object node) 195: { 196: if (node instanceof TreeNode) 197: return ((TreeNode) node).getChildCount(); 198: else 199: return 0; 200: } 201: 202: /** 203: * isLeaf 204: * @param value0 TODO 205: * @return boolean 206: */ 207: public boolean isLeaf(Object node) 208: { 209: if (node instanceof TreeNode) 210: return ((TreeNode) node).isLeaf(); 211: else 212: return true; 213: } 214: 215: /** 216: * reload 217: */ 218: public void reload() 219: { 220: // TODO 221: } 222: 223: /** 224: * reload 225: * @param value0 TODO 226: */ 227: public void reload(TreeNode value0) 228: { 229: // TODO 230: } 231: 232: /** 233: * valueForPathChanged 234: * @param value0 TODO 235: * @param value1 TODO 236: */ 237: public void valueForPathChanged(TreePath value0, Object value1) 238: { 239: // TODO 240: } 241: 242: /** 243: * insertNodeInto 244: * @param value0 TODO 245: * @param value1 TODO 246: * @param value2 TODO 247: */ 248: public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1, 249: int value2) 250: { 251: // TODO 252: } 253: 254: /** 255: * removeNodeFromParent 256: * @param value0 TODO 257: */ 258: public void removeNodeFromParent(MutableTreeNode value0) 259: { 260: // TODO 261: } 262: 263: /** 264: * nodeChanged 265: * @param value0 TODO 266: */ 267: public void nodeChanged(TreeNode value0) 268: { 269: // TODO 270: } 271: 272: /** 273: * nodesWereInserted 274: * @param value0 TODO 275: * @param value1 TODO 276: */ 277: public void nodesWereInserted(TreeNode value0, int[] value1) 278: { 279: // TODO 280: } 281: 282: /** 283: * nodesWereRemoved 284: * @param value0 TODO 285: * @param value1 TODO 286: * @param value2 TODO 287: */ 288: public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2) 289: { 290: // TODO 291: } 292: 293: /** 294: * nodesChanged 295: * @param value0 TODO 296: * @param value1 TODO 297: */ 298: public void nodesChanged(TreeNode value0, int[] value1) 299: { 300: // TODO 301: } 302: 303: /** 304: * nodeStructureChanged 305: * @param value0 TODO 306: */ 307: public void nodeStructureChanged(TreeNode value0) 308: { 309: // TODO 310: } 311: 312: /** 313: * getPathToRoot 314: * @param value0 TODO 315: * @return TreeNode[] 316: */ 317: public TreeNode[] getPathToRoot(TreeNode value0) 318: { 319: return null; // TODO 320: } 321: 322: /** 323: * getPathToRoot 324: * @param value0 TODO 325: * @param value1 TODO 326: * @return TreeNode[] 327: */ 328: protected TreeNode[] getPathToRoot(TreeNode value0, int value1) 329: { 330: return null; // TODO 331: } 332: 333: /** 334: * Registers a listere to the model. 335: * 336: * @param listener the listener to add 337: */ 338: public void addTreeModelListener(TreeModelListener listener) 339: { 340: listenerList.add(TreeModelListener.class, listener); 341: } 342: 343: /** 344: * Removes a listener from the model. 345: * 346: * @param listener the listener to remove 347: */ 348: public void removeTreeModelListener(TreeModelListener listener) 349: { 350: listenerList.remove(TreeModelListener.class, listener); 351: } 352: 353: /** 354: * Returns all registered <code>TreeModelListener</code> listeners. 355: * 356: * @return an array of listeners. 357: * 358: * @since 1.4 359: */ 360: public TreeModelListener[] getTreeModelListeners() 361: { 362: return (TreeModelListener[]) listenerList 363: .getListeners(TreeModelListener.class); 364: } 365: 366: /** 367: * fireTreeNodesChanged 368: * 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 373: */ 374: protected void fireTreeNodesChanged(Object source, Object[] path, 375: int[] childIndices, Object[] children) 376: { 377: TreeModelEvent event = new TreeModelEvent(source, path, childIndices, 378: children); 379: TreeModelListener[] listeners = getTreeModelListeners(); 380: 381: for (int i = listeners.length - 1; i >= 0; --i) 382: listeners[i].treeNodesChanged(event); 383: } 384: 385: /** 386: * fireTreeNodesInserted 387: * 388: * @param source the node where new nodes got inserted 389: * @param path the path to the root node 390: * @param childIndices the indices of the new elements 391: * @param children the new elements 392: */ 393: protected void fireTreeNodesInserted(Object source, Object[] path, 394: int[] childIndices, Object[] children) 395: { 396: TreeModelEvent event = new TreeModelEvent(source, path, childIndices, 397: children); 398: TreeModelListener[] listeners = getTreeModelListeners(); 399: 400: for (int i = listeners.length - 1; i >= 0; --i) 401: listeners[i].treeNodesInserted(event); 402: } 403: 404: /** 405: * fireTreeNodesRemoved 406: * 407: * @param source the node where nodes got removed- 408: * @param path the path to the root node 409: * @param childIndices the indices of the removed elements 410: * @param children the removed elements 411: */ 412: protected void fireTreeNodesRemoved(Object source, Object[] path, 413: int[] childIndices, Object[] children) 414: { 415: TreeModelEvent event = new TreeModelEvent(source, path, childIndices, 416: children); 417: TreeModelListener[] listeners = getTreeModelListeners(); 418: 419: for (int i = listeners.length - 1; i >= 0; --i) 420: listeners[i].treeNodesRemoved(event); 421: } 422: 423: /** 424: * fireTreeStructureChanged 425: * 426: * @param source the node where the model has changed 427: * @param path the path to the root node 428: * @param childIndices the indices of the affected elements 429: * @param children the affected elements 430: */ 431: protected void fireTreeStructureChanged(Object source, Object[] path, 432: int[] childIndices, Object[] children) 433: { 434: TreeModelEvent event = new TreeModelEvent(source, path, childIndices, 435: children); 436: TreeModelListener[] listeners = getTreeModelListeners(); 437: 438: for (int i = listeners.length - 1; i >= 0; --i) 439: listeners[i].treeStructureChanged(event); 440: } 441: 442: /** 443: * Returns the registered listeners of a given type. 444: * 445: * @param listenerType the listener type to return 446: * 447: * @return an array of listeners 448: * 449: * @since 1.3 450: */ 451: public EventListener[] getListeners(Class listenerType) 452: { 453: return listenerList.getListeners(listenerType); 454: } 455: }
GNU Classpath (0.17) |