KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > event > TreeModelEvent


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: TreeModelEvent.java,v $
11    Revision 1.4 2003/12/14 09:13:39 bobintetley
12    Added CVS log to source headers
13
14 */

15
16 package swingwtx.swing.event;
17
18 import swingwtx.swing.tree.*;
19
20 public class TreeModelEvent extends java.util.EventObject JavaDoc {
21
22     protected TreePath path;
23     protected int[] childIndices;
24     protected Object JavaDoc[] children;
25
26     public TreeModelEvent(Object JavaDoc source, Object JavaDoc[] path, int[] childIndices,
27               Object JavaDoc[] children)
28     {
29     this(source, new TreePath(path), childIndices, children);
30     }
31
32     public TreeModelEvent(Object JavaDoc source, TreePath path, int[] childIndices,
33               Object JavaDoc[] children)
34     {
35     super(source);
36     this.path = path;
37     this.childIndices = childIndices;
38     this.children = children;
39     }
40
41     public TreeModelEvent(Object JavaDoc source, Object JavaDoc[] path)
42     {
43     this(source, new TreePath(path));
44     }
45
46     public TreeModelEvent(Object JavaDoc source, TreePath path)
47     {
48     super(source);
49     this.path = path;
50     this.childIndices = new int[0];
51     }
52
53     public TreePath getTreePath() { return path; }
54
55     public Object JavaDoc[] getPath() {
56     if(path != null)
57         return path.getPath();
58     return null;
59     }
60
61     public Object JavaDoc[] getChildren() {
62     if(children != null) {
63         int cCount = children.length;
64         Object JavaDoc[] retChildren = new Object JavaDoc[cCount];
65
66         System.arraycopy(children, 0, retChildren, 0, cCount);
67         return retChildren;
68     }
69     return null;
70     }
71
72     public int[] getChildIndices() {
73     if(childIndices != null) {
74         int cCount = childIndices.length;
75         int[] retArray = new int[cCount];
76
77         System.arraycopy(childIndices, 0, retArray, 0, cCount);
78         return retArray;
79     }
80     return null;
81     }
82
83     public String JavaDoc toString() {
84     StringBuffer JavaDoc retBuffer = new StringBuffer JavaDoc();
85
86     retBuffer.append(getClass().getName() + " " +
87              Integer.toString(hashCode()));
88     if(path != null)
89         retBuffer.append(" path " + path);
90     if(childIndices != null) {
91         retBuffer.append(" indices [ ");
92         for(int counter = 0; counter < childIndices.length; counter++)
93         retBuffer.append(Integer.toString(childIndices[counter])+ " ");
94         retBuffer.append("]");
95     }
96     if(children != null) {
97         retBuffer.append(" children [ ");
98         for(int counter = 0; counter < children.length; counter++)
99         retBuffer.append(children[counter] + " ");
100         retBuffer.append("]");
101     }
102     return retBuffer.toString();
103     }
104 }
105
Popular Tags