Changeset 1042
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-events-test/src/test/java/de/ugoe/cs/autoquest/eventcore/gui/MouseClickCondenserTest.java
r995 r1042 161 161 162 162 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 163 simulateEvent(new MouseButtonUp(leftBtn, 1, 0), element1);163 simulateEvent(new MouseButtonUp(leftBtn, 5, 0), element1); 164 164 assertCondensedMouseClicks("drag left elem1"); 165 165 166 166 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 167 simulateEvent(new MouseButtonUp(leftBtn, 1, 1), element1);167 simulateEvent(new MouseButtonUp(leftBtn, 5, 5), element1); 168 168 assertCondensedMouseClicks("drag left elem1", "drag left elem1"); 169 169 170 170 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 171 simulateEvent(new MouseButtonUp(leftBtn, 0, 1), element1);171 simulateEvent(new MouseButtonUp(leftBtn, 0, 5), element1); 172 172 simulateEvent(new MouseClick(leftBtn, 0, 0), element1); 173 173 assertCondensedMouseClicks("drag left elem1", "drag left elem1", "drag left elem1", 174 174 "click left elem1"); 175 175 176 simulateEvent(new MouseButtonDown(middleBtn, 1, 0), element1);176 simulateEvent(new MouseButtonDown(middleBtn, 5, 0), element1); 177 177 simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1); 178 178 simulateEvent(new MouseClick(middleBtn, 0, 0), element1); … … 180 180 "click left elem1", "", "", "click middle elem1"); 181 181 182 simulateEvent(new MouseButtonDown(rightBtn, 0, 1), element1);182 simulateEvent(new MouseButtonDown(rightBtn, 0, 5), element1); 183 183 simulateEvent(new MouseButtonUp(rightBtn, 0, 0), element1); 184 184 simulateEvent(new MouseClick(rightBtn, 0, 0), element1); … … 191 191 * 192 192 */ 193 @Test 194 public void testDoubleClick() { 195 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 196 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 197 198 IGUIElement element1 = new DummyGUIElement("elem1"); 199 200 simulateEventWithTimestamp(new MouseClick(leftBtn, 0, 0), element1); 201 simulateEventWithTimestamp(new MouseClick(leftBtn, 0, 0), element1); 202 assertCondensedMouseClicks("dblclick left elem1"); 203 204 simulateEventWithTimestamp(new MouseButtonDown(leftBtn, 5, 5), element1); 205 simulateEventWithTimestamp(new MouseButtonUp(leftBtn, 5, 5), element1); 206 simulateEventWithTimestamp(new MouseButtonDown(leftBtn, 5, 5), element1); 207 simulateEventWithTimestamp(new MouseButtonUp(leftBtn, 5, 5), element1); 208 assertCondensedMouseClicks("dblclick left elem1", "dblclick left elem1"); 209 210 simulateEventWithTimestamp(new MouseClick(leftBtn, 0, 0), element1); 211 simulateEventWithTimestamp(new MouseClick(leftBtn, 5, 5), element1); 212 assertCondensedMouseClicks("dblclick left elem1", "dblclick left elem1", 213 "click left elem1", "click left elem1"); 214 215 simulateEventWithTimestamp(new MouseButtonDown(leftBtn, 0, 0), element1); 216 simulateEventWithTimestamp(new MouseButtonUp(leftBtn, 0, 0), element1); 217 simulateEventWithTimestamp(new MouseButtonDown(leftBtn, 5, 5), element1); 218 simulateEventWithTimestamp(new MouseButtonUp(leftBtn, 5, 5), element1); 219 assertCondensedMouseClicks("dblclick left elem1", "dblclick left elem1", 220 "click left elem1", "click left elem1", 221 "click left elem1", "click left elem1"); 222 223 simulateEventWithTimestamp(new MouseClick(rightBtn, 0, 0), element1); 224 simulateEventWithTimestamp(new MouseClick(rightBtn, 5, 5), element1); 225 assertCondensedMouseClicks("dblclick left elem1", "dblclick left elem1", 226 "click left elem1", "click left elem1", 227 "click left elem1", "click left elem1", 228 "click right elem1", "click right elem1"); 229 230 simulateEventWithTimestamp(new MouseButtonDown(rightBtn, 0, 0), element1); 231 simulateEventWithTimestamp(new MouseButtonUp(rightBtn, 0, 0), element1); 232 simulateEventWithTimestamp(new MouseButtonDown(rightBtn, 5, 5), element1); 233 simulateEventWithTimestamp(new MouseButtonUp(rightBtn, 5, 5), element1); 234 assertCondensedMouseClicks("dblclick left elem1", "dblclick left elem1", 235 "click left elem1", "click left elem1", 236 "click left elem1", "click left elem1", 237 "click right elem1", "click right elem1", 238 "click right elem1", "click right elem1"); 239 240 } 241 242 /** 243 * 244 */ 193 245 private void simulateEvent(IEventType eventType, IGUIElement guiElement) { 194 246 events.add(new Event(eventType, guiElement)); 247 } 248 249 /** 250 * 251 */ 252 private void simulateEventWithTimestamp(IEventType eventType, IGUIElement guiElement) { 253 Event event = new Event(eventType, guiElement); 254 event.setTimestamp(System.currentTimeMillis()); 255 events.add(event); 195 256 } 196 257 … … 214 275 assertTrue(result.get(i).getType() instanceof MouseClick); 215 276 } 277 else if ("dblclick".equals(parts[0])) { 278 assertTrue(result.get(i).getType() instanceof MouseDoubleClick); 279 } 216 280 else if ("drag".equals(parts[0])) { 217 281 assertTrue(result.get(i).getType() instanceof MouseDragAndDrop); -
trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/MouseClickCondenser.java
r995 r1042 72 72 } 73 73 else if (mouseClickSequenceFound(mbDown, mbUp)) { 74 // skip the mouse button down and mouse button up event and add a mouse click 74 // replace the mouse button down and mouse button up event with a generated 75 // mouse click 75 76 index += 2; 76 77 resultingSequence.add(createClick(mbDown, mbUp)); … … 78 79 } 79 80 else if (mouseDragAndDropSequenceFound(mbDown, mbUp)) { 80 // skip the mouse button down and mouse button up event and add a mouse click 81 // replace the mouse button down and mouse button up event with a generated 82 // mouse drag and drop 81 83 index += 2; 82 84 resultingSequence.add(createDragAndDrop(mbDown, mbUp)); 83 85 mouseClickHandled = true; 84 86 } 87 else if (mouseDoubleClickSequenceFound(mbDown, mbUp)) { 88 // replace the two mouse click events with a generated mouse double click 89 index += 2; 90 resultingSequence.add(createDoubleClick(mbDown, mbUp)); 91 mouseClickHandled = true; 92 } 85 93 } 86 94 … … 88 96 resultingSequence.add(sequence.get(index)); 89 97 index++; 98 } 99 100 if (resultingSequence.size() > 1) { 101 // check for double clicks 102 int resultingSequenceIndex = resultingSequence.size() - 1; 103 Event click1 = resultingSequence.get(resultingSequenceIndex - 1); 104 Event click2 = resultingSequence.get(resultingSequenceIndex); 105 if (mouseDoubleClickSequenceFound(click1, click2)) { 106 resultingSequence.remove(resultingSequenceIndex); 107 resultingSequence.remove(resultingSequenceIndex - 1); 108 resultingSequence.add(createDoubleClick(click1, click2)); 109 } 90 110 } 91 111 } … … 195 215 196 216 /** 217 * 218 */ 219 private boolean mouseDoubleClickSequenceFound(Event click1, 220 Event click2) 221 { 222 // check the first in a row of three for validity 223 if (!(click1.getType() instanceof MouseClick)) { 224 return false; 225 } 226 227 if (((MouseClick) click1.getType()).getButton() != MouseButtonInteraction.Button.LEFT) { 228 return false; 229 } 230 231 // check the second node for validity 232 if (!(click2.getType() instanceof MouseClick)) { 233 return false; 234 } 235 236 // use 500 milliseconds as timestamp difference as this is more or less similar to default 237 // values in Microsoft Windows 238 if (!timestampDifferenceSmallerThan(click1, click2, 500)) { 239 return false; 240 } 241 242 if (!targetsEqual(click1, click2)) { 243 return false; 244 } 245 246 if (!buttonsEqual(click1, click2)) { 247 return false; 248 } 249 250 if (!coordinatesEqual(click1, click2)) { 251 return false; 252 } 253 254 return true; 255 } 256 257 /** 197 258 * 198 259 */ … … 204 265 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 205 266 206 return new Event(new MouseClick(button, x, y), mouseButtonDown.getTarget()); 267 Event click = new Event(new MouseClick(button, x, y), mouseButtonDown.getTarget()); 268 click.setTimestamp(mouseButtonDown.getTimestamp()); 269 return click; 270 } 271 272 /** 273 * 274 */ 275 private Event createDoubleClick(Event click1, Event click2) { 276 MouseButtonInteraction.Button button = ((MouseClick) click1.getType()).getButton(); 277 278 int x = ((MouseClick) click1.getType()).getX(); 279 int y = ((MouseClick) click1.getType()).getY(); 280 281 Event doubleClick = new Event(new MouseDoubleClick(button, x, y), click1.getTarget()); 282 doubleClick.setTimestamp(click1.getTimestamp()); 283 return doubleClick; 207 284 } 208 285 … … 216 293 int yEnd = ((MouseButtonUp) mouseButtonUp.getType()).getY(); 217 294 218 returnnew Event295 Event dragAndDrop = new Event 219 296 (new MouseDragAndDrop(xStart, yStart, xEnd, yEnd), mouseButtonDown.getTarget()); 297 298 dragAndDrop.setTimestamp(mouseButtonDown.getTimestamp()); 299 return dragAndDrop; 220 300 } 221 301 … … 248 328 * 249 329 */ 330 private boolean timestampDifferenceSmallerThan(Event event1, Event event2, long difference) { 331 long timestamp1 = event1.getTimestamp(); 332 333 if (timestamp1 < 0) { 334 return false; 335 } 336 337 long timestamp2 = event2.getTimestamp(); 338 339 if (timestamp2 < 0) { 340 return false; 341 } 342 343 return (Math.abs((timestamp2 - timestamp1))) < difference; 344 } 345 346 /** 347 * 348 */ 250 349 private boolean coordinatesEqual(Event event1, Event event2) { 251 350 int x1 = … … 256 355 (event2.getType() instanceof MouseButtonInteraction) ? 257 356 ((MouseButtonInteraction) event2.getType()).getX() : -1; 258 259 if ((x1 == -1) || (x1 != x2)) { 357 358 // allow a deviation of one pixel to identify it as click anyway 359 if ((x1 == -1) || (x2 == -1) || (x2 < (x1 - 1)) || ((x1 + 1) < x2)) { 260 360 return false; 261 361 } … … 269 369 ((MouseButtonInteraction) event2.getType()).getY() : -1; 270 370 271 return (y1 != -1) && (y 1 == y2);371 return (y1 != -1) && (y2 != -1) && ((y1 - 1) < y2) && (y2 < (y1 + 1)); 272 372 } 273 373
Note: See TracChangeset
for help on using the changeset viewer.