source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/GUIEventTaskComparisonRule.java @ 1588

Last change on this file since 1588 was 1294, checked in by pharms, 11 years ago
  • rework of task model to move event instance stuff to task instances
  • introduction of sequence, selection, iteration and optional instances
File size: 27.1 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.tasktrees.taskequality;
16
17import java.util.Collection;
18
19import de.ugoe.cs.autoquest.eventcore.IEventTarget;
20import de.ugoe.cs.autoquest.eventcore.gui.IInteraction;
21import de.ugoe.cs.autoquest.eventcore.gui.KeyInteraction;
22import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed;
23import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased;
24import de.ugoe.cs.autoquest.eventcore.gui.KeyTyped;
25import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonDown;
26import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
27import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonUp;
28import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
29import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick;
30import de.ugoe.cs.autoquest.eventcore.gui.MouseDragAndDrop;
31import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
32import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
33import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection;
34import de.ugoe.cs.autoquest.eventcore.guimodel.IButton;
35import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox;
36import de.ugoe.cs.autoquest.eventcore.guimodel.IComboBox;
37import de.ugoe.cs.autoquest.eventcore.guimodel.IImage;
38import de.ugoe.cs.autoquest.eventcore.guimodel.IListBox;
39import de.ugoe.cs.autoquest.eventcore.guimodel.IMenu;
40import de.ugoe.cs.autoquest.eventcore.guimodel.IMenuButton;
41import de.ugoe.cs.autoquest.eventcore.guimodel.IRadioButton;
42import de.ugoe.cs.autoquest.eventcore.guimodel.IShape;
43import de.ugoe.cs.autoquest.eventcore.guimodel.IText;
44import de.ugoe.cs.autoquest.eventcore.guimodel.IToolTip;
45import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
46import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
47import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
48
49/**
50 * <p>
51 * This rule compares GUI event tasks (i.e. it is more concrete, than the
52 * {@link EventTaskComparisonRule}). Two GUI event tasks are only equal if their event type and
53 * target are equal. The returned equality is even more fine-grained for events whose type is
54 * {@link TextInput} and {@link ValueSelection}. For text inputs, lexical equality is returned if
55 * the same text is entered using the same key interactions. Syntactical equality is returned if
56 * the same text is entered using different key interactions. Semantical equality is returned if
57 * different text is entered, but into the same event target. Value selections are syntactically
58 * equal, if the same value is selected. Otherwise they are semantically equal.
59 * </p>
60 *
61 * @author Patrick Harms
62 */
63public class GUIEventTaskComparisonRule implements TaskComparisonRule {
64   
65    /* (non-Javadoc)
66     * @see TaskComparisonRule#isApplicable(ITask, ITask)
67     */
68    @Override
69    public boolean isApplicable(ITask task1, ITask task2) {
70        for (ITaskInstance instance : task1.getInstances()) {
71            if ((!(instance instanceof IEventTaskInstance)) ||
72                (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction)))
73            {
74                return false;
75            }
76        }
77       
78        for (ITaskInstance instance : task2.getInstances()) {
79            if ((!(instance instanceof IEventTaskInstance)) ||
80                (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction)))
81            {
82                return false;
83            }
84        }
85       
86        return true;
87    }
88
89    /* (non-Javadoc)
90     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask)
91     */
92    @Override
93    public boolean areLexicallyEqual(ITask task1, ITask task2) {
94        TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL);
95        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL));
96    }
97
98    /* (non-Javadoc)
99     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask)
100     */
101    @Override
102    public boolean areSyntacticallyEqual(ITask task1, ITask task2) {
103        TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL);
104        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL));
105    }
106
107    /* (non-Javadoc)
108     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask)
109     */
110    @Override
111    public boolean areSemanticallyEqual(ITask task1, ITask task2) {
112        TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL);
113        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL));
114    }
115
116    /* (non-Javadoc)
117     * @see TaskComparisonRule#compare(ITask, ITask)
118     */
119    @Override
120    public TaskEquality compare(ITask task1, ITask task2) {
121        return getEquality(task1, task2, null);
122    }
123
124    /* (non-Javadoc)
125     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#isApplicable(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
126     */
127    @Override
128    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) {
129        return
130            (instance1 instanceof IEventTaskInstance) &&
131            (instance2 instanceof IEventTaskInstance) &&
132            (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction) &&
133            (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction);
134    }
135
136    /* (non-Javadoc)
137     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areLexicallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
138     */
139    @Override
140    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) {
141        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL);
142        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL));
143    }
144
145    /* (non-Javadoc)
146     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areSyntacticallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
147     */
148    @Override
149    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) {
150        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL);
151        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL));
152    }
153
154    /* (non-Javadoc)
155     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areSemanticallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
156     */
157    @Override
158    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) {
159        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL);
160        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL));
161    }
162
163    /* (non-Javadoc)
164     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#compare(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance)
165     */
166    @Override
167    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) {
168        return getEquality(instance1, instance2, null);
169    }
170
171    /**
172     *
173     */
174    private TaskEquality getEquality(ITask         task1,
175                                     ITask         task2,
176                                     TaskEquality  requiredEqualityLevel)
177    {
178        Collection<ITaskInstance> taskInstances1 = task1.getInstances();
179        Collection<ITaskInstance> taskInstances2 = task2.getInstances();
180       
181        TaskEquality checkedEquality =
182            requiredEqualityLevel != null ? requiredEqualityLevel : TaskEquality.SEMANTICALLY_EQUAL;
183       
184        TaskEquality commonDenominator = TaskEquality.LEXICALLY_EQUAL;
185       
186        for (ITaskInstance instance1 : taskInstances1) {
187            TaskEquality mostConcreteEquality = null;
188           
189            for (ITaskInstance instance2 : taskInstances2) {
190                TaskEquality equality = getEquality(instance1, instance2, requiredEqualityLevel);
191               
192                if ((equality != null) && ((mostConcreteEquality == null) ||
193                                           (equality.isAtLeast(mostConcreteEquality))))
194                {
195                    mostConcreteEquality = equality;
196                   
197                    if (((requiredEqualityLevel != null) &&
198                         (mostConcreteEquality.isAtLeast(requiredEqualityLevel))) ||
199                        (mostConcreteEquality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)))
200                    {
201                        break;
202                    }
203                }
204            }
205           
206            commonDenominator = commonDenominator.getCommonDenominator(mostConcreteEquality);
207           
208            if (!commonDenominator.isAtLeast(checkedEquality)) {
209                return TaskEquality.UNEQUAL;
210            }
211        }
212       
213        return commonDenominator;
214    }
215
216    /**
217     *
218     */
219    private TaskEquality getEquality(ITaskInstance instance1,
220                                     ITaskInstance instance2,
221                                     TaskEquality  requiredEqualityLevel)
222    {
223        IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1;
224        IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2;
225       
226        if (!eventTask1.getEvent().getTarget().equals(eventTask2.getEvent().getTarget())) {
227            return TaskEquality.UNEQUAL;
228        }
229       
230        IInteraction interaction1 = (IInteraction) eventTask1.getEvent().getType();
231        IInteraction interaction2 = (IInteraction) eventTask2.getEvent().getType();
232       
233        return compareInteractions
234            (interaction1, interaction2, eventTask1.getEvent().getTarget(), requiredEqualityLevel);
235    }
236
237    /**
238     * <p>
239     * compares two interactions. The method delegates to other, more specific compare method, e.g.,
240     * {@link #compareTextInputs(TextInput, TextInput)} and
241     * {@link #compareValueSelections(ValueSelection, ValueSelection)}, if any exist for the
242     * concrete interaction types. Otherwise it uses the equals method of the interactions for
243     * comparison. In this case, if the interactions equals method returns true, this method
244     * returns lexical equality.
245     * </p>
246     * <p>
247     * The provided equality level can be used to restrict the quality check to the given level.
248     * This is done for optimization purposes. The returned equality level can be at most as
249     * concrete as the provided one. If the provided one is null, it is expected to be lexical
250     * equality.
251     * </p>
252     *
253     * @param interaction1  the first interaction to compare
254     * @param interaction2  the second interaction to compare
255     * @param eventTarget   the event target on which the interactions happened (used within
256     *                      special comparisons like mouse clicks on buttons, where the coordinates
257     *                      can be ignored)
258     * @param equalityLevel the equality level to be checked for
259     *
260     * @return as described
261     */
262    private TaskEquality compareInteractions(IInteraction interaction1,
263                                             IInteraction interaction2,
264                                             IEventTarget eventTarget,
265                                             TaskEquality equalityLevel)
266    {
267        TaskEquality level = equalityLevel;
268       
269        if (level == null) {
270            level = TaskEquality.LEXICALLY_EQUAL;
271        }
272       
273        if (interaction1 == interaction2) {
274            return TaskEquality.LEXICALLY_EQUAL;
275        }
276        else if ((interaction1 instanceof KeyInteraction) &&
277                 (interaction2 instanceof KeyInteraction))
278        {
279            return compareKeyInteractions
280                ((KeyInteraction) interaction1, (KeyInteraction) interaction2, level);
281        }
282        else if ((interaction1 instanceof MouseButtonInteraction) &&
283                 (interaction2 instanceof MouseButtonInteraction))
284        {
285            return compareMouseButtonInteractions
286                ((MouseButtonInteraction) interaction1, (MouseButtonInteraction) interaction2,
287                 eventTarget, level);
288        }
289        else if ((interaction1 instanceof Scroll) && (interaction2 instanceof Scroll)) {
290            return compareScrolls((Scroll) interaction1, (Scroll) interaction2, level);
291        }
292        else if ((interaction1 instanceof TextInput) && (interaction2 instanceof TextInput)) {
293            return compareTextInputs
294                ((TextInput) interaction1, (TextInput) interaction2, level);
295        }
296        else if ((interaction1 instanceof ValueSelection) &&
297                 (interaction2 instanceof ValueSelection))
298        {
299            return compareValueSelections
300                ((ValueSelection<?>) interaction1, (ValueSelection<?>) interaction2, level);
301        }
302        else if (interaction1.equals(interaction2)) {
303            return TaskEquality.LEXICALLY_EQUAL;
304        }
305        else {
306            return TaskEquality.UNEQUAL;
307        }
308    }
309
310    /**
311     * <p>
312     * compares two key interactions. If both are of the same type and if both have the
313     * same key, they are lexically equal. If both are only of the same type, they are
314     * semantically equal. Otherwise, they are unequal.
315     * </p>
316     * <p>
317     * The provided equality level can be used to restrict the quality check to the given level.
318     * This is done for optimization purposes. The returned equality level is as concrete as
319     * the provided one. It may be more concrete if there is no difference regarding the
320     * comparison on the levels.
321     * </p>
322     *
323     * @param interaction1  the first key interaction
324     * @param interaction2  the second key interaction
325     * @param equalityLevel the equality level to be checked for
326     *
327     * @return as described
328     */
329    private TaskEquality compareKeyInteractions(KeyInteraction interaction1,
330                                                KeyInteraction interaction2,
331                                                TaskEquality   equalityLevel)
332    {
333        if (((interaction1 instanceof KeyPressed) && (interaction2 instanceof KeyPressed)) ||
334            ((interaction1 instanceof KeyReleased) && (interaction2 instanceof KeyReleased)) ||
335            ((interaction1 instanceof KeyTyped) && (interaction2 instanceof KeyTyped)))
336        {
337            if ((equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) &&
338                (interaction1.getKey() == interaction2.getKey()))
339            {
340                return TaskEquality.LEXICALLY_EQUAL;
341            }
342            else {
343                return TaskEquality.SEMANTICALLY_EQUAL;
344            }
345        }
346       
347        return TaskEquality.UNEQUAL;
348    }
349   
350    /**
351     * <p>
352     * compares two mouse drag and drops. If both drag and drops have the same start and end
353     * coordinates, they are lexically equal. Otherwise, they are semantically equal.
354     * </p>
355     * <p>
356     * The provided equality level can be used to restrict the quality check to the given level.
357     * This is done for optimization purposes. The returned equality level is as concrete as
358     * the provided one. It may be more concrete if there is no difference regarding the
359     * comparison on the levels.
360     * </p>
361     *
362     * @param interaction1  the first mouse drag and drop to compare
363     * @param interaction2  the second mouse drag and drop to compare
364     * @param equalityLevel the equality level to be checked for
365     *
366     * @return as described
367     */
368    private TaskEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1,
369                                                  MouseDragAndDrop interaction2,
370                                                  TaskEquality     equalityLevel)
371    {
372        if (interaction1.getButton() != interaction2.getButton()) {
373            return TaskEquality.UNEQUAL;
374        }
375       
376        if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) {
377            int x1 = interaction1.getX();
378            int x1Start = interaction1.getXStart();
379            int x2 = interaction2.getX();
380            int x2Start = interaction2.getXStart();
381            int y1 = interaction1.getY();
382            int y1Start = interaction1.getYStart();
383            int y2 = interaction2.getY();
384            int y2Start = interaction2.getYStart();
385       
386            if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) {
387                return TaskEquality.LEXICALLY_EQUAL;
388            }
389        }
390       
391        return TaskEquality.SEMANTICALLY_EQUAL;
392    }
393
394    /**
395     * <p>
396     * compares two mouse button interactions such as clicks, mouse button down, or double clicks.
397     * If both interactions have the same coordinates, they are lexically equal. Otherwise, they
398     * are semantically equal. Mouse clicks for which the coordinates make no lexical difference
399     * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as
400     * lexically equal.
401     * </p>
402     * <p>
403     * The provided equality level can be used to restrict the quality check to the given level.
404     * This is done for optimization purposes. The returned equality level is as concrete as
405     * the provided one. It may be more concrete if there is no difference regarding the
406     * comparison on the levels.
407     * </p>
408     *
409     * @param interaction1  the first mouse button interaction to compare
410     * @param interaction2  the second mouse button interaction to compare
411     * @param eventTarget   the event target on which the interactions happened (used within
412     *                      special comparisons like mouse clicks on buttons, where the coordinates
413     *                      can be ignored)
414     * @param equalityLevel the equality level to be checked for
415     *
416     * @return as described
417     */
418    private TaskEquality compareMouseButtonInteractions(MouseButtonInteraction interaction1,
419                                                        MouseButtonInteraction interaction2,
420                                                        IEventTarget           eventTarget,
421                                                        TaskEquality           equalityLevel)
422    {
423        boolean coordinatesMatch = true;
424       
425        if ((interaction1 instanceof MouseDragAndDrop) &&
426            (interaction2 instanceof MouseDragAndDrop))
427        {
428            return compareMouseDragAndDrops
429                ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2, equalityLevel);
430        }
431        else if (interaction1.getButton() != interaction2.getButton()) {
432            return TaskEquality.UNEQUAL;
433        }
434        else if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL) &&
435                 clickCoordinatesMakeLexicalDifference(eventTarget))
436        {
437            int x1 = interaction1.getX();
438            int x2 = interaction2.getX();
439            int y1 = interaction1.getY();
440            int y2 = interaction2.getY();
441
442            if ((x1 != x2) || (y1 != y2)) {
443                coordinatesMatch = false;
444            }
445        }
446       
447        // up to now, they can be equal. Now check the types. Do it as last action as these
448        // checks take the most time and should, therefore, only be done latest
449        if (((interaction1 instanceof MouseClick) && (interaction2 instanceof MouseClick)) ||
450            ((interaction1 instanceof MouseDoubleClick) &&
451             (interaction2 instanceof MouseDoubleClick)) ||
452            ((interaction1 instanceof MouseButtonDown) &&
453             (interaction2 instanceof MouseButtonDown)) ||
454            ((interaction1 instanceof MouseButtonUp) &&
455             (interaction2 instanceof MouseButtonUp)))
456        {
457            if (coordinatesMatch) {
458                return TaskEquality.LEXICALLY_EQUAL;
459            }
460            else {
461                return TaskEquality.SEMANTICALLY_EQUAL;
462            }
463        }
464       
465        return TaskEquality.UNEQUAL;
466    }
467
468    /**
469     * <p>
470     * compares two mouse button interactions such as clicks, mouse button down, or double clicks.
471     * If both interactions have the same coordinates, they are lexically equal. Otherwise, they
472     * are semantically equal. Mouse clicks for which the coordinates make no lexical difference
473     * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as
474     * lexically equal.
475     * </p>
476     * <p>
477     * The provided equality level can be used to restrict the quality check to the given level.
478     * This is done for optimization purposes. The returned equality level is as concrete as
479     * the provided one. It may be more concrete if there is no difference regarding the
480     * comparison on the levels.
481     * </p>
482     *
483     * @param interaction1  the first mouse button interaction to compare
484     * @param interaction2  the second mouse button interaction to compare
485     * @param eventTarget   the event target on which the interactions happened (used within
486     *                      special comparisons like mouse clicks on buttons, where the coordinates
487     *                      can be ignored)
488     * @param equalityLevel the equality level to be checked for
489     *
490     * @return as described
491     */
492    private TaskEquality compareScrolls(Scroll       interaction1,
493                                        Scroll       interaction2,
494                                        TaskEquality equalityLevel)
495    {
496        if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) {
497            int x1 = interaction1.getXPosition();
498            int x2 = interaction2.getXPosition();
499            int y1 = interaction1.getYPosition();
500            int y2 = interaction2.getYPosition();
501       
502            if ((x1 == x2) && (y1 == y2)) {
503                return TaskEquality.LEXICALLY_EQUAL;
504            }
505        }
506       
507        return TaskEquality.SEMANTICALLY_EQUAL;
508    }
509
510    /**
511     * <p>
512     * compares two text inputs. If both text inputs have the same entered text and text input
513     * events, they are lexically equal. If they only have the same entered text, they are
514     * syntactically equal. If they are only both text inputs, they are semantically equal.
515     * (the equality of the event targets is checked beforehand).
516     * </p>
517     * <p>
518     * The provided equality level can be used to restrict the quality check to the given level.
519     * This is done for optimization purposes. The returned equality level is as concrete as
520     * the provided one. It may be more concrete if there is no difference regarding the
521     * comparison on the levels.
522     * </p>
523     *
524     * @param interaction1  the first text input to compare
525     * @param interaction2  the second text input to compare
526     * @param equalityLevel the equality level to be checked for
527     *
528     * @return as described
529     */
530    private TaskEquality compareTextInputs(TextInput    interaction1,
531                                           TextInput    interaction2,
532                                           TaskEquality equalityLevel)
533    {
534        switch (equalityLevel) {
535            case LEXICALLY_EQUAL:
536                if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) {
537                    return TaskEquality.LEXICALLY_EQUAL;
538                }
539                // fall through
540            case SYNTACTICALLY_EQUAL:
541                if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) {
542                    return TaskEquality.SYNTACTICALLY_EQUAL;
543                }
544                // fall through
545            case SEMANTICALLY_EQUAL:
546                return TaskEquality.SEMANTICALLY_EQUAL;
547            default:
548                return TaskEquality.UNEQUAL;
549        }
550    }
551
552    /**
553     * <p>
554     * compares two value selections. If both value selections have the same selected value, they
555     * are syntactically equal, otherwise they are semantically equal.
556     * (the equality of the event targets is checked beforehand).
557     * </p>
558     * <p>
559     * The provided equality level can be used to restrict the quality check to the given level.
560     * This is done for optimization purposes. The returned equality level is as concrete as
561     * the provided one. It may be more concrete if there is no difference regarding the
562     * comparison on the levels.
563     * </p>
564     *
565     * @param interaction1  the first value selection to compare
566     * @param interaction2  the second value selection to compare
567     * @param equalityLevel the equality level to be checked for
568     *
569     * @return as described
570     */
571    private TaskEquality compareValueSelections(ValueSelection<?> interaction1,
572                                                ValueSelection<?> interaction2,
573                                                TaskEquality      equalityLevel)
574    {
575        if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) {
576            Object value1 = interaction1.getSelectedValue();
577            Object value2 = interaction2.getSelectedValue();
578       
579            if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) {
580                return TaskEquality.LEXICALLY_EQUAL;
581            }
582        }
583       
584        return TaskEquality.SEMANTICALLY_EQUAL;
585    }
586
587    /**
588     * <p>
589     * Checks, if the coordinates of a click or double click on the provided event target makes
590     * a lexical difference. Mouse clicks and double clicks on buttons, check boxes,
591     * combo boxes, images, list boxes, menu buttons, radio buttons, shapes, uneditable text,
592     * and tool tips have no lexical difference as long as they happen on the same event target.
593     * The concrete coordinates are not relevant.
594     * </p>
595     *
596     * @param eventTarget the event target on which the interaction occurred
597     *
598     * @return if the coordinates are important to be considered for clicks and double clicks,
599     *         false else
600     */
601    private boolean clickCoordinatesMakeLexicalDifference(IEventTarget eventTarget) {
602        if ((eventTarget instanceof IButton) ||
603            (eventTarget instanceof ICheckBox) ||
604            (eventTarget instanceof IComboBox) ||
605            (eventTarget instanceof IImage) ||
606            (eventTarget instanceof IListBox) ||
607            (eventTarget instanceof IMenu) ||
608            (eventTarget instanceof IMenuButton) ||
609            (eventTarget instanceof IRadioButton) ||
610            (eventTarget instanceof IShape) ||
611            (eventTarget instanceof IText) ||
612            (eventTarget instanceof IToolTip))
613        {
614            return false;
615        }
616        else {
617            return true;
618        }
619    }
620
621}
Note: See TracBrowser for help on using the repository browser.