1 15 16 package swingwtx.swing.event; 17 18 import swingwtx.swing.tree.*; 19 20 public class TreeSelectionEvent extends java.util.EventObject { 21 22 protected TreePath[] paths; 23 protected boolean[] areNew; 24 protected TreePath oldLeadSelectionPath; 25 protected TreePath newLeadSelectionPath; 26 27 public TreeSelectionEvent(Object 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 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 ("Invalid path"); 69 } 70 71 public boolean isAddedPath(int index) { 72 if (paths == null || index < 0 || index >= paths.length) { 73 throw new IllegalArgumentException ("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 |