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