Changeset 1825 for trunk/autoquest-plugin-jfc/src/main/java/de/ugoe
- Timestamp:
- 11/14/14 06:10:51 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateJacaretoReplay.java
r1809 r1825 20 20 import java.io.IOException; 21 21 import java.io.OutputStreamWriter; 22 import java.nio.charset.Charset; 23 import java.nio.file.Files; 24 import java.nio.file.Paths; 22 25 import java.util.ArrayList; 23 26 import java.util.Calendar; … … 26 29 import java.util.Iterator; 27 30 import java.util.List; 31 import java.util.Stack; 28 32 import java.util.UUID; 29 33 import java.util.logging.Level; … … 35 39 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 36 40 import de.ugoe.cs.autoquest.eventcore.gui.*; 41 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 42 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 37 43 import de.ugoe.cs.autoquest.keyboardmaps.VirtualKey; 38 44 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElement; 45 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenu; 46 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenuButton; 39 47 import de.ugoe.cs.util.console.Console; 40 48 import de.ugoe.cs.util.console.GlobalDataContainer; … … 113 121 private StructureNode lastItemActionEvent; 114 122 private IEventTarget lastMouseDownTarget; 123 private HashMap<String, JFCGUIElement> menuElements; 124 private List<String> menuList; 115 125 116 126 /* … … 121 131 @Override 122 132 public String help() { 123 return "generateJacaretoReplay <filename> <sequences> <class> <basepath> <classpathext> {< initclass>}";133 return "generateJacaretoReplay <filename> <sequences> <class> <basepath> <classpathext> {<menufile>}"; 124 134 } 125 135 … … 137 147 String basepath; 138 148 String classpathext; 139 String initclass = "";140 149 try { 141 150 filename = (String) parameters.get(0); … … 150 159 151 160 if (parameters.size() > 5) { 152 initclass = (String) parameters.get(5); 161 try { 162 menuList = 163 Files.readAllLines(Paths.get((String) parameters.get(5)), 164 Charset.defaultCharset()); 165 } 166 catch (IOException e) { 167 Console.printerrln("Unable to open menu file"); 168 Console.logException(e); 169 } 153 170 } 154 171 … … 165 182 166 183 sequences = (Collection<List<Event>>) dataObject; 184 185 menuElements = new HashMap<>(); 167 186 168 187 // map which maps VirtualKeys back to awt key modifier codes … … 176 195 StructureNode.nextRef = 0; 177 196 178 writeJacaretoXML(sequences, filename, classpath, initclass,basepath, classpathext);197 writeJacaretoXML(sequences, filename, classpath, basepath, classpathext); 179 198 } 180 199 … … 186 205 private void writeJacaretoHead(BufferedWriter writer, 187 206 String classname, 188 String initclass,189 207 String basepath, 190 208 String classpathext) throws IOException … … 218 236 + "name=\"Autoquest Replay\" " 219 237 + "class=\"" + classname + "\" " 220 + "initclass=\" " + initclass + "\" "238 + "initclass=\"\" " 221 239 + "basepath=\"" + basepath + "\" " 222 240 + "classpathext=\"" + classpathext + "\" " … … 250 268 lastMouseClickEvent = new StructureNode("MouseClick"); 251 269 lastMouseDownTarget = event.getTarget(); 252 writeMouseClickEvent(writer, event, EVENT_DURATION, 501); 270 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 271 EVENT_DURATION, 501); 253 272 } 254 273 else if (event.getType() instanceof MouseButtonUp) { 255 274 lastKeySequenceEvent = null; 256 275 257 writeMouseClickEvent(writer, event, EVENT_DURATION, 502); 276 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 277 EVENT_DURATION, 502); 258 278 } 259 279 else if (event.getType() instanceof MouseDoubleClick) { … … 262 282 // first click 263 283 lastMouseClickEvent = multiClick.add("MouseClick"); 264 writeMouseClickEvent(writer, event, DOUBLE_CLICK_DURATION, 501); 265 writeMouseClickEvent(writer, event, DOUBLE_CLICK_DURATION, 502); 266 writeMouseClickEvent(writer, event, DOUBLE_CLICK_DURATION, 500); 284 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 285 DOUBLE_CLICK_DURATION, 501); 286 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 287 DOUBLE_CLICK_DURATION, 502); 288 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 289 DOUBLE_CLICK_DURATION, 500); 267 290 // second click 268 291 lastMouseClickEvent = multiClick.add("MouseClick"); 269 writeMouseClickEvent(writer, event, DOUBLE_CLICK_DURATION, 501); 270 writeMouseClickEvent(writer, event, DOUBLE_CLICK_DURATION, 502); 271 writeMouseClickEvent(writer, event, DOUBLE_CLICK_DURATION, 500); 292 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 293 DOUBLE_CLICK_DURATION, 501); 294 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 295 DOUBLE_CLICK_DURATION, 502); 296 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 297 DOUBLE_CLICK_DURATION, 500); 272 298 273 299 lastMouseClickEvent = null; 274 300 } 275 301 else if (event.getType() instanceof MouseClick) { 302 // if a menu file was provided, use the improved event 303 // generation 304 if (menuList != null) { 305 if (event.getTarget() instanceof JFCMenuButton) { 306 if (menuElements.isEmpty()) { 307 // parse the menu structure 308 GUIModel model = ((IGUIElement) event.getTarget()).getGUIModel(); 309 getMenuElements(model.getRootElements(), model); 310 } 311 312 Stack<JFCGUIElement> hierarchy = 313 findMenuItemHierarchy((JFCGUIElement) event.getTarget()); 314 315 while (!hierarchy.empty()) { 316 generateFullClick(writer, event, hierarchy.pop()); 317 } 318 continue; 319 } 320 } 321 276 322 lastKeySequenceEvent = null; 277 323 … … 282 328 // was triggered on this target 283 329 284 writeMouseClickEvent(writer, event, EVENT_DURATION, 500); 330 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 331 EVENT_DURATION, 500); 285 332 writeItemActionEvent(writer, event); 286 333 … … 307 354 308 355 // finish the last click on the old target 309 writeMouseClickEvent(writer, event, EVENT_DURATION, 500); 356 writeMouseClickEvent(writer, event, (JFCGUIElement) event.getTarget(), 357 EVENT_DURATION, 500); 310 358 structure.children.add(lastMouseClickEvent); 311 359 312 360 // and generate a new one 313 generateFullClick(writer, event );361 generateFullClick(writer, event, (JFCGUIElement) event.getTarget()); 314 362 } 315 363 } … … 319 367 // mouseUps anymore 320 368 // -> just generate another full click 321 generateFullClick(writer, event );369 generateFullClick(writer, event, (JFCGUIElement) event.getTarget()); 322 370 } 323 371 } … … 345 393 } 346 394 395 private void getMenuElements(List<IGUIElement> elements, GUIModel model) { 396 for (IGUIElement child : elements) { 397 if (child instanceof JFCMenuButton || child instanceof JFCMenu) { 398 menuElements.put(((JFCGUIElement) child).getName().replaceAll("^\"|\"$", ""), 399 (JFCGUIElement) child); 400 } 401 getMenuElements(model.getChildren(child), model); 402 } 403 } 404 405 private Stack<JFCGUIElement> findMenuItemHierarchy(JFCGUIElement item) { 406 Stack<JFCGUIElement> elements = new Stack<>(); 407 408 // find line that contains this menu item name 409 int lineOfItem = -1; 410 for (int i = 0; i < menuList.size(); i++) { 411 String name = "\"" + menuList.get(i).trim().toLowerCase() + "\""; 412 if (name.equals(item.getName().trim().toLowerCase())) { 413 lineOfItem = i; 414 } 415 } 416 417 // now go backwards until the toplevel menu is found 418 int oldIndent = Integer.MAX_VALUE; 419 for (int j = lineOfItem; j >= 0; j--) { 420 String stripped = menuList.get(j).replaceFirst("^ *", ""); 421 int indent = menuList.get(j).length() - stripped.length(); 422 423 if (indent < oldIndent) { 424 // this is a parent submenu 425 elements.add(menuElements.get(stripped)); 426 oldIndent = indent; 427 } 428 } 429 430 return elements; 431 } 432 347 433 private void commitFocusEvent() { 348 434 if (lastFocusChangeEvent != null) { … … 352 438 } 353 439 354 private void generateFullClick(BufferedWriter writer, Event event) throws IOException { 440 private void generateFullClick(BufferedWriter writer, Event event, JFCGUIElement target) 441 throws IOException 442 { 355 443 lastMouseClickEvent = new StructureNode("MouseClick"); 356 444 lastMouseDownTarget = event.getTarget(); 357 445 358 writeMouseClickEvent(writer, event, EVENT_DURATION, 501);359 writeMouseClickEvent(writer, event, EVENT_DURATION, 502);360 writeMouseClickEvent(writer, event, EVENT_DURATION, 500);446 writeMouseClickEvent(writer, event, target, EVENT_DURATION, 501); 447 writeMouseClickEvent(writer, event, target, EVENT_DURATION, 502); 448 writeMouseClickEvent(writer, event, target, EVENT_DURATION, 500); 361 449 writeItemActionEvent(writer, event); 362 450 … … 365 453 366 454 lastMouseDownTarget = null; 367 368 455 } 369 456 … … 381 468 String filename, 382 469 String classpath, 383 String initclass,384 470 String basepath, 385 471 String classpathext) … … 388 474 389 475 try { 390 writeJacaretoHead(writer, classpath, initclass,basepath, classpathext);476 writeJacaretoHead(writer, classpath, basepath, classpathext); 391 477 writeJacaretoEvents(writer, sequences); 392 478 writeJacaretoTail(writer); … … 519 605 } 520 606 521 private void writeMouseClickEvent(BufferedWriter writer, Event event, int duration, int jacId) 522 throws IOException 607 private void writeMouseClickEvent(BufferedWriter writer, 608 Event event, 609 JFCGUIElement target, 610 int duration, 611 int jacId) throws IOException 523 612 { 524 613 MouseButtonInteraction info = (MouseButtonInteraction) event.getType(); 525 JFCGUIElement target = (JFCGUIElement) event.getTarget();526 614 int clickCount = event.getType() instanceof MouseDoubleClick ? 2 : 1; 527 615 528 // TODO: change procTime and duration to adequate values529 616 //@formatter:off 530 617 writeLine(writer,
Note: See TracChangeset
for help on using the changeset viewer.