1 | package de.ugoe.cs.quest.plugin.mfc.eventcore; |
---|
2 | |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | import de.ugoe.cs.quest.eventcore.IEventType; |
---|
6 | import de.ugoe.cs.quest.eventcore.gui.KeyPressed; |
---|
7 | import de.ugoe.cs.quest.eventcore.gui.KeyReleased; |
---|
8 | import de.ugoe.cs.quest.eventcore.gui.KeyboardFocusChange; |
---|
9 | import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; |
---|
10 | import de.ugoe.cs.quest.eventcore.gui.MouseClick; |
---|
11 | import de.ugoe.cs.quest.eventcore.gui.ValueSelection; |
---|
12 | import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; |
---|
13 | |
---|
14 | /** |
---|
15 | * <p> |
---|
16 | * TODO comment |
---|
17 | * </p> |
---|
18 | * |
---|
19 | * @version $Revision: $ $Date: 21.08.2012$ |
---|
20 | * @author 2012, last modified by $Author: pharms$ |
---|
21 | */ |
---|
22 | public class MFCEventTypeFactory { |
---|
23 | |
---|
24 | /** |
---|
25 | * <p> |
---|
26 | * the instance of the singleton |
---|
27 | * </p> |
---|
28 | */ |
---|
29 | private static MFCEventTypeFactory instance = new MFCEventTypeFactory(); |
---|
30 | |
---|
31 | /** |
---|
32 | * <p> |
---|
33 | * TODO: comment |
---|
34 | * </p> |
---|
35 | * |
---|
36 | */ |
---|
37 | private MFCEventTypeFactory() { |
---|
38 | // prevent external instantiation |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * <p> |
---|
43 | * TODO: comment |
---|
44 | * </p> |
---|
45 | * |
---|
46 | * @return |
---|
47 | */ |
---|
48 | public static MFCEventTypeFactory getInstance() { |
---|
49 | return instance; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * <p> |
---|
54 | * TODO: comment |
---|
55 | * </p> |
---|
56 | * |
---|
57 | * @param currentRuleName |
---|
58 | * @return |
---|
59 | */ |
---|
60 | public IEventType getEventType(String eventName, |
---|
61 | Map<String, String> messageParameters) |
---|
62 | { |
---|
63 | if ("LeftClickButton".equals(eventName)) { |
---|
64 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
65 | } |
---|
66 | else if ("LeftClickListBox".equals(eventName)) { |
---|
67 | return new ValueSelection<Integer>(getSelectedValue(messageParameters)); |
---|
68 | } |
---|
69 | else if ("TabChange".equals(eventName)) { |
---|
70 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
71 | } |
---|
72 | else if ("LeftClickCommand".equals(eventName)) { |
---|
73 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
74 | } |
---|
75 | else if ("LeftClickSysCommand".equals(eventName)) { |
---|
76 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
77 | } |
---|
78 | else if ("NCLeftClickSysCommand".equals(eventName)) { |
---|
79 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
80 | } |
---|
81 | else if ("LeftClickMenuItemCmd".equals(eventName)) { |
---|
82 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
83 | } |
---|
84 | else if ("HScroll_TrackBar".equals(eventName)) { |
---|
85 | return new ValueSelection<Integer>(getSelectedValue(messageParameters)); |
---|
86 | } |
---|
87 | else if ("VScroll_TrackBar".equals(eventName)) { |
---|
88 | return new ValueSelection<Integer>(getSelectedValue(messageParameters)); |
---|
89 | } |
---|
90 | else if ("HScroll_ScrollBar".equals(eventName)) { |
---|
91 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
92 | } |
---|
93 | else if ("VScroll_ScrollBar".equals(eventName)) { |
---|
94 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
95 | } |
---|
96 | else if ("VScrollNC".equals(eventName)) { |
---|
97 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
98 | } |
---|
99 | else if ("LeftClickSetFocus".equals(eventName)) { |
---|
100 | return new KeyboardFocusChange(); |
---|
101 | } |
---|
102 | else if ("LeftClickChangeFocus".equals(eventName)) { |
---|
103 | return new KeyboardFocusChange(); |
---|
104 | } |
---|
105 | else if ("KeyDown".equals(eventName)) { |
---|
106 | return new KeyPressed(getKey(messageParameters)); |
---|
107 | } |
---|
108 | else if ("KeyUp".equals(eventName)) { |
---|
109 | return new KeyReleased(getKey(messageParameters)); |
---|
110 | } |
---|
111 | else if ("SysKeyDown".equals(eventName)) { |
---|
112 | return new KeyPressed(getKey(messageParameters)); |
---|
113 | } |
---|
114 | else if ("SysKeyUp".equals(eventName)) { |
---|
115 | return new KeyReleased(getKey(messageParameters)); |
---|
116 | } |
---|
117 | else if ("LeftClickCoordinates".equals(eventName)) { |
---|
118 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
119 | } |
---|
120 | else if ("NCLeftClickCoordinates".equals(eventName)) { |
---|
121 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
122 | } |
---|
123 | else if ("NCLeftClickCoordinates2".equals(eventName)) { |
---|
124 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
125 | } |
---|
126 | else if ("LeftClickCoordinatesTargetChanged".equals(eventName)) { |
---|
127 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
128 | } |
---|
129 | else if ("LeftClickCoordinatesTargetChanged2".equals(eventName)) { |
---|
130 | return new MouseClick(MouseButtonInteraction.Button.LEFT); |
---|
131 | } |
---|
132 | else { |
---|
133 | throw new IllegalArgumentException("unknown event name: " + eventName); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * @param message |
---|
139 | * @return |
---|
140 | */ |
---|
141 | private VirtualKey getKey(Map<String, String> messageParameters) { |
---|
142 | String value = null; |
---|
143 | |
---|
144 | if (messageParameters != null) { |
---|
145 | value = messageParameters.get("key"); |
---|
146 | } |
---|
147 | |
---|
148 | if (value == null) { |
---|
149 | throw new IllegalArgumentException |
---|
150 | ("no parameter \"key\" provided for key event. Please correct the event " + |
---|
151 | "generation rules"); |
---|
152 | } |
---|
153 | |
---|
154 | return WindowsVirtualKey.parseVirtualKey(value).getKey(); |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * <p> |
---|
159 | * TODO: comment |
---|
160 | * </p> |
---|
161 | * |
---|
162 | * @param messageParameters |
---|
163 | * @return |
---|
164 | */ |
---|
165 | private int getSelectedValue(Map<String, String> messageParameters) { |
---|
166 | String value = null; |
---|
167 | |
---|
168 | if (messageParameters != null) { |
---|
169 | value = messageParameters.get("scrollPos"); |
---|
170 | } |
---|
171 | |
---|
172 | if (value == null) { |
---|
173 | throw new IllegalArgumentException |
---|
174 | ("no parameter \"scrollPos\" provided for scroll event. Please correct the event " + |
---|
175 | "generation rules"); |
---|
176 | } |
---|
177 | |
---|
178 | return Integer.parseInt(value); |
---|
179 | } |
---|
180 | |
---|
181 | } |
---|