[922] | 1 | package de.ugoe.cs.autoquest.tasktrees.nodeequality; |
---|
[807] | 2 | |
---|
[1061] | 3 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
[922] | 4 | import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; |
---|
[1043] | 5 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; |
---|
[1056] | 6 | import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; |
---|
[1043] | 7 | import de.ugoe.cs.autoquest.eventcore.gui.MouseDragAndDrop; |
---|
[922] | 8 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput; |
---|
| 9 | import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; |
---|
[1061] | 10 | import de.ugoe.cs.autoquest.eventcore.guimodel.IButton; |
---|
| 11 | import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox; |
---|
| 12 | import de.ugoe.cs.autoquest.eventcore.guimodel.IComboBox; |
---|
| 13 | import de.ugoe.cs.autoquest.eventcore.guimodel.IImage; |
---|
| 14 | import de.ugoe.cs.autoquest.eventcore.guimodel.IListBox; |
---|
| 15 | import de.ugoe.cs.autoquest.eventcore.guimodel.IMenuButton; |
---|
| 16 | import de.ugoe.cs.autoquest.eventcore.guimodel.IRadioButton; |
---|
| 17 | import de.ugoe.cs.autoquest.eventcore.guimodel.IShape; |
---|
| 18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IText; |
---|
| 19 | import de.ugoe.cs.autoquest.eventcore.guimodel.IToolTip; |
---|
[922] | 20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
| 21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; |
---|
[807] | 22 | |
---|
| 23 | /** |
---|
| 24 | * <p> |
---|
| 25 | * This rule compares GUI event tasks (i.e. it is more concrete, than the |
---|
| 26 | * {@link EventTaskComparisonRule}). Two GUI event tasks are only equal if their event type and |
---|
| 27 | * target are equal. The returned equality is even more fine-grained for events whose type is |
---|
| 28 | * {@link TextInput} and {@link ValueSelection}. For text inputs, lexical equality is returned if |
---|
| 29 | * the same text is entered using the same key interactions. Syntactical equality is returned if |
---|
| 30 | * the same text is entered using different key interactions. Semantical equality is returned if |
---|
| 31 | * different text is entered, but into the same event target. Value selections are syntactically |
---|
| 32 | * equal, if the same value is selected. Otherwise they are semantically equal. |
---|
| 33 | * </p> |
---|
| 34 | * |
---|
| 35 | * @author Patrick Harms |
---|
| 36 | */ |
---|
| 37 | public class GUIEventTaskComparisonRule implements NodeComparisonRule { |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * (non-Javadoc) |
---|
| 41 | * |
---|
| 42 | * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) |
---|
| 43 | */ |
---|
| 44 | @Override |
---|
| 45 | public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { |
---|
| 46 | if ((!(node1 instanceof IEventTask)) || (!(node2 instanceof IEventTask))) { |
---|
| 47 | return null; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | IEventTask task1 = (IEventTask) node1; |
---|
| 51 | IEventTask task2 = (IEventTask) node2; |
---|
| 52 | |
---|
| 53 | if ((!(task1.getEventType() instanceof IInteraction)) || |
---|
| 54 | (!(task2.getEventType() instanceof IInteraction))) |
---|
| 55 | { |
---|
| 56 | return null; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if (node1 == node2) { |
---|
| 60 | return NodeEquality.IDENTICAL; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if (!task1.getEventTarget().equals(task2.getEventTarget())) { |
---|
| 64 | return NodeEquality.UNEQUAL; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | IInteraction interaction1 = (IInteraction) task1.getEventType(); |
---|
| 68 | IInteraction interaction2 = (IInteraction) task2.getEventType(); |
---|
| 69 | |
---|
[1061] | 70 | return compareInteractions(interaction1, interaction2, task1.getEventTarget()); |
---|
[807] | 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * <p> |
---|
[1061] | 75 | * compares two interactions. The method delegates to other, more specific compare method, e.g., |
---|
[807] | 76 | * {@link #compareTextInputs(TextInput, TextInput)} and |
---|
[1061] | 77 | * {@link #compareValueSelections(ValueSelection, ValueSelection)}, if any exist for the |
---|
| 78 | * concrete interaction types. Otherwise it uses the equals method of the interactions for |
---|
| 79 | * comparison. In this case, if the interactions equals method returns true, this method |
---|
| 80 | * returns lexical equality. |
---|
[807] | 81 | * </p> |
---|
| 82 | * |
---|
| 83 | * @param interaction1 the first interaction to compare |
---|
| 84 | * @param interaction2 the second interaction to compare |
---|
[1061] | 85 | * @param eventTarget the event target on which the interactions happened (used within |
---|
| 86 | * special comparisons like mouse clicks on buttons, where the coordinates |
---|
| 87 | * can be ignored) |
---|
[807] | 88 | * |
---|
| 89 | * @return as described |
---|
| 90 | */ |
---|
[1061] | 91 | private NodeEquality compareInteractions(IInteraction interaction1, |
---|
| 92 | IInteraction interaction2, |
---|
| 93 | IEventTarget eventTarget) |
---|
| 94 | { |
---|
[807] | 95 | if (interaction1 == interaction2) { |
---|
| 96 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 97 | } |
---|
| 98 | else if ((interaction1 instanceof TextInput) && (interaction2 instanceof TextInput)) { |
---|
| 99 | return compareTextInputs((TextInput) interaction1, (TextInput) interaction2); |
---|
| 100 | } |
---|
| 101 | else if ((interaction1 instanceof ValueSelection) && |
---|
| 102 | (interaction2 instanceof ValueSelection)) |
---|
| 103 | { |
---|
| 104 | return compareValueSelections |
---|
| 105 | ((ValueSelection<?>) interaction1, (ValueSelection<?>) interaction2); |
---|
| 106 | } |
---|
[1043] | 107 | else if ((interaction1 instanceof MouseClick) && |
---|
| 108 | (interaction2 instanceof MouseClick)) |
---|
| 109 | { |
---|
[1061] | 110 | return compareMouseClicks |
---|
| 111 | ((MouseClick) interaction1, (MouseClick) interaction2, eventTarget); |
---|
[1043] | 112 | } |
---|
[1056] | 113 | else if ((interaction1 instanceof MouseDoubleClick) && |
---|
| 114 | (interaction2 instanceof MouseDoubleClick)) |
---|
| 115 | { |
---|
| 116 | return compareMouseDoubleClicks |
---|
[1061] | 117 | ((MouseDoubleClick) interaction1, (MouseDoubleClick) interaction2, eventTarget); |
---|
[1056] | 118 | } |
---|
[1043] | 119 | else if ((interaction1 instanceof MouseDragAndDrop) && |
---|
| 120 | (interaction2 instanceof MouseDragAndDrop)) |
---|
| 121 | { |
---|
| 122 | return compareMouseDragAndDrops |
---|
| 123 | ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2); |
---|
| 124 | } |
---|
[807] | 125 | else if (interaction1.equals(interaction2)) { |
---|
| 126 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 127 | } |
---|
| 128 | else { |
---|
| 129 | return NodeEquality.UNEQUAL; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * <p> |
---|
| 135 | * compares two text inputs. If both text inputs have the same entered text and text input |
---|
| 136 | * events, they are lexically equal. If they only have the same entered text, they are |
---|
| 137 | * syntactically equal. If they are only both text inputs, they are semantically equal. |
---|
| 138 | * (the equality of the event targets is checked beforehand). |
---|
| 139 | * </p> |
---|
| 140 | * |
---|
| 141 | * @param interaction1 the first text input to compare |
---|
| 142 | * @param interaction2 the second text input to compare |
---|
| 143 | * |
---|
| 144 | * @return as described |
---|
| 145 | */ |
---|
| 146 | private NodeEquality compareTextInputs(TextInput interaction1, TextInput interaction2) { |
---|
| 147 | if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) { |
---|
| 148 | if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) { |
---|
| 149 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 150 | } |
---|
| 151 | else { |
---|
| 152 | return NodeEquality.SYNTACTICALLY_EQUAL; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | else { |
---|
| 156 | return NodeEquality.SEMANTICALLY_EQUAL; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * <p> |
---|
| 162 | * compares two value selections. If both value selections have the same selected value, they |
---|
| 163 | * are syntactically equal, otherwise they are semantically equal. |
---|
| 164 | * (the equality of the event targets is checked beforehand). |
---|
| 165 | * </p> |
---|
| 166 | * |
---|
| 167 | * @param interaction1 the first value selection to compare |
---|
| 168 | * @param interaction2 the second value selection to compare |
---|
| 169 | * |
---|
| 170 | * @return as described |
---|
| 171 | */ |
---|
| 172 | private NodeEquality compareValueSelections(ValueSelection<?> interaction1, |
---|
| 173 | ValueSelection<?> interaction2) |
---|
| 174 | { |
---|
| 175 | Object value1 = interaction1.getSelectedValue(); |
---|
| 176 | Object value2 = interaction2.getSelectedValue(); |
---|
| 177 | |
---|
| 178 | if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) { |
---|
[969] | 179 | return NodeEquality.LEXICALLY_EQUAL; |
---|
[807] | 180 | } |
---|
| 181 | else { |
---|
| 182 | return NodeEquality.SEMANTICALLY_EQUAL; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
[1043] | 186 | /** |
---|
| 187 | * <p> |
---|
| 188 | * compares two mouse clicks. If both clicks have the same coordinates, they are lexically |
---|
[1061] | 189 | * equal. Otherwise, they are semantically equal. Mouse clicks for which the coordinates make |
---|
| 190 | * no lexical difference (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) |
---|
| 191 | * are treated as lexically equal. |
---|
[1043] | 192 | * </p> |
---|
| 193 | * |
---|
| 194 | * @param interaction1 the first mouse click to compare |
---|
| 195 | * @param interaction2 the second mouse click to compare |
---|
[1061] | 196 | * @param eventTarget the event target on which the interactions happened (used within |
---|
| 197 | * special comparisons like mouse clicks on buttons, where the coordinates |
---|
| 198 | * can be ignored) |
---|
[1043] | 199 | * |
---|
| 200 | * @return as described |
---|
| 201 | */ |
---|
[1061] | 202 | private NodeEquality compareMouseClicks(MouseClick interaction1, |
---|
| 203 | MouseClick interaction2, |
---|
| 204 | IEventTarget eventTarget) |
---|
[1043] | 205 | { |
---|
[1057] | 206 | if (interaction1.getButton() != interaction2.getButton()) { |
---|
| 207 | return NodeEquality.UNEQUAL; |
---|
| 208 | } |
---|
| 209 | |
---|
[1061] | 210 | if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { |
---|
| 211 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 212 | } |
---|
| 213 | |
---|
[1043] | 214 | int x1 = interaction1.getX(); |
---|
| 215 | int x2 = interaction2.getX(); |
---|
| 216 | int y1 = interaction1.getY(); |
---|
| 217 | int y2 = interaction2.getY(); |
---|
| 218 | |
---|
| 219 | if ((x1 == x2) && (y1 == y2)) { |
---|
| 220 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 221 | } |
---|
| 222 | else { |
---|
| 223 | return NodeEquality.SEMANTICALLY_EQUAL; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | /** |
---|
| 228 | * <p> |
---|
[1056] | 229 | * compares two mouse double clicks. If both double clicks have the same coordinates, they are |
---|
[1061] | 230 | * lexically equal. Otherwise, they are semantically equal. Double clicks for which the |
---|
| 231 | * coordinates make no lexical difference |
---|
| 232 | * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as lexically |
---|
| 233 | * equal. |
---|
[1056] | 234 | * </p> |
---|
| 235 | * |
---|
| 236 | * @param interaction1 the first mouse double click to compare |
---|
| 237 | * @param interaction2 the second mouse double click to compare |
---|
[1061] | 238 | * @param eventTarget the event target on which the interactions happened (used within |
---|
| 239 | * special comparisons like mouse clicks on buttons, where the coordinates |
---|
| 240 | * can be ignored) |
---|
[1056] | 241 | * |
---|
| 242 | * @return as described |
---|
| 243 | */ |
---|
| 244 | private NodeEquality compareMouseDoubleClicks(MouseDoubleClick interaction1, |
---|
[1061] | 245 | MouseDoubleClick interaction2, |
---|
| 246 | IEventTarget eventTarget) |
---|
[1056] | 247 | { |
---|
[1057] | 248 | if (interaction1.getButton() != interaction2.getButton()) { |
---|
| 249 | return NodeEquality.UNEQUAL; |
---|
| 250 | } |
---|
| 251 | |
---|
[1061] | 252 | if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { |
---|
| 253 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 254 | } |
---|
| 255 | |
---|
[1056] | 256 | int x1 = interaction1.getX(); |
---|
| 257 | int x2 = interaction2.getX(); |
---|
| 258 | int y1 = interaction1.getY(); |
---|
| 259 | int y2 = interaction2.getY(); |
---|
| 260 | |
---|
| 261 | if ((x1 == x2) && (y1 == y2)) { |
---|
| 262 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 263 | } |
---|
| 264 | else { |
---|
| 265 | return NodeEquality.SEMANTICALLY_EQUAL; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /** |
---|
| 270 | * <p> |
---|
[1043] | 271 | * compares two mouse drag and drops. If both drag and drops have the same start and end |
---|
| 272 | * coordinates, they are lexically equal. Otherwise, they are semantically equal. |
---|
| 273 | * </p> |
---|
| 274 | * |
---|
| 275 | * @param interaction1 the first mouse drag and drop to compare |
---|
| 276 | * @param interaction2 the second mouse drag and drop to compare |
---|
| 277 | * |
---|
| 278 | * @return as described |
---|
| 279 | */ |
---|
| 280 | private NodeEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1, |
---|
| 281 | MouseDragAndDrop interaction2) |
---|
| 282 | { |
---|
[1057] | 283 | if (interaction1.getButton() != interaction2.getButton()) { |
---|
| 284 | return NodeEquality.UNEQUAL; |
---|
| 285 | } |
---|
| 286 | |
---|
[1043] | 287 | int x1 = interaction1.getX(); |
---|
| 288 | int x1Start = interaction1.getXStart(); |
---|
| 289 | int x2 = interaction2.getX(); |
---|
| 290 | int x2Start = interaction2.getXStart(); |
---|
| 291 | int y1 = interaction1.getY(); |
---|
| 292 | int y1Start = interaction1.getYStart(); |
---|
| 293 | int y2 = interaction2.getY(); |
---|
| 294 | int y2Start = interaction2.getYStart(); |
---|
| 295 | |
---|
| 296 | if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) { |
---|
| 297 | return NodeEquality.LEXICALLY_EQUAL; |
---|
| 298 | } |
---|
| 299 | else { |
---|
| 300 | return NodeEquality.SEMANTICALLY_EQUAL; |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | |
---|
[1061] | 304 | /** |
---|
| 305 | * <p> |
---|
| 306 | * Checks, if the coordinates of a click or double click on the provided event target makes |
---|
| 307 | * a lexical difference. Mouse clicks and double clicks on buttons, check boxes, |
---|
| 308 | * combo boxes, images, list boxes, menu buttons, radio buttons, shapes, uneditable text, |
---|
| 309 | * and tool tips have no lexical difference as long as they happen on the same event target. |
---|
| 310 | * The concrete coordinates are not relevant. |
---|
| 311 | * </p> |
---|
| 312 | * |
---|
| 313 | * @param eventTarget the event target on which the interaction occurred |
---|
| 314 | * |
---|
| 315 | * @return if the coordinates are important to be considered for clicks and double clicks, |
---|
| 316 | * false else |
---|
| 317 | */ |
---|
| 318 | private boolean clickCoordinatesMakeLexicalDifference(IEventTarget eventTarget) { |
---|
| 319 | if ((eventTarget instanceof IButton) || |
---|
| 320 | (eventTarget instanceof ICheckBox) || |
---|
| 321 | (eventTarget instanceof IComboBox) || |
---|
| 322 | (eventTarget instanceof IImage) || |
---|
| 323 | (eventTarget instanceof IListBox) || |
---|
| 324 | (eventTarget instanceof IMenuButton) || |
---|
| 325 | (eventTarget instanceof IRadioButton) || |
---|
| 326 | (eventTarget instanceof IShape) || |
---|
| 327 | (eventTarget instanceof IText) || |
---|
| 328 | (eventTarget instanceof IToolTip)) |
---|
| 329 | { |
---|
| 330 | return false; |
---|
| 331 | } |
---|
| 332 | else { |
---|
| 333 | return true; |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
[807] | 337 | } |
---|