From 5adc2cd57a00e238e1d5c10e1678af825fc9d52c Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Fri, 26 Jul 2013 20:05:46 +0000 Subject: [PATCH] keyboard: set keymap on content pane, not root pane. This way, when the menu bar is active, the normal menu key sequences (such as ESCAPE) will still work normally. One quirk is the following- * MINUS will still zoom out while the menu is active, but PLUS will not work. git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@778 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/gui/MainWindow.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/micropolisj/gui/MainWindow.java b/src/micropolisj/gui/MainWindow.java index 2ca33c0..848ca8f 100644 --- a/src/micropolisj/gui/MainWindow.java +++ b/src/micropolisj/gui/MainWindow.java @@ -184,24 +184,25 @@ public class MainWindow extends JFrame setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); setLocationRelativeTo(null); - InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + InputMap inputMap = ((JComponent)getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke("ADD"), "zoomIn"); inputMap.put(KeyStroke.getKeyStroke("shift EQUALS"), "zoomIn"); inputMap.put(KeyStroke.getKeyStroke("SUBTRACT"), "zoomOut"); inputMap.put(KeyStroke.getKeyStroke("MINUS"), "zoomOut"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); - getRootPane().getActionMap().put("zoomIn", new AbstractAction() { + ActionMap actionMap = ((JComponent)getContentPane()).getActionMap(); + actionMap.put("zoomIn", new AbstractAction() { public void actionPerformed(ActionEvent evt) { doZoom(1); } }); - getRootPane().getActionMap().put("zoomOut", new AbstractAction() { + actionMap.put("zoomOut", new AbstractAction() { public void actionPerformed(ActionEvent evt) { doZoom(-1); } }); - getRootPane().getActionMap().put("escape", new AbstractAction() { + actionMap.put("escape", new AbstractAction() { public void actionPerformed(ActionEvent evt) { onEscapePressed(); }