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 |
|
---|
15 | package de.ugoe.cs.autoquest.commands.sequences;
|
---|
16 |
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.LinkedList;
|
---|
19 | import java.util.List;
|
---|
20 |
|
---|
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.KeyInteractionTargetCorrector;
|
---|
25 | import de.ugoe.cs.util.console.Command;
|
---|
26 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * <p>
|
---|
30 | * This command iterates the provided sequences and sets the target of all key interaction events
|
---|
31 | * to the GUI element having the current keyboard focus. The current keyboard focus is determined
|
---|
32 | * either by keyboard focus events or by using the target of the first key interaction in a
|
---|
33 | * sequence. Events changing the keyboard focus are discarded herewith.
|
---|
34 | * </p>
|
---|
35 | *
|
---|
36 | * @author Patrick Harms
|
---|
37 | * @version 1.0
|
---|
38 | */
|
---|
39 | public class CMDcorrectKeyInteractionTargets implements Command {
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * (non-Javadoc)
|
---|
43 | *
|
---|
44 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
45 | */
|
---|
46 | @Override
|
---|
47 | public String help() {
|
---|
48 | return "correctKeyInteractionTargets <sequences> {<new sequences>}";
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*
|
---|
52 | * (non-Javadoc)
|
---|
53 | *
|
---|
54 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
55 | */
|
---|
56 | @SuppressWarnings("unchecked")
|
---|
57 | @Override
|
---|
58 | public void run(List<Object> parameters) {
|
---|
59 | String sequencesName;
|
---|
60 | String newSequencesName;
|
---|
61 | try {
|
---|
62 | sequencesName = (String) parameters.get(0);
|
---|
63 | if (parameters.size() > 1) {
|
---|
64 | newSequencesName = (String) parameters.get(1);
|
---|
65 | }
|
---|
66 | else {
|
---|
67 | newSequencesName = sequencesName;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | catch (Exception e) {
|
---|
71 | throw new IllegalArgumentException("must provide a sequences name");
|
---|
72 | }
|
---|
73 |
|
---|
74 | Collection<List<Event>> sequences = null;
|
---|
75 | Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
|
---|
76 | if (dataObject == null) {
|
---|
77 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
78 | return;
|
---|
79 | }
|
---|
80 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
81 | CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
|
---|
82 | return;
|
---|
83 | }
|
---|
84 |
|
---|
85 | sequences = (Collection<List<Event>>) dataObject;
|
---|
86 |
|
---|
87 | Collection<List<Event>> newSequences = new LinkedList<List<Event>>();
|
---|
88 |
|
---|
89 | for (List<Event> sequence : sequences) {
|
---|
90 | newSequences.add
|
---|
91 | (new KeyInteractionTargetCorrector().correctKeyInteractionTargets(sequence));
|
---|
92 | }
|
---|
93 |
|
---|
94 | if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) {
|
---|
95 | CommandHelpers.dataOverwritten(newSequencesName);
|
---|
96 | }
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|