[927] | 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.
|
---|
[701] | 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.sequences;
|
---|
[701] | 16 |
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.LinkedList;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
[922] | 21 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 22 | import de.ugoe.cs.autoquest.SequenceInstanceOf;
|
---|
| 23 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed;
|
---|
| 25 | import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased;
|
---|
| 26 | import de.ugoe.cs.autoquest.eventcore.gui.KeyTyped;
|
---|
| 27 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
|
---|
| 28 | import de.ugoe.cs.autoquest.eventcore.gui.TextInputDetector;
|
---|
| 29 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput.TextEquality;
|
---|
[701] | 30 | import de.ugoe.cs.util.console.Command;
|
---|
[751] | 31 | import de.ugoe.cs.util.console.Console;
|
---|
[701] | 32 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * <p>
|
---|
[784] | 36 | * Command that converts {@link KeyPressed}, {@link KeyReleased}, and {@link KeyTyped} sequences
|
---|
| 37 | * into {@link TextInput} events if possible.
|
---|
[701] | 38 | * </p>
|
---|
| 39 | *
|
---|
| 40 | * @author Patrick Harms
|
---|
| 41 | * @version 1.0
|
---|
| 42 | */
|
---|
| 43 | public class CMDdetectTextInputEvents implements Command {
|
---|
| 44 |
|
---|
| 45 | /*
|
---|
| 46 | * (non-Javadoc)
|
---|
| 47 | *
|
---|
| 48 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 49 | */
|
---|
| 50 | @Override
|
---|
| 51 | public String help() {
|
---|
[751] | 52 | return "detectTextInputEvents <sequences> {<new sequences>} {<textEqualityType>}";
|
---|
[701] | 53 | }
|
---|
| 54 |
|
---|
| 55 | /*
|
---|
| 56 | * (non-Javadoc)
|
---|
| 57 | *
|
---|
| 58 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 59 | */
|
---|
| 60 | @SuppressWarnings("unchecked")
|
---|
| 61 | @Override
|
---|
| 62 | public void run(List<Object> parameters) {
|
---|
| 63 | String sequencesName;
|
---|
| 64 | String newSequencesName;
|
---|
[751] | 65 | String textEqualityTypeString = "LEXICAL";
|
---|
[701] | 66 | try {
|
---|
| 67 | sequencesName = (String) parameters.get(0);
|
---|
| 68 | if (parameters.size() > 1) {
|
---|
| 69 | newSequencesName = (String) parameters.get(1);
|
---|
| 70 | }
|
---|
| 71 | else {
|
---|
| 72 | newSequencesName = sequencesName;
|
---|
| 73 | }
|
---|
[784] | 74 | if (parameters.size() > 2) {
|
---|
[751] | 75 | textEqualityTypeString = (String) parameters.get(2);
|
---|
| 76 | }
|
---|
[701] | 77 | }
|
---|
| 78 | catch (Exception e) {
|
---|
[766] | 79 | throw new IllegalArgumentException("must provide a sequences name");
|
---|
[701] | 80 | }
|
---|
| 81 |
|
---|
| 82 | Collection<List<Event>> sequences = null;
|
---|
| 83 | Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
|
---|
| 84 | if (dataObject == null) {
|
---|
| 85 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
| 86 | return;
|
---|
| 87 | }
|
---|
| 88 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
| 89 | CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
|
---|
| 90 | return;
|
---|
| 91 | }
|
---|
[784] | 92 |
|
---|
[751] | 93 | TextEquality textEqualityType = null;
|
---|
| 94 | try {
|
---|
| 95 | textEqualityType = TextEquality.valueOf(textEqualityTypeString);
|
---|
| 96 | }
|
---|
| 97 | catch (IllegalArgumentException e) {
|
---|
[784] | 98 | Console
|
---|
| 99 | .printerrln("Invalid mode. Only LEXICAL, SYNTACTICAL, and SEMANTICAL are allowed values!");
|
---|
[751] | 100 | return;
|
---|
| 101 | }
|
---|
[701] | 102 |
|
---|
| 103 | sequences = (Collection<List<Event>>) dataObject;
|
---|
| 104 |
|
---|
| 105 | Collection<List<Event>> newSequences = new LinkedList<List<Event>>();
|
---|
[784] | 106 |
|
---|
[701] | 107 | for (List<Event> sequence : sequences) {
|
---|
[751] | 108 | newSequences.add(new TextInputDetector(textEqualityType).detectTextInputs(sequence));
|
---|
[701] | 109 | }
|
---|
| 110 |
|
---|
| 111 | if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) {
|
---|
[750] | 112 | CommandHelpers.dataOverwritten(newSequencesName);
|
---|
[701] | 113 | }
|
---|
[784] | 114 |
|
---|
[701] | 115 | }
|
---|
| 116 |
|
---|
| 117 | }
|
---|