source: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/eventcore/HTMLEventTypeFactory.java @ 1047

Last change on this file since 1047 was 1047, checked in by fglaser, 11 years ago
  • First version of new HTMLLogParser added
  • Property svn:mime-type set to text/plain
File size: 2.9 KB
Line 
1
2package de.ugoe.cs.autoquest.plugin.html.eventcore;
3
4import java.util.Map;
5import java.util.logging.Level;
6
7import de.ugoe.cs.autoquest.eventcore.IEventType;
8import de.ugoe.cs.autoquest.eventcore.gui.IInteraction;
9import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange;
10import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
11import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
12import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
13import de.ugoe.cs.util.console.Console;
14
15public class HTMLEventTypeFactory {
16    private static HTMLEventTypeFactory instance = new HTMLEventTypeFactory();
17
18    private HTMLEventTypeFactory() {}
19
20    public static HTMLEventTypeFactory getInstance() {
21        return instance;
22    }
23
24    public IEventType getEventType(String eventName, Map<String, String> eventParameters) {
25        IInteraction result = null;
26
27        if ("onscroll".equals(eventName)) {
28            int[] coordinates = getCoordinateParameter(eventName, eventParameters);
29            result = new Scroll(coordinates[0], coordinates[1]);
30        }
31        else if ("onclick".equals(eventName)) {
32            int[] coordinates = getCoordinateParameter(eventName, eventParameters);
33            result =
34                new MouseClick(MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]);
35        }
36        else if ("onchange".equals(eventName)) {
37            // TODO: Implement "onchange" event handling
38            Console.traceln(Level.FINE, "Unhandled event of type \"" + eventName + "\"");
39        }
40        else if ("onfocus".equals(eventName)) {
41            result = new KeyboardFocusChange();
42        }
43        else if ("onunload".equals(eventName) || "onbeforeunload".equals(eventName) ||
44            "onpagehide".equals(eventName) || "onpageshow".equals(eventName))
45        {
46            Console.traceln(Level.FINE, "Ignored event name \"" + eventName + "\"");
47        }
48        else {
49            throw new IllegalArgumentException("unknown event name: \"" + eventName + "\"");
50        }
51        return result;
52    }
53
54    /**
55     * <p>
56     * TODO: comment
57     * </p>
58     *
59     * @param eventName
60     * @param eventParameters
61     * @return
62     */
63    private int[] getCoordinateParameter(String eventName, Map<String, String> eventParameters) {
64        String xCoord = eventParameters.get("X");
65        if (xCoord == null) {
66            throw new IllegalArgumentException("eventParameters do not contain X coordinate.");
67        }
68
69        String yCoord = eventParameters.get("Y");
70        if (yCoord == null) {
71            throw new IllegalArgumentException("eventParameters do not contain Y coordinate.");
72        }
73
74        try {
75            return new int[]
76                { Integer.parseInt(xCoord), Integer.parseInt(yCoord) };
77        }
78        catch (NumberFormatException e) {
79            throw new IllegalArgumentException("the coordinates provided" + " of an " + eventName +
80                " event are no numbers");
81        }
82    }
83}
Note: See TracBrowser for help on using the repository browser.