source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDcondenseMouseClicks.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: 3.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;
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.MouseClickCondenser;
25import de.ugoe.cs.util.console.Command;
26import de.ugoe.cs.util.console.GlobalDataContainer;
27
28/**
29 * <p>
30 * This command condenses mouse clicks, i.e. it reduces a sequence of mouse button down,
31 * mouse button up and mouse click with the same button on the same event target to a single
32 * mouse click with that button on that target. The mouse button down and mouse button up events
33 * are discarded.
34 * </p>
35 *
36 * @author Patrick Harms
37 * @version 1.0
38 */
39public class CMDcondenseMouseClicks 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 "condenseMouseClicks <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(new MouseClickCondenser().condenseMouseClicks(sequence));
91        }
92
93        if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) {
94            CommandHelpers.dataOverwritten(newSequencesName);
95        }
96       
97    }
98
99}
Note: See TracBrowser for help on using the repository browser.