1 | package de.ugoe.cs.autoquest.tasktrees.nodeequality; |
---|
2 | |
---|
3 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
4 | import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; |
---|
5 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; |
---|
6 | import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; |
---|
7 | import de.ugoe.cs.autoquest.eventcore.gui.MouseDragAndDrop; |
---|
8 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput; |
---|
9 | import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; |
---|
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; |
---|
20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; |
---|
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 | |
---|
70 | return compareInteractions(interaction1, interaction2, task1.getEventTarget()); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * <p> |
---|
75 | * compares two interactions. The method delegates to other, more specific compare method, e.g., |
---|
76 | * {@link #compareTextInputs(TextInput, TextInput)} and |
---|
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. |
---|
81 | * </p> |
---|
82 | * |
---|
83 | * @param interaction1 the first interaction to compare |
---|
84 | * @param interaction2 the second interaction to compare |
---|
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) |
---|
88 | * |
---|
89 | * @return as described |
---|
90 | */ |
---|
91 | private NodeEquality compareInteractions(IInteraction interaction1, |
---|
92 | IInteraction interaction2, |
---|
93 | IEventTarget eventTarget) |
---|
94 | { |
---|
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 | } |
---|
107 | else if ((interaction1 instanceof MouseClick) && |
---|
108 | (interaction2 instanceof MouseClick)) |
---|
109 | { |
---|
110 | return compareMouseClicks |
---|
111 | ((MouseClick) interaction1, (MouseClick) interaction2, eventTarget); |
---|
112 | } |
---|
113 | else if ((interaction1 instanceof MouseDoubleClick) && |
---|
114 | (interaction2 instanceof MouseDoubleClick)) |
---|
115 | { |
---|
116 | return compareMouseDoubleClicks |
---|
117 | ((MouseDoubleClick) interaction1, (MouseDoubleClick) interaction2, eventTarget); |
---|
118 | } |
---|
119 | else if ((interaction1 instanceof MouseDragAndDrop) && |
---|
120 | (interaction2 instanceof MouseDragAndDrop)) |
---|
121 | { |
---|
122 | return compareMouseDragAndDrops |
---|
123 | ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2); |
---|
124 | } |
---|
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)))) { |
---|
179 | return NodeEquality.LEXICALLY_EQUAL; |
---|
180 | } |
---|
181 | else { |
---|
182 | return NodeEquality.SEMANTICALLY_EQUAL; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * <p> |
---|
188 | * compares two mouse clicks. If both clicks have the same coordinates, they are lexically |
---|
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. |
---|
192 | * </p> |
---|
193 | * |
---|
194 | * @param interaction1 the first mouse click to compare |
---|
195 | * @param interaction2 the second mouse click to compare |
---|
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) |
---|
199 | * |
---|
200 | * @return as described |
---|
201 | */ |
---|
202 | private NodeEquality compareMouseClicks(MouseClick interaction1, |
---|
203 | MouseClick interaction2, |
---|
204 | IEventTarget eventTarget) |
---|
205 | { |
---|
206 | if (interaction1.getButton() != interaction2.getButton()) { |
---|
207 | return NodeEquality.UNEQUAL; |
---|
208 | } |
---|
209 | |
---|
210 | if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { |
---|
211 | return NodeEquality.LEXICALLY_EQUAL; |
---|
212 | } |
---|
213 | |
---|
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> |
---|
229 | * compares two mouse double clicks. If both double clicks have the same coordinates, they are |
---|
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. |
---|
234 | * </p> |
---|
235 | * |
---|
236 | * @param interaction1 the first mouse double click to compare |
---|
237 | * @param interaction2 the second mouse double click to compare |
---|
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) |
---|
241 | * |
---|
242 | * @return as described |
---|
243 | */ |
---|
244 | private NodeEquality compareMouseDoubleClicks(MouseDoubleClick interaction1, |
---|
245 | MouseDoubleClick interaction2, |
---|
246 | IEventTarget eventTarget) |
---|
247 | { |
---|
248 | if (interaction1.getButton() != interaction2.getButton()) { |
---|
249 | return NodeEquality.UNEQUAL; |
---|
250 | } |
---|
251 | |
---|
252 | if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { |
---|
253 | return NodeEquality.LEXICALLY_EQUAL; |
---|
254 | } |
---|
255 | |
---|
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> |
---|
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 | { |
---|
283 | if (interaction1.getButton() != interaction2.getButton()) { |
---|
284 | return NodeEquality.UNEQUAL; |
---|
285 | } |
---|
286 | |
---|
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 | |
---|
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 | |
---|
337 | } |
---|