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