1 7 8 package javax.swing.event; 9 10 import java.util.EventObject ; 11 import javax.swing.tree.TreePath ; 12 13 35 public class TreeSelectionEvent extends EventObject 36 { 37 38 protected TreePath [] paths; 39 40 protected boolean[] areNew; 41 42 protected TreePath oldLeadSelectionPath; 43 44 protected TreePath newLeadSelectionPath; 45 46 54 public TreeSelectionEvent(Object source, TreePath [] paths, 55 boolean[] areNew, TreePath oldLeadSelectionPath, 56 TreePath newLeadSelectionPath) 57 { 58 super(source); 59 this.paths = paths; 60 this.areNew = areNew; 61 this.oldLeadSelectionPath = oldLeadSelectionPath; 62 this.newLeadSelectionPath = newLeadSelectionPath; 63 } 64 65 75 public TreeSelectionEvent(Object source, TreePath path, boolean isNew, 76 TreePath oldLeadSelectionPath, 77 TreePath newLeadSelectionPath) 78 { 79 super(source); 80 paths = new TreePath [1]; 81 paths[0] = path; 82 areNew = new boolean[1]; 83 areNew[0] = isNew; 84 this.oldLeadSelectionPath = oldLeadSelectionPath; 85 this.newLeadSelectionPath = newLeadSelectionPath; 86 } 87 88 92 public TreePath [] getPaths() 93 { 94 int numPaths; 95 TreePath [] retPaths; 96 97 numPaths = paths.length; 98 retPaths = new TreePath [numPaths]; 99 System.arraycopy(paths, 0, retPaths, 0, numPaths); 100 return retPaths; 101 } 102 103 106 public TreePath getPath() 107 { 108 return paths[0]; 109 } 110 111 116 public boolean isAddedPath() { 117 return areNew[0]; 118 } 119 120 126 public boolean isAddedPath(TreePath path) { 127 for(int counter = paths.length - 1; counter >= 0; counter--) 128 if(paths[counter].equals(path)) 129 return areNew[counter]; 130 throw new IllegalArgumentException ("path is not a path identified by the TreeSelectionEvent"); 131 } 132 133 141 public boolean isAddedPath(int index) { 142 if (paths == null || index < 0 || index >= paths.length) { 143 throw new IllegalArgumentException ("index is beyond range of added paths identified by TreeSelectionEvent"); 144 } 145 return areNew[index]; 146 } 147 148 151 public TreePath getOldLeadSelectionPath() { 152 return oldLeadSelectionPath; 153 } 154 155 158 public TreePath getNewLeadSelectionPath() { 159 return newLeadSelectionPath; 160 } 161 162 165 public Object cloneWithSource(Object newSource) { 166 return new TreeSelectionEvent (newSource, paths,areNew, 168 oldLeadSelectionPath, 169 newLeadSelectionPath); 170 } 171 } 172 | Popular Tags |