use of org.apache.pivot.wtk.TextInput in project pivot by apache.
the class TextInputs method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
stateTextInput = (TextInput) namespace.get("stateTextInput");
stateTextInput.getTextInputContentListeners().add(new TextInputContentListener() {
@Override
public void textInserted(final TextInput textInput, int index, int count) {
String text = textInput.getText();
int i = ArrayList.binarySearch(states, text, states.getComparator());
if (i < 0) {
i = -(i + 1);
int n = states.getLength();
if (i < n) {
text = text.toLowerCase();
final String state = states.get(i);
if (state.toLowerCase().startsWith(text)) {
String nextState = (i == n - 1) ? null : states.get(i + 1);
if (nextState == null || !nextState.toLowerCase().startsWith(text)) {
textInput.setText(state);
int selectionStart = text.length();
int selectionLength = state.length() - selectionStart;
textInput.setSelection(selectionStart, selectionLength);
}
}
}
}
}
});
}
Aggregations