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