[619] | 1 | |
---|
| 2 | package de.ugoe.cs.quest.plugin.mfc.eventcore; |
---|
| 3 | |
---|
| 4 | import java.util.HashMap; |
---|
| 5 | import java.util.Map; |
---|
| 6 | |
---|
| 7 | import de.ugoe.cs.quest.plugin.mfc.guimodel.MFCGUIElement; |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * <p> |
---|
| 11 | * Contains all informations about a windows message, i.e., all parameters that are read when a |
---|
| 12 | * windows message is parsed as well as its target, hwnd, etc. |
---|
| 13 | * </p> |
---|
| 14 | * |
---|
| 15 | * @author Steffen Herbold |
---|
| 16 | * @version 1.0 |
---|
| 17 | * |
---|
| 18 | */ |
---|
| 19 | public class WindowsMessage { |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * <p> |
---|
| 23 | * Type of the message. |
---|
| 24 | * </p> |
---|
| 25 | */ |
---|
| 26 | final WindowsMessageType type; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * <p> |
---|
| 30 | * LPARAM of the message. Default: 0 |
---|
| 31 | * </p> |
---|
| 32 | */ |
---|
| 33 | private long LPARAM = 0; |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * <p> |
---|
| 37 | * WPARAM of the message. Default: 0 |
---|
| 38 | * </p> |
---|
| 39 | */ |
---|
| 40 | private long WPARAM = 0; |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * <p> |
---|
| 44 | * A map of all parameters, associated with the message, created during the parsing of messages |
---|
| 45 | * from the logs {@code param}-nodes. |
---|
| 46 | * </p> |
---|
| 47 | */ |
---|
| 48 | private Map<String, Object> params = new HashMap<String, Object>(); |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * <p> |
---|
| 52 | * the target GUI element to which the message was sent |
---|
| 53 | * </p> |
---|
| 54 | */ |
---|
| 55 | private MFCGUIElement target; |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * <p> |
---|
| 59 | * an XML representation of the target to preserve it as it was when this message was created |
---|
| 60 | * </p> |
---|
| 61 | */ |
---|
| 62 | protected String targetXML; |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * <p> |
---|
| 66 | * Constructor. Creates a new message with a given message type. |
---|
| 67 | * </p> |
---|
| 68 | * |
---|
| 69 | * @param type |
---|
| 70 | * type of the message |
---|
| 71 | * @param currentMessageParameters |
---|
| 72 | * @param target |
---|
| 73 | */ |
---|
| 74 | public WindowsMessage(WindowsMessageType type, |
---|
| 75 | MFCGUIElement target, |
---|
| 76 | Map<String, Object> messageParameters) |
---|
| 77 | { |
---|
| 78 | this.type = type; |
---|
| 79 | setTarget(target); |
---|
| 80 | |
---|
| 81 | for (Map.Entry<String, Object> entry : messageParameters.entrySet()) { |
---|
| 82 | addParameter(entry.getKey(), entry.getValue()); |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * <p> |
---|
| 88 | * Constructor. Creates a new message with a given message type. |
---|
| 89 | * </p> |
---|
| 90 | * |
---|
| 91 | * @param type |
---|
| 92 | * type of the message |
---|
| 93 | */ |
---|
| 94 | public WindowsMessage(WindowsMessageType type) |
---|
| 95 | { |
---|
| 96 | this.type = type; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * <p> |
---|
| 101 | * Adds a parameter to the message. |
---|
| 102 | * </p> |
---|
| 103 | * |
---|
| 104 | * @param type |
---|
| 105 | * type descriptor of the parameter |
---|
| 106 | * @param value |
---|
| 107 | * value of the parameter |
---|
| 108 | */ |
---|
| 109 | public void addParameter(String type, Object value) { |
---|
| 110 | params.put(type, value); |
---|
| 111 | if (type.equals("LPARAM")) { |
---|
| 112 | LPARAM = (Long) value; |
---|
| 113 | } |
---|
| 114 | else if (type.equals("WPARAM")) { |
---|
| 115 | WPARAM = (Long) value; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * <p> |
---|
| 121 | * Returns the type of the message. |
---|
| 122 | * </p> |
---|
| 123 | * |
---|
| 124 | * @return type of the message |
---|
| 125 | */ |
---|
| 126 | public WindowsMessageType getType() { |
---|
| 127 | return type; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | * <p> |
---|
| 132 | * TODO: comment |
---|
| 133 | * </p> |
---|
| 134 | * |
---|
| 135 | * @param target2 |
---|
| 136 | */ |
---|
| 137 | public void setTarget(MFCGUIElement target) { |
---|
| 138 | this.target = target; |
---|
| 139 | this.targetXML = target.toXML(); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | * <p> |
---|
| 144 | * TODO: comment |
---|
| 145 | * </p> |
---|
| 146 | * |
---|
| 147 | * @return |
---|
| 148 | */ |
---|
| 149 | public MFCGUIElement getTarget() { |
---|
| 150 | return target; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | * <p> |
---|
| 155 | * Returns the value of a parameter, given its type. If the parameter is not found, {@code null} |
---|
| 156 | * is returned. |
---|
| 157 | * </p> |
---|
| 158 | * |
---|
| 159 | * @param type |
---|
| 160 | * type of the parameter |
---|
| 161 | * @return value of the parameter |
---|
| 162 | */ |
---|
| 163 | public Object getParameter(String type) { |
---|
| 164 | return params.get(type); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * <p> |
---|
| 169 | * Two {@link WindowsMessage} are equal, if their {@link #type}, {@link #xmlWindowDescription}, |
---|
| 170 | * and {@link #params} are equal. |
---|
| 171 | * </p> |
---|
| 172 | * |
---|
| 173 | * @see java.lang.Object#equals(java.lang.Object) |
---|
| 174 | */ |
---|
| 175 | @Override |
---|
| 176 | public boolean equals(Object other) { |
---|
| 177 | if (other == this) { |
---|
| 178 | return true; |
---|
| 179 | } |
---|
| 180 | boolean isEqual = false; |
---|
| 181 | if (other instanceof WindowsMessage) { |
---|
| 182 | isEqual = |
---|
| 183 | ((WindowsMessage) other).type == this.type && |
---|
| 184 | ((WindowsMessage) other).target.equals(this.target) && |
---|
| 185 | ((WindowsMessage) other).params.equals(this.params); |
---|
| 186 | } |
---|
| 187 | return isEqual; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | /* |
---|
| 191 | * (non-Javadoc) |
---|
| 192 | * |
---|
| 193 | * @see java.lang.Object#hashCode() |
---|
| 194 | */ |
---|
| 195 | @Override |
---|
| 196 | public int hashCode() { |
---|
| 197 | int multiplier = 17; |
---|
| 198 | int hash = 42; |
---|
| 199 | |
---|
| 200 | hash = multiplier * hash + type.hashCode(); |
---|
| 201 | hash = multiplier * hash + target.hashCode(); |
---|
| 202 | hash = multiplier * hash + params.hashCode(); |
---|
| 203 | |
---|
| 204 | return hash; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | /** |
---|
| 208 | * <p> |
---|
| 209 | * Returns a string representation of the message of the form "msg[target=HWND;type=TYPE]". |
---|
| 210 | * </p> |
---|
| 211 | * |
---|
| 212 | * @see java.lang.Object#toString() |
---|
| 213 | */ |
---|
| 214 | @Override |
---|
| 215 | public String toString() { |
---|
| 216 | return "msg[target=" + getParameter("window.hwnd") + ";type=" + type + "]"; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | /** |
---|
| 220 | * <p> |
---|
| 221 | * Returns the LPARAM of a message. |
---|
| 222 | * </p> |
---|
| 223 | * |
---|
| 224 | * @return LPARAM of the message |
---|
| 225 | */ |
---|
| 226 | public long getLPARAM() { |
---|
| 227 | return LPARAM; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | /** |
---|
| 231 | * <p> |
---|
| 232 | * Returns the WPARAM of a message. |
---|
| 233 | * </p> |
---|
| 234 | * |
---|
| 235 | * @return WPARAM of the message |
---|
| 236 | */ |
---|
| 237 | public long getWPARAM() { |
---|
| 238 | return WPARAM; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /** |
---|
| 242 | * <p> |
---|
| 243 | * Returns the number of parameters stored together with this message. |
---|
| 244 | * </p> |
---|
| 245 | * |
---|
| 246 | * @return number of parameters stored with this message |
---|
| 247 | */ |
---|
| 248 | public int getNumParams() { |
---|
| 249 | return params.size(); |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | /** |
---|
| 253 | * <p> |
---|
| 254 | * TODO: comment |
---|
| 255 | * </p> |
---|
| 256 | * |
---|
| 257 | * @return |
---|
| 258 | */ |
---|
| 259 | protected Map<String, Object> getParameters() { |
---|
| 260 | return params; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | /** |
---|
| 264 | * <p> |
---|
| 265 | * TODO: comment |
---|
| 266 | * </p> |
---|
| 267 | * |
---|
| 268 | * @return |
---|
| 269 | */ |
---|
| 270 | public String getTargetXML() { |
---|
| 271 | return targetXML; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | } |
---|