Changeset 1049 for trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs
- Timestamp:
- 01/31/13 18:12:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/JFCSimplifiedLogParser.java
r1027 r1049 1 1 2 package de.ugoe.cs.autoquest.plugin.jfc; 2 3 … … 58 59 /** 59 60 * <p> 61 * Map that holds events that had no registered target GUI element during parsing. Keys are the 62 * IDs of the unregistered targets. 63 * </p> 64 */ 65 private Map<Long, List<Event>> eventsWithoutTargets; 66 67 /** 68 * <p> 60 69 * Collection of event sequences that is contained in the log file, which is parsed. 61 70 * </p> … … 81 90 * 82 91 * <p> 83 * Internal handle to the hashcode of the parent of the GUI element, that is currently parsed. 92 * Internal handle to the hashcode of the parent of the GUI element, that is currently parsed. 84 93 * </p> 85 94 */ … … 129 138 /** 130 139 * <p> 131 * internal handle to the GUI element of the previous event to be potentially reused for the132 * current133 * </p>134 */135 private IGUIElement lastGUIElement;136 137 /**138 * <p>139 140 * internal handle to the class ancestors 140 * </p> 141 * </p> 141 142 */ 142 143 private List<String> currentTypeHierarchy; … … 165 166 sequences = new LinkedList<List<Event>>(); 166 167 currentSequence = null; 167 //setupDefaultEventFilter(); 168 eventsWithoutTargets = new HashMap<Long, List<Event>>(); 169 // setupDefaultEventFilter(); 168 170 } 169 171 … … 183 185 sequences = new LinkedList<List<Event>>(); 184 186 currentSequence = null; 187 eventsWithoutTargets = new HashMap<Long, List<Event>>(); 185 188 eventFilter = ignoredEvents; 186 189 } … … 223 226 saxParser = spf.newSAXParser(); 224 227 inputSource = 225 228 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 226 229 } 227 230 catch (UnsupportedEncodingException e) { … … 255 258 catch (SAXParseException e) { 256 259 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 257 260 ", column " + e.getColumnNumber() + "."); 258 261 Console.logException(e); 259 262 return; … … 270 273 } 271 274 } 275 if (!eventsWithoutTargets.isEmpty()) { 276 Console.printerr("Some events reference GUI elments that are not part of logfile. +" 277 + "These events have been ignored."); 278 } 272 279 } 273 280 … … 301 308 */ 302 309 public void startElement(String uri, String localName, String qName, Attributes atts) 303 throws SAXException{ 310 throws SAXException 311 { 304 312 if (qName.equals("sessions")) { 305 313 currentSequence = new LinkedList<Event>(); … … 336 344 } 337 345 else if (qName.equals("param")) { 338 if (currentEventId != null) {339 if ("source".equals(atts.getValue("name"))) {346 if (currentEventId != null) { 347 if ("source".equals(atts.getValue("name"))) { 340 348 currentEventSource = Long.parseLong(atts.getValue("value"), 16); 341 349 } 342 if ("timestamp".equals(atts.getValue("name"))) {350 if ("timestamp".equals(atts.getValue("name"))) { 343 351 currentEventTimestamp = Long.parseLong(atts.getValue("value")); 344 352 } 345 353 currentEventParameters.put(atts.getValue("name"), atts.getValue("value")); 346 } else if(currentGUIElementHash != null){ 354 } 355 else if (currentGUIElementHash != null) { 347 356 if ("title".equals(atts.getValue("name"))) { 348 357 currentGuiElementSpec.setName(atts.getValue("value")); … … 362 371 } 363 372 } 364 else if (qName.equals("ancestor")) {373 else if (qName.equals("ancestor")) { 365 374 currentTypeHierarchy.add(atts.getValue("name")); 366 375 } 367 else if (qName.equals("ancestors")) {376 else if (qName.equals("ancestors")) { 368 377 currentTypeHierarchy = new LinkedList<String>(); 369 378 } … … 384 393 currentSequence = null; 385 394 } 386 else if (qName.equals("ancestors")) {395 else if (qName.equals("ancestors")) { 387 396 currentGuiElementSpec.setTypeHierarchy(currentTypeHierarchy); 388 397 } 389 398 else if (qName.equals("component") && currentGUIElementHash != null) { 390 currentGUIElementTree.add(currentGUIElementHash, currentParentHash, currentGuiElementSpec); 391 399 currentGUIElementTree.add(currentGUIElementHash, currentParentHash, 400 currentGuiElementSpec); 401 List<Event> unhandledEvents = eventsWithoutTargets.get(currentGUIElementHash); 402 if (unhandledEvents != null) { 403 JFCGUIElement guiElement = 404 (JFCGUIElement) currentGUIElementTree.find(currentGUIElementHash); 405 for (Event event : unhandledEvents) { 406 event.setTarget(guiElement); 407 guiElement.markAsUsed(); 408 currentSequence.add(event); 409 } 410 eventsWithoutTargets.remove(currentGUIElementHash); 411 } 392 412 currentGUIElementHash = null; 393 413 currentParentHash = null; … … 400 420 currentGUIElement = currentGUIElementTree.find(currentEventSource); 401 421 402 Event event = new Event 403 (instantiateInteraction(currentEventId, currentEventParameters), 404 (currentGUIElement == null ? lastGUIElement : currentGUIElement)); 405 event.setTimestamp(currentEventTimestamp); 406 JFCGUIElement currentEventTarget = (JFCGUIElement) event.getTarget(); 407 currentEventTarget.markAsUsed(); 408 409 currentSequence.add(event); 422 // in some rare cases the target GUI element of the event is not 423 // known yet 424 if (currentGUIElement == null) { 425 Event event = 426 new Event(instantiateInteraction(currentEventId, currentEventParameters)); 427 event.setTimestamp(currentEventTimestamp); 428 429 List<Event> eventList = eventsWithoutTargets.get(currentEventSource); 430 if (eventList == null) { 431 eventList = new ArrayList<Event>(); 432 eventsWithoutTargets.put(currentEventSource, eventList); 433 } 434 eventList.add(event); 435 } 436 else { 437 Event event = 438 new Event(instantiateInteraction(currentEventId, currentEventParameters), 439 currentGUIElement); 440 event.setTimestamp(currentEventTimestamp); 441 JFCGUIElement currentEventTarget = (JFCGUIElement) event.getTarget(); 442 currentEventTarget.markAsUsed(); 443 444 currentSequence.add(event); 445 } 410 446 411 447 currentEventParameters = null; 412 448 currentEventId = null; 413 449 currentEventTimestamp = -1l; 414 415 if (currentGUIElement != null) {416 lastGUIElement = currentGUIElement;417 }418 419 currentGUIElement = null;420 450 } 421 451 } … … 427 457 * interaction, that took place, i.e. the event type 428 458 * </p> 429 * 459 * 430 460 * @param eventId 431 461 * the id of the event 432 462 * @param eventParameters 433 463 * the parameters provided for the event 434 * 464 * 435 465 * @return as described 436 466 * 437 * @throws SAXException thrown if the provided event id is unknown 438 */ 439 private IInteraction instantiateInteraction(JFCEventId eventId, 467 * @throws SAXException 468 * thrown if the provided event id is unknown 469 */ 470 private IInteraction instantiateInteraction(JFCEventId eventId, 440 471 Map<String, String> eventParameters) 441 442 472 throws SAXException 473 { 443 474 switch (eventId) 444 475 { … … 464 495 throw new SAXException("unhandled event id " + eventId); 465 496 } 466 497 } 467 498 468 499 /** … … 471 502 * which mouse button is pressed, released or clicked. 472 503 * </p> 473 * 504 * 474 505 * @param eventId 475 506 * the id of the event 476 507 * @param eventParameters 477 508 * the parameters provided for the event 478 * 509 * 479 510 * @return as described 480 511 * 481 * @throws SAXException thrown if the provided event id or button index is unknown 512 * @throws SAXException 513 * thrown if the provided event id or button index is unknown 482 514 */ 483 515 private IInteraction handleMouseAction(JFCEventId eventId, Map<String, String> eventParameters) 484 485 516 throws SAXException 517 { 486 518 MouseButtonInteraction.Button button = null; 487 519 488 if (eventParameters.get("Button") != null) 489 { 520 if (eventParameters.get("Button") != null) { 490 521 int buttonId = Integer.parseInt(eventParameters.get("Button")); 491 if (buttonId == MouseEvent.BUTTON1) 492 { 522 if (buttonId == MouseEvent.BUTTON1) { 493 523 button = MouseButtonInteraction.Button.LEFT; 494 524 } 495 else if (buttonId == MouseEvent.BUTTON2) 496 { 525 else if (buttonId == MouseEvent.BUTTON2) { 497 526 button = MouseButtonInteraction.Button.MIDDLE; 498 527 } 499 else if (buttonId == MouseEvent.BUTTON3) 500 { 528 else if (buttonId == MouseEvent.BUTTON3) { 501 529 button = MouseButtonInteraction.Button.RIGHT; 502 530 } 503 else 504 { 531 else { 505 532 throw new SAXException("unknown mouse button index " + buttonId); 506 533 } 507 534 } 508 535 509 if (JFCEventId.MOUSE_CLICKED == eventId) 510 { 536 if (JFCEventId.MOUSE_CLICKED == eventId) { 511 537 int x = Integer.parseInt(eventParameters.get("X")); 512 538 int y = Integer.parseInt(eventParameters.get("Y")); 513 539 return new MouseClick(button, x, y); 514 540 } 515 else if (JFCEventId.MOUSE_PRESSED == eventId) 516 { 541 else if (JFCEventId.MOUSE_PRESSED == eventId) { 517 542 int x = Integer.parseInt(eventParameters.get("X")); 518 543 int y = Integer.parseInt(eventParameters.get("Y")); 519 544 return new MouseButtonDown(button, x, y); 520 545 } 521 else if (JFCEventId.MOUSE_RELEASED == eventId) 522 { 546 else if (JFCEventId.MOUSE_RELEASED == eventId) { 523 547 int x = Integer.parseInt(eventParameters.get("X")); 524 548 int y = Integer.parseInt(eventParameters.get("Y")); 525 549 return new MouseButtonUp(button, x, y); 526 550 } 527 else 528 { 551 else { 529 552 throw new SAXException("unknown event id " + eventId); 530 553 } 531 554 } 532 555 533 556 /** 534 557 * <p> 535 558 * handles a keyboard interaction. The method determines based on the event id and the 536 * parameters which key on the keyboard is pressed or released. It further checks, if for 537 * everyreleased key there is also a pressed event538 * </p> 539 * 559 * parameters which key on the keyboard is pressed or released. It further checks, if for every 560 * released key there is also a pressed event 561 * </p> 562 * 540 563 * @param eventId 541 564 * the id of the event 542 565 * @param eventParameters 543 566 * the parameters provided for the event 544 * 567 * 545 568 * @return as described 546 569 * 547 * @throws SAXException thrown if the provided event id is unknown or if there is a key 548 * release without a preceding press of the same key 570 * @throws SAXException 571 * thrown if the provided event id is unknown or if there is a key release without a 572 * preceding press of the same key 549 573 */ 550 574 private IInteraction handleKeyAction(JFCEventId eventId, Map<String, String> eventParameters) 551 552 575 throws SAXException 576 { 553 577 // TODO handle shortcuts 554 if (JFCEventId.KEY_PRESSED == eventId) 555 { 578 if (JFCEventId.KEY_PRESSED == eventId) { 556 579 VirtualKey key = VirtualKey.parseVirtualKey(eventParameters.get("KeyCode")); 557 580 mPressedKeys.add(key); … … 559 582 return new KeyPressed(key); 560 583 } 561 else if (JFCEventId.KEY_RELEASED == eventId) 562 { 584 else if (JFCEventId.KEY_RELEASED == eventId) { 563 585 VirtualKey key = VirtualKey.parseVirtualKey(eventParameters.get("KeyCode")); 564 if (mPressedKeys.contains(key)) 565 { 586 if (mPressedKeys.contains(key)) { 566 587 mPressedKeys.remove(key); 567 588 } 568 else 569 {570 Console.traceln(Level.SEVERE,"log file has an error, as it contains a key up event on key " +571 key + " for which there is no preceeding key down event");589 else { 590 Console.traceln(Level.SEVERE, 591 "log file has an error, as it contains a key up event on key " + 592 key + " for which there is no preceeding key down event"); 572 593 } 573 594 … … 576 597 577 598 throw new SAXException("unknown event id " + eventId); 578 599 } 579 600 580 601 /** … … 582 603 * handles explicit keyboard focus changes. 583 604 * </p> 584 * 605 * 585 606 * @param eventId 586 607 * the id of the event 587 608 * @param eventParameters 588 609 * the parameters provided for the event 589 * 610 * 590 611 * @return as described 591 612 * 592 * @throws SAXException thrown if the provided event id is unknown 613 * @throws SAXException 614 * thrown if the provided event id is unknown 593 615 */ 594 616 private IInteraction handleNewFocus(JFCEventId eventId, Map<String, String> eventParameters) 595 throws SAXException 596 { 597 if (JFCEventId.FOCUS_GAINED == eventId) 598 { 617 throws SAXException 618 { 619 if (JFCEventId.FOCUS_GAINED == eventId) { 599 620 return new KeyboardFocusChange(); 600 621 } 601 else 602 { 622 else { 603 623 throw new SAXException("unknown event id " + eventId); 604 624 } 605 625 } 606 626 607 627 /** … … 611 631 * </p> 612 632 */ 613 /*private void setupDefaultEventFilter() { 614 eventFilter = new HashSet<JFCEventId>(); 615 eventFilter.add(JFCEventId.MOUSE_PRESSED); 616 eventFilter.add(JFCEventId.MOUSE_RELEASED); 617 eventFilter.add(JFCEventId.FOCUS_GAINED); 618 }*/ 633 /* 634 * private void setupDefaultEventFilter() { eventFilter = new HashSet<JFCEventId>(); 635 * eventFilter.add(JFCEventId.MOUSE_PRESSED); eventFilter.add(JFCEventId.MOUSE_RELEASED); 636 * eventFilter.add(JFCEventId.FOCUS_GAINED); } 637 */ 619 638 }
Note: See TracChangeset
for help on using the changeset viewer.