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
This commit is contained in:
parent
9e3e681a81
commit
5adc2cd57a
1 changed files with 5 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Reference in a new issue