Changeset 1125 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/GUIEventTaskComparisonRule.java
- Timestamp:
- 03/18/13 11:46:47 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/GUIEventTaskComparisonRule.java
r1113 r1125 17 17 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 18 18 import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; 19 import de.ugoe.cs.autoquest.eventcore.gui.KeyInteraction; 20 import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed; 21 import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased; 22 import de.ugoe.cs.autoquest.eventcore.gui.KeyTyped; 23 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonDown; 24 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 25 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonUp; 19 26 import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 20 27 import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 21 28 import de.ugoe.cs.autoquest.eventcore.gui.MouseDragAndDrop; 29 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 22 30 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 23 31 import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; … … 27 35 import de.ugoe.cs.autoquest.eventcore.guimodel.IImage; 28 36 import de.ugoe.cs.autoquest.eventcore.guimodel.IListBox; 37 import de.ugoe.cs.autoquest.eventcore.guimodel.IMenu; 29 38 import de.ugoe.cs.autoquest.eventcore.guimodel.IMenuButton; 30 39 import de.ugoe.cs.autoquest.eventcore.guimodel.IRadioButton; … … 51 60 public class GUIEventTaskComparisonRule implements NodeComparisonRule { 52 61 53 /* 54 * (non-Javadoc) 55 * 56 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 62 /* (non-Javadoc) 63 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 64 */ 65 @Override 66 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 67 return 68 ((node1 instanceof IEventTask) && (node2 instanceof IEventTask) && 69 (((IEventTask) node1).getEventType() instanceof IInteraction) && 70 (((IEventTask) node2).getEventType() instanceof IInteraction)); 71 } 72 73 /* (non-Javadoc) 74 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 75 */ 76 @Override 77 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 78 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL); 79 return (equality != null) && (equality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)); 80 } 81 82 /* (non-Javadoc) 83 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 84 */ 85 @Override 86 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 87 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL); 88 return (equality != null) && (equality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)); 89 } 90 91 /* (non-Javadoc) 92 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 93 */ 94 @Override 95 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 96 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL); 97 return (equality != null) && (equality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)); 98 } 99 100 /* (non-Javadoc) 101 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 57 102 */ 58 103 @Override 59 104 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 60 if ((!(node1 instanceof IEventTask)) || (!(node2 instanceof IEventTask))) { 61 return null; 62 } 63 105 return getEquality(node1, node2, null); 106 } 107 108 /** 109 * 110 */ 111 private NodeEquality getEquality(ITaskTreeNode node1, 112 ITaskTreeNode node2, 113 NodeEquality requiredEqualityLevel) 114 { 64 115 IEventTask task1 = (IEventTask) node1; 65 116 IEventTask task2 = (IEventTask) node2; 66 117 67 if ((!(task1.getEventType() instanceof IInteraction)) ||68 (!(task2.getEventType() instanceof IInteraction)))69 {70 return null;71 }72 73 if (node1 == node2) {74 return NodeEquality.IDENTICAL;75 }76 77 118 if (!task1.getEventTarget().equals(task2.getEventTarget())) { 78 119 return NodeEquality.UNEQUAL; … … 82 123 IInteraction interaction2 = (IInteraction) task2.getEventType(); 83 124 84 return compareInteractions(interaction1, interaction2, task1.getEventTarget()); 125 return compareInteractions 126 (interaction1, interaction2, task1.getEventTarget(), requiredEqualityLevel); 85 127 } 86 128 … … 105 147 private NodeEquality compareInteractions(IInteraction interaction1, 106 148 IInteraction interaction2, 107 IEventTarget eventTarget) 108 { 149 IEventTarget eventTarget, 150 NodeEquality equalityLevel) 151 { 152 NodeEquality level = equalityLevel; 153 154 if (level == null) { 155 level = NodeEquality.LEXICALLY_EQUAL; 156 } 157 109 158 if (interaction1 == interaction2) { 110 159 return NodeEquality.LEXICALLY_EQUAL; 111 160 } 161 else if ((interaction1 instanceof KeyInteraction) && 162 (interaction2 instanceof KeyInteraction)) 163 { 164 return compareKeyInteractions 165 ((KeyInteraction) interaction1, (KeyInteraction) interaction2, level); 166 } 167 else if ((interaction1 instanceof MouseButtonInteraction) && 168 (interaction2 instanceof MouseButtonInteraction)) 169 { 170 return compareMouseButtonInteractions 171 ((MouseButtonInteraction) interaction1, (MouseButtonInteraction) interaction2, 172 eventTarget, level); 173 } 174 else if ((interaction1 instanceof Scroll) && (interaction2 instanceof Scroll)) { 175 return compareScrolls((Scroll) interaction1, (Scroll) interaction2, level); 176 } 112 177 else if ((interaction1 instanceof TextInput) && (interaction2 instanceof TextInput)) { 113 return compareTextInputs((TextInput) interaction1, (TextInput) interaction2); 178 return compareTextInputs 179 ((TextInput) interaction1, (TextInput) interaction2, level); 114 180 } 115 181 else if ((interaction1 instanceof ValueSelection) && … … 117 183 { 118 184 return compareValueSelections 119 ((ValueSelection<?>) interaction1, (ValueSelection<?>) interaction2); 120 } 121 else if ((interaction1 instanceof MouseClick) && 122 (interaction2 instanceof MouseClick)) 123 { 124 return compareMouseClicks 125 ((MouseClick) interaction1, (MouseClick) interaction2, eventTarget); 126 } 127 else if ((interaction1 instanceof MouseDoubleClick) && 128 (interaction2 instanceof MouseDoubleClick)) 129 { 130 return compareMouseDoubleClicks 131 ((MouseDoubleClick) interaction1, (MouseDoubleClick) interaction2, eventTarget); 132 } 133 else if ((interaction1 instanceof MouseDragAndDrop) && 134 (interaction2 instanceof MouseDragAndDrop)) 135 { 136 return compareMouseDragAndDrops 137 ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2); 185 ((ValueSelection<?>) interaction1, (ValueSelection<?>) interaction2, level); 138 186 } 139 187 else if (interaction1.equals(interaction2)) { … … 143 191 return NodeEquality.UNEQUAL; 144 192 } 193 } 194 195 /** 196 * <p> 197 * TODO: comment 198 * </p> 199 * 200 * @param interaction1 201 * @param interaction2 202 * @param eventTarget 203 * @param level 204 * @return 205 */ 206 private NodeEquality compareKeyInteractions(KeyInteraction interaction1, 207 KeyInteraction interaction2, 208 NodeEquality equalityLevel) 209 { 210 if (((interaction1 instanceof KeyPressed) && (interaction2 instanceof KeyPressed)) || 211 ((interaction1 instanceof KeyReleased) && (interaction2 instanceof KeyReleased)) || 212 ((interaction1 instanceof KeyTyped) && (interaction2 instanceof KeyTyped))) 213 { 214 if ((equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) && 215 (interaction1.getKey() == interaction2.getKey())) 216 { 217 return NodeEquality.LEXICALLY_EQUAL; 218 } 219 else { 220 return NodeEquality.SEMANTICALLY_EQUAL; 221 } 222 } 223 224 return NodeEquality.UNEQUAL; 225 } 226 227 /** 228 * <p> 229 * compares two mouse drag and drops. If both drag and drops have the same start and end 230 * coordinates, they are lexically equal. Otherwise, they are semantically equal. 231 * </p> 232 * 233 * @param interaction1 the first mouse drag and drop to compare 234 * @param interaction2 the second mouse drag and drop to compare 235 * 236 * @return as described 237 */ 238 private NodeEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1, 239 MouseDragAndDrop interaction2, 240 NodeEquality equalityLevel) 241 { 242 if (interaction1.getButton() != interaction2.getButton()) { 243 return NodeEquality.UNEQUAL; 244 } 245 246 if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 247 int x1 = interaction1.getX(); 248 int x1Start = interaction1.getXStart(); 249 int x2 = interaction2.getX(); 250 int x2Start = interaction2.getXStart(); 251 int y1 = interaction1.getY(); 252 int y1Start = interaction1.getYStart(); 253 int y2 = interaction2.getY(); 254 int y2Start = interaction2.getYStart(); 255 256 if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) { 257 return NodeEquality.LEXICALLY_EQUAL; 258 } 259 } 260 261 return NodeEquality.SEMANTICALLY_EQUAL; 262 } 263 264 /** 265 * <p> 266 * compares two mouse button interactions such as clicks, mouse button down, or double clicks. 267 * If both interactions have the same coordinates, they are lexically equal. Otherwise, they 268 * are semantically equal. Mouse clicks for which the coordinates make no lexical difference 269 * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as 270 * lexically equal. 271 * </p> 272 * 273 * @param interaction1 the first mouse button interaction to compare 274 * @param interaction2 the second mouse button interaction to compare 275 * @param eventTarget the event target on which the interactions happened (used within 276 * special comparisons like mouse clicks on buttons, where the coordinates 277 * can be ignored) 278 * 279 * @return as described 280 */ 281 private NodeEquality compareMouseButtonInteractions(MouseButtonInteraction interaction1, 282 MouseButtonInteraction interaction2, 283 IEventTarget eventTarget, 284 NodeEquality equalityLevel) 285 { 286 boolean coordinatesMatch = true; 287 288 if ((interaction1 instanceof MouseDragAndDrop) && 289 (interaction2 instanceof MouseDragAndDrop)) 290 { 291 return compareMouseDragAndDrops 292 ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2, equalityLevel); 293 } 294 else if (interaction1.getButton() != interaction2.getButton()) { 295 return NodeEquality.UNEQUAL; 296 } 297 else if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL) && 298 clickCoordinatesMakeLexicalDifference(eventTarget)) 299 { 300 int x1 = interaction1.getX(); 301 int x2 = interaction2.getX(); 302 int y1 = interaction1.getY(); 303 int y2 = interaction2.getY(); 304 305 if ((x1 != x2) || (y1 != y2)) { 306 coordinatesMatch = false; 307 } 308 } 309 310 // up to now, they can be equal. Now check the types. Do it as last action as these 311 // checks take the most time and should, therefore, only be done latest 312 if (((interaction1 instanceof MouseClick) && (interaction2 instanceof MouseClick)) || 313 ((interaction1 instanceof MouseDoubleClick) && 314 (interaction2 instanceof MouseDoubleClick)) || 315 ((interaction1 instanceof MouseButtonDown) && 316 (interaction2 instanceof MouseButtonDown)) || 317 ((interaction1 instanceof MouseButtonUp) && 318 (interaction2 instanceof MouseButtonUp))) 319 { 320 if (coordinatesMatch) { 321 return NodeEquality.LEXICALLY_EQUAL; 322 } 323 else { 324 return NodeEquality.SEMANTICALLY_EQUAL; 325 } 326 } 327 328 return NodeEquality.UNEQUAL; 329 } 330 331 /** 332 * <p> 333 * compares two mouse button interactions such as clicks, mouse button down, or double clicks. 334 * If both interactions have the same coordinates, they are lexically equal. Otherwise, they 335 * are semantically equal. Mouse clicks for which the coordinates make no lexical difference 336 * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as 337 * lexically equal. 338 * </p> 339 * 340 * @param interaction1 the first mouse button interaction to compare 341 * @param interaction2 the second mouse button interaction to compare 342 * @param eventTarget the event target on which the interactions happened (used within 343 * special comparisons like mouse clicks on buttons, where the coordinates 344 * can be ignored) 345 * 346 * @return as described 347 */ 348 private NodeEquality compareScrolls(Scroll interaction1, 349 Scroll interaction2, 350 NodeEquality equalityLevel) 351 { 352 if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 353 int x1 = interaction1.getXPosition(); 354 int x2 = interaction2.getXPosition(); 355 int y1 = interaction1.getYPosition(); 356 int y2 = interaction2.getYPosition(); 357 358 if ((x1 == x2) && (y1 == y2)) { 359 return NodeEquality.LEXICALLY_EQUAL; 360 } 361 } 362 363 return NodeEquality.SEMANTICALLY_EQUAL; 145 364 } 146 365 … … 158 377 * @return as described 159 378 */ 160 private NodeEquality compareTextInputs(TextInput interaction1, TextInput interaction2) { 161 if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) { 162 if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) { 163 return NodeEquality.LEXICALLY_EQUAL; 164 } 165 else { 166 return NodeEquality.SYNTACTICALLY_EQUAL; 167 } 168 } 169 else { 170 return NodeEquality.SEMANTICALLY_EQUAL; 379 private NodeEquality compareTextInputs(TextInput interaction1, 380 TextInput interaction2, 381 NodeEquality equalityLevel) 382 { 383 switch (equalityLevel) { 384 case LEXICALLY_EQUAL: 385 if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) { 386 return NodeEquality.LEXICALLY_EQUAL; 387 } 388 // fall through 389 case SYNTACTICALLY_EQUAL: 390 if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) { 391 return NodeEquality.SYNTACTICALLY_EQUAL; 392 } 393 // fall through 394 case SEMANTICALLY_EQUAL: 395 return NodeEquality.SEMANTICALLY_EQUAL; 396 default: 397 return NodeEquality.UNEQUAL; 171 398 } 172 399 } … … 185 412 */ 186 413 private NodeEquality compareValueSelections(ValueSelection<?> interaction1, 187 ValueSelection<?> interaction2) 188 { 189 Object value1 = interaction1.getSelectedValue(); 190 Object value2 = interaction2.getSelectedValue(); 191 192 if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) { 193 return NodeEquality.LEXICALLY_EQUAL; 194 } 195 else { 196 return NodeEquality.SEMANTICALLY_EQUAL; 197 } 198 } 199 200 /** 201 * <p> 202 * compares two mouse clicks. If both clicks have the same coordinates, they are lexically 203 * equal. Otherwise, they are semantically equal. Mouse clicks for which the coordinates make 204 * no lexical difference (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) 205 * are treated as lexically equal. 206 * </p> 207 * 208 * @param interaction1 the first mouse click to compare 209 * @param interaction2 the second mouse click to compare 210 * @param eventTarget the event target on which the interactions happened (used within 211 * special comparisons like mouse clicks on buttons, where the coordinates 212 * can be ignored) 213 * 214 * @return as described 215 */ 216 private NodeEquality compareMouseClicks(MouseClick interaction1, 217 MouseClick interaction2, 218 IEventTarget eventTarget) 219 { 220 if (interaction1.getButton() != interaction2.getButton()) { 221 return NodeEquality.UNEQUAL; 222 } 223 224 if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { 225 return NodeEquality.LEXICALLY_EQUAL; 226 } 227 228 int x1 = interaction1.getX(); 229 int x2 = interaction2.getX(); 230 int y1 = interaction1.getY(); 231 int y2 = interaction2.getY(); 232 233 if ((x1 == x2) && (y1 == y2)) { 234 return NodeEquality.LEXICALLY_EQUAL; 235 } 236 else { 237 return NodeEquality.SEMANTICALLY_EQUAL; 238 } 239 } 240 241 /** 242 * <p> 243 * compares two mouse double clicks. If both double clicks have the same coordinates, they are 244 * lexically equal. Otherwise, they are semantically equal. Double clicks for which the 245 * coordinates make no lexical difference 246 * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as lexically 247 * equal. 248 * </p> 249 * 250 * @param interaction1 the first mouse double click to compare 251 * @param interaction2 the second mouse double click to compare 252 * @param eventTarget the event target on which the interactions happened (used within 253 * special comparisons like mouse clicks on buttons, where the coordinates 254 * can be ignored) 255 * 256 * @return as described 257 */ 258 private NodeEquality compareMouseDoubleClicks(MouseDoubleClick interaction1, 259 MouseDoubleClick interaction2, 260 IEventTarget eventTarget) 261 { 262 if (interaction1.getButton() != interaction2.getButton()) { 263 return NodeEquality.UNEQUAL; 264 } 265 266 if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { 267 return NodeEquality.LEXICALLY_EQUAL; 268 } 269 270 int x1 = interaction1.getX(); 271 int x2 = interaction2.getX(); 272 int y1 = interaction1.getY(); 273 int y2 = interaction2.getY(); 274 275 if ((x1 == x2) && (y1 == y2)) { 276 return NodeEquality.LEXICALLY_EQUAL; 277 } 278 else { 279 return NodeEquality.SEMANTICALLY_EQUAL; 280 } 281 } 282 283 /** 284 * <p> 285 * compares two mouse drag and drops. If both drag and drops have the same start and end 286 * coordinates, they are lexically equal. Otherwise, they are semantically equal. 287 * </p> 288 * 289 * @param interaction1 the first mouse drag and drop to compare 290 * @param interaction2 the second mouse drag and drop to compare 291 * 292 * @return as described 293 */ 294 private NodeEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1, 295 MouseDragAndDrop interaction2) 296 { 297 if (interaction1.getButton() != interaction2.getButton()) { 298 return NodeEquality.UNEQUAL; 299 } 300 301 int x1 = interaction1.getX(); 302 int x1Start = interaction1.getXStart(); 303 int x2 = interaction2.getX(); 304 int x2Start = interaction2.getXStart(); 305 int y1 = interaction1.getY(); 306 int y1Start = interaction1.getYStart(); 307 int y2 = interaction2.getY(); 308 int y2Start = interaction2.getYStart(); 309 310 if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) { 311 return NodeEquality.LEXICALLY_EQUAL; 312 } 313 else { 314 return NodeEquality.SEMANTICALLY_EQUAL; 315 } 414 ValueSelection<?> interaction2, 415 NodeEquality equalityLevel) 416 { 417 if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 418 Object value1 = interaction1.getSelectedValue(); 419 Object value2 = interaction2.getSelectedValue(); 420 421 if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) { 422 return NodeEquality.LEXICALLY_EQUAL; 423 } 424 } 425 426 return NodeEquality.SEMANTICALLY_EQUAL; 316 427 } 317 428 … … 336 447 (eventTarget instanceof IImage) || 337 448 (eventTarget instanceof IListBox) || 449 (eventTarget instanceof IMenu) || 338 450 (eventTarget instanceof IMenuButton) || 339 451 (eventTarget instanceof IRadioButton) ||
Note: See TracChangeset
for help on using the changeset viewer.