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

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