Changeset 1834
- Timestamp:
- 11/24/14 01:51:10 (10 years ago)
- Location:
- trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java
r1825 r1834 302 302 // if a menu file was provided, use the improved event 303 303 // generation 304 // TODO: check how much of this is still necessary with 305 // the new menu index system 304 306 if (menuList != null) { 305 307 if (event.getTarget() instanceof JFCMenuButton) { … … 423 425 if (indent < oldIndent) { 424 426 // this is a parent submenu 425 elements. add(menuElements.get(stripped));427 elements.push(menuElements.get(stripped)); 426 428 oldIndent = indent; 427 429 } -
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDparseJFCwithJacaretoIndices.java
r1722 r1834 15 15 package de.ugoe.cs.autoquest.plugin.jfc.commands; 16 16 17 import java.nio.charset.Charset; 18 import java.nio.file.Files; 19 import java.nio.file.Paths; 17 20 import java.util.Collection; 18 21 import java.util.HashMap; … … 24 27 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 25 28 import de.ugoe.cs.autoquest.plugin.jfc.JFCSimplifiedLogParser; 29 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElement; 26 30 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElementSpec; 31 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenu; 32 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenuButton; 27 33 import de.ugoe.cs.util.console.Command; 28 34 import de.ugoe.cs.util.console.Console; … … 40 46 public class CMDparseJFCwithJacaretoIndices implements Command { 41 47 48 private List<String> menuList; 49 42 50 @Override 43 51 public void run(List<Object> parameters) { … … 47 55 filename = (String) parameters.get(0); 48 56 if (parameters.size() >= 2) { 49 sequencesName = (String) parameters.get(1); 57 menuList = 58 Files.readAllLines(Paths.get((String) parameters.get(1)), 59 Charset.defaultCharset()); 50 60 } 51 61 } … … 80 90 @Override 81 91 public String help() { 82 return "parseJFCwithJacaretoIndices <filename> {<sequences>}"; 92 return "parseJFCwithJacaretoIndices <filename> {<menufile>}"; 93 } 94 95 private int findPopupMenuIndex(IGUIElement item, GUIModel model) { 96 // TODO: refactor 97 int index = -1; 98 List<IGUIElement> children = model.getChildren(item); 99 IGUIElement menuChild = null; 100 101 // try to identify this popup menu by looking at its children 102 // find the first menu item child of this item 103 for (IGUIElement child : children) { 104 if (child instanceof JFCMenuButton || child instanceof JFCMenu) { 105 menuChild = child; 106 break; 107 } 108 } 109 110 if (menuChild == null) { 111 // this popup menu cannot be identified 112 // TODO: exception, logging etc 113 return -1; 114 } 115 116 // find line that contains this menu item name 117 String itemName = ((JFCGUIElement) menuChild).getName().trim().toLowerCase(); 118 int lineOfItem = -1; 119 120 for (int i = 0; i < menuList.size(); i++) { 121 String name = "\"" + menuList.get(i).trim().toLowerCase() + "\""; 122 if (name.equals(itemName)) { 123 lineOfItem = i; 124 break; 125 } 126 } 127 128 if (lineOfItem == -1) { 129 // failed to find this item in the menu file 130 // TODO: exception, logging etc 131 return -1; 132 } 133 134 // find menu item's parent line 135 String stripped = menuList.get(lineOfItem).replaceFirst("^ *", ""); 136 int indent = menuList.get(lineOfItem).length() - stripped.length(); 137 138 if (indent != 0) { 139 for (int i = lineOfItem; i >= 0; i--) { 140 stripped = menuList.get(i).replaceFirst("^ *", ""); 141 int oldIndent = menuList.get(i).length() - stripped.length(); 142 143 if (oldIndent < indent) { 144 lineOfItem = i; 145 break; 146 } 147 } 148 } 149 150 // get the item's indentation 151 stripped = menuList.get(lineOfItem).replaceFirst("^ *", ""); 152 indent = menuList.get(lineOfItem).length() - stripped.length(); 153 154 if (indent == 0) { 155 // top level menu item, just count in which position it is 156 for (int i = 0; i <= lineOfItem; i++) { 157 if (!menuList.get(i).startsWith(" ")) { 158 index++; 159 } 160 } 161 } 162 else { 163 // find the topmenu index in the menu file by going backwards 164 for (int i = lineOfItem; i >= 0; i--) { 165 stripped = menuList.get(i).replaceFirst("^ *", ""); 166 int oldIndent = menuList.get(i).length() - stripped.length(); 167 168 if (oldIndent < indent) { 169 index = lineOfItem - i; 170 break; 171 } 172 } 173 } 174 175 return index; 83 176 } 84 177 … … 98 191 } 99 192 100 ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count); 193 if (menuList != null && type.equals("javax.swing.JPopupMenu")) { 194 // try to use a workaround for popup menu index problems 195 int index = findPopupMenuIndex((IGUIElement) child, targets); 196 if (index != -1) { 197 ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(index); 198 } 199 else { 200 // workaround failed, use normal method as fallback 201 ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count); 202 } 203 } 204 else { 205 ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count); 206 } 101 207 102 208 generateJacaretoIndices(targets.getChildren(child), targets);
Note: See TracChangeset
for help on using the changeset viewer.