// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.plugin.mfc; import java.util.LinkedList; import java.util.List; import java.util.logging.Level; import de.ugoe.cs.autoquest.eventcore.Event; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree; import de.ugoe.cs.autoquest.plugin.mfc.eventcore.WindowsMessage; import de.ugoe.cs.autoquest.plugin.mfc.eventcore.WindowsMessageType; import de.ugoe.cs.util.console.Console; /** *
* Responsible to split sequences into subsequences, such that each subsequences contains exactly * one event. *
* * @author Steffen Herbold * @version 1.0 */ public class SequenceSplitter { /** ** Contains the current subsequence. *
*/ private List* Number of messages in the current sequences, that signal that a key or mouse button has been * pressed down to which not yet a message has been found, that signals that the button has been * released. *
*/ private int openDowns; /** ** Internal flag that signals if {@link #currentSequence} needs to be initialized. *
*/ private boolean initMessages; /** ** The {@link EventGenerator} used to convert the subsequences into {@link Event}s *
*/ private EventGenerator tokenGenerator; /** ** The event sequence generated. *
*/ private List* Type of the previous message. *
*/ private WindowsMessageType prevMsg; /** ** Constructor. Creates a new SequenceSplitter. *
*/ public SequenceSplitter(GUIElementTree* Called by the {@link MFCLogParser} every time a message is parsed. *
* * @param msg * message to be added */ public void addMessage(WindowsMessage msg) { if (startOfSequence(msg)) { if (!initMessages) { Event currentAction = tokenGenerator.generateEvent(currentSequence); if (currentAction != null) { actionSequence.add(currentAction); } if (msg.getType().isKeyMessage() && openDowns > 0) { Console.traceln(Level.SEVERE, "Key message found with open down mouse " + "messages - will probabably result in a faulty sequence."); } } else { initMessages = false; } currentSequence = new LinkedList* Returns the event sequence generated from the message that have been added. *
* * @return generated event sequence */ public List* Called when a session in the log file is finished, i.e., a closing session-node is found. *
*/ public void endSession() { Event currentAction = tokenGenerator.generateEvent(currentSequence); if (currentAction != null) { actionSequence.add(currentAction); } } /** ** Checks if the message starts a new subsequence and returns the result. *
* * @param msg * message that is checked * @return true, if a new subsequence begins */ private boolean startOfSequence(WindowsMessage msg) { boolean isStart = false; WindowsMessageType msgType = msg.getType(); if (msgType.isKeyMessage()) { isStart = true; } if (msgType.isDownMessage()) { openDowns++; if (openDowns == 1) { isStart = true; } } if (msgType.isDblclkMessage()) { openDowns++; } return isStart; } }