- Timestamp:
- 09/07/12 15:21:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculator.java
r785 r796 1 1 package de.ugoe.cs.quest.plugin.jfc; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Arrays; 4 5 import java.util.LinkedHashMap; 5 6 import java.util.List; 7 import java.util.ListIterator; 6 8 import java.util.Map; 7 import java.util.Stack;8 9 import java.util.regex.Matcher; 9 10 import java.util.regex.Pattern; … … 50 51 "javax.swing.JScrollPane$ScrollBar", 51 52 "javax.swing.plaf.metal.MetalScrollButton"); 52 53 54 /** 55 * Calculates the replayID needed for compatibility with Guitar suite of a JFCEvent 53 54 /** 55 * Calculates the replayID of a JFCEvent needed for compatibility with guitar suite 56 * @param List of {@link JFCGUIElementSpec}s that represent the component path of a event target 57 * for which the replayID should be calculated. 58 * @return replayID 59 */ 60 61 public String calculateReplayID(List<JFCGUIElementSpec> guiElementPath){ 62 String replayID = ""; 63 long hashCode = 1; 64 65 ListIterator<JFCGUIElementSpec> iterator = guiElementPath.listIterator(); 66 67 JFCGUIElementSpec currentSpec = iterator.next(); 68 String title = currentSpec.getName(); 69 String fuzzyTitle = getFuzzyTitle(title); 70 long windowHashCode = fuzzyTitle.hashCode(); 71 windowHashCode = (windowHashCode * 2) & 0xffffffffL; 72 73 long propagatedHashCode = windowHashCode; 74 75 // construct looks complicated but avoids going back and force through path 76 if (iterator.hasNext()) 77 currentSpec = iterator.next(); 78 else 79 currentSpec = null; 80 81 // walk through component path and calculate hashcode 82 while(currentSpec != null){ 83 long localHashCode = getLocalHashCode(currentSpec); 84 hashCode = propagatedHashCode * prime + localHashCode; 85 hashCode = (hashCode * 2) & 0xffffffffL; 86 87 if (iterator.hasNext()){ 88 currentSpec = iterator.next(); 89 Integer index = currentSpec.getIndex(); 90 propagatedHashCode = prime * propagatedHashCode 91 + index.hashCode(); 92 } 93 else 94 currentSpec = null; 95 96 } 97 98 replayID = "e" + hashCode; 99 100 return replayID; 101 } 102 103 104 /** 105 * Calculates the replayID of a JFCEvent needed for compatibility with guitar suite 56 106 * @param event for which the ID should be calculated 57 107 * @return replayID 58 108 */ 59 109 public String calculateReplayID(Event event){ 60 String replayID = ""; 61 long hashCode = 1; 62 Stack<JFCGUIElement> path = new Stack<JFCGUIElement>(); 110 List<JFCGUIElementSpec> guiElementPath = new ArrayList<JFCGUIElementSpec>(); 63 111 64 112 IEventTarget target = event.getTarget(); 65 113 JFCGUIElement jfcTarget = (JFCGUIElement) target; 66 114 67 // extract target path115 // extract element path 68 116 JFCGUIElement currentTarget = jfcTarget; 69 117 while (currentTarget != null){ 70 path.push(currentTarget); 118 JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 119 guiElementPath.add(0, currentSpec); 71 120 currentTarget = (JFCGUIElement) currentTarget.getParent(); 72 121 } 73 122 74 // calculate window hashcode 75 currentTarget = path.pop(); 76 77 JFCGUIElementSpec currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 78 String title = currentSpec.getName(); 79 String fuzzyTitle = getFuzzyTitle(title); 80 long windowHashCode = fuzzyTitle.hashCode(); 81 windowHashCode = (windowHashCode * 2) & 0xffffffffL; 82 83 long propagatedHashCode = windowHashCode; 84 85 // walk through component path and calculate hashcode 86 87 while(!path.isEmpty()){ 88 currentTarget = path.pop(); 89 currentSpec = (JFCGUIElementSpec) currentTarget.getSpecification(); 90 long localHashCode = getLocalHashCode(currentSpec); 91 hashCode = propagatedHashCode * prime + localHashCode; 92 hashCode = (hashCode * 2) & 0xffffffffL; 93 94 if (!path.isEmpty()){ 95 Integer index = ((JFCGUIElementSpec) path.lastElement().getSpecification()).getIndex(); 96 propagatedHashCode = prime * propagatedHashCode 97 + index.hashCode(); 98 } 99 } 100 101 replayID = "e" + hashCode; 102 103 return replayID; 123 // calculation is delegated to other calculateReplayID method 124 return this.calculateReplayID(guiElementPath); 104 125 } 105 126
Note: See TracChangeset
for help on using the changeset viewer.