Changeset 1167 for trunk


Ignore:
Timestamp:
09/27/18 17:00:46 (6 years ago)
Author:
bln4
Message:

org.expeditee.gio.swing.MouseEventRouter ->

Adjusted when window existed events get triggered.
Fixed the function that determined if a popup is currently visible (even though it will never get called)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gio/swing/MouseEventRouter.java

    r1097 r1167  
    8181         *            Must not be null.
    8282         */
    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                }
    8687
    8788                // Listen for all AWT events (ensures popups are included)
     
    99100         *            The listener to add.
    100101         */
    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
    105107                _mouseListeners.add(listener);
    106108        }
    107109
    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
    112115                _mouseListeners.remove(listener);
    113116        }
    114117
    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
    119123                _mouseMotionListeners.add(listener);
    120124        }
    121125
    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
    126131                _mouseMotionListeners.remove(listener);
    127132        }
    128133
    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
    133139                _mouseWheelListeners.add(listener);
    134140        }
    135141
    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
    140147                _mouseWheelListeners.remove(listener);
    141148        }
     
    146153         * @author Brook Novak
    147154         */
    148         private class EventCatcher implements AWTEventListener
    149         {
     155        private class EventCatcher implements AWTEventListener {
    150156                /**
    151157                 * All events for every component in frame are fired to here
    152158                 */
     159                @Override
    153160                public void eventDispatched(AWTEvent event) {
    154161                        if (event instanceof MouseEvent) {
     
    161168        /**
    162169         * 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          * the mouse actions handler.
     170         * belong to Expeditee space the events are consumed and manually routed to the
     171         * mouse actions handler.
    165172         *
    166173         * @param e
    167174         *            The mouse event for any component in the browser frame
    168175         */
    169         private void routeMouseEvent(MouseEvent e)
    170         {
     176        private void routeMouseEvent(MouseEvent e) {
    171177                _currentMouseEvent = e;
    172178
    173179                // First convert the point to expeditee space
    174180                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) {
    178196                        // 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);
    183201                        }
    184202                }
     
    195213                                // Could handle specially.
    196214                        }
    197 
    198215                } else {
    199216
     
    201218                        // whether an expeditee item is currently picked up
    202219                        boolean forwardToExpeditee = false;
    203                         boolean isOverPopup = PopupManager.getInstance().isPointOverPopup(SwingConversions.fromSwingPoint(containerPoint));
     220                        boolean isOverPopup = PopupManager.getInstance()
     221                                        .isPointOverPopup(SwingConversions.fromSwingPoint(containerPoint));
    204222                        if (isOverPopup) {
    205223                                // Popups have highest preference
     
    210228                                // popups.
    211229                                if (!FreeItems.getInstance().isEmpty()) {
    212                                         StandardGestureActions.move(FreeItems.getInstance(), SwingConversions.fromSwingPoint(containerPoint));
     230                                        StandardGestureActions.move(FreeItems.getInstance(),
     231                                                        SwingConversions.fromSwingPoint(containerPoint));
    213232                                }
    214233
    215234                                // 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()) {
    218238                                forwardToExpeditee = true;
    219239                        } else if (DisplayController.getCurrentFrame() != null) {
     
    223243                                /*
    224244                                 * 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                                 * } }
    227247                                 */// 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);
    231252                        } else {
    232253                                forwardToExpeditee = false;
    233254                        }
     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);
    234259
    235260                        // Create artificial mouse event and forward it to expeditee
     
    255280                                        if (g.getContentPane() != null) {
    256281                                                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();
    258287                                                }
    259288                                        }
     
    282311
    283312                                case MouseEvent.MOUSE_RELEASED:
    284                                        
     313
    285314                                        withExtensions = duplicateMouseEvent(expediteeEvent, e.getModifiers() | e.getModifiersEx());
    286315
     
    318347
    319348                                // 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();
    322351
    323352                                // If forwarding to swing ensure that widgets are not highlighted
     
    339368                                        // Auto-hide pop-ups when user click on something other
    340369                                        // 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() {
    353381                return isPopupVisible(SwingMiscManager.getIfUsingSwingGraphicsManager().getLayeredPane());
    354382        }
    355383
    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)) {
    365410                                        return true;
    366                         }
    367                 }
    368 
     411                                }
     412                        }
     413                }
    369414                return false;
    370415        }
    371416
    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(),
    376419                                /** The below methods are not compatible with Java 1.5 */
    377420                                /*
     
    381424        }
    382425
    383         public static MouseEvent getCurrentMouseEvent()
    384         {
     426        public static MouseEvent getCurrentMouseEvent() {
    385427                return _currentMouseEvent;
    386428        }
Note: See TracChangeset for help on using the changeset viewer.