Changeset 1336 for trunk/autoquest-plugin-html/src/main/java
- Timestamp:
- 01/25/14 14:00:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDcondenseHTMLGUIModel.java
r1334 r1336 15 15 package de.ugoe.cs.autoquest.plugin.html.commands; 16 16 17 import java.io.PrintStream;18 17 import java.util.Arrays; 19 18 import java.util.Comparator; … … 74 73 * \-- html 75 74 * \-- body 76 * |-- group (common) 77 * | |-- div (id = menu) 78 * | | \-- ... 79 * | \-- div (id = footer) 80 * | \-- ... 75 * |-- div (id = menu) 76 * | \-- ... 81 77 * |-- group (document1) 82 78 * | \-- div (id = textcontent) … … 85 81 * | \-- div (id = imagecontent) 86 82 * | \-- ... 83 * \-- div (id = footer) 84 * \-- ... 87 85 * </pre> 88 86 * This now allows the menu and the footer to be treated as identical over several pages. … … 128 126 for (IGUIElement root : model.getRootElements()) { 129 127 if (root instanceof HTMLServer) { 130 mergeServer((HTMLServer) root, model); 128 try { 129 mergeServer((HTMLServer) root, model); 130 } 131 catch (Exception e) { 132 Console.printerrln("problems while condensing model of server " + root); 133 //e.printStackTrace(System.out); 134 break; 135 } 131 136 } 132 137 } … … 148 153 GUIElementsCluster rootCluster = getSimilarElementClusterHierarchy(server, model); 149 154 150 rootCluster.dump(System.out, "");151 152 Console.traceln(Level.FINE, " grouping GUI elements according to clusters");153 groupGUIElementsAccordingToClusters(rootCluster, model, "");155 //rootCluster.dump(System.out, ""); 156 157 Console.traceln(Level.FINE, "merging GUI elements in same clusters and creating groups"); 158 mergeGUIElementsAccordingToClusters(rootCluster, model, ""); 154 159 155 160 //model.dump(System.out, "UTF-8"); … … 176 181 177 182 List<IGUIElement> children = model.getChildren(server); 183 178 184 179 185 SimilarGUIElements similarGuiElements = new SimilarGUIElements(); … … 182 188 // when starting with the root, the cluster parent is the child itself, i.e. the 183 189 // document. We expect all documents to be similar. 190 184 191 similarGuiElements.add(new SimilarGUIElement(child, child)); 185 192 } … … 243 250 } 244 251 } 252 // else { 253 // // search for a default cluster to add all elements to, which have no children 254 // GUIElementsCluster defaultCluster = null; 255 // 256 // for (GUIElementsCluster candidate : parentCluster.childClusters) { 257 // if (candidate.similarChildrenGUIElements.size() == 0) { 258 // defaultCluster = candidate; 259 // break; 260 // } 261 // } 262 // 263 // if (defaultCluster == null) { 264 // defaultCluster = new GUIElementsCluster(); 265 // parentCluster.addChildCluster(defaultCluster); 266 // } 267 // 268 // defaultCluster.clusteredGUIElements.add(similarGuiElement); 269 // } 245 270 } 246 271 } … … 354 379 createClusterHierachies(subClusterToHandle); 355 380 356 GUIElementsCluster commonCluster = new GUIElementsCluster();381 /*GUIElementsCluster commonCluster = new GUIElementsCluster(); 357 382 //commonCluster.setClusteredGUIElements(subClusterToHandle.clusteredGUIElements); 358 383 commonCluster.similarChildrenGUIElements.addAll … … 360 385 361 386 subClusterToHandle.similarChildrenGUIElements.clear(); 362 subClusterToHandle.childClusters.add(0, commonCluster); 387 subClusterToHandle.childClusters.add(0, commonCluster);*/ 388 } 389 } 390 } 391 392 /** 393 * <p> 394 * called for each cluster to merge similar GUI elements depending on the clusters and to 395 * create GUI element groups if required. Calls itself recursively to be also applied on 396 * child clusters. 397 * </p> 398 * 399 * @param cluster the cluster of which the similar children shall be merged 400 * @param model the model to be adapted through the merge 401 */ 402 private void mergeGUIElementsAccordingToClusters(GUIElementsCluster cluster, 403 GUIModel model, 404 String indent) 405 { 406 //System.out.println(indent + "handling " + cluster); 407 408 for (SimilarGUIElements similarGUIElements : cluster.similarChildrenGUIElements) { 409 mergeGUIElements(similarGUIElements, model, indent + " "); 410 } 411 412 if (cluster.childClusters.size() > 0) { 413 //System.out.println(indent + " handling child clusters"); 414 415 for (GUIElementsCluster childCluster : cluster.childClusters) { 416 if (cluster.isDefault() || cluster.clusterParentsMatch(childCluster)) { 417 // for default cluster or children not creating subgroups, just traverse the 418 // cluster hierarchy 419 mergeGUIElementsAccordingToClusters(childCluster, model, indent + " "); 420 } 421 else { 422 createClusterGroup(childCluster, model, indent + " "); 423 } 363 424 } 364 425 } … … 380 441 381 442 while (similarGUIElements.size() > 1) { 382 System.out.println(indent + "merging " + mergeResult + " and " +383 similarGUIElements.get(1).similarGUIElement);443 //System.out.println(indent + "merging " + mergeResult + " and " + 444 // similarGUIElements.get(1).similarGUIElement); 384 445 mergeResult = model.mergeGUIElements 385 446 (mergeResult, similarGUIElements.remove(1).similarGUIElement, false); … … 396 457 * @param model the model to be used for creating the groups 397 458 */ 398 private void groupGUIElementsAccordingToClusters(GUIElementsCluster cluster, 399 GUIModel model, 400 String indent) 401 { 402 System.out.println(indent + "handling " + cluster); 403 459 private void createClusterGroup(GUIElementsCluster cluster, GUIModel model, String indent) { 460 //System.out.println(indent + "creating group for " + cluster); 461 404 462 List<IGUIElement> guiElementsToGroup = new LinkedList<IGUIElement>(); 405 463 … … 409 467 } 410 468 411 List<IGUIElement> subgroups = new LinkedList<IGUIElement>(); 412 413 414 System.out.println(indent + "iterating child clusters of " + cluster); 469 //System.out.println(indent + " iterating child clusters of " + cluster); 415 470 for (GUIElementsCluster childCluster : cluster.childClusters) { 416 groupGUIElementsAccordingToClusters(childCluster, model, indent + " "); 417 418 if (cluster.childClusters.size() > 1) { 419 List<IGUIElement> childGuiElemsToGroup = new LinkedList<IGUIElement>(); 420 421 for (SimilarGUIElements similarGUIElems : childCluster.similarChildrenGUIElements) { 422 childGuiElemsToGroup.addAll(similarGUIElems.toGUIElementList()); 423 } 424 425 for (GUIElementsCluster subsubcluster : childCluster.childClusters) { 426 if (subsubcluster.getGroup() != null) { 427 childGuiElemsToGroup.add(subsubcluster.getGroup()); 428 } 429 } 430 431 if (childGuiElemsToGroup.size() > 0) { 432 System.out.println(indent + " grouping: " + childGuiElemsToGroup); 433 IGUIElement group = model.groupGUIElements 434 (childGuiElemsToGroup, getGroupName(childCluster)); 435 System.out.println 436 (indent + " created group for " + childCluster + ": " + group); 437 438 if (group != null) { 439 childCluster.setGroup(group); 440 if (cluster.isSubCluster(childCluster)) { 441 subgroups.add(childCluster.getGroup()); 442 } 443 else { 444 subgroups.add(childCluster.getGroup().getParent()); 445 } 446 } 447 } 448 } 449 450 System.out.println(); 451 } 452 471 if (cluster.isDefault() || cluster.clusterParentsMatch(childCluster)) { 472 // for default cluster or children not creating subgroups, just traverse the 473 // cluster hierarchy 474 mergeGUIElementsAccordingToClusters(childCluster, model, indent + " "); 475 } 476 else { 477 createClusterGroup(childCluster, model, indent + " "); 478 } 479 480 if (childCluster.getGroup() != null) { 481 if (cluster.isSubCluster(childCluster)) { 482 guiElementsToGroup.add(childCluster.getGroup()); 483 } 484 else { 485 guiElementsToGroup.add(childCluster.getGroup().getParent()); 486 } 487 } 488 } 489 490 //System.out.println(indent + "grouping: " + guiElementsToGroup); 491 IGUIElement group = model.groupGUIElements(guiElementsToGroup, getGroupName(cluster)); 492 //System.out.println(indent + " created group for " + cluster + ": " + group); 493 494 cluster.setGroup(group); 453 495 } 454 496 … … 541 583 public String toString() { 542 584 return getName(); 585 } 586 587 /** 588 * <p> 589 * checks, if the main cluster parents, i.e., the documents of this and the provided cluster 590 * match 591 * </p> 592 * 593 * @param other the other cluster of which the main cluster parents shall be compared to 594 * this 595 * 596 * @return true if they match, false else 597 */ 598 private boolean clusterParentsMatch(GUIElementsCluster other) { 599 // cluster parent may already be merged and therefore equals --> use system identity 600 // hash code for uniqueness 601 Set<Integer> mainClusterParents1 = new HashSet<Integer>(); 602 for (SimilarGUIElement clusteredElem1 : clusteredGUIElements) { 603 mainClusterParents1.add(System.identityHashCode(clusteredElem1.mainClusterParent)); 604 } 605 606 Set<Integer> mainClusterParents2 = new HashSet<Integer>(); 607 for (SimilarGUIElement clusteredElem2 : other.clusteredGUIElements) { 608 mainClusterParents2.add(System.identityHashCode(clusteredElem2.mainClusterParent)); 609 } 610 611 return mainClusterParents1.equals(mainClusterParents2); 612 } 613 614 /** 615 * <p> 616 * returns true, if this cluster is a default cluster 617 * </p> 618 * 619 * @return 620 */ 621 public boolean isDefault() { 622 return clusteredGUIElements.size() <= 0; 543 623 } 544 624 … … 688 768 * </p> 689 769 */ 690 private void dump(PrintStream out, String indent) {691 out.print(indent);692 out.print(getName());693 out.println(" { ");694 695 if (clusteredGUIElements.size() > 0) {696 out.print(indent);697 out.println(" clustered GUIElements {");698 699 for (SimilarGUIElement clusteredGUIElement : clusteredGUIElements) {700 clusteredGUIElement.dump(out, indent + " ");701 }702 703 out.print(indent);704 out.println(" }");705 }706 707 if (similarChildrenGUIElements.size() > 0) {708 out.print(indent);709 out.println(" similar children {");710 711 for (SimilarGUIElements similarGuiElements : similarChildrenGUIElements) {712 similarGuiElements.dump(out, indent + " ");713 }714 715 out.print(indent);716 out.println(" }");717 }718 719 if (childClusters.size() > 0) {720 out.print(indent);721 out.println(" child clusters {");722 723 for (GUIElementsCluster childCluster : childClusters) {724 childCluster.dump(out, indent + " ");725 }726 727 out.print(indent);728 out.println(" }");729 }730 731 out.print(indent);732 out.println("}");733 }770 // private void dump(PrintStream out, String indent) { 771 // out.print(indent); 772 // out.print(getName()); 773 // out.println(" { "); 774 // 775 // if (clusteredGUIElements.size() > 0) { 776 // out.print(indent); 777 // out.println(" clustered GUIElements {"); 778 // 779 // for (SimilarGUIElement clusteredGUIElement : clusteredGUIElements) { 780 // clusteredGUIElement.dump(out, indent + " "); 781 // } 782 // 783 // out.print(indent); 784 // out.println(" }"); 785 // } 786 // 787 // if (similarChildrenGUIElements.size() > 0) { 788 // out.print(indent); 789 // out.println(" similar children {"); 790 // 791 // for (SimilarGUIElements similarGuiElements : similarChildrenGUIElements) { 792 // similarGuiElements.dump(out, indent + " "); 793 // } 794 // 795 // out.print(indent); 796 // out.println(" }"); 797 // } 798 // 799 // if (childClusters.size() > 0) { 800 // out.print(indent); 801 // out.println(" child clusters {"); 802 // 803 // for (GUIElementsCluster childCluster : childClusters) { 804 // childCluster.dump(out, indent + " "); 805 // } 806 // 807 // out.print(indent); 808 // out.println(" }"); 809 // } 810 // 811 // out.print(indent); 812 // out.println("}"); 813 // } 734 814 735 815 } … … 787 867 * </p> 788 868 */ 789 private void dump(PrintStream out, String indent) {790 out.print(indent);791 out.print("{ ");792 793 for (int i = 0; i < super.size(); i++) {794 if (i > 0) {795 out.print(", ");796 }797 out.print(super.get(i));798 }799 800 out.println(" }");801 }869 // private void dump(PrintStream out, String indent) { 870 // out.print(indent); 871 // out.print("{ "); 872 // 873 // for (int i = 0; i < super.size(); i++) { 874 // if (i > 0) { 875 // out.print(", "); 876 // } 877 // out.print(super.get(i)); 878 // } 879 // 880 // out.println(" }"); 881 // } 802 882 } 803 883 … … 839 919 * </p> 840 920 */ 841 private void dump(PrintStream out, String indent) {842 out.print(indent);843 out.println(this);844 }921 // private void dump(PrintStream out, String indent) { 922 // out.print(indent); 923 // out.println(this); 924 // } 845 925 846 926 /* (non-Javadoc)
Note: See TracChangeset
for help on using the changeset viewer.