[837] | 1 | |
---|
[922] | 2 | package de.ugoe.cs.autoquest.plugin.mfc.eventcore; |
---|
[619] | 3 | |
---|
| 4 | import java.util.Map; |
---|
| 5 | |
---|
[922] | 6 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
| 7 | import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; |
---|
| 8 | import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed; |
---|
| 9 | import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased; |
---|
| 10 | import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange; |
---|
| 11 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; |
---|
| 12 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; |
---|
| 13 | import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; |
---|
| 14 | import de.ugoe.cs.autoquest.keyboardmaps.VirtualKey; |
---|
[619] | 15 | |
---|
| 16 | /** |
---|
| 17 | * <p> |
---|
[837] | 18 | * Creates the GUI event types (i.e., {@link IInteraction}s) for MFC events. |
---|
[619] | 19 | * </p> |
---|
| 20 | * |
---|
[837] | 21 | * @version 1.0 |
---|
| 22 | * @author Patrick Harms |
---|
[619] | 23 | */ |
---|
| 24 | public class MFCEventTypeFactory { |
---|
[837] | 25 | |
---|
[619] | 26 | /** |
---|
| 27 | * <p> |
---|
[837] | 28 | * Instance of the singleton |
---|
[619] | 29 | * </p> |
---|
| 30 | */ |
---|
| 31 | private static MFCEventTypeFactory instance = new MFCEventTypeFactory(); |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * <p> |
---|
[837] | 35 | * Constructor. Creates a new MFCEventTypeFactory. Private to preserve singleton property. |
---|
[619] | 36 | * </p> |
---|
[837] | 37 | * |
---|
[619] | 38 | */ |
---|
[837] | 39 | private MFCEventTypeFactory() {} |
---|
[619] | 40 | |
---|
| 41 | /** |
---|
| 42 | * <p> |
---|
[837] | 43 | * Returns the instance of the MFCEventTypeFactory. |
---|
[619] | 44 | * </p> |
---|
[837] | 45 | * |
---|
| 46 | * @return the instance |
---|
[619] | 47 | */ |
---|
| 48 | public static MFCEventTypeFactory getInstance() { |
---|
| 49 | return instance; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * <p> |
---|
[837] | 54 | * Returns the event type based on the name and parameters of a MFC event. |
---|
[619] | 55 | * </p> |
---|
[837] | 56 | * |
---|
| 57 | * @param eventName |
---|
| 58 | * name of the MFC event |
---|
| 59 | * @param messageParameters |
---|
| 60 | * parameters of the MFC event |
---|
| 61 | * @return the event type |
---|
[619] | 62 | */ |
---|
[837] | 63 | public IEventType getEventType(String eventName, Map<String, String> messageParameters) { |
---|
[619] | 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 | /** |
---|
[837] | 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 |
---|
[619] | 149 | */ |
---|
[837] | 150 | private VirtualKey getKey(Map<String, String> messageParameters) |
---|
| 151 | throws IllegalArgumentException |
---|
| 152 | { |
---|
[619] | 153 | String value = null; |
---|
[837] | 154 | |
---|
[619] | 155 | if (messageParameters != null) { |
---|
| 156 | value = messageParameters.get("key"); |
---|
| 157 | } |
---|
[837] | 158 | |
---|
[619] | 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> |
---|
[837] | 170 | * If the message parameters contain information about a scroll position, the respective |
---|
| 171 | * position is returned. |
---|
[619] | 172 | * </p> |
---|
[837] | 173 | * |
---|
[619] | 174 | * @param messageParameters |
---|
[837] | 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 |
---|
[619] | 180 | */ |
---|
[837] | 181 | private int getSelectedValue(Map<String, String> messageParameters) |
---|
| 182 | throws IllegalArgumentException |
---|
| 183 | { |
---|
[619] | 184 | String value = null; |
---|
[837] | 185 | |
---|
[619] | 186 | if (messageParameters != null) { |
---|
| 187 | value = messageParameters.get("scrollPos"); |
---|
| 188 | } |
---|
[837] | 189 | |
---|
[619] | 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 | } |
---|