package de.ugoe.cs.quest.plugin.mfc.eventcore; import java.util.HashMap; import java.util.Map; import de.ugoe.cs.quest.plugin.mfc.guimodel.MFCGUIElement; /** *

* Contains all informations about a windows message, i.e., all parameters that are read when a * windows message is parsed as well as its target, hwnd, etc. *

* * @author Steffen Herbold * @version 1.0 * */ public class WindowsMessage { /** *

* Type of the message. *

*/ final WindowsMessageType type; /** *

* LPARAM of the message. Default: 0 *

*/ private long LPARAM = 0; /** *

* WPARAM of the message. Default: 0 *

*/ private long WPARAM = 0; /** *

* A map of all parameters, associated with the message, created during the parsing of messages * from the logs {@code param}-nodes. *

*/ private Map params = new HashMap(); /** *

* the target GUI element to which the message was sent *

*/ private MFCGUIElement target; /** *

* an XML representation of the target to preserve it as it was when this message was created *

*/ protected String targetXML; /** *

* Constructor. Creates a new message with a given message type. *

* * @param type * type of the message * @param currentMessageParameters * @param target */ public WindowsMessage(WindowsMessageType type, MFCGUIElement target, Map messageParameters) { this.type = type; setTarget(target); for (Map.Entry entry : messageParameters.entrySet()) { addParameter(entry.getKey(), entry.getValue()); } } /** *

* Constructor. Creates a new message with a given message type. *

* * @param type * type of the message */ public WindowsMessage(WindowsMessageType type) { this.type = type; } /** *

* Adds a parameter to the message. *

* * @param type * type descriptor of the parameter * @param value * value of the parameter */ public void addParameter(String type, Object value) { params.put(type, value); if (type.equals("LPARAM")) { LPARAM = (Long) value; } else if (type.equals("WPARAM")) { WPARAM = (Long) value; } } /** *

* Returns the type of the message. *

* * @return type of the message */ public WindowsMessageType getType() { return type; } /** *

* TODO: comment *

* * @param target2 */ public void setTarget(MFCGUIElement target) { this.target = target; this.targetXML = target.toXML(); } /** *

* TODO: comment *

* * @return */ public MFCGUIElement getTarget() { return target; } /** *

* Returns the value of a parameter, given its type. If the parameter is not found, {@code null} * is returned. *

* * @param type * type of the parameter * @return value of the parameter */ public Object getParameter(String type) { return params.get(type); } /** *

* Two {@link WindowsMessage} are equal, if their {@link #type}, {@link #xmlWindowDescription}, * and {@link #params} are equal. *

* * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object other) { if (other == this) { return true; } boolean isEqual = false; if (other instanceof WindowsMessage) { isEqual = ((WindowsMessage) other).type == this.type && ((WindowsMessage) other).target.equals(this.target) && ((WindowsMessage) other).params.equals(this.params); } return isEqual; } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { int multiplier = 17; int hash = 42; hash = multiplier * hash + type.hashCode(); hash = multiplier * hash + target.hashCode(); hash = multiplier * hash + params.hashCode(); return hash; } /** *

* Returns a string representation of the message of the form "msg[target=HWND;type=TYPE]". *

* * @see java.lang.Object#toString() */ @Override public String toString() { return "msg[target=" + getParameter("window.hwnd") + ";type=" + type + "]"; } /** *

* Returns the LPARAM of a message. *

* * @return LPARAM of the message */ public long getLPARAM() { return LPARAM; } /** *

* Returns the WPARAM of a message. *

* * @return WPARAM of the message */ public long getWPARAM() { return WPARAM; } /** *

* Returns the number of parameters stored together with this message. *

* * @return number of parameters stored with this message */ public int getNumParams() { return params.size(); } /** *

* TODO: comment *

* * @return */ protected Map getParameters() { return params; } /** *

* TODO: comment *

* * @return */ public String getTargetXML() { return targetXML; } }