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.tasktree.filters;
|
---|
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.MouseButtonInteraction;
|
---|
24 | import de.ugoe.cs.autoquest.eventcore.gui.MouseInteraction;
|
---|
25 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
|
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * <p>
|
---|
31 | * TODO comment
|
---|
32 | * </p>
|
---|
33 | *
|
---|
34 | * @author Alexander Deicke
|
---|
35 | */
|
---|
36 | public enum EventTypeFilter implements TaskTreeNodeFilter<IEventType> {
|
---|
37 |
|
---|
38 | MOUSE_BUTTON_INTERACTION(MouseButtonInteraction.class),
|
---|
39 |
|
---|
40 | MOUSE_INTERACTION(MouseInteraction.class),
|
---|
41 |
|
---|
42 | TEXT_INPUT(TextInput.class),
|
---|
43 |
|
---|
44 | USER_INTERACTION(IInteraction.class);
|
---|
45 |
|
---|
46 | private Class<? extends IEventType> eventTypeClazz;
|
---|
47 |
|
---|
48 | private EventTypeFilter(Class<? extends IEventType> eventTypeClazz) {
|
---|
49 | this.eventTypeClazz = eventTypeClazz;
|
---|
50 | }
|
---|
51 |
|
---|
52 | @SuppressWarnings("unchecked")
|
---|
53 | @Override
|
---|
54 | public Class<IEventType> clazz() {
|
---|
55 | return (Class<IEventType>) eventTypeClazz;
|
---|
56 | }
|
---|
57 |
|
---|
58 | @SuppressWarnings("rawtypes")
|
---|
59 | @Override
|
---|
60 | public Predicate filterPredicate() {
|
---|
61 | Predicate<Object> instanceOfIEventTaskPredicate = Predicates.instanceOf(IEventTask.class);
|
---|
62 | Predicate<ITaskTreeNode> nodeHoldsInstanceOfFilterArgument =
|
---|
63 | Predicates.compose(Predicates.instanceOf(eventTypeClazz), nodeExtractionFunction());
|
---|
64 | return Predicates.and(instanceOfIEventTaskPredicate, nodeHoldsInstanceOfFilterArgument);
|
---|
65 | }
|
---|
66 |
|
---|
67 | private Function<ITaskTreeNode, IEventType> nodeExtractionFunction() {
|
---|
68 | return new Function<ITaskTreeNode, IEventType>() {
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public IEventType apply(ITaskTreeNode treeNode) {
|
---|
72 | return ((IEventTask) treeNode).getEventType();
|
---|
73 | }
|
---|
74 | };
|
---|
75 | }
|
---|
76 | }
|
---|