1 | package de.ugoe.cs.eventbench.windows;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.windows.data.WindowsMessage;
|
---|
7 | import de.ugoe.cs.util.console.Console;
|
---|
8 |
|
---|
9 | public class SequenceSplitter {
|
---|
10 |
|
---|
11 | private List<WindowsMessage> currentSequence;
|
---|
12 |
|
---|
13 | private int openDowns;
|
---|
14 |
|
---|
15 | private boolean initMessages;
|
---|
16 |
|
---|
17 | private EventGenerator tokenGenerator;
|
---|
18 |
|
---|
19 | private List<WindowsEvent> actionSequence;
|
---|
20 |
|
---|
21 | public SequenceSplitter() {
|
---|
22 | currentSequence = new LinkedList<WindowsMessage>();
|
---|
23 | openDowns = 0;
|
---|
24 | initMessages = true;
|
---|
25 | tokenGenerator = new EventGenerator();
|
---|
26 | actionSequence = new LinkedList<WindowsEvent>();
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void addMessage(WindowsMessage msg) {
|
---|
30 | if( startOfSequence(msg) ) {
|
---|
31 | if( !initMessages ) {
|
---|
32 | WindowsEvent currentAction = tokenGenerator.generateEvent(currentSequence);
|
---|
33 | if( currentAction!=null ) {
|
---|
34 | actionSequence.add(currentAction);
|
---|
35 | }
|
---|
36 | if( isKeyMessage(msg.getType()) && openDowns>0 ) {
|
---|
37 | Console.traceln("Key message found with open down mouse messages - will probabably result in a faulty sequence.");
|
---|
38 | }
|
---|
39 | } else {
|
---|
40 | initMessages = false;
|
---|
41 | }
|
---|
42 | currentSequence = new LinkedList<WindowsMessage>();
|
---|
43 | }
|
---|
44 | if( isUpMessage(msg.getType()) ) {
|
---|
45 | if( openDowns>0 ) {
|
---|
46 | openDowns--;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | currentSequence.add(msg);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public List<WindowsEvent> getSequence() {
|
---|
53 | return actionSequence;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void endSession() {
|
---|
57 | WindowsEvent currentAction = tokenGenerator.generateEvent(currentSequence);
|
---|
58 | if( currentAction!=null ) {
|
---|
59 | actionSequence.add(currentAction);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | private boolean startOfSequence(WindowsMessage msg) {
|
---|
64 | boolean isStart = false;
|
---|
65 | int msgType = msg.getType();
|
---|
66 | if( isKeyMessage(msgType) ) {
|
---|
67 | isStart = true;
|
---|
68 | }
|
---|
69 | if( isDownMessage(msgType) ) {
|
---|
70 | openDowns++;
|
---|
71 | if( openDowns==1 ) {
|
---|
72 | isStart = true;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | if( isDblclkMessage(msgType) ) {
|
---|
76 | openDowns++;
|
---|
77 | }
|
---|
78 | return isStart;
|
---|
79 | }
|
---|
80 |
|
---|
81 | private boolean isKeyMessage(int msgType) {
|
---|
82 | boolean isKeyMsg = false;
|
---|
83 | switch (msgType) {
|
---|
84 | case MessageDefs.WM_KEYDOWN:
|
---|
85 | case MessageDefs.WM_KEYUP:
|
---|
86 | case MessageDefs.WM_SYSKEYDOWN:
|
---|
87 | case MessageDefs.WM_SYSKEYUP:
|
---|
88 | isKeyMsg = true;
|
---|
89 | break;
|
---|
90 | default:
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | return isKeyMsg;
|
---|
94 | }
|
---|
95 |
|
---|
96 | private boolean isDownMessage(int msgType) {
|
---|
97 | boolean isDownMsg = false;
|
---|
98 | switch (msgType) {
|
---|
99 | case MessageDefs.WM_LBUTTONDOWN:
|
---|
100 | case MessageDefs.WM_RBUTTONDOWN:
|
---|
101 | case MessageDefs.WM_MBUTTONDOWN:
|
---|
102 | case MessageDefs.WM_XBUTTONDOWN:
|
---|
103 | case MessageDefs.WM_NCLBUTTONDOWN:
|
---|
104 | case MessageDefs.WM_NCRBUTTONDOWN:
|
---|
105 | case MessageDefs.WM_NCMBUTTONDOWN:
|
---|
106 | case MessageDefs.WM_NCXBUTTONDOWN:
|
---|
107 | isDownMsg = true;
|
---|
108 | break;
|
---|
109 | default:
|
---|
110 | break;
|
---|
111 | }
|
---|
112 | return isDownMsg;
|
---|
113 | }
|
---|
114 |
|
---|
115 | private boolean isDblclkMessage(int msgType) {
|
---|
116 | boolean isDblclkMsg = false;
|
---|
117 | switch (msgType) {
|
---|
118 | case MessageDefs.WM_LBUTTONDBLCLK:
|
---|
119 | case MessageDefs.WM_RBUTTONDBLCLK:
|
---|
120 | case MessageDefs.WM_MBUTTONDBLCLK:
|
---|
121 | case MessageDefs.WM_XBUTTONDBLCLK:
|
---|
122 | case MessageDefs.WM_NCLBUTTONDBLCLK:
|
---|
123 | case MessageDefs.WM_NCRBUTTONDBLCLK:
|
---|
124 | case MessageDefs.WM_NCMBUTTONDBLCLK:
|
---|
125 | case MessageDefs.WM_NCXBUTTONDBLCLK:
|
---|
126 | isDblclkMsg = true;
|
---|
127 | break;
|
---|
128 | default:
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | return isDblclkMsg;
|
---|
132 | }
|
---|
133 |
|
---|
134 | private boolean isUpMessage(int msgType) {
|
---|
135 | boolean isUpMsg = false;
|
---|
136 | switch (msgType) {
|
---|
137 | case MessageDefs.WM_LBUTTONUP:
|
---|
138 | case MessageDefs.WM_RBUTTONUP:
|
---|
139 | case MessageDefs.WM_MBUTTONUP:
|
---|
140 | case MessageDefs.WM_XBUTTONUP:
|
---|
141 | case MessageDefs.WM_NCLBUTTONUP:
|
---|
142 | case MessageDefs.WM_NCRBUTTONUP:
|
---|
143 | case MessageDefs.WM_NCMBUTTONUP:
|
---|
144 | case MessageDefs.WM_NCXBUTTONUP:
|
---|
145 | isUpMsg = true;
|
---|
146 | break;
|
---|
147 | default:
|
---|
148 | break;
|
---|
149 | }
|
---|
150 | return isUpMsg;
|
---|
151 | }
|
---|
152 |
|
---|
153 | }
|
---|