- Timestamp:
- 09/27/18 17:00:46 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gio/swing/MouseEventRouter.java
r1097 r1167 81 81 * Must not be null. 82 82 */ 83 public MouseEventRouter(JMenuBar menuBar, Container contentPane) 84 { 85 if (contentPane == null) throw new NullPointerException("contentPane"); 83 public MouseEventRouter(JMenuBar menuBar, Container contentPane) { 84 if (contentPane == null) { 85 throw new NullPointerException("contentPane"); 86 } 86 87 87 88 // Listen for all AWT events (ensures popups are included) … … 99 100 * The listener to add. 100 101 */ 101 public void addExpediteeMouseListener(MouseListener listener) 102 { 103 if (listener == null) throw new NullPointerException("listener"); 104 102 public void addExpediteeMouseListener(MouseListener listener) { 103 if (listener == null) { 104 throw new NullPointerException("listener"); 105 } 106 105 107 _mouseListeners.add(listener); 106 108 } 107 109 108 public void removeExpediteeMouseListener(MouseListener listener) 109 { 110 if (listener == null) throw new NullPointerException("listener"); 111 110 public void removeExpediteeMouseListener(MouseListener listener) { 111 if (listener == null) { 112 throw new NullPointerException("listener"); 113 } 114 112 115 _mouseListeners.remove(listener); 113 116 } 114 117 115 public void addExpediteeMouseMotionListener(MouseMotionListener listener) 116 { 117 if (listener == null) throw new NullPointerException("listener"); 118 118 public void addExpediteeMouseMotionListener(MouseMotionListener listener) { 119 if (listener == null) { 120 throw new NullPointerException("listener"); 121 } 122 119 123 _mouseMotionListeners.add(listener); 120 124 } 121 125 122 public void removeExpediteeMouseMotionListener(MouseMotionListener listener) 123 { 124 if (listener == null) throw new NullPointerException("listener"); 125 126 public void removeExpediteeMouseMotionListener(MouseMotionListener listener) { 127 if (listener == null) { 128 throw new NullPointerException("listener"); 129 } 130 126 131 _mouseMotionListeners.remove(listener); 127 132 } 128 133 129 public void addExpediteeMouseWheelListener(MouseWheelListener listener) 130 { 131 if (listener == null) throw new NullPointerException("listener"); 132 134 public void addExpediteeMouseWheelListener(MouseWheelListener listener) { 135 if (listener == null) { 136 throw new NullPointerException("listener"); 137 } 138 133 139 _mouseWheelListeners.add(listener); 134 140 } 135 141 136 public void removeExpediteeMouseWheelListener(MouseWheelListener listener) 137 { 138 if (listener == null) throw new NullPointerException("listener"); 139 142 public void removeExpediteeMouseWheelListener(MouseWheelListener listener) { 143 if (listener == null) { 144 throw new NullPointerException("listener"); 145 } 146 140 147 _mouseWheelListeners.remove(listener); 141 148 } … … 146 153 * @author Brook Novak 147 154 */ 148 private class EventCatcher implements AWTEventListener 149 { 155 private class EventCatcher implements AWTEventListener { 150 156 /** 151 157 * All events for every component in frame are fired to here 152 158 */ 159 @Override 153 160 public void eventDispatched(AWTEvent event) { 154 161 if (event instanceof MouseEvent) { … … 161 168 /** 162 169 * Forwards the mouse event to its appropriate destination. For events that 163 * belong to Expeditee space the events are consumed and manually routed to 164 * themouse actions handler.170 * belong to Expeditee space the events are consumed and manually routed to the 171 * mouse actions handler. 165 172 * 166 173 * @param e 167 174 * The mouse event for any component in the browser frame 168 175 */ 169 private void routeMouseEvent(MouseEvent e) 170 { 176 private void routeMouseEvent(MouseEvent e) { 171 177 _currentMouseEvent = e; 172 178 173 179 // First convert the point to expeditee space 174 180 Point containerPoint = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), _contentPane); 175 176 // TODO: Find a reliable way of detecting when the mouse moved onto a window that isn't a child of ours 177 if(e.getID() == MouseEvent.MOUSE_EXITED) { 181 182 // TODO: Find a reliable way of detecting when the mouse moved onto a window 183 // that isn't a child of ours 184 // if(e.getID() == MouseEvent.MOUSE_EXITED) { 185 // // System.out.println(e.getComponent()); 186 // if(containerPoint.x <= 0 || containerPoint.x >= _contentPane.getWidth() || 187 // containerPoint.y <= 0 || containerPoint.y >= _contentPane.getHeight()) 188 // { 189 // //FrameGestureActions.mouseExitedWindow(e); 190 // } 191 // } 192 193 // TODO: Find a reliable way of detecting when the mouse moved onto a window 194 // that isn't a child of ours 195 if (e.getID() == MouseEvent.MOUSE_EXITED) { 178 196 // System.out.println(e.getComponent()); 179 if (containerPoint.x <= 0 || containerPoint.x >= _contentPane.getWidth() ||180 containerPoint.y <= 0 || containerPoint.y >= _contentPane.getHeight())181 {182 // FrameGestureActions.mouseExitedWindow(e);197 if (containerPoint.x >= 0 && containerPoint.x <= _contentPane.getWidth() && containerPoint.y >= 0 198 && containerPoint.y <= _contentPane.getHeight()) { 199 return; 200 // FrameGestureActions.mouseExitedWindow(e); 183 201 } 184 202 } … … 195 213 // Could handle specially. 196 214 } 197 198 215 } else { 199 216 … … 201 218 // whether an expeditee item is currently picked up 202 219 boolean forwardToExpeditee = false; 203 boolean isOverPopup = PopupManager.getInstance().isPointOverPopup(SwingConversions.fromSwingPoint(containerPoint)); 220 boolean isOverPopup = PopupManager.getInstance() 221 .isPointOverPopup(SwingConversions.fromSwingPoint(containerPoint)); 204 222 if (isOverPopup) { 205 223 // Popups have highest preference … … 210 228 // popups. 211 229 if (!FreeItems.getInstance().isEmpty()) { 212 StandardGestureActions.move(FreeItems.getInstance(), SwingConversions.fromSwingPoint(containerPoint)); 230 StandardGestureActions.move(FreeItems.getInstance(), 231 SwingConversions.fromSwingPoint(containerPoint)); 213 232 } 214 233 215 234 // Note: all frame.content pane events belong to expeditee 216 } else if (e.getSource() == _contentPane || e.getSource() == SwingMiscManager.getIfUsingSwingGraphicsManager().getJFrame() || !FreeItems.getInstance().isEmpty()) 217 { 235 } else if (e.getSource() == _contentPane 236 || e.getSource() == SwingMiscManager.getIfUsingSwingGraphicsManager().getJFrame() 237 || !FreeItems.getInstance().isEmpty()) { 218 238 forwardToExpeditee = true; 219 239 } else if (DisplayController.getCurrentFrame() != null) { … … 223 243 /* 224 244 * for (Item i : DisplayIO.getCurrentFrame().getItems()) { if 225 * (i.getPolygon().contains(containerPoint)) { 226 * forwardToExpiditee = true; break;} }245 * (i.getPolygon().contains(containerPoint)) { forwardToExpiditee = true; break; 246 * } } 227 247 */// ABOVE: Does not consider overlays 228 // NOTE: Below is an expensive operation and could be re-used 229 // when passing mouse events!!! 230 forwardToExpeditee = (FrameUtils.onItem(DisplayController.getCurrentFrame(), containerPoint.x, containerPoint.y, true) != null); 248 // NOTE: Below is an expensive operation and could be re-used 249 // when passing mouse events!!! 250 forwardToExpeditee = (FrameUtils.onItem(DisplayController.getCurrentFrame(), containerPoint.x, 251 containerPoint.y, true) != null); 231 252 } else { 232 253 forwardToExpeditee = false; 233 254 } 255 256 //System.err.println("MouseEventRouter::routeMouseEvent::contentPane: " + _contentPane); 257 //System.err.println("MouseEventRouter::routeMouseEvent::e.getSource():" + e.getSource()); 258 //System.err.println("MouseEventRouter::routeMouseEvent::forwardToExpeditee:" + forwardToExpeditee); 234 259 235 260 // Create artificial mouse event and forward it to expeditee … … 255 280 if (g.getContentPane() != null) { 256 281 if (!g.getContentPane().isFocusOwner() && !isPopupVisible()) { 257 g.getContentPane().requestFocus(); 282 System.err.println("MouseEventRouter::Content Pane Requesting Focus"); 283 //System.err.println("MouseEventRouter::Content Pane Requesting Focus::Focus owner is content pane: " + g.getContentPane().isFocusOwner()); 284 System.err.println("MouseEventRouter::Content Pane Requesting Focus::Popups visible: " + isPopupVisible()); 285 System.err.println("MouseEventRouter::Content Pane Requesting Focus::Focus owner is: " + g.getJFrame().getFocusOwner()); 286 //g.getContentPane().requestFocus(); 258 287 } 259 288 } … … 282 311 283 312 case MouseEvent.MOUSE_RELEASED: 284 313 285 314 withExtensions = duplicateMouseEvent(expediteeEvent, e.getModifiers() | e.getModifiersEx()); 286 315 … … 318 347 319 348 // Keep expeditees mouse X/Y updated 320 // FrameMouseActions.MouseX = expediteeEvent.getX();321 // FrameMouseActions.MouseY = expediteeEvent.getY();349 // FrameMouseActions.MouseX = expediteeEvent.getX(); 350 // FrameMouseActions.MouseY = expediteeEvent.getY(); 322 351 323 352 // If forwarding to swing ensure that widgets are not highlighted … … 339 368 // Auto-hide pop-ups when user click on something other 340 369 // than a pop-up - and is not on a pop-up invoker 341 } /*else if (!isOverPopup // TODO: Reinstate. cts16 342 && e.getID() == MouseEvent.MOUSE_PRESSED 343 && !PopupManager.getInstance().isInvoker(e.getComponent())) 344 { 345 PopupManager.getInstance().hideAutohidePopups(); 346 }*/ 347 } 348 } 349 } 350 351 public static boolean isPopupVisible() 352 { 370 } /* 371 * else if (!isOverPopup // TODO: Reinstate. cts16 && e.getID() == 372 * MouseEvent.MOUSE_PRESSED && 373 * !PopupManager.getInstance().isInvoker(e.getComponent())) { 374 * PopupManager.getInstance().hideAutohidePopups(); } 375 */ 376 } 377 } 378 } 379 380 public static boolean isPopupVisible() { 353 381 return isPopupVisible(SwingMiscManager.getIfUsingSwingGraphicsManager().getLayeredPane()); 354 382 } 355 383 356 private static boolean isPopupVisible(Container parent) 357 { 358 for (Component c : parent.getComponents()) { 359 360 if (c instanceof JPopupMenu && ((JPopupMenu) c).isVisible()) { 361 return true; 362 363 } else if (c instanceof Container && c != SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()) { 364 if (isPopupVisible((Container) c)) 384 // private static boolean isPopupVisible(Container parent) { 385 // for (Component c : parent.getComponents()) { 386 // if (c instanceof JPopupMenu && ((JPopupMenu) c).isVisible()) { 387 // return true; 388 // 389 // } else if (c instanceof Container 390 // && c != SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()) { 391 // if (isPopupVisible((Container) c)) { 392 // return true; 393 // } 394 // } 395 // } 396 // 397 // return false; 398 // } 399 400 private static boolean isPopupVisible(final JComponent parent) { 401 final JPopupMenu popup = parent.getComponentPopupMenu(); 402 if(popup != null) { 403 System.err.println("Here"); 404 } 405 if(popup != null && popup.isVisible()) { 406 return true; 407 } else { 408 for (final Component c : parent.getComponents()) { 409 if(c instanceof JComponent && isPopupVisible((JComponent) c)) { 365 410 return true; 366 }367 }368 411 } 412 } 413 } 369 414 return false; 370 415 } 371 416 372 private MouseEvent duplicateMouseEvent(MouseEvent e, int modifiers) 373 { 374 return new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), 375 modifiers, e.getX(), e.getY(), 417 private MouseEvent duplicateMouseEvent(MouseEvent e, int modifiers) { 418 return new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(), 376 419 /** The below methods are not compatible with Java 1.5 */ 377 420 /* … … 381 424 } 382 425 383 public static MouseEvent getCurrentMouseEvent() 384 { 426 public static MouseEvent getCurrentMouseEvent() { 385 427 return _currentMouseEvent; 386 428 }
Note:
See TracChangeset
for help on using the changeset viewer.