Changeset 10791 in josm


Ignore:
Timestamp:
2016-08-12T21:08:00+02:00 (8 years ago)
Author:
simon04
Message:

see #13319 - Use InputMapUtils where applicable (VK_ESCAPE)

Location:
trunk/src/org/openstreetmap/josm
Files:
19 edited

Legend:

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

    r10680 r10791  
    2323import javax.swing.Icon;
    2424import javax.swing.JButton;
    25 import javax.swing.JComponent;
    2625import javax.swing.JDialog;
    2726import javax.swing.JLabel;
     
    4140import org.openstreetmap.josm.tools.GBC;
    4241import org.openstreetmap.josm.tools.ImageProvider;
     42import org.openstreetmap.josm.tools.InputMapUtils;
    4343import org.openstreetmap.josm.tools.Utils;
    4444import org.openstreetmap.josm.tools.WindowGeometry;
     
    473473        };
    474474
    475         getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
    476             .put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE");
    477         getRootPane().getActionMap().put("ESCAPE", actionListener);
     475        InputMapUtils.addEscapeAction(getRootPane(), actionListener);
    478476    }
    479477
  • trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java

    r10790 r10791  
    88import java.awt.GraphicsEnvironment;
    99import java.awt.event.ActionEvent;
    10 import java.awt.event.KeyEvent;
    1110import java.awt.event.WindowAdapter;
    1211import java.awt.event.WindowEvent;
     
    2019import javax.swing.Icon;
    2120import javax.swing.JButton;
    22 import javax.swing.JComponent;
    2321import javax.swing.JDialog;
    2422import javax.swing.JOptionPane;
    25 import javax.swing.KeyStroke;
    2623import javax.swing.event.ChangeEvent;
    2724import javax.swing.event.ChangeListener;
     
    287284            }
    288285        });
    289         dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
    290                 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
    291         dialog.getRootPane().getActionMap().put("close", new AbstractAction() {
     286        InputMapUtils.addEscapeAction(dialog.getRootPane(), new AbstractAction() {
    292287            @Override
    293288            public void actionPerformed(ActionEvent e) {
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

    r10762 r10791  
    4949import org.openstreetmap.josm.tools.CheckParameterUtil;
    5050import org.openstreetmap.josm.tools.ImageProvider;
     51import org.openstreetmap.josm.tools.InputMapUtils;
    5152import org.openstreetmap.josm.tools.StreamUtils;
    5253import org.openstreetmap.josm.tools.UserCancelException;
     
    170171        addWindowListener(new AdjustDividerLocationAction());
    171172        HelpUtil.setHelpContext(getRootPane(), ht("/"));
     173        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    172174    }
    173175
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/PasteTagsConflictResolverDialog.java

    r10737 r10791  
    4141import org.openstreetmap.josm.gui.util.GuiHelper;
    4242import org.openstreetmap.josm.tools.ImageProvider;
     43import org.openstreetmap.josm.tools.InputMapUtils;
    4344import org.openstreetmap.josm.tools.WindowGeometry;
    4445
     
    104105        gc.weighty = 0.0;
    105106        getContentPane().add(buildButtonPanel(), gc);
     107        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
     108
    106109    }
    107110
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r10790 r10791  
    291291
    292292        // make the dialog respond to ESC
    293         getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
    294                 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancelAndClose");
    295         getRootPane().getActionMap().put("cancelAndClose", new CancelAction());
     293        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    296294
    297295        // install a window event handler
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java

    r10627 r10791  
    1010import java.awt.Window;
    1111import java.awt.event.ActionEvent;
    12 import java.awt.event.KeyEvent;
    1312import java.awt.event.WindowAdapter;
    1413import java.awt.event.WindowEvent;
     
    1615import javax.swing.AbstractAction;
    1716import javax.swing.JButton;
    18 import javax.swing.JComponent;
    1917import javax.swing.JDialog;
    2018import javax.swing.JOptionPane;
    2119import javax.swing.JPanel;
    2220import javax.swing.JTabbedPane;
    23 import javax.swing.KeyStroke;
    2421
    2522import org.openstreetmap.josm.Main;
     
    2926import org.openstreetmap.josm.io.ChangesetQuery;
    3027import org.openstreetmap.josm.tools.ImageProvider;
     28import org.openstreetmap.josm.tools.InputMapUtils;
    3129import org.openstreetmap.josm.tools.WindowGeometry;
    3230
     
    9088
    9189        // cancel on ESC
    92         getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
    93         getRootPane().getActionMap().put("cancel", new CancelAction());
     90        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    9491
    9592        // context sensitive help
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java

    r10424 r10791  
    66import java.awt.event.ActionEvent;
    77
    8 import javax.swing.JComponent;
    98import javax.swing.JOptionPane;
    10 import javax.swing.JRootPane;
    11 import javax.swing.KeyStroke;
    129import javax.swing.RootPaneContainer;
    1310
     
    2320import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    2421import org.openstreetmap.josm.tools.ImageProvider;
     22import org.openstreetmap.josm.tools.InputMapUtils;
    2523
    2624/**
     
    4745
    4846        if (editor instanceof RootPaneContainer) {
    49             JRootPane root = ((RootPaneContainer) editor).getRootPane();
    50             root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE");
    51             root.getActionMap().put("ESCAPE", this);
     47            InputMapUtils.addEscapeAction(((RootPaneContainer) editor).getRootPane(), this);
    5248        }
    5349        setEnabled(true);
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r10790 r10791  
    190190
    191191        // -- cancel on ESC
    192         getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
    193         getRootPane().getActionMap().put("cancel", actCancel);
     192        InputMapUtils.addEscapeAction(getRootPane(), actCancel);
    194193
    195194        // -- help button
  • trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java

    r10627 r10791  
    1212import java.awt.Rectangle;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.KeyEvent;
    1514import java.awt.event.WindowAdapter;
    1615import java.awt.event.WindowEvent;
     
    2423import javax.swing.AbstractAction;
    2524import javax.swing.JButton;
    26 import javax.swing.JComponent;
    2725import javax.swing.JDialog;
    2826import javax.swing.JMenuItem;
     
    3230import javax.swing.JSeparator;
    3331import javax.swing.JToolBar;
    34 import javax.swing.KeyStroke;
    3532import javax.swing.SwingUtilities;
    3633import javax.swing.event.ChangeEvent;
     
    5451import org.openstreetmap.josm.gui.widgets.JosmHTMLEditorKit;
    5552import org.openstreetmap.josm.tools.ImageProvider;
     53import org.openstreetmap.josm.tools.InputMapUtils;
    5654import org.openstreetmap.josm.tools.LanguageInfo.LocaleType;
    5755import org.openstreetmap.josm.tools.OpenBrowser;
     
    195193
    196194        p.add(buildToolBar(), BorderLayout.NORTH);
    197         help.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Close");
    198         help.getActionMap().put("Close", new AbstractAction() {
     195        InputMapUtils.addEscapeAction(getRootPane(), new AbstractAction() {
    199196            @Override
    200197            public void actionPerformed(ActionEvent e) {
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialog.java

    r10481 r10791  
    99import java.awt.FlowLayout;
    1010import java.awt.event.ActionEvent;
    11 import java.awt.event.KeyEvent;
    1211import java.awt.event.WindowAdapter;
    1312import java.awt.event.WindowEvent;
     
    1514import javax.swing.AbstractAction;
    1615import javax.swing.JButton;
    17 import javax.swing.JComponent;
    1816import javax.swing.JDialog;
    1917import javax.swing.JLabel;
    2018import javax.swing.JPanel;
    21 import javax.swing.KeyStroke;
    2219
    2320import org.openstreetmap.josm.Main;
     
    3027import org.openstreetmap.josm.gui.util.GuiHelper;
    3128import org.openstreetmap.josm.tools.ImageProvider;
     29import org.openstreetmap.josm.tools.InputMapUtils;
    3230
    3331/**
     
    107105        btn = new JButton(closeAction);
    108106        final String closeHistoryBrowserDialogKey = "CloseHistoryBrowserDialog";
    109         KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    110         getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escapeKey, closeHistoryBrowserDialogKey);
    111         getRootPane().getActionMap().put(closeHistoryBrowserDialogKey, closeAction);
    112107        btn.setName("btn.close");
    113108        pnl.add(btn);
     109        InputMapUtils.addEscapeAction(getRootPane(), closeAction);
    114110
    115111        btn = new JButton(new ContextSensitiveHelpAction(ht("/Action/ObjectHistory")));
  • trunk/src/org/openstreetmap/josm/gui/io/CloseChangesetDialog.java

    r10179 r10791  
    88import java.awt.FlowLayout;
    99import java.awt.event.ActionEvent;
    10 import java.awt.event.KeyEvent;
    1110import java.awt.event.WindowAdapter;
    1211import java.awt.event.WindowEvent;
     
    1817import javax.swing.BorderFactory;
    1918import javax.swing.DefaultListModel;
    20 import javax.swing.JComponent;
    2119import javax.swing.JDialog;
    2220import javax.swing.JLabel;
     
    2422import javax.swing.JPanel;
    2523import javax.swing.JScrollPane;
    26 import javax.swing.KeyStroke;
    2724import javax.swing.event.ListSelectionEvent;
    2825import javax.swing.event.ListSelectionListener;
     
    9188        getContentPane().add(buildSouthPanel(), BorderLayout.SOUTH);
    9289
    93         getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
    94         getRootPane().getActionMap().put("escape", new CancelAction());
     90        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    9591        addWindowListener(new WindowEventHandler());
    9692    }
  • trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java

    r10627 r10791  
    2323import javax.swing.BorderFactory;
    2424import javax.swing.JCheckBox;
    25 import javax.swing.JComponent;
    2625import javax.swing.JDialog;
    2726import javax.swing.JLabel;
    2827import javax.swing.JPanel;
    2928import javax.swing.JTextField;
    30 import javax.swing.KeyStroke;
    3129
    3230import org.openstreetmap.josm.Main;
     
    4038import org.openstreetmap.josm.io.OsmApi;
    4139import org.openstreetmap.josm.tools.ImageProvider;
     40import org.openstreetmap.josm.tools.InputMapUtils;
    4241import org.openstreetmap.josm.tools.WindowGeometry;
    4342
     
    9796
    9897        addWindowListener(new WindowEventHander());
    99         getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
    100                 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
    101         getRootPane().getActionMap().put("escape", new CancelAction());
     98        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    10299
    103100        getRootPane().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r10627 r10791  
    3030import javax.swing.ImageIcon;
    3131import javax.swing.JButton;
    32 import javax.swing.JComponent;
    3332import javax.swing.JDialog;
    3433import javax.swing.JLabel;
     
    3736import javax.swing.JPanel;
    3837import javax.swing.JScrollPane;
    39 import javax.swing.KeyStroke;
    4038import javax.swing.ListCellRenderer;
    4139import javax.swing.WindowConstants;
     
    5452import org.openstreetmap.josm.tools.GBC;
    5553import org.openstreetmap.josm.tools.ImageProvider;
     54import org.openstreetmap.josm.tools.InputMapUtils;
    5655import org.openstreetmap.josm.tools.UserCancelException;
    5756import org.openstreetmap.josm.tools.Utils;
     
    299298            putValue(SHORT_DESCRIPTION, tr("Close this dialog and resume editing in JOSM"));
    300299            putValue(SMALL_ICON, ImageProvider.get("cancel"));
    301             getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
    302             .put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE");
    303             getRootPane().getActionMap().put("ESCAPE", this);
     300            InputMapUtils.addEscapeAction(getRootPane(), this);
    304301        }
    305302
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r10783 r10791  
    1212import java.awt.GridBagLayout;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.KeyEvent;
    1514import java.awt.event.WindowAdapter;
    1615import java.awt.event.WindowEvent;
     
    3130import javax.swing.Icon;
    3231import javax.swing.JButton;
    33 import javax.swing.JComponent;
    3432import javax.swing.JOptionPane;
    3533import javax.swing.JPanel;
    3634import javax.swing.JTabbedPane;
    37 import javax.swing.KeyStroke;
    3835
    3936import org.openstreetmap.josm.Main;
     
    189186        CancelAction cancelAction = new CancelAction(this);
    190187        pnl.add(new JButton(cancelAction));
    191         getRootPane().registerKeyboardAction(
    192                 cancelAction,
    193                 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
    194                 JComponent.WHEN_IN_FOCUSED_WINDOW
    195         );
     188        InputMapUtils.addEscapeAction(getRootPane(), cancelAction);
    196189        pnl.add(new JButton(new ContextSensitiveHelpAction(ht("/Dialog/Upload"))));
    197190        HelpUtil.setHelpContext(getRootPane(), ht("/Dialog/Upload"));
  • trunk/src/org/openstreetmap/josm/gui/io/UploadSelectionDialog.java

    r10680 r10791  
    2020import javax.swing.Action;
    2121import javax.swing.BorderFactory;
    22 import javax.swing.JComponent;
    2322import javax.swing.JDialog;
    2423import javax.swing.JLabel;
     
    2726import javax.swing.JScrollPane;
    2827import javax.swing.JSplitPane;
    29 import javax.swing.KeyStroke;
    3028import javax.swing.ListSelectionModel;
    3129import javax.swing.event.ListSelectionEvent;
     
    4240import org.openstreetmap.josm.gui.util.GuiHelper;
    4341import org.openstreetmap.josm.tools.ImageProvider;
     42import org.openstreetmap.josm.tools.InputMapUtils;
    4443import org.openstreetmap.josm.tools.WindowGeometry;
    4544
     
    258257            putValue(Action.NAME, tr("Cancel"));
    259258            new ImageProvider("cancel").getResource().attachImageIcon(this);
    260             getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
    261             .put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE");
    262             getRootPane().getActionMap().put("ESCAPE", this);
     259            InputMapUtils.addEscapeAction(getRootPane(), this);
    263260            setEnabled(true);
    264261        }
  • trunk/src/org/openstreetmap/josm/gui/oauth/OAuthAuthorizationWizard.java

    r10378 r10791  
    1717import java.awt.event.ItemEvent;
    1818import java.awt.event.ItemListener;
    19 import java.awt.event.KeyEvent;
    2019import java.awt.event.WindowAdapter;
    2120import java.awt.event.WindowEvent;
     
    2726import javax.swing.BorderFactory;
    2827import javax.swing.JButton;
    29 import javax.swing.JComponent;
    3028import javax.swing.JDialog;
    3129import javax.swing.JLabel;
    3230import javax.swing.JPanel;
    3331import javax.swing.JScrollPane;
    34 import javax.swing.KeyStroke;
    3532import javax.swing.UIManager;
    3633import javax.swing.event.HyperlinkEvent;
     
    5148import org.openstreetmap.josm.tools.CheckParameterUtil;
    5249import org.openstreetmap.josm.tools.ImageProvider;
     50import org.openstreetmap.josm.tools.InputMapUtils;
    5351import org.openstreetmap.josm.tools.OpenBrowser;
    5452import org.openstreetmap.josm.tools.UserCancelException;
     
    232230
    233231        addWindowListener(new WindowEventHandler());
    234         getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
    235         getRootPane().getActionMap().put("cancel", new CancelAction());
     232        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    236233
    237234        refreshAuthorisationProcedurePanel();
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r10611 r10791  
    1212import java.awt.Insets;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.KeyEvent;
    1514import java.awt.event.WindowAdapter;
    1615import java.awt.event.WindowEvent;
     
    2019import javax.swing.JButton;
    2120import javax.swing.JCheckBox;
    22 import javax.swing.JComponent;
    2321import javax.swing.JDialog;
    2422import javax.swing.JPanel;
    25 import javax.swing.KeyStroke;
    2623
    2724import org.openstreetmap.josm.actions.ExpertToggleAction;
     
    3229import org.openstreetmap.josm.tools.GBC;
    3330import org.openstreetmap.josm.tools.ImageProvider;
     31import org.openstreetmap.josm.tools.InputMapUtils;
    3432import org.openstreetmap.josm.tools.WindowGeometry;
    3533
     
    7977        addWindowListener(new WindowEventHandler());
    8078
    81         getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
    82         getRootPane().getActionMap().put("cancel", new CancelAction());
     79        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    8380        HelpUtil.setHelpContext(getRootPane(), HelpUtil.ht("/Action/Preferences"));
    8481    }
  • trunk/src/org/openstreetmap/josm/tools/InputMapUtils.java

    r10790 r10791  
    105105         c.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "spacebar");
    106106    }
     107
     108    /**
     109     * Add an action activated with ESCAPE key on a component or its children.
     110     * @param c The Swing component
     111     * @param a action activated with ESCAPE key
     112     * @see JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
     113     * @since 10791
     114     */
     115    public static void addEscapeAction(JComponent c, Action a) {
     116         c.getActionMap().put("escape", a);
     117         c.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
     118    }
    107119}
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportDialog.java

    r10720 r10791  
    99import java.awt.GridBagLayout;
    1010import java.awt.event.ActionEvent;
    11 import java.awt.event.KeyEvent;
    1211
    1312import javax.swing.AbstractAction;
     
    1615import javax.swing.JButton;
    1716import javax.swing.JCheckBox;
    18 import javax.swing.JComponent;
    1917import javax.swing.JDialog;
    2018import javax.swing.JLabel;
    2119import javax.swing.JPanel;
    22 import javax.swing.KeyStroke;
    2320import javax.swing.UIManager;
    2421
     
    2926import org.openstreetmap.josm.tools.GBC;
    3027import org.openstreetmap.josm.tools.ImageProvider;
     28import org.openstreetmap.josm.tools.InputMapUtils;
    3129
    3230/**
     
    7270        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    7371
    74         getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
    75         getRootPane().getActionMap().put("escape", new AbstractAction() {
     72        InputMapUtils.addEscapeAction(getRootPane(), new AbstractAction() {
    7673            @Override
    7774            public void actionPerformed(ActionEvent e) {
Note: See TracChangeset for help on using the changeset viewer.