Search in sources :

Example 51 with TextInput

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);
                        }
                    }
                }
            }
        }
    });
}
Also used : TextInputContentListener(org.apache.pivot.wtk.TextInputContentListener) TextInput(org.apache.pivot.wtk.TextInput)

Aggregations

TextInput (org.apache.pivot.wtk.TextInput)51 Component (org.apache.pivot.wtk.Component)21 BoxPane (org.apache.pivot.wtk.BoxPane)15 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)11 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)9 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)8 Label (org.apache.pivot.wtk.Label)8 Point (org.apache.pivot.wtk.Point)8 IntValidator (org.apache.pivot.wtk.validation.IntValidator)8 FlowPane (org.apache.pivot.wtk.FlowPane)7 ArrayList (org.apache.pivot.collections.ArrayList)6 IOException (java.io.IOException)5 Button (org.apache.pivot.wtk.Button)5 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5 Keyboard (org.apache.pivot.wtk.Keyboard)5 Mouse (org.apache.pivot.wtk.Mouse)5 Sequence (org.apache.pivot.collections.Sequence)4 SerializationException (org.apache.pivot.serialization.SerializationException)4 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)4