1 | |
---|
2 | package de.ugoe.cs.quest.plugin.mfc.eventcore; |
---|
3 | |
---|
4 | import java.util.Map; |
---|
5 | |
---|
6 | import de.ugoe.cs.quest.eventcore.IEventType; |
---|
7 | import de.ugoe.cs.quest.eventcore.gui.IInteraction; |
---|
8 | import de.ugoe.cs.quest.eventcore.gui.KeyPressed; |
---|
9 | import de.ugoe.cs.quest.eventcore.gui.KeyReleased; |
---|
10 | import de.ugoe.cs.quest.eventcore.gui.KeyboardFocusChange; |
---|
11 | import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; |
---|
12 | import de.ugoe.cs.quest.eventcore.gui.MouseClick; |
---|
13 | import de.ugoe.cs.quest.eventcore.gui.ValueSelection; |
---|
14 | import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; |
---|
15 | |
---|
16 | /** |
---|
17 | * <p> |
---|
18 | * Creates the GUI event types (i.e., {@link IInteraction}s) for MFC events. |
---|
19 | * </p> |
---|
20 | * |
---|
21 | * @version 1.0 |
---|
22 | * @author Patrick Harms |
---|
23 | */ |
---|
24 | public class MFCEventTypeFactory { |
---|
25 | |
---|
26 | /** |
---|
27 | * <p> |
---|
28 | * Instance of the singleton |
---|
29 | * </p> |
---|
30 | */ |
---|
31 | private static MFCEventTypeFactory instance = new MFCEventTypeFactory(); |
---|
32 | |
---|
33 | /** |
---|
34 | * <p> |
---|
35 | * Constructor. Creates a new MFCEventTypeFactory. Private to preserve singleton property. |
---|
36 | * </p> |
---|
37 | * |
---|
38 | */ |
---|
39 | private MFCEventTypeFactory() {} |
---|
40 | |
---|
41 | /** |
---|
42 | * <p> |
---|
43 | * Returns the instance of the MFCEventTypeFactory. |
---|
44 | * </p> |
---|
45 | * |
---|
46 | * @return the instance |
---|
47 | */ |
---|
48 | public static MFCEventTypeFactory getInstance() { |
---|
49 | return instance; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * <p> |
---|
54 | * Returns the event type based on the name and parameters of a MFC event. |
---|
55 | * </p> |
---|
56 | * |
---|
57 | * @param eventName |
---|
58 | * name of the MFC event |
---|
59 | * @param messageParameters |
---|
60 | * parameters of the MFC event |
---|
61 | * @return the event type |
---|
62 | */ |
---|
63 | public IEventType getEventType(String eventName, Map<String, String> messageParameters) { |
---|
64 | if ("LeftClickButton".equals(eventName)) { |
---|
65 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
66 | } |
---|
67 | else if ("LeftClickListBox".equals(eventName)) { |
---|
68 | return new ValueSelection<Integer>(getSelectedValue(messageParameters)); |
---|
69 | } |
---|
70 | else if ("TabChange".equals(eventName)) { |
---|
71 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
72 | } |
---|
73 | else if ("LeftClickCommand".equals(eventName)) { |
---|
74 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
75 | } |
---|
76 | else if ("LeftClickSysCommand".equals(eventName)) { |
---|
77 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
78 | } |
---|
79 | else if ("NCLeftClickSysCommand".equals(eventName)) { |
---|
80 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
81 | } |
---|
82 | else if ("LeftClickMenuItemCmd".equals(eventName)) { |
---|
83 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
84 | } |
---|
85 | else if ("HScroll_TrackBar".equals(eventName)) { |
---|
86 | return new ValueSelection<Integer>(getSelectedValue(messageParameters)); |
---|
87 | } |
---|
88 | else if ("VScroll_TrackBar".equals(eventName)) { |
---|
89 | return new ValueSelection<Integer>(getSelectedValue(messageParameters)); |
---|
90 | } |
---|
91 | else if ("HScroll_ScrollBar".equals(eventName)) { |
---|
92 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
93 | } |
---|
94 | else if ("VScroll_ScrollBar".equals(eventName)) { |
---|
95 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
96 | } |
---|
97 | else if ("VScrollNC".equals(eventName)) { |
---|
98 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
99 | } |
---|
100 | else if ("LeftClickSetFocus".equals(eventName)) { |
---|
101 | return new KeyboardFocusChange(); |
---|
102 | } |
---|
103 | else if ("LeftClickChangeFocus".equals(eventName)) { |
---|
104 | return new KeyboardFocusChange(); |
---|
105 | } |
---|
106 | else if ("KeyDown".equals(eventName)) { |
---|
107 | return new KeyPressed(getKey(messageParameters)); |
---|
108 | } |
---|
109 | else if ("KeyUp".equals(eventName)) { |
---|
110 | return new KeyReleased(getKey(messageParameters)); |
---|
111 | } |
---|
112 | else if ("SysKeyDown".equals(eventName)) { |
---|
113 | return new KeyPressed(getKey(messageParameters)); |
---|
114 | } |
---|
115 | else if ("SysKeyUp".equals(eventName)) { |
---|
116 | return new KeyReleased(getKey(messageParameters)); |
---|
117 | } |
---|
118 | else if ("LeftClickCoordinates".equals(eventName)) { |
---|
119 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
120 | } |
---|
121 | else if ("NCLeftClickCoordinates".equals(eventName)) { |
---|
122 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
123 | } |
---|
124 | else if ("NCLeftClickCoordinates2".equals(eventName)) { |
---|
125 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
126 | } |
---|
127 | else if ("LeftClickCoordinatesTargetChanged".equals(eventName)) { |
---|
128 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
129 | } |
---|
130 | else if ("LeftClickCoordinatesTargetChanged2".equals(eventName)) { |
---|
131 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
132 | } |
---|
133 | else { |
---|
134 | throw new IllegalArgumentException("unknown event name: " + eventName); |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * <p> |
---|
140 | * If the message parameters contain information about a key that has been pressed, the |
---|
141 | * associated {@link VirtualKey} is returned. |
---|
142 | * </p> |
---|
143 | * |
---|
144 | * @param messageParameters |
---|
145 | * the message parameters |
---|
146 | * @return key extracted from the message parameters |
---|
147 | * @throws IllegalArgumentException |
---|
148 | * thrown if the messageParameters do not contain information about a key |
---|
149 | */ |
---|
150 | private VirtualKey getKey(Map<String, String> messageParameters) |
---|
151 | throws IllegalArgumentException |
---|
152 | { |
---|
153 | String value = null; |
---|
154 | |
---|
155 | if (messageParameters != null) { |
---|
156 | value = messageParameters.get("key"); |
---|
157 | } |
---|
158 | |
---|
159 | if (value == null) { |
---|
160 | throw new IllegalArgumentException |
---|
161 | ("no parameter \"key\" provided for key event. Please correct the event " + |
---|
162 | "generation rules"); |
---|
163 | } |
---|
164 | |
---|
165 | return WindowsVirtualKey.parseVirtualKey(value).getKey(); |
---|
166 | } |
---|
167 | |
---|
168 | /** |
---|
169 | * <p> |
---|
170 | * If the message parameters contain information about a scroll position, the respective |
---|
171 | * position is returned. |
---|
172 | * </p> |
---|
173 | * |
---|
174 | * @param messageParameters |
---|
175 | * the message parameters |
---|
176 | * @return the scroll position |
---|
177 | * @throws IllegalArgumentException |
---|
178 | * thrown if the messageParameters do not contain information about a scroll |
---|
179 | * position |
---|
180 | */ |
---|
181 | private int getSelectedValue(Map<String, String> messageParameters) |
---|
182 | throws IllegalArgumentException |
---|
183 | { |
---|
184 | String value = null; |
---|
185 | |
---|
186 | if (messageParameters != null) { |
---|
187 | value = messageParameters.get("scrollPos"); |
---|
188 | } |
---|
189 | |
---|
190 | if (value == null) { |
---|
191 | throw new IllegalArgumentException |
---|
192 | ("no parameter \"scrollPos\" provided for scroll event. Please correct the event " + |
---|
193 | "generation rules"); |
---|
194 | } |
---|
195 | |
---|
196 | return Integer.parseInt(value); |
---|
197 | } |
---|
198 | |
---|
199 | } |
---|