Ignore:
Timestamp:
10/31/18 10:20:25 (6 years ago)
Author:
bln4
Message:

Updated how the SwingInputManager deals with popups so that the call to focus can be re-enabled.

Location:
trunk/src/org/expeditee/gio/swing
Files:
2 edited

Legend:

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

    r1180 r1187  
    3333import java.util.List;
    3434
     35import javax.swing.JComboBox;
    3536import javax.swing.JComponent;
    3637import javax.swing.JMenuBar;
    37 import javax.swing.JPopupMenu;
    3838import javax.swing.SwingUtilities;
    3939
     
    280280                                        if (g.getContentPane() != null) {
    281281                                                if (!g.getContentPane().isFocusOwner() && !isPopupVisible()) {
    282                                                         //g.getContentPane().requestFocus();
     282                                                        g.getContentPane().requestFocus();
    283283                                                }
    284284                                        }
     
    381381//              for (Component c : parent.getComponents()) {
    382382//                      if (c instanceof JPopupMenu && ((JPopupMenu) c).isVisible()) {
     383//                              System.err.println("Popup visible");
    383384//                              return true;
    384385//
     
    386387//                                      && c != SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()) {
    387388//                              if (isPopupVisible((Container) c)) {
     389//                                      System.err.println("Popup visible");
    388390//                                      return true;
    389391//                              }
    390392//                      }
    391393//              }
    392 //
     394//              System.err.println("Popup not visible");
    393395//              return false;
    394396//      }
    395397       
    396398        private static boolean isPopupVisible(final JComponent parent) {
    397                 final JPopupMenu popup = parent.getComponentPopupMenu();
    398                 if(popup != null) {
    399                         System.err.println("Here");
    400                 }
    401                 if(popup != null && popup.isVisible()) {
    402                         return true;
    403                 } else {
    404                         for (final Component c : parent.getComponents()) {
    405                                 if(c instanceof JComponent && isPopupVisible((JComponent) c)) {
    406                                         return true;
    407                                 }
     399                if(parent instanceof JComboBox) {
     400                        if(((JComboBox<?>) parent).isPopupVisible()) { return true; }
     401                }
     402                for (final Component c : parent.getComponents()) {
     403                        if(c instanceof JComponent && isPopupVisible((JComponent) c)) {
     404                                //System.err.println("MouseEventRouter::found visible popup");
     405                                return true;
    408406                        }
    409407                }
    410408                return false;
    411409        }
     410       
     411//      private static boolean isPopupVisible(final JComponent parent) {
     412//              final JPopupMenu popup = parent.getComponentPopupMenu();
     413//              if(popup != null) {
     414//                      System.err.println("Found control with popup");
     415//              }
     416//              if(popup != null && popup.isVisible()) {
     417//                      System.err.println("Popup visible");
     418//                      return true;
     419//              } else {
     420//                      for (final Component c : parent.getComponents()) {
     421//                              if(c instanceof JComponent && isPopupVisible((JComponent) c)) {
     422//                                      System.err.println("Popup visible");
     423//                                      return true;
     424//                              }
     425//                      }
     426//              }
     427//              System.err.println("Popup not visible");
     428//              return false;
     429//      }
    412430
    413431        private MouseEvent duplicateMouseEvent(MouseEvent e, int modifiers) {
  • trunk/src/org/expeditee/gio/swing/SwingInputManager.java

    r1169 r1187  
    2121import java.awt.event.WindowListener;
    2222import java.awt.event.WindowStateListener;
     23import java.util.List;
    2324
    2425import javax.swing.SwingUtilities;
     
    348349        @Override
    349350        public void keyTyped(KeyEvent e) {
     351                //System.err.println("SwingInputManager::keyTyped::KeyEvent: " + e.getKeyChar());
    350352                // Give widgets first whack at input
    351353                distributeNativeInput(e);
    352354                if (e.isConsumed()) {
     355                        //System.err.println("SwingInputManager::keyTyped::Widget/Popup Consumed KeyEvent");
    353356                        return;
    354357                }
     
    383386        /** Handles key pressed/released events. */
    384387        private void keyAction(KeyEvent e, boolean down) {
     388                //System.err.println("SwingInputManager::keyAction::KeyEvent: " + e.getKeyChar());
    385389                // Give widgets first whack at input
    386390                distributeNativeInput(e);
    387391                if (e.isConsumed()) {
    388                         return;
    389                 }
     392                        //System.err.println("SwingInputManager::keyAction::Was consumed: " + e.isConsumed());
     393                        return;
     394                }
     395                //System.err.println("SwingInputManager::keyAction::Was consumed: " + e.isConsumed());
    390396
    391397                KBMInputEvent.Key key = SwingConversions.fromSwingVirtualKey(e.getKeyCode());
     
    418424        /** Forwards the given input event to the listener if it is listening for it. */
    419425        private void forwardNativeInputToListener(Object listener, java.awt.event.InputEvent event) {
     426                //System.err.println("SwingInputManager::forwardNativeInputToListener");
    420427                if (listener == null || event == null) {
    421428                        return;
    422429                }
    423 
     430                //System.err.println("SwingInputManager::forwardNativeInputToListener::Recieving input: " + event.toString());
    424431                if (listener instanceof KeyListener && event instanceof KeyEvent) {
    425432
     
    435442                                return;
    436443                        case KeyEvent.KEY_TYPED:
     444                                //System.err.println("SwingInputManager::forwardNativeInputToListener::Recieving key typed: " + event.toString());
    437445                                keyListener.keyTyped(ke);
    438446                                return;
     
    505513                        return;
    506514                }
    507 
    508                 for (Popup popup : PopupManager.getInstance().getPopups()) {
     515                final List<Popup> popups = PopupManager.getInstance().getPopups();
     516                for (Popup popup : popups) {
    509517                        forwardNativeInputToListener(popup, event);
    510518
     
    520528                        return;
    521529                }
    522 
    523530                for (Widget iw : _widgets) {
    524531                        java.awt.event.InputEvent e = respecInputEventForWidget(event, iw);
Note: See TracChangeset for help on using the changeset viewer.