Changeset 1042 for trunk/autoquest-core-events/src/main/java/de/ugoe
- Timestamp:
- 01/24/13 18:20:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.