@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = super.keyPressed(component, keyCode, keyLocation);
ListView listView = (ListView)getComponent();
switch (keyCode) {
case Keyboard.KeyCode.UP: {
int index = listView.getFirstSelectedIndex();
do {
index--;
} while (index >= 0
&& listView.isItemDisabled(index));
if (index >= 0) {
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
&& listView.getSelectMode() == ListView.SelectMode.MULTI) {
listView.addSelectedIndex(index);
} else {
listView.setSelectedIndex(index);
}
listView.scrollAreaToVisible(getItemBounds(index));
}
consumed = true;
break;
}
case Keyboard.KeyCode.DOWN: {
int index = listView.getLastSelectedIndex();
int count = listView.getListData().getLength();
do {
index++;
} while (index < count
&& listView.isItemDisabled(index));
if (index < count) {
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
&& listView.getSelectMode() == ListView.SelectMode.MULTI) {
listView.addSelectedIndex(index);
} else {
listView.setSelectedIndex(index);
}
listView.scrollAreaToVisible(getItemBounds(index));
}
consumed = true;
break;
}
}
// Clear the highlight
if (highlightedIndex != -1
&& listView.getSelectMode() != ListView.SelectMode.NONE
&& showHighlight) {
repaintComponent(getItemBounds(highlightedIndex));
}
highlightedIndex = -1;