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