source: trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/commands/sequences/CMDcorrectKeyInteractionTargets.java @ 766

Last change on this file since 766 was 766, checked in by sherbold, 12 years ago
File size: 2.8 KB
Line 
1
2package de.ugoe.cs.quest.commands.sequences;
3
4import java.util.Collection;
5import java.util.LinkedList;
6import java.util.List;
7
8import de.ugoe.cs.quest.CommandHelpers;
9import de.ugoe.cs.quest.SequenceInstanceOf;
10import de.ugoe.cs.quest.eventcore.Event;
11import de.ugoe.cs.quest.eventcore.gui.KeyInteractionTargetCorrector;
12import de.ugoe.cs.util.console.Command;
13import de.ugoe.cs.util.console.GlobalDataContainer;
14
15/**
16 * <p>
17 * This command iterates the provided sequences and sets the target of all key interaction events
18 * to the GUI element having the current keyboard focus. The current keyboard focus is determined
19 * either by keyboard focus events or by using the target of the first key interaction in a
20 * sequence. Events changing the keyboard focus are discarded herewith.
21 * </p>
22 *
23 * @author Patrick Harms
24 * @version 1.0
25 */
26public class CMDcorrectKeyInteractionTargets implements Command {
27
28    /*
29     * (non-Javadoc)
30     *
31     * @see de.ugoe.cs.util.console.Command#help()
32     */
33    @Override
34    public String help() {
35        return "correctKeyInteractionTargets <sequences> {<new sequences>}";
36    }
37
38    /*
39     * (non-Javadoc)
40     *
41     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
42     */
43    @SuppressWarnings("unchecked")
44    @Override
45    public void run(List<Object> parameters) {
46        String sequencesName;
47        String newSequencesName;
48        try {
49            sequencesName = (String) parameters.get(0);
50            if (parameters.size() > 1) {
51                newSequencesName = (String) parameters.get(1);
52            }
53            else {
54                newSequencesName = sequencesName;
55            }
56        }
57        catch (Exception e) {
58            throw new IllegalArgumentException("must provide a sequences name");
59        }
60
61        Collection<List<Event>> sequences = null;
62        Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
63        if (dataObject == null) {
64            CommandHelpers.objectNotFoundMessage(sequencesName);
65            return;
66        }
67        if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
68            CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
69            return;
70        }
71
72        sequences = (Collection<List<Event>>) dataObject;
73
74        Collection<List<Event>> newSequences = new LinkedList<List<Event>>();
75       
76        for (List<Event> sequence : sequences) {
77            newSequences.add
78                (new KeyInteractionTargetCorrector().correctKeyInteractionTargets(sequence));
79        }
80
81        if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) {
82            CommandHelpers.dataOverwritten(newSequencesName);
83        }
84       
85    }
86
87}
Note: See TracBrowser for help on using the repository browser.