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