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

Last change on this file since 2218 was 2218, checked in by pharms, 7 years ago
  • java doc issues removal
File size: 4.3 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;
20import java.util.logging.Level;
21
22import de.ugoe.cs.autoquest.CommandHelpers;
23import de.ugoe.cs.autoquest.SequenceInstanceOf;
24import de.ugoe.cs.autoquest.eventcore.Event;
25import de.ugoe.cs.autoquest.eventcore.gui.KeyInteractionCorrector;
26import de.ugoe.cs.autoquest.eventcore.gui.KeyInteractionCorrector.CleanupMode;
27import de.ugoe.cs.util.console.Command;
28import de.ugoe.cs.util.console.Console;
29import de.ugoe.cs.util.console.GlobalDataContainer;
30
31/**
32 * <p>
33 * Command to sort the key interactions in a sequence of events. An example, the sequence to write
34 * the upper case D
35 * </p>
36 * <ul>
37 * <li>press shift key</li>
38 * <li>press D key</li>
39 * <li>release shift key</li>
40 * <li>release D key</li>
41 * </ul>
42 *
43 * <p>
44 * is transformed to the sequence
45 * </p>
46 *
47 * <ul>
48 * <li>press shift key</li>
49 * <li>press D key</li>
50 * <li>release D key</li>
51 * <li>release shift key</li>
52 * </ul>
53 *
54 * <p>
55 * in which the first pressed key (shift in this case) is always released last. The same is done for
56 * the alt and the ctrl keys.
57 * </p>
58 *
59 * @author Patrick Harms
60 * @version 1.0
61 */
62public class CMDsortKeyInteractions implements Command {
63
64    /*
65     * (non-Javadoc)
66     *
67     * @see de.ugoe.cs.util.console.Command#help()
68     */
69    @Override
70    public String help() {
71        return "sortKeyInteractions <sequences> {<new sequences>}";
72    }
73
74    /*
75     * (non-Javadoc)
76     *
77     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
78     */
79    @SuppressWarnings("unchecked")
80    @Override
81    public void run(List<Object> parameters) {
82        String sequencesName;
83        String newSequencesName;
84        String modeString = "ADDITION";
85        try {
86            sequencesName = (String) parameters.get(0);
87            if (parameters.size() > 1) {
88                newSequencesName = (String) parameters.get(1);
89            }
90            else {
91                newSequencesName = sequencesName;
92            }
93            if (parameters.size() > 2) {
94                modeString = (String) parameters.get(2);
95            }
96        }
97        catch (Exception e) {
98            throw new IllegalArgumentException("must provide a sequences name");
99        }
100
101        Collection<List<Event>> sequences = null;
102        Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
103        if (dataObject == null) {
104            CommandHelpers.objectNotFoundMessage(sequencesName);
105            return;
106        }
107        if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
108            CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
109            return;
110        }
111
112        CleanupMode mode = null;
113        try {
114            mode = CleanupMode.valueOf(modeString);
115        }
116        catch (IllegalArgumentException e) {
117            Console.printerrln("Invalid mode. Only REMOVAL and ADDITION are allowed values!");
118            return;
119        }
120
121        sequences = (Collection<List<Event>>) dataObject;
122
123        Collection<List<Event>> newSequences = new LinkedList<List<Event>>();
124
125        int i = 1;
126        for (List<Event> sequence : sequences) {
127            Console.traceln(Level.INFO, "Processing sequence " + i++);
128            newSequences.add(new KeyInteractionCorrector(mode).sortKeyInteractions(sequence));
129        }
130
131        if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) {
132            CommandHelpers.dataOverwritten(newSequencesName);
133        }
134
135    }
136
137}
Note: See TracBrowser for help on using the repository browser.