[927] | 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 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.plugin.mfc;
|
---|
[1] | 16 |
|
---|
| 17 | import java.util.LinkedList;
|
---|
| 18 | import java.util.List;
|
---|
[652] | 19 | import java.util.logging.Level;
|
---|
[1] | 20 |
|
---|
[922] | 21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 22 | import de.ugoe.cs.autoquest.plugin.mfc.eventcore.WindowsMessage;
|
---|
| 23 | import de.ugoe.cs.autoquest.plugin.mfc.eventcore.WindowsMessageType;
|
---|
[940] | 24 | import de.ugoe.cs.autoquest.plugin.mfc.guimodel.MFCWindowTree;
|
---|
[1] | 25 | import de.ugoe.cs.util.console.Console;
|
---|
| 26 |
|
---|
[171] | 27 | /**
|
---|
| 28 | * <p>
|
---|
[619] | 29 | * Responsible to split sequences into subsequences, such that each subsequences contains exactly
|
---|
| 30 | * one event.
|
---|
[171] | 31 | * </p>
|
---|
| 32 | *
|
---|
| 33 | * @author Steffen Herbold
|
---|
| 34 | * @version 1.0
|
---|
| 35 | */
|
---|
[1] | 36 | public class SequenceSplitter {
|
---|
| 37 |
|
---|
[619] | 38 | /**
|
---|
| 39 | * <p>
|
---|
| 40 | * Contains the current subsequence.
|
---|
| 41 | * </p>
|
---|
| 42 | */
|
---|
| 43 | private List<WindowsMessage> currentSequence;
|
---|
[171] | 44 |
|
---|
[619] | 45 | /**
|
---|
| 46 | * <p>
|
---|
| 47 | * Number of messages in the current sequences, that signal that a key or mouse button has been
|
---|
| 48 | * pressed down to which not yet a message has been found, that signals that the button has been
|
---|
| 49 | * released.
|
---|
| 50 | * </p>
|
---|
| 51 | */
|
---|
| 52 | private int openDowns;
|
---|
[171] | 53 |
|
---|
[619] | 54 | /**
|
---|
| 55 | * <p>
|
---|
| 56 | * Internal flag that signals if {@link #currentSequence} needs to be initialized.
|
---|
| 57 | * </p>
|
---|
| 58 | */
|
---|
| 59 | private boolean initMessages;
|
---|
[171] | 60 |
|
---|
[619] | 61 | /**
|
---|
| 62 | * <p>
|
---|
| 63 | * The {@link EventGenerator} used to convert the subsequences into {@link Event}s
|
---|
| 64 | * </p>
|
---|
| 65 | */
|
---|
| 66 | private EventGenerator tokenGenerator;
|
---|
[171] | 67 |
|
---|
[619] | 68 | /**
|
---|
| 69 | * <p>
|
---|
| 70 | * The event sequence generated.
|
---|
| 71 | * </p>
|
---|
| 72 | */
|
---|
| 73 | private List<Event> actionSequence;
|
---|
[171] | 74 |
|
---|
[619] | 75 | /**
|
---|
| 76 | * <p>
|
---|
| 77 | * Type of the previous message.
|
---|
| 78 | * </p>
|
---|
| 79 | */
|
---|
| 80 | private WindowsMessageType prevMsg;
|
---|
[414] | 81 |
|
---|
[619] | 82 | /**
|
---|
| 83 | * <p>
|
---|
| 84 | * Constructor. Creates a new SequenceSplitter.
|
---|
| 85 | * </p>
|
---|
| 86 | */
|
---|
[940] | 87 | public SequenceSplitter(MFCWindowTree windowTree) {
|
---|
[619] | 88 | currentSequence = new LinkedList<WindowsMessage>();
|
---|
| 89 | openDowns = 0;
|
---|
| 90 | initMessages = true;
|
---|
| 91 | tokenGenerator = new EventGenerator(windowTree);
|
---|
| 92 | actionSequence = new LinkedList<Event>();
|
---|
| 93 | prevMsg = null;
|
---|
| 94 | }
|
---|
[171] | 95 |
|
---|
[619] | 96 | /**
|
---|
| 97 | * <p>
|
---|
| 98 | * Called by the {@link MFCLogParser} every time a message is parsed.
|
---|
| 99 | * </p>
|
---|
| 100 | *
|
---|
| 101 | * @param msg
|
---|
| 102 | * message to be added
|
---|
| 103 | */
|
---|
| 104 | public void addMessage(WindowsMessage msg) {
|
---|
| 105 | if (startOfSequence(msg)) {
|
---|
| 106 | if (!initMessages) {
|
---|
| 107 | Event currentAction = tokenGenerator.generateEvent(currentSequence);
|
---|
| 108 | if (currentAction != null) {
|
---|
| 109 | actionSequence.add(currentAction);
|
---|
| 110 | }
|
---|
| 111 | if (msg.getType().isKeyMessage() && openDowns > 0) {
|
---|
[652] | 112 | Console.traceln(Level.SEVERE, "Key message found with open down mouse " +
|
---|
| 113 | "messages - will probabably result in a faulty sequence.");
|
---|
[619] | 114 | }
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | initMessages = false;
|
---|
| 118 | }
|
---|
| 119 | currentSequence = new LinkedList<WindowsMessage>();
|
---|
| 120 | }
|
---|
| 121 | if (msg.getType().isUpMessage()) {
|
---|
| 122 | if (openDowns > 0) {
|
---|
| 123 | openDowns--;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
[414] | 126 |
|
---|
[619] | 127 | // this fix checks if there are two consecutive mouse-down messages.
|
---|
| 128 | // This sometimes occurs due to incorrect filtering in the monitoring
|
---|
| 129 | // dll.
|
---|
| 130 | if (!(prevMsg == WindowsMessageType.WM_LBUTTONDOWN && prevMsg == msg.getType())) {
|
---|
| 131 | currentSequence.add(msg);
|
---|
| 132 | }
|
---|
| 133 | else {
|
---|
| 134 | openDowns--;
|
---|
| 135 | }
|
---|
| 136 | prevMsg = msg.getType();
|
---|
| 137 | }
|
---|
[171] | 138 |
|
---|
[619] | 139 | /**
|
---|
| 140 | * <p>
|
---|
| 141 | * Returns the event sequence generated from the message that have been added.
|
---|
| 142 | * </p>
|
---|
| 143 | *
|
---|
| 144 | * @return generated event sequence
|
---|
| 145 | */
|
---|
| 146 | public List<Event> getSequence() {
|
---|
| 147 | return actionSequence;
|
---|
| 148 | }
|
---|
[171] | 149 |
|
---|
[619] | 150 | /**
|
---|
| 151 | * <p>
|
---|
| 152 | * Called when a session in the log file is finished, i.e., a closing session-node is found.
|
---|
| 153 | * </p>
|
---|
| 154 | */
|
---|
| 155 | public void endSession() {
|
---|
| 156 | Event currentAction = tokenGenerator.generateEvent(currentSequence);
|
---|
| 157 | if (currentAction != null) {
|
---|
| 158 | actionSequence.add(currentAction);
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
[1] | 161 |
|
---|
[619] | 162 | /**
|
---|
| 163 | * <p>
|
---|
| 164 | * Checks if the message starts a new subsequence and returns the result.
|
---|
| 165 | * </p>
|
---|
| 166 | *
|
---|
| 167 | * @param msg
|
---|
| 168 | * message that is checked
|
---|
| 169 | * @return true, if a new subsequence begins
|
---|
| 170 | */
|
---|
| 171 | private boolean startOfSequence(WindowsMessage msg) {
|
---|
| 172 | boolean isStart = false;
|
---|
| 173 | WindowsMessageType msgType = msg.getType();
|
---|
| 174 | if (msgType.isKeyMessage()) {
|
---|
| 175 | isStart = true;
|
---|
| 176 | }
|
---|
| 177 | if (msgType.isDownMessage()) {
|
---|
| 178 | openDowns++;
|
---|
| 179 | if (openDowns == 1) {
|
---|
| 180 | isStart = true;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | if (msgType.isDblclkMessage()) {
|
---|
| 184 | openDowns++;
|
---|
| 185 | }
|
---|
| 186 | return isStart;
|
---|
| 187 | }
|
---|
[1] | 188 |
|
---|
| 189 | }
|
---|