Ignore:
Timestamp:
2015-10-23T12:12:50+02:00 (4 years ago)
Author:
Don-vip
Message:

fix #11971 - -/=`key in Overpass Download changes map size

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OverpassDownloadAction.java

    r8756 r8932  
    1111import java.awt.event.ActionEvent;
    1212import java.awt.event.ActionListener;
     13import java.awt.event.FocusEvent;
     14import java.awt.event.FocusListener;
    1315import java.awt.event.KeyEvent;
    1416import java.util.ArrayList;
     
    2123
    2224import javax.swing.AbstractAction;
     25import javax.swing.Action;
     26import javax.swing.ActionMap;
    2327import javax.swing.JButton;
    2428import javax.swing.JComponent;
     
    8387    }
    8488
    85     static final class OverpassDownloadDialog extends DownloadDialog {
    86 
    87         protected HistoryComboBox overpassServer;
    88         protected HistoryComboBox overpassWizard;
    89         protected JosmTextArea overpassQuery;
     89    private static final class DisableActionsFocusListener implements FocusListener {
     90
     91        private final ActionMap actionMap;
     92
     93        private DisableActionsFocusListener(ActionMap actionMap) {
     94            this.actionMap = actionMap;
     95        }
     96
     97        @Override
     98        public void focusGained(FocusEvent e) {
     99            enableActions(false);
     100        }
     101
     102        @Override
     103        public void focusLost(FocusEvent e) {
     104            enableActions(true);
     105        }
     106
     107        private void enableActions(boolean enabled) {
     108            for (Object key : actionMap.allKeys()) {
     109                Action action = actionMap.get(key);
     110                if (action != null) {
     111                    action.setEnabled(enabled);
     112                }
     113            }
     114        }
     115    }
     116
     117    private static final class OverpassDownloadDialog extends DownloadDialog {
     118
     119        private HistoryComboBox overpassServer;
     120        private HistoryComboBox overpassWizard;
     121        private JosmTextArea overpassQuery;
    90122        private static OverpassDownloadDialog instance;
    91         static final StringProperty OVERPASS_SERVER = new StringProperty("download.overpass.server", "http://overpass-api.de/api/");
    92         static final CollectionProperty OVERPASS_SERVER_HISTORY = new CollectionProperty("download.overpass.servers",
     123        private static final StringProperty OVERPASS_SERVER = new StringProperty("download.overpass.server", "http://overpass-api.de/api/");
     124        private static final CollectionProperty OVERPASS_SERVER_HISTORY = new CollectionProperty("download.overpass.servers",
    93125                Arrays.asList("http://overpass-api.de/api/", "http://overpass.osm.rambler.ru/cgi/"));
    94         static final CollectionProperty OVERPASS_WIZARD_HISTORY = new CollectionProperty("download.overpass.wizard", new ArrayList<String>());
     126        private static final CollectionProperty OVERPASS_WIZARD_HISTORY = new CollectionProperty("download.overpass.wizard",
     127                new ArrayList<String>());
    95128
    96129        private OverpassDownloadDialog(Component parent) {
     
    113146        protected void buildMainPanelAboveDownloadSelections(JPanel pnl) {
    114147
     148            DisableActionsFocusListener disableActionsFocusListener =
     149                    new DisableActionsFocusListener(slippyMapChooser.getNavigationComponentActionMap());
     150
    115151            pnl.add(new JLabel(), GBC.eol()); // needed for the invisible checkboxes cbDownloadGpxData, cbDownloadNotes
    116152
     
    118154            overpassWizard = new HistoryComboBox();
    119155            overpassWizard.setToolTipText(tooltip);
     156            overpassWizard.getEditor().getEditorComponent().addFocusListener(disableActionsFocusListener);
    120157            final JButton buildQuery = new JButton(tr("Build query"));
    121158            buildQuery.addActionListener(new AbstractAction() {
     
    143180            overpassQuery = new JosmTextArea("", 8, 80);
    144181            overpassQuery.setFont(GuiHelper.getMonospacedFont(overpassQuery));
     182            overpassQuery.addFocusListener(disableActionsFocusListener);
    145183            JScrollPane scrollPane = new JScrollPane(overpassQuery);
    146184            final JPanel pane = new JPanel(new BorderLayout());
     
    160198
    161199            overpassServer = new HistoryComboBox();
     200            overpassServer.getEditor().getEditorComponent().addFocusListener(disableActionsFocusListener);
    162201            pnl.add(new JLabel(tr("Overpass server: ")), GBC.std().insets(5, 5, 5, 5));
    163202            pnl.add(overpassServer, GBC.eol().fill(GBC.HORIZONTAL));
    164 
    165203        }
    166204
Note: See TracChangeset for help on using the changeset viewer.