Changeset 995 for trunk/autoquest-core-events/src/main/java
- Timestamp:
- 11/15/12 19:55:45 (12 years ago)
- Location:
- trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/MouseClickCondenser.java
r958 r995 30 30 * condensed to the mouse click event. 31 31 * </p> 32 * TODO correctly identify drag and drop33 32 * 34 33 * @version 1.0 … … 78 77 mouseClickHandled = true; 79 78 } 79 else if (mouseDragAndDropSequenceFound(mbDown, mbUp)) { 80 // skip the mouse button down and mouse button up event and add a mouse click 81 index += 2; 82 resultingSequence.add(createDragAndDrop(mbDown, mbUp)); 83 mouseClickHandled = true; 84 } 80 85 } 81 86 … … 105 110 } 106 111 107 IEventTarget eventTarget = mouseButtonDown.getTarget(); 108 109 if (!eventTarget.equals(mouseClick.getTarget())) { 110 return false; 111 } 112 113 MouseButtonInteraction.Button button = 114 ((MouseButtonDown) mouseButtonDown.getType()).getButton(); 115 116 if (!button.equals(((MouseClick) mouseClick.getType()).getButton())) { 117 return false; 118 } 119 120 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 121 122 if (x != ((MouseClick) mouseClick.getType()).getX()) { 123 return false; 124 } 125 126 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 127 128 if (y != ((MouseClick) mouseClick.getType()).getY()) { 112 if (!targetsEqual(mouseButtonDown, mouseClick)) { 113 return false; 114 } 115 116 if (!buttonsEqual(mouseButtonDown, mouseClick)) { 117 return false; 118 } 119 120 if (!coordinatesEqual(mouseButtonDown, mouseClick)) { 129 121 return false; 130 122 } … … 149 141 } 150 142 151 IEventTarget eventTarget = mouseButtonDown.getTarget(); 152 153 if (!eventTarget.equals(mouseButtonUp.getTarget())) { 154 return false; 155 } 156 143 if (!targetsEqual(mouseButtonDown, mouseButtonUp)) { 144 return false; 145 } 146 147 if (!buttonsEqual(mouseButtonDown, mouseButtonUp)) { 148 return false; 149 } 150 151 if (!coordinatesEqual(mouseButtonDown, mouseButtonUp)) { 152 return false; 153 } 154 155 return true; 156 } 157 158 /** 159 * 160 */ 161 private boolean mouseDragAndDropSequenceFound(Event mouseButtonDown, 162 Event mouseButtonUp) 163 { 164 // check the first in a row of three for validity 165 if (!(mouseButtonDown.getType() instanceof MouseButtonDown)) { 166 return false; 167 } 168 169 // check the second node for validity 170 if (!(mouseButtonUp.getType() instanceof MouseButtonUp)) { 171 return false; 172 } 173 174 if (!targetsEqual(mouseButtonDown, mouseButtonUp)) { 175 return false; 176 } 177 157 178 MouseButtonInteraction.Button button = 158 179 ((MouseButtonDown) mouseButtonDown.getType()).getButton(); 159 160 if (!button.equals(((MouseButtonUp) mouseButtonUp.getType()).getButton())) { 161 return false; 162 } 163 164 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 165 166 if (x != ((MouseButtonUp) mouseButtonUp.getType()).getX()) { 167 return false; 168 } 169 170 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 171 172 if (y != ((MouseButtonUp) mouseButtonUp.getType()).getY()) { 180 181 if (MouseButtonInteraction.Button.LEFT != button) { 182 return false; 183 } 184 185 if (!buttonsEqual(mouseButtonDown, mouseButtonUp)) { 186 return false; 187 } 188 189 if (coordinatesEqual(mouseButtonDown, mouseButtonUp)) { 173 190 return false; 174 191 } … … 190 207 } 191 208 209 /** 210 * 211 */ 212 private Event createDragAndDrop(Event mouseButtonDown, Event mouseButtonUp) { 213 int xStart = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 214 int yStart = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 215 int xEnd = ((MouseButtonUp) mouseButtonUp.getType()).getX(); 216 int yEnd = ((MouseButtonUp) mouseButtonUp.getType()).getY(); 217 218 return new Event 219 (new MouseDragAndDrop(xStart, yStart, xEnd, yEnd), mouseButtonDown.getTarget()); 220 } 221 222 /** 223 * 224 */ 225 private boolean targetsEqual(Event event1, Event event2) { 226 IEventTarget target1 = event1.getTarget(); 227 IEventTarget target2 = event2.getTarget(); 228 229 return target1 == null ? target2 == null : target1.equals(target2); 230 } 231 232 /** 233 * 234 */ 235 private boolean buttonsEqual(Event event1, Event event2) { 236 MouseButtonInteraction.Button button1 = 237 (event1.getType() instanceof MouseButtonInteraction) ? 238 ((MouseButtonInteraction) event1.getType()).getButton() : null; 239 240 MouseButtonInteraction.Button button2 = 241 (event2.getType() instanceof MouseButtonInteraction) ? 242 ((MouseButtonInteraction) event2.getType()).getButton() : null; 243 244 return button1 == null ? button2 == null : button1.equals(button2); 245 } 246 247 /** 248 * 249 */ 250 private boolean coordinatesEqual(Event event1, Event event2) { 251 int x1 = 252 (event1.getType() instanceof MouseButtonInteraction) ? 253 ((MouseButtonInteraction) event1.getType()).getX() : -1; 254 255 int x2 = 256 (event2.getType() instanceof MouseButtonInteraction) ? 257 ((MouseButtonInteraction) event2.getType()).getX() : -1; 258 259 if ((x1 == -1) || (x1 != x2)) { 260 return false; 261 } 262 263 int y1 = 264 (event1.getType() instanceof MouseButtonInteraction) ? 265 ((MouseButtonInteraction) event1.getType()).getY() : -1; 266 267 int y2 = 268 (event2.getType() instanceof MouseButtonInteraction) ? 269 ((MouseButtonInteraction) event2.getType()).getY() : -1; 270 271 return (y1 != -1) && (y1 == y2); 272 } 273 192 274 }
Note: See TracChangeset
for help on using the changeset viewer.