Changeset 846 for trunk/quest-core-events/src/main
- Timestamp:
- 09/21/12 11:06:24 (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
r831 r846 227 227 mergeSubTree(root); 228 228 } 229 230 /** 231 * <p> 232 * Merges the tree nodes of two GUI elements. The GUI elements need to have the same parent. 233 * </p> 234 * 235 * @param guiElement1 236 * the first merge GUI element 237 * @param guiElement2 238 * the second merge GUI element 239 * @throws IllegalArgumentException 240 * thrown if the two GUI elements do not have the same parent 241 */ 242 public void mergeGUIElements(IGUIElement guiElement1, IGUIElement guiElement2) 243 throws IllegalArgumentException 244 { 245 // check if both nodes have the same parent 246 IGUIElement parentElement = guiElement1.getParent(); 247 if (parentElement != null && !parentElement.equals(guiElement2.getParent())) { 248 throw new IllegalArgumentException("can only merge nodes with the same parent"); 249 } 250 251 // get the TreeNode of the parent of the GUI elements 252 TreeNode parent = findNode(parentElement); 253 254 // get the TreeNodes for both GUI elements 255 TreeNode node1 = findNode(guiElement1); 256 TreeNode node2 = findNode(guiElement2); 257 258 if (node1 == null || node2 == null) { 259 throw new IllegalArgumentException( 260 "Error while merging nodes: one element is not part of the GUI model!"); 261 } 262 263 TreeNode replacement = mergeTreeNodes(node1, node2); 264 265 if (parent != null) { 266 // remove node1 and node2 from the parent's children and add the replacement instead 267 // assumes that there are no duplicates of node1 and node2 268 if (parent.children != null) { 269 parent.children.set(parent.children.indexOf(node1), replacement); 270 parent.children.remove(node2); 271 } 272 } 273 274 } 229 275 230 276 /** … … 428 474 429 475 out.println(); 476 } 477 478 /** 479 * <p> 480 * Retrieves the TreeNode associated with a GUI element. Returns null if no such TreeNode is 481 * found. 482 * </p> 483 * 484 * @param element 485 * the GUI element 486 * @return associated TreeNode; null if no such node exists 487 */ 488 private TreeNode findNode(IGUIElement element) { 489 if (element == null) { 490 return null; 491 } 492 493 TreeNode result = null; 494 for (TreeNode node : allNodes) { 495 if (node.guiElement.equals(element)) { 496 if (result == null) { 497 result = node; 498 } 499 else { 500 Console 501 .traceln(Level.SEVERE, 502 "Multiple nodes in the internal GUI model match the same GUI element. " 503 + "This should not be the case and the GUI model is probably invalid."); 504 } 505 } 506 } 507 return result; 430 508 } 431 509
Note: See TracChangeset
for help on using the changeset viewer.