- Timestamp:
- 09/09/11 06:23:36 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/SequenceSplitter.java
r77 r171 4 4 import java.util.List; 5 5 6 import de.ugoe.cs.eventbench.data.Event; 6 7 import de.ugoe.cs.eventbench.windows.data.WindowsMessage; 7 8 import de.ugoe.cs.util.console.Console; 8 9 10 /** 11 * <p> 12 * Responsible to split sequences into subsequences, such that each subsequences 13 * contains exactly one event. 14 * </p> 15 * 16 * @author Steffen Herbold 17 * @version 1.0 18 */ 9 19 public class SequenceSplitter { 10 20 21 /** 22 * <p> 23 * Contains the current subsequence. 24 * </p> 25 */ 11 26 private List<WindowsMessage> currentSequence; 12 27 28 /** 29 * <p> 30 * Number of messages in the current sequences, that signal that a key or 31 * mouse button has been pressed down to which not yet a message has been 32 * found, that signals that the button has been released. 33 * </p> 34 */ 13 35 private int openDowns; 14 36 37 /** 38 * <p> 39 * Internal flag that signals if {@link #currentSequence} needs to be 40 * initialized. 41 * </p> 42 */ 15 43 private boolean initMessages; 16 44 45 /** 46 * <p> 47 * The {@link EventGenerator} used to convert the subsequences into 48 * {@link Event}s 49 * </p> 50 */ 17 51 private EventGenerator tokenGenerator; 18 52 53 /** 54 * <p> 55 * The event sequence generated. 56 * </p> 57 */ 19 58 private List<WindowsEvent> actionSequence; 20 59 60 /** 61 * <p> 62 * Constructor. Creates a new SequenceSplitter. 63 * </p> 64 */ 21 65 public SequenceSplitter() { 22 66 currentSequence = new LinkedList<WindowsMessage>(); … … 26 70 actionSequence = new LinkedList<WindowsEvent>(); 27 71 } 28 72 73 /** 74 * <p> 75 * Called by the {@link LogParser} every time a message is parsed. 76 * </p> 77 * 78 * @param msg 79 * message to be added 80 */ 29 81 public void addMessage(WindowsMessage msg) { 30 if( startOfSequence(msg) ) { 31 if( !initMessages ) { 32 WindowsEvent currentAction = tokenGenerator.generateEvent(currentSequence); 33 if( currentAction!=null ) { 82 if (startOfSequence(msg)) { 83 if (!initMessages) { 84 WindowsEvent currentAction = tokenGenerator 85 .generateEvent(currentSequence); 86 if (currentAction != null) { 34 87 actionSequence.add(currentAction); 35 88 } 36 if ( isKeyMessage(msg.getType()) && openDowns>0) {89 if (isKeyMessage(msg.getType()) && openDowns > 0) { 37 90 Console.traceln("Key message found with open down mouse messages - will probabably result in a faulty sequence."); 38 91 } … … 41 94 } 42 95 currentSequence = new LinkedList<WindowsMessage>(); 43 } 44 if ( isUpMessage(msg.getType())) {45 if ( openDowns>0 ) {96 } 97 if (isUpMessage(msg.getType())) { 98 if (openDowns > 0) { 46 99 openDowns--; 47 100 } … … 49 102 currentSequence.add(msg); 50 103 } 51 104 105 /** 106 * <p> 107 * Returns the event sequence generated from the message that have been 108 * added. 109 * </p> 110 * 111 * @return generated event sequence 112 */ 52 113 public List<WindowsEvent> getSequence() { 53 114 return actionSequence; 54 115 } 55 116 117 /** 118 * <p> 119 * Called when a session in the log file is finished, i.e., a closing 120 * session-node is found. 121 * </p> 122 */ 56 123 public void endSession() { 57 WindowsEvent currentAction = tokenGenerator.generateEvent(currentSequence); 58 if( currentAction!=null ) { 124 WindowsEvent currentAction = tokenGenerator 125 .generateEvent(currentSequence); 126 if (currentAction != null) { 59 127 actionSequence.add(currentAction); 60 128 } 61 129 } 62 130 131 /** 132 * <p> 133 * Checks if the message starts a new subsequence and returns the result. 134 * </p> 135 * 136 * @param msg 137 * message that is checked 138 * @return true, if a new subsequence begins 139 */ 63 140 private boolean startOfSequence(WindowsMessage msg) { 64 141 boolean isStart = false; 65 142 int msgType = msg.getType(); 66 if ( isKeyMessage(msgType)) {143 if (isKeyMessage(msgType)) { 67 144 isStart = true; 68 145 } 69 if ( isDownMessage(msgType)) {146 if (isDownMessage(msgType)) { 70 147 openDowns++; 71 if ( openDowns==1) {148 if (openDowns == 1) { 72 149 isStart = true; 73 150 } 74 151 } 75 if ( isDblclkMessage(msgType)) {152 if (isDblclkMessage(msgType)) { 76 153 openDowns++; 77 154 } … … 79 156 } 80 157 158 /** 159 * <p> 160 * Checks if the type of a message is generated is a keyboard interaction. 161 * </p> 162 * 163 * @param msgType 164 * type of the message 165 * @return true if it is a keyboard interaction; false otherwise 166 */ 81 167 private boolean isKeyMessage(int msgType) { 82 168 boolean isKeyMsg = false; 83 169 switch (msgType) { 84 85 86 87 88 89 90 91 170 case MessageDefs.WM_KEYDOWN: 171 case MessageDefs.WM_KEYUP: 172 case MessageDefs.WM_SYSKEYDOWN: 173 case MessageDefs.WM_SYSKEYUP: 174 isKeyMsg = true; 175 break; 176 default: 177 break; 92 178 } 93 179 return isKeyMsg; 94 180 } 95 181 182 /** 183 * <p> 184 * Checks if the type of a message indicates that the mouse has been pressed 185 * down. 186 * </p> 187 * 188 * @param msgType 189 * type of the message 190 * @return true if it is mouse-down message; false otherwise 191 */ 96 192 private boolean isDownMessage(int msgType) { 97 193 boolean isDownMsg = false; 98 194 switch (msgType) { 99 100 101 102 103 104 105 106 107 108 109 110 195 case MessageDefs.WM_LBUTTONDOWN: 196 case MessageDefs.WM_RBUTTONDOWN: 197 case MessageDefs.WM_MBUTTONDOWN: 198 case MessageDefs.WM_XBUTTONDOWN: 199 case MessageDefs.WM_NCLBUTTONDOWN: 200 case MessageDefs.WM_NCRBUTTONDOWN: 201 case MessageDefs.WM_NCMBUTTONDOWN: 202 case MessageDefs.WM_NCXBUTTONDOWN: 203 isDownMsg = true; 204 break; 205 default: 206 break; 111 207 } 112 208 return isDownMsg; 113 209 } 114 210 211 /** 212 * <p> 213 * Checks if the type of a message indicates that a double click has been 214 * performed. 215 * </p> 216 * 217 * @param msgType 218 * type of the message 219 * @return true if it is a double click message; false otherwise 220 */ 115 221 private boolean isDblclkMessage(int msgType) { 116 222 boolean isDblclkMsg = false; 117 223 switch (msgType) { 118 119 120 121 122 123 124 125 126 127 128 129 224 case MessageDefs.WM_LBUTTONDBLCLK: 225 case MessageDefs.WM_RBUTTONDBLCLK: 226 case MessageDefs.WM_MBUTTONDBLCLK: 227 case MessageDefs.WM_XBUTTONDBLCLK: 228 case MessageDefs.WM_NCLBUTTONDBLCLK: 229 case MessageDefs.WM_NCRBUTTONDBLCLK: 230 case MessageDefs.WM_NCMBUTTONDBLCLK: 231 case MessageDefs.WM_NCXBUTTONDBLCLK: 232 isDblclkMsg = true; 233 break; 234 default: 235 break; 130 236 } 131 237 return isDblclkMsg; 132 238 } 133 239 240 /** 241 * <p> 242 * Checks if the type of a message indicates that the mouse has been 243 * released. 244 * </p> 245 * 246 * @param msgType 247 * type of the message 248 * @return true if it is mouse-up message; false otherwise 249 */ 134 250 private boolean isUpMessage(int msgType) { 135 251 boolean isUpMsg = false; 136 252 switch (msgType) { 137 138 139 140 141 142 143 144 145 146 147 148 253 case MessageDefs.WM_LBUTTONUP: 254 case MessageDefs.WM_RBUTTONUP: 255 case MessageDefs.WM_MBUTTONUP: 256 case MessageDefs.WM_XBUTTONUP: 257 case MessageDefs.WM_NCLBUTTONUP: 258 case MessageDefs.WM_NCRBUTTONUP: 259 case MessageDefs.WM_NCMBUTTONUP: 260 case MessageDefs.WM_NCXBUTTONUP: 261 isUpMsg = true; 262 break; 263 default: 264 break; 149 265 } 150 266 return isUpMsg; 151 267 } 152 268 153 269 }
Note: See TracChangeset
for help on using the changeset viewer.