Package org.apache.pivot.wtk.validation

Examples of org.apache.pivot.wtk.validation.Validator


     *
     * @param validator
     * The validator to use, or <tt>null</tt> to use no validator.
     */
    public void setValidator(Validator validator) {
        Validator previousValidator = this.validator;

        if (validator != previousValidator) {
            this.validator = validator;

            // Store previous text valid flag
View Full Code Here


            if (textNode != null) {
                if (selectionLength == 0
                    && textNode.getCharacterCount() == textInput.getMaximumLength()) {
                    Toolkit.getDefaultToolkit().beep();
                } else {
                    Validator validator = textInput.getValidator();
                    boolean strictValidation = textInput.isStrictValidation();

                    if (validator != null
                        && strictValidation) {
                          String text = textInput.getText();
                          int selectionStart = textInput.getSelectionStart();

                          StringBuilder buf = new StringBuilder(text.substring(0, selectionStart));
                          buf.append(character);
                          buf.append(text.substring(selectionStart + selectionLength));

                        if (validator.isValid(buf.toString())) {
                            textInput.insert(character);
                        } else {
                            Toolkit.getDefaultToolkit().beep();
                        }
                    } else {
View Full Code Here

            Keyboard.Modifier commandModifier = Platform.getCommandModifier();
            if (keyCode == Keyboard.KeyCode.DELETE
                || keyCode == Keyboard.KeyCode.BACKSPACE) {
                boolean backspace = (keyCode == Keyboard.KeyCode.DELETE ? false : true);

                Validator validator = textInput.getValidator();
                boolean strictValidation = textInput.isStrictValidation();

                if (validator != null
                    && strictValidation) {
                    StringBuilder buf = new StringBuilder(textNode.getText());
                    int index = textInput.getSelectionStart();
                    int count = textInput.getSelectionLength();

                    if (count > 0) {
                        buf.delete(index, index + count);
                    } else {
                        if (backspace) {
                            index--;
                        }

                        if (index >= 0
                            && index < textNode.getCharacterCount()) {
                            buf.deleteCharAt(index);
                        }
                    }

                    if (validator.isValid(buf.toString())) {
                        textInput.delete(backspace);
                    } else {
                        Toolkit.getDefaultToolkit().beep();
                    }
                } else {
View Full Code Here

     *
     * @param validator
     * The validator to use, or <tt>null</tt> to use no validator.
     */
    public void setValidator(Validator validator) {
        Validator previousValidator = this.validator;

        if (validator != previousValidator) {
            this.validator = validator;
            textInputListeners.textValidatorChanged(this, previousValidator);
            validateText();
View Full Code Here

        textinputDateRegex.setValidator(new RegexTextValidator(
            "(19|20)\\d\\d[- /.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])"));

        // creating a custom model that only accepts "true" or "false"
        textinputCustomBoolean.setText("true");
        textinputCustomBoolean.setValidator(new Validator() {
            @Override
            public boolean isValid(String s) {
                return "true".equals(s) || "false".equals(s);
            }
        });
View Full Code Here

     *
     * @param validator
     * The validator to use, or <tt>null</tt> to use no validator.
     */
    public void setValidator(Validator validator) {
        Validator previousValidator = this.validator;

        if (validator != previousValidator) {
            this.validator = validator;

            // Store previous text valid flag
View Full Code Here

    @Override
    public Vote previewInsertText(TextInput textInput, CharSequence text, int index) {
        Vote vote = Vote.APPROVE;

        if (textInput.isStrictValidation()) {
            Validator validator = textInput.getValidator();
            if (validator != null) {
                StringBuilder textBuilder = new StringBuilder();
                textBuilder.append(textInput.getText(0, index));
                textBuilder.append(text);
                textBuilder.append(textInput.getText(index, textInput.getCharacterCount()));

                if (!validator.isValid(textBuilder.toString())) {
                    vote = Vote.DENY;
                    Toolkit.getDefaultToolkit().beep();
                }
            }
        }
View Full Code Here

    @Override
    public Vote previewRemoveText(TextInput textInput, int index, int count) {
        Vote vote = Vote.APPROVE;

        if (textInput.isStrictValidation()) {
            Validator validator = textInput.getValidator();
            if (validator != null) {
                StringBuilder textBuilder = new StringBuilder();
                textBuilder.append(textInput.getText(0, index));
                textBuilder.append(textInput.getText(index + count, textInput.getCharacterCount()));

                if (!validator.isValid(textBuilder.toString())) {
                    vote = Vote.DENY;
                    Toolkit.getDefaultToolkit().beep();
                }
            }
        }
View Full Code Here

     *
     * @param validator
     * The validator to use, or <tt>null</tt> to use no validator.
     */
    public void setValidator(Validator validator) {
        Validator previousValidator = this.validator;

        if (validator != previousValidator) {
            this.validator = validator;
            textInputListeners.textValidatorChanged(this, previousValidator);
            validateText();
View Full Code Here

        textinputDateRegex.setValidator(new RegexTextValidator(
            "(19|20)\\d\\d[- /.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])"));

        // creating a custom model that only accepts "true" or "false"
        textinputCustomBoolean.setText("true");
        textinputCustomBoolean.setValidator(new Validator() {
            @Override
            public boolean isValid(String s) {
                return "true".equals(s) || "false".equals(s);
            }
        });
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.validation.Validator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.