Changeset 957 for trunk/autoquest-core-events/src/main/java/de/ugoe/cs
- Timestamp:
- 10/30/12 10:40:25 (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
r947 r957 24 24 * <p> 25 25 * This class condenses mouse clicks, i.e. it reduces a sequence of mouse button down, mouse button 26 * up and mouse click with the same button on the same event target to a single mouse click with 27 * that button on that target. The mouse button down and mouse button up events are discarded. For 28 * this, it iterates the provided sequence and identifies any match of the named event sequence 29 * pattern. This match is condensed to the mouse click event. 26 * up and possibly a subsequent mouse click with the same button on the same event target and the 27 * same coordinates to a single mouse click with that button on that target at the coordinates. 28 * The mouse button down and mouse button up events are discarded. For this, it iterates the 29 * provided sequence and identifies any match of the named event sequence pattern. This match is 30 * condensed to the mouse click event. 31 * </p> 32 * <p> 33 * This class does not create events of proper type if the events are not of type {@link Event} 34 * but derived from it. 30 35 * </p> 31 36 * TODO correctly identify drag and drop … … 54 59 55 60 int index = 0; 56 while (index < sequence.size()) // -2 because we don't need to go to the end 61 boolean mouseClickHandled; 62 while (index < sequence.size()) 57 63 { 58 if ((index + 2) < sequence.size()) { 59 Event mouseButtonDown = sequence.get(index); 60 Event mouseButtonUp = sequence.get(index + 1); 61 Event mouseClick = sequence.get(index + 2); 62 if (mouseClickSequenceFound(mouseButtonDown, mouseButtonUp, mouseClick)) { 63 // skip the mouse button down and mouse button up event 64 mouseClickHandled = false; 65 if ((index + 1) < sequence.size()) { 66 Event mbDown = sequence.get(index); 67 Event mbUp = sequence.get(index + 1); 68 69 if (((index + 2) < sequence.size()) && 70 mouseClickSequenceFound(mbDown, mbUp, sequence.get(index + 2))) 71 { 72 // skip the mouse button down and mouse button up event and add the mouse click 64 73 index += 2; 74 resultingSequence.add(sequence.get(index)); 75 index++; 76 mouseClickHandled = true; 77 } 78 else if (mouseClickSequenceFound(mbDown, mbUp)) { 79 // skip the mouse button down and mouse button up event and add a mouse click 80 index += 2; 81 resultingSequence.add(createClick(mbDown, mbUp)); 82 mouseClickHandled = true; 65 83 } 66 84 } 67 85 68 resultingSequence.add(sequence.get(index)); 69 index++; 86 if (!mouseClickHandled) { 87 resultingSequence.add(sequence.get(index)); 88 index++; 89 } 70 90 } 71 91 … … 79 99 Event mouseButtonUp, 80 100 Event mouseClick) 101 { 102 if (!mouseClickSequenceFound(mouseButtonDown, mouseButtonUp)) { 103 return false; 104 } 105 106 // check the third node for validity 107 if (!(mouseClick.getType() instanceof MouseClick)) { 108 return false; 109 } 110 111 IEventTarget eventTarget = mouseButtonDown.getTarget(); 112 113 if (!eventTarget.equals(mouseClick.getTarget())) { 114 return false; 115 } 116 117 MouseButtonInteraction.Button button = 118 ((MouseButtonDown) mouseButtonDown.getType()).getButton(); 119 120 if (!button.equals(((MouseClick) mouseClick.getType()).getButton())) { 121 return false; 122 } 123 124 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 125 126 if (x != ((MouseClick) mouseClick.getType()).getX()) { 127 return false; 128 } 129 130 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 131 132 if (y != ((MouseClick) mouseClick.getType()).getY()) { 133 return false; 134 } 135 136 return true; 137 } 138 139 /** 140 * 141 */ 142 private boolean mouseClickSequenceFound(Event mouseButtonDown, 143 Event mouseButtonUp) 81 144 { 82 145 // check the first in a row of three for validity … … 103 166 } 104 167 105 // check the third node for validity 106 if (!(mouseClick.getType() instanceof MouseClick)) { 168 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 169 170 if (x != ((MouseButtonUp) mouseButtonUp.getType()).getX()) { 107 171 return false; 108 172 } 173 174 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 109 175 110 if ( !eventTarget.equals(mouseClick.getTarget())) {176 if (y != ((MouseButtonUp) mouseButtonUp.getType()).getY()) { 111 177 return false; 112 178 } 113 114 if (!button.equals(((MouseClick) mouseClick.getType()).getButton())) { 115 return false; 116 } 117 179 118 180 return true; 119 181 } 120 182 183 /** 184 * 185 */ 186 private Event createClick(Event mouseButtonDown, Event mouseButtonUp) { 187 MouseButtonInteraction.Button button = 188 ((MouseButtonDown) mouseButtonDown.getType()).getButton(); 189 190 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 191 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 192 193 return new Event(new MouseClick(button, x, y), mouseButtonDown.getTarget()); 194 } 195 121 196 }
Note: See TracChangeset
for help on using the changeset viewer.