@Override public void actionPerformed(ActionEvent e) { final NavBarKeyboardCommand cmd = NavBarKeyboardCommand.fromString(e.getActionCommand()); if (cmd != null) { switch (cmd) { case LEFT: myPanel.moveLeft(); break; case RIGHT: myPanel.moveRight(); break; case HOME: myPanel.moveHome(); break; case END: myPanel.moveEnd(); break; case DOWN: myPanel.moveDown(); break; case UP: myPanel.moveDown(); break; case ENTER: myPanel.enter(); break; case ESCAPE: myPanel.escape(); break; case NAVIGATE: myPanel.navigate(); break; } } }
NavBarListener(NavBarPanel panel) { myPanel = panel; for (NavBarKeyboardCommand command : NavBarKeyboardCommand.values()) { registerKey(command); } myPanel.addFocusListener(this); }
private void registerKey(NavBarKeyboardCommand cmd) { myPanel.registerKeyboardAction(this, cmd.name(), cmd.getKeyStroke(), JComponent.WHEN_FOCUSED); }