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