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 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.taskmodel.filter.types;
|
---|
16 |
|
---|
17 | import com.google.common.base.Function;
|
---|
18 | import com.google.common.base.Predicate;
|
---|
19 | import com.google.common.base.Predicates;
|
---|
20 |
|
---|
21 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
22 | import de.ugoe.cs.autoquest.eventcore.gui.IInteraction;
|
---|
23 | import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed;
|
---|
24 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
25 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
|
---|
26 | import de.ugoe.cs.autoquest.eventcore.gui.MouseInteraction;
|
---|
27 | import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
|
---|
28 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
|
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * <p>
|
---|
34 | * Event type filter for {@link EventTask}s.
|
---|
35 | * </p>
|
---|
36 | *
|
---|
37 | * @author Alexander Deicke
|
---|
38 | */
|
---|
39 | public enum EventTypeFilter implements TaskFilter<IEventType> {
|
---|
40 |
|
---|
41 | KEY_PRESSED(KeyPressed.class),
|
---|
42 |
|
---|
43 | MOUSE_BUTTON_INTERACTION(MouseButtonInteraction.class),
|
---|
44 |
|
---|
45 | MOUSE_CLICK(MouseClick.class),
|
---|
46 |
|
---|
47 | MOUSE_INTERACTION(MouseInteraction.class),
|
---|
48 |
|
---|
49 | TEXT_INPUT(TextInput.class),
|
---|
50 |
|
---|
51 | SCROLL(Scroll.class),
|
---|
52 |
|
---|
53 | USER_INTERACTION(IInteraction.class);
|
---|
54 |
|
---|
55 | private Class<? extends IEventType> eventTypeClazz;
|
---|
56 |
|
---|
57 | private EventTypeFilter(Class<? extends IEventType> eventTypeClazz) {
|
---|
58 | this.eventTypeClazz = eventTypeClazz;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * (non-Javadoc)
|
---|
63 | *
|
---|
64 | * @see de.ugoe.cs.autoquest.usability.tasktree.filters.TaskFilter#getId()
|
---|
65 | */
|
---|
66 | @SuppressWarnings("unchecked")
|
---|
67 | @Override
|
---|
68 | public Class<IEventType> clazz() {
|
---|
69 | return (Class<IEventType>) eventTypeClazz;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * (non-Javadoc)
|
---|
74 | *
|
---|
75 | * @see de.ugoe.cs.autoquest.usability.tasktree.filters.TaskFilter#getId()
|
---|
76 | */
|
---|
77 | @SuppressWarnings("rawtypes")
|
---|
78 | @Override
|
---|
79 | public Predicate filterPredicate() {
|
---|
80 | Predicate<Object> instanceOfIEventTaskPredicate = Predicates.instanceOf(IEventTask.class);
|
---|
81 | Predicate<ITask> taskHoldsInstanceOfFilterArgument =
|
---|
82 | Predicates.compose(Predicates.instanceOf(eventTypeClazz), taskExtractionFunction());
|
---|
83 | return Predicates.and(instanceOfIEventTaskPredicate, taskHoldsInstanceOfFilterArgument);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | *
|
---|
88 | * <p>
|
---|
89 | * Gets the event type of a {@link ITask}.
|
---|
90 | * </p>
|
---|
91 | *
|
---|
92 | * @return event type
|
---|
93 | */
|
---|
94 | private Function<ITask, IEventType> taskExtractionFunction() {
|
---|
95 | return new Function<ITask, IEventType>() {
|
---|
96 |
|
---|
97 | @Override
|
---|
98 | public IEventType apply(ITask task) {
|
---|
99 | return ((IEventTask) task).getEventType();
|
---|
100 | }
|
---|
101 | };
|
---|
102 | }
|
---|
103 | }
|
---|