- Timestamp:
- 01/02/13 10:07:51 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/guimodel/GUIElementTree.java
r1025 r1026 31 31 * <p> 32 32 * The GUIElementTree represents the hierarchical structure of the GUI elements "as it is" currently during 33 * a session. It may change during the session due to creation and destruction of GUI elements. 33 * a session. It may change during the session due to creation and destruction of GUI elements. The parameter 34 * T represents the id type of the GUI elements that are handled internally. 34 35 * </p> 35 36 * … … 38 39 * @version 1.0 39 40 */ 40 public class GUIElementTree { 41 /* Note that in the current version the id of a GUI element is assumed to be a long. For future 42 versions it might be more suitable to change to some generic id type. */ 43 44 /** 41 public class GUIElementTree<T> { 42 /** 45 43 * <p> 46 44 * Map of all GUI elements that are part of the tree for efficient searching. The keys of the … … 48 46 * </p> 49 47 */ 50 private Map< Long, IGUIElement> guiElements;48 private Map<T, IGUIElement> guiElements; 51 49 52 50 /** … … 56 54 * </p> 57 55 */ 58 private Map< Long, IGUIElementSpec> guiElementSpecs;56 private Map<T, IGUIElementSpec> guiElementSpecs; 59 57 60 58 /** … … 64 62 * </p> 65 63 */ 66 private Map< Long, List<Long>> childRelations;64 private Map<T, List<T>> childRelations; 67 65 68 66 /** … … 72 70 * </p> 73 71 */ 74 private Map< Long, Long> parentRelations;72 private Map<T, T> parentRelations; 75 73 76 74 /** … … 96 94 */ 97 95 public GUIElementTree() { 98 guiElementSpecs = new HashMap< Long, IGUIElementSpec>();99 childRelations = new HashMap< Long, List<Long>>();100 parentRelations = new HashMap< Long, Long>();101 guiElements = new HashMap< Long, IGUIElement>();96 guiElementSpecs = new HashMap<T, IGUIElementSpec>(); 97 childRelations = new HashMap<T, List<T>>(); 98 parentRelations = new HashMap<T, T>(); 99 guiElements = new HashMap<T, IGUIElement>(); 102 100 guiModel = new GUIModel(); 103 101 } … … 110 108 */ 111 109 public GUIElementTree(GUIModel guiModel){ 112 guiElementSpecs = new HashMap< Long, IGUIElementSpec>();113 childRelations = new HashMap< Long, List<Long>>();114 parentRelations = new HashMap< Long, Long>();115 guiElements = new HashMap< Long, IGUIElement>();110 guiElementSpecs = new HashMap<T, IGUIElementSpec>(); 111 childRelations = new HashMap<T, List<T>>(); 112 parentRelations = new HashMap<T, T>(); 113 guiElements = new HashMap<T, IGUIElement>(); 116 114 this.guiModel = guiModel; 117 115 } … … 129 127 * the GUI element specification 130 128 */ 131 public void add( LongguiElementID,132 LongparentID,129 public void add(T guiElementID, 130 T parentID, 133 131 IGUIElementSpec guiElementSpec) 134 132 { … … 138 136 IGUIElementSpec parent = guiElementSpecs.get(parentID); 139 137 if (parent != null) { 140 List< Long> otherChildren = childRelations.get(parentID);138 List<T> otherChildren = childRelations.get(parentID); 141 139 142 140 if (otherChildren == null) { 143 otherChildren = new ArrayList< Long>();141 otherChildren = new ArrayList<T>(); 144 142 childRelations.put(parentID, otherChildren); 145 143 } … … 153 151 List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); 154 152 155 LongcurrentElementID = guiElementID;153 T currentElementID = guiElementID; 156 154 while (guiElementSpec != null) { 157 155 guiElementPath.add(0, guiElementSpec); … … 180 178 * @return {@link IGUIElementSpec} of the GUI element with the given id if found, null otherwise 181 179 */ 182 public IGUIElement find( longid) {180 public IGUIElement find(T id) { 183 181 return guiElements.get(id); 184 182 } … … 194 192 * @return number of GUI elements that were removed 195 193 */ 196 public int remove( longid) {194 public int remove(T id) { 197 195 int removedCounter = 0; 198 196 IGUIElementSpec node = guiElementSpecs.remove(id); … … 200 198 if (node != null) { 201 199 removedCounter++; 202 List< Long> nodesToBeRemoved = childRelations.remove(id);200 List<T> nodesToBeRemoved = childRelations.remove(id); 203 201 204 202 // remove all children and sub-children, if any 205 203 if (nodesToBeRemoved != null) { 206 204 for (int i = 0; i < nodesToBeRemoved.size(); i++) { 207 LongnodeToBeRemoved = nodesToBeRemoved.get(i);208 List< Long> children =205 T nodeToBeRemoved = nodesToBeRemoved.get(i); 206 List<T> children = 209 207 childRelations.remove(nodeToBeRemoved); 210 208 … … 221 219 /* the node may be a child node of a parent. So search for it in the child relations 222 220 of the parent and remove it */ 223 Longparent = parentRelations.remove(id);221 T parent = parentRelations.remove(id); 224 222 if (parent != null) { 225 List< Long> children = childRelations.get(parent);223 List<T> children = childRelations.get(parent); 226 224 227 225 if (children != null) {
Note: See TracChangeset
for help on using the changeset viewer.