if ( ! _visible)
return; // the popup has already been dismissed.
int key = e.getKeyCode();
Toolkit term = Toolkit.getDefaultToolkit();
if (key == KeyEvent.VK_UP) {
super.previousFocus();
}
else if (key == KeyEvent.VK_DOWN) {
super.nextFocus();
}
else if (key == KeyEvent.VK_LEFT) {
/* Pressing the LEFT cursor key has the effect of cancelling
* the selected menu and invoking the next menu on the left.
*/
_leftWasPressed = true;
hide();
}
else if (key == KeyEvent.VK_RIGHT) {
/* Pressing the RIGHT cursor key has the effect of cancelling
* the selected menu and invoking the next menu on the right.
*/
_rightWasPressed = true;
hide();
}
else if (key == KeyEvent.VK_ENTER) {
/* Pressing ENTER sends an ActionEvent. The source of the
* event is the menu item, not the menu; this means that the
* client program has to add an ActionListener to each menu
* item. This is inconvenient, but it's the way that the Java
* Swing menus do it.
*/
JMenuItem item = (JMenuItem) super.getCurrentFocus();
_activate(item);
e.consume();
}
else if (key == KeyEvent.VK_BACK_SPACE || key == 0x1b) {
// Backspace or ESC was pressed
_wasCancelled = true;
hide();
}
else {
/* Check if one of the mnemonic keys was pressed.
* Note that the user can press a lowercase or an uppercase
* key.
*/
char keyLower = Character.toLowerCase((char) key);
for (int i=0; i < super._components.size(); i++) {
JMenuItem item = getMenuItem(i);
if (item != null) {
if (item.getMnemonic() == -1)
continue; // this item doesn't have a mnemonic
char mnemonicLower =
Character.toLowerCase((char) item.getMnemonic());
if (keyLower == mnemonicLower) {
_activate(item);
return;
}
}
}
term.beep();
}
} // end of processKeyEvent()