Changeset 8081 in josm for trunk/src


Ignore:
Timestamp:
2015-02-17T23:11:29+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #10882 - fix focus issues properly

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r8075 r8081  
    77
    88import java.awt.Component;
     9import java.awt.DefaultFocusTraversalPolicy;
    910import java.awt.Dimension;
    1011import java.awt.GraphicsEnvironment;
     
    2021import javax.swing.Box;
    2122import javax.swing.JCheckBoxMenuItem;
    22 import javax.swing.JComponent;
    2323import javax.swing.JMenu;
    2424import javax.swing.JMenuBar;
     
    797797        add(helpMenu, about);
    798798        add(Box.createHorizontalGlue());
    799         add(createSearchField());
     799        final DisableShortcutsOnFocusGainedTextField searchField = createSearchField();
     800        add(searchField);
     801
     802        // Do not let search field take the focus automatically
     803        setFocusTraversalPolicyProvider(true);
     804        setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
     805            @Override
     806            protected boolean accept(Component aComponent) {
     807                return super.accept(aComponent) && !searchField.equals(aComponent);
     808            }
     809        });
    800810
    801811        windowMenu.addMenuListener(menuSeparatorHandler);
     
    818828     * Create search field.
    819829     */
    820     private JComponent createSearchField() {
     830    private DisableShortcutsOnFocusGainedTextField createSearchField() {
    821831        DisableShortcutsOnFocusGainedTextField searchField = new DisableShortcutsOnFocusGainedTextField() {
    822832            @Override
     
    9961006            currentSearchText = searchTerm;
    9971007            if (searchTerm.length() == 0) {
    998                 //No text to search
     1008                // No text to search
    9991009                hideMenu();
    10001010                return;
     
    10031013            List<JMenuItem> searchResult = mainMenu.findMenuItems(currentSearchText);
    10041014            if(searchResult.size() == 0) {
    1005                 //Nothing found
     1015                // Nothing found
    10061016                hideMenu();
    10071017                return;
     
    10091019
    10101020            if(searchResult.size() > 20) {
    1011                 //Too many items found...
     1021                // Too many items found...
    10121022                searchResult = searchResult.subList(0, 20);
    10131023            }
    10141024
    1015             //Update Popup menu
     1025            // Update Popup menu
    10161026            searchResultsMenu.removeAll();
    10171027            for (JMenuItem foundItem : searchResult) {
    10181028                searchResultsMenu.add(foundItem.getText()).setAction(foundItem.getAction());
    10191029            }
     1030            // Put menu right under search field
    10201031            searchResultsMenu.pack();
    1021             searchResultsMenu.show(mainMenu, searchField.getX(), searchField.getY() + searchField.getHeight()); //Put menu right under search field
    1022 
    1023             searchField.grabFocus(); //This is tricky. User still is able to edit search text. While Up and Down keys are handled by Popup Menu.
     1032            searchResultsMenu.show(mainMenu, searchField.getX(), searchField.getY() + searchField.getHeight());
     1033
     1034            // This is tricky. User still is able to edit search text. While Up and Down keys are handled by Popup Menu.
     1035            searchField.requestFocusInWindow();
    10241036        }
    10251037
     
    10271039            searchResultsMenu.setVisible(false);
    10281040        }
    1029 
    10301041    }
    10311042}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r8072 r8081  
    587587                            dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null);
    588588                            hideNotify();
    589                             if (Main.map != null) {
    590                                 // To avoid menu bar search field from taking focus when a toggle dialog is closed
    591                                 Main.map.requestFocusInWindow();
    592                             }
    593589                        }
    594590                    }
Note: See TracChangeset for help on using the changeset viewer.