@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = super.keyPressed(component, keyCode, keyLocation);
if (!consumed) {
Accordion accordion = (Accordion)getComponent();
Accordion.PanelSequence panels = accordion.getPanels();
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(commandModifier)) {
int selectedIndex = -1;
switch (keyCode) {
case Keyboard.KeyCode.KEYPAD_1:
case Keyboard.KeyCode.N1: {
selectedIndex = 0;
break;
}
case Keyboard.KeyCode.KEYPAD_2:
case Keyboard.KeyCode.N2: {
selectedIndex = 1;
break;
}
case Keyboard.KeyCode.KEYPAD_3:
case Keyboard.KeyCode.N3: {
selectedIndex = 2;
break;
}
case Keyboard.KeyCode.KEYPAD_4:
case Keyboard.KeyCode.N4: {
selectedIndex = 3;
break;
}
case Keyboard.KeyCode.KEYPAD_5:
case Keyboard.KeyCode.N5: {
selectedIndex = 4;
break;
}
case Keyboard.KeyCode.KEYPAD_6:
case Keyboard.KeyCode.N6: {
selectedIndex = 5;
break;
}
case Keyboard.KeyCode.KEYPAD_7:
case Keyboard.KeyCode.N7: {
selectedIndex = 6;
break;
}
case Keyboard.KeyCode.KEYPAD_8:
case Keyboard.KeyCode.N8: {
selectedIndex = 7;
break;
}
case Keyboard.KeyCode.KEYPAD_9:
case Keyboard.KeyCode.N9: {
selectedIndex = 8;
break;
}
}
if (selectedIndex >= 0
&& selectedIndex < panels.getLength()
&& panels.get(selectedIndex).isEnabled()) {
accordion.setSelectedIndex(selectedIndex);
consumed = true;
}
} else if (Keyboard.isPressed(Keyboard.Modifier.ALT)) {
int n = panels.getLength();
int selectedIndex = accordion.getSelectedIndex();
switch (keyCode) {
case Keyboard.KeyCode.UP: {
do {
selectedIndex--;
} while (selectedIndex >= 0
&& !panels.get(selectedIndex).isEnabled());
break;
}
case Keyboard.KeyCode.DOWN: {
do {
selectedIndex++;
} while (selectedIndex < n
&& !panels.get(selectedIndex).isEnabled());
break;
}
}
if (selectedIndex >= 0
&& selectedIndex < n
&& panels.get(selectedIndex).isEnabled()) {
accordion.setSelectedIndex(selectedIndex);
consumed = true;
}
}
}