public int selectionForKey(char aKey,
ComboBoxModel aModel) {
if (lastTime == 0L) {
prefix = "";
typedString = "";
}
boolean startingFromSelection = true;
int startIndex = comboBox.getSelectedIndex();
if (time - lastTime < timeFactor) {
typedString += aKey;
if((prefix.length() == 1) && (aKey == prefix.charAt(0))) {
// Subsequent same key presses move the keyboard focus to the next
// object that starts with the same letter.
startIndex++;
} else {
prefix = typedString;
}
} else {
startIndex++;
typedString = "" + aKey;
prefix = typedString;
}
lastTime = time;
if (startIndex < 0 || startIndex >= aModel.getSize()) {
startingFromSelection = false;
startIndex = 0;
}
int index = listBox.getNextMatch(prefix, startIndex,
Position.Bias.Forward);
if (index < 0 && startingFromSelection) { // wrap
index = listBox.getNextMatch(prefix, 0,
Position.Bias.Forward);
}
return index;
}
|