Changeset 821 for trunk/quest-core-events
- Timestamp:
- 09/19/12 09:40:07 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/GUIModel.java
r820 r821 8 8 import java.util.LinkedList; 9 9 import java.util.List; 10 import java.util.logging.Level; 11 12 import de.ugoe.cs.util.console.Console; 10 13 11 14 /** … … 17 20 * </p> 18 21 * 19 * TODO: getChildren and getParent should be rewritten to at least throw warnings, in case there are 20 * multiple nodes in allNodes that match the current GUI element. 21 * 22 * @version $Revision: $ $Date: 14.08.2012$ 22 * @version 1.0 23 23 * @author Patrick Harms, Steffen Herbold 24 24 */ … … 110 110 */ 111 111 public List<IGUIElement> getChildren(IGUIElement guiElement) { 112 List<IGUIElement> result = null; 112 113 for (TreeNode node : allNodes) { 113 114 if (node.guiElement.equals(guiElement)) { 114 List<IGUIElement> result = new ArrayList<IGUIElement>(); 115 116 if (node.children != null) { 117 for (TreeNode child : node.children) { 118 result.add(child.guiElement); 115 if (result == null) { 116 result = new ArrayList<IGUIElement>(); 117 118 if (node.children != null) { 119 for (TreeNode child : node.children) { 120 result.add(child.guiElement); 121 } 119 122 } 120 123 } 121 122 return result; 123 } 124 } 125 126 return null; 124 else { 125 Console 126 .traceln(Level.SEVERE, 127 "Multiple nodes in the internal GUI model match the same GUI element. " 128 + "This should not be the case and the GUI model is probably invalid."); 129 } 130 } 131 } 132 133 return result; 127 134 } 128 135 … … 139 146 */ 140 147 public IGUIElement getParent(IGUIElement guiElement) { 148 IGUIElement parent = null; 149 141 150 for (TreeNode node : allNodes) { 142 151 for (TreeNode child : node.children) { 143 152 if (child.guiElement.equals(guiElement)) { 144 return node.guiElement; 153 if (parent != null) { 154 parent = node.guiElement; 155 } 156 else { 157 Console 158 .traceln(Level.SEVERE, 159 "Multiple nodes in the internal GUI model match the same GUI element. " 160 + "This should not be the case and the GUI model is probably invalid."); 161 } 145 162 } 146 163 } 147 164 } 148 165 149 return null;166 return parent; 150 167 } 151 168 … … 203 220 /** 204 221 * <p> 205 * TODO: comment222 * By calling this method, the GUIModel is traversed and similar nodes are merged. 206 223 * </p> 207 224 * 208 225 */ 209 226 public void condenseModel() { 210 mergeS imilarChildren(root);227 mergeSubTree(root); 211 228 } 212 229 … … 238 255 239 256 TreeNode child = findEqualChild(parentNode, specToIntegrateElementFor); 240 if (child != null) { 241 // TODO this call should be deprecated and change nothing 242 child.guiElement.updateSpecification(specToIntegrateElementFor); 243 } 244 else { 257 if (child == null) { 245 258 IGUIElement newElement = 246 259 guiElementFactory.instantiateGUIElement(specToIntegrateElementFor, … … 260 273 /** 261 274 * <p> 262 * TODO: comment 263 * </p> 264 * 265 * @param parentNode 266 * @param specToMatch 267 * @return 275 * Searches the children of a tree node to see if the {@link IGUIElementSpec} of equals the 276 * specification of the {@link TreeNode#guiElement} of the child. If a match is found, the child 277 * is returned. 278 * </p> 268 279 */ 269 280 private TreeNode findEqualChild(TreeNode parentNode, IGUIElementSpec specToMatch) { … … 280 291 /** 281 292 * <p> 282 * merges similar children of a parent node. The method compares all children of the parent node 283 * with each other. If two of them are similar, it merges them, registers them with each other 284 * for equality checks, and removes one of them from the list of children. 285 * </p> 286 */ 287 private void mergeSimilarChildren(TreeNode parentNode) { 288 if (parentNode.children == null || parentNode.children.isEmpty()) { 293 * Merges all similar nodes in the sub-tree of the GUI model defined by the subTreeRoot. 294 * </p> 295 * <p> 296 * The merging order is a bottom-up. This means, that we first call mergeSubTree recursively for 297 * the grand children of the subTreeRoot, before we merge subTreeRoot. 298 * </p> 299 * <p> 300 * The merging strategy is top-down. This means, that every time we merge two child nodes, we 301 * call mergeSubTree recursively for all children of the merged nodes in order to check if we 302 * can merge the children, too. 303 * </p> 304 */ 305 private void mergeSubTree(TreeNode subTreeRoot) { 306 if (subTreeRoot.children == null || subTreeRoot.children.isEmpty()) { 289 307 return; 290 308 } 291 309 292 // lets first merge the grand children293 for (TreeNode child : parentNode.children) {294 mergeS imilarChildren(child);310 // lets first merge the grand children of the parentNode 311 for (TreeNode child : subTreeRoot.children) { 312 mergeSubTree(child); 295 313 } 296 314 … … 299 317 do { 300 318 performedMerge = false; 301 for (int i = 0; !performedMerge && i < parentNode.children.size(); i++) {319 for (int i = 0; !performedMerge && i < subTreeRoot.children.size(); i++) { 302 320 IGUIElementSpec elemSpec1 = 303 parentNode.children.get(i).guiElement.getSpecification();304 for (int j = i + 1; !performedMerge && j < parentNode.children.size(); j++) {321 subTreeRoot.children.get(i).guiElement.getSpecification(); 322 for (int j = i + 1; !performedMerge && j < subTreeRoot.children.size(); j++) { 305 323 IGUIElementSpec elemSpec2 = 306 parentNode.children.get(j).guiElement.getSpecification();324 subTreeRoot.children.get(j).guiElement.getSpecification(); 307 325 if (elemSpec1.getSimilarity(elemSpec2)) { 308 326 TreeNode replacement = 309 mergeTreeNodes( parentNode.children.get(i), parentNode.children.get(j));310 311 parentNode.children.set(i, replacement);312 parentNode.children.remove(j);327 mergeTreeNodes(subTreeRoot.children.get(i), subTreeRoot.children.get(j)); 328 329 subTreeRoot.children.set(i, replacement); 330 subTreeRoot.children.remove(j); 313 331 performedMerge = true; 314 332 i--; … … 344 362 if (treeNode1.children != null) { 345 363 for (TreeNode child : treeNode1.children) { 346 // replacement.addChild(child.guiElement);347 364 replacement.addChildNode(child); 348 365 } … … 350 367 if (treeNode2.children != null) { 351 368 for (TreeNode child : treeNode2.children) { 352 // replacement.addChild(child.guiElement);353 369 replacement.addChildNode(child); 354 370 } 355 371 } 356 372 357 mergeS imilarChildren(replacement);373 mergeSubTree(replacement); 358 374 359 375 replacement.guiElement.updateSpecification(treeNode2.guiElement.getSpecification()); … … 405 421 /** */ 406 422 private List<TreeNode> children; 407 408 /** */409 // private TreeNode parent;410 423 411 424 /** … … 421 434 TreeNode child = new TreeNode(); 422 435 child.guiElement = guiElement; 423 // child.parent = this;424 436 children.add(child); 425 437 … … 432 444 * 433 445 * <p> 434 * TODO: comment446 * Adds a TreeNode as child to the current node. This way, the whole sub-tree is added. 435 447 * </p> 436 *437 * @param node438 * @return439 448 */ 440 449 private TreeNode addChildNode(TreeNode node) {
Note: See TracChangeset
for help on using the changeset viewer.