source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDdetectTextInputEvents.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
File size: 4.0 KB
Line 
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
15package de.ugoe.cs.autoquest.commands.sequences;
16
17import java.util.Collection;
18import java.util.LinkedList;
19import java.util.List;
20
21import de.ugoe.cs.autoquest.CommandHelpers;
22import de.ugoe.cs.autoquest.SequenceInstanceOf;
23import de.ugoe.cs.autoquest.eventcore.Event;
24import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed;
25import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased;
26import de.ugoe.cs.autoquest.eventcore.gui.KeyTyped;
27import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
28import de.ugoe.cs.autoquest.eventcore.gui.TextInputDetector;
29import de.ugoe.cs.autoquest.eventcore.gui.TextInput.TextEquality;
30import de.ugoe.cs.util.console.Command;
31import de.ugoe.cs.util.console.Console;
32import de.ugoe.cs.util.console.GlobalDataContainer;
33
34/**
35 * <p>
36 * Command that converts {@link KeyPressed}, {@link KeyReleased}, and {@link KeyTyped} sequences
37 * into {@link TextInput} events if possible.
38 * </p>
39 *
40 * @author Patrick Harms
41 * @version 1.0
42 */
43public 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() {
52        return "detectTextInputEvents <sequences> {<new sequences>} {<textEqualityType>}";
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;
65        String textEqualityTypeString = "LEXICAL";
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            }
74            if (parameters.size() > 2) {
75                textEqualityTypeString = (String) parameters.get(2);
76            }
77        }
78        catch (Exception e) {
79            throw new IllegalArgumentException("must provide a sequences name");
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        }
92
93        TextEquality textEqualityType = null;
94        try {
95            textEqualityType = TextEquality.valueOf(textEqualityTypeString);
96        }
97        catch (IllegalArgumentException e) {
98            Console
99                .printerrln("Invalid mode. Only LEXICAL, SYNTACTICAL, and SEMANTICAL are allowed values!");
100            return;
101        }
102
103        sequences = (Collection<List<Event>>) dataObject;
104
105        Collection<List<Event>> newSequences = new LinkedList<List<Event>>();
106
107        for (List<Event> sequence : sequences) {
108            newSequences.add(new TextInputDetector(textEqualityType).detectTextInputs(sequence));
109        }
110
111        if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) {
112            CommandHelpers.dataOverwritten(newSequencesName);
113        }
114
115    }
116
117}
Note: See TracBrowser for help on using the repository browser.