Example usage for javax.swing InputVerifier verify

List of usage examples for javax.swing InputVerifier verify

Introduction

In this page you can find the example usage for javax.swing InputVerifier verify.

Prototype

public abstract boolean verify(JComponent input);

Source Link

Document

Checks whether the JComponent's input is valid.

Usage

From source file:com.anrisoftware.prefdialog.miscswing.validatingfields.ValidatingTextField.java

/**
 * Verifies the field.//from  w w w.  j av  a2s .co m
 *
 * @param verifier
 *            the {@link InputVerifier} that verifiers the input.
 *
 * @param input
 *            the {@link JTextField}.
 *
 * @return {@code true} if the input is valid and the focus can be yield.
 */
protected boolean verifyField(InputVerifier verifier, JTextField input) {
    return verifier.verify(input);
}

From source file:com.anrisoftware.prefdialog.miscswing.validatingfields.ValidatingFormattedTextField.java

/**
 * Verifies the field./* w  ww .j  av a 2  s.  c  o m*/
 *
 * @param verifier
 *            the {@link InputVerifier} that verifiers the input.
 *
 * @param input
 *            the {@link JTextFormattedField}.
 *
 * @return {@code true} if the input is valid and the focus can be yield.
 */
protected boolean verifyField(InputVerifier verifier, JFormattedTextField input) {
    try {
        input.commitEdit();
        return verifier.verify(input);
    } catch (ParseException e) {
        return false;
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JPasswordField createPasswordField(DocumentListener... docListeners) {
    final JPasswordField field = new JPasswordField();
    final Border oldBorder = field.getBorder();
    if (docListeners != null) {
        for (DocumentListener docListener : docListeners) {
            field.getDocument().addDocumentListener(docListener);
            field.getDocument().putProperty("owner", field);
        }/*from  ww  w.  jav  a2  s. c  om*/
    }
    final InputVerifier verifier = new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            final JPasswordField field = (JPasswordField) input;
            char[] txt = field.getPassword();
            if (txt.length == 0) {
                // Run in EDT to avoid deadlock in case this gets called
                // from not swing thread
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        field.setToolTipText(UILabels.STL50084_CANT_BE_BLANK.getDescription());
                        input.setBackground(UIConstants.INTEL_LIGHT_RED);
                        input.setBorder(BorderFactory.createLineBorder(UIConstants.INTEL_RED, 2));
                        // show tooltip immediately
                        ToolTipManager.sharedInstance()
                                .mouseMoved(new MouseEvent(field, 0, 0, 0, 0, 0, 0, false));
                    }
                });
                return false;
            } else {
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        input.setBackground(UIConstants.INTEL_WHITE);
                        input.setBorder(oldBorder);
                    }
                });
                return true;
            }
        }

    };

    DocumentListener dynamicChecker = new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

    };
    field.getDocument().addDocumentListener(dynamicChecker);

    // Add the input verifier
    field.setInputVerifier(verifier);

    return field;
}

From source file:org.lisapark.octopus.swing.BaseFormattedTextField.java

/**
 * Returns true if we should try and commit the text for the formatted text field.
 * This method will see if there is an <code>InputVerifier</code> to ensure that
 * the input is verified before trying to commit. This is needed because what is allowed
 * by the formatted field may not be always allowed by the input verifier
 *
 * @return true if we can try and commit
 *//* w w w . j a  va2 s  .c o m*/
protected boolean canCommitEdit() {
    boolean canCommit;

    InputVerifier inputVerifier = getInputVerifier();

    // if there is no verifier, or the verify says it is valid
    canCommit = (inputVerifier == null) || (inputVerifier.verify(this));

    return canCommit;
}