KickJava   Java API By Example, From Geeks To Geeks.

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


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: TreeSelectionEvent.java,v $
11    Revision 1.2 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 TreeSelectionEvent extends java.util.EventObject JavaDoc {
21     
22     protected TreePath[] paths;
23     protected boolean[] areNew;
24     protected TreePath oldLeadSelectionPath;
25     protected TreePath newLeadSelectionPath;
26
27     public TreeSelectionEvent(Object JavaDoc source, TreePath[] paths, boolean[] areNew, TreePath oldLeadSelectionPath, TreePath newLeadSelectionPath) {
28     super(source);
29     this.paths = paths;
30     this.areNew = areNew;
31     this.oldLeadSelectionPath = oldLeadSelectionPath;
32     this.newLeadSelectionPath = newLeadSelectionPath;
33     }
34
35     public TreeSelectionEvent(Object JavaDoc source, TreePath path, boolean isNew, TreePath oldLeadSelectionPath, TreePath newLeadSelectionPath) {
36     super(source);
37     paths = new TreePath[1];
38     paths[0] = path;
39     areNew = new boolean[1];
40     areNew[0] = isNew;
41     this.oldLeadSelectionPath = oldLeadSelectionPath;
42     this.newLeadSelectionPath = newLeadSelectionPath;
43     }
44
45     public TreePath[] getPaths() {
46         int numPaths;
47     TreePath[] retPaths;
48
49     numPaths = paths.length;
50     retPaths = new TreePath[numPaths];
51     System.arraycopy(paths, 0, retPaths, 0, numPaths);
52     return retPaths;
53     }
54
55
56     public TreePath getPath() {
57     return paths[0];
58     }
59
60     public boolean isAddedPath() {
61     return areNew[0];
62     }
63
64     public boolean isAddedPath(TreePath path) {
65     for(int counter = paths.length - 1; counter >= 0; counter--)
66         if(paths[counter].equals(path))
67         return areNew[counter];
68         throw new IllegalArgumentException JavaDoc("Invalid path");
69     }
70
71     public boolean isAddedPath(int index) {
72     if (paths == null || index < 0 || index >= paths.length) {
73         throw new IllegalArgumentException JavaDoc("Index too high");
74     }
75     return areNew[index];
76     }
77
78     public TreePath getOldLeadSelectionPath() {
79     return oldLeadSelectionPath;
80     }
81
82     public TreePath getNewLeadSelectionPath() {
83     return newLeadSelectionPath;
84     }
85     
86 }
87
Popular Tags