@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = false;
Spinner spinner = (Spinner)TerraSpinnerSkin.this.getComponent();
boolean circular = spinner.isCircular();
int count = spinner.getSpinnerData().getLength();
int selectedIndex = spinner.getSelectedIndex();
int newSelectedIndex = selectedIndex;
if (keyCode == Keyboard.KeyCode.UP) {
if (selectedIndex < count - 1) {
newSelectedIndex++;
} else if (circular) {
newSelectedIndex = 0;
}
} else if (keyCode == Keyboard.KeyCode.DOWN) {
if (selectedIndex > 0) {
newSelectedIndex--;
} else if (circular) {
newSelectedIndex = count - 1;
}
} else {
consumed = super.keyPressed(component, keyCode, keyLocation);
}
if (newSelectedIndex != selectedIndex) {
spinner.setSelectedIndex(newSelectedIndex);
consumed = true;
}
return consumed;
}