Changeset 995
- Timestamp:
- 11/15/12 19:55:45 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-events-test/src/test/java/de/ugoe/cs/autoquest/eventcore/gui/MouseClickCondenserTest.java
r957 r995 146 146 simulateEvent(new MouseClick(leftBtn, 1, 1), element1); 147 147 assertCondensedMouseClicks("", "", "click left elem1", "", "", "click middle elem1", 148 "", "", "click left elem1"); 148 "drag left elem1", "click left elem1"); 149 } 150 151 /** 152 * 153 */ 154 @Test 155 public void testDragAndDrop() { 156 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 157 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 158 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 159 160 IGUIElement element1 = new DummyGUIElement("elem1"); 161 162 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 163 simulateEvent(new MouseButtonUp(leftBtn, 1, 0), element1); 164 assertCondensedMouseClicks("drag left elem1"); 165 166 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 167 simulateEvent(new MouseButtonUp(leftBtn, 1, 1), element1); 168 assertCondensedMouseClicks("drag left elem1", "drag left elem1"); 169 170 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 171 simulateEvent(new MouseButtonUp(leftBtn, 0, 1), element1); 172 simulateEvent(new MouseClick(leftBtn, 0, 0), element1); 173 assertCondensedMouseClicks("drag left elem1", "drag left elem1", "drag left elem1", 174 "click left elem1"); 175 176 simulateEvent(new MouseButtonDown(middleBtn, 1, 0), element1); 177 simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1); 178 simulateEvent(new MouseClick(middleBtn, 0, 0), element1); 179 assertCondensedMouseClicks("drag left elem1", "drag left elem1", "drag left elem1", 180 "click left elem1", "", "", "click middle elem1"); 181 182 simulateEvent(new MouseButtonDown(rightBtn, 0, 1), element1); 183 simulateEvent(new MouseButtonUp(rightBtn, 0, 0), element1); 184 simulateEvent(new MouseClick(rightBtn, 0, 0), element1); 185 assertCondensedMouseClicks("drag left elem1", "drag left elem1", "drag left elem1", 186 "click left elem1", "", "", "click middle elem1", 187 "", "", "click right elem1"); 149 188 } 150 189 … … 175 214 assertTrue(result.get(i).getType() instanceof MouseClick); 176 215 } 216 else if ("drag".equals(parts[0])) { 217 assertTrue(result.get(i).getType() instanceof MouseDragAndDrop); 218 } 177 219 else { 178 220 fail("invalid assertion in test case"); -
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.