Giter VIP home page Giter VIP logo

jinputvalidator's Introduction

JInputValidator

An InputVerifier for Java Swing that shows validation state to the right of the validating component.

Maven Central Javadocs Build CodeQL Quality Gate Status Maintainability Rating Coverage OpenSSF Scorecard

JInputValidator extends the verify idiom to use six states, each with its own graphical representation and tool tip text:

  • DANGER, a failure state, which defaults to a red letter X in a circle.
  • INFORMATION, a non-failure state, which defaults to a light blue letter i in a circle.
  • NONE, the default state, which does not show any icon.
  • SUCCESS, a non-failure state, which defaults to a green check mark in a circle.
  • UNKNOWN, a non-failure state, which defaults to a light blue question mark in a circle.
  • WARNING, a failure state, which defaults to a yellow-orange exclamtion mark in a triangle.

When a status is set to a "failure state" InputVerifier.verify(Component c) returns false, while for "non-failure states" that method returns true.

Screenshots

Nimbus L&F Screenshot

Using the Control

Simple example that shows a Danger indicator if an input is less than 8 characters:

// create a control
JTextField myJTextField = new JTextField();
// add a new JInputValidator as the InputVerifier
myJTextField.setInputVerifier(new JInputValidator(myJTextField, true) {
            @Override
            protected Validation getValidation(JComponent input, JInputValidatorPreferences preferences) {
                if (myJTextField.getText().length < 8) {
                    return new Validation(Validation.Type.DANGER, "Too short", preferences);
                }
                return new Validation(Validation.Type.NONE, "", preferences);
            }
        });

You can also use existing verifiers with the JInputValidator subclass VerifyingValidator:

myJTextField.setInputVerifier(new InputVerifer() {
    @Override
    public boolean verify(JComponent input) {
        return (myJTextField.getText().length >= 8);
    }
})
myJTextField.setInputVerifier(new VerifyingValidator(myJTextField,
        myJTextField.getInputVerifier(),
        new Validation(Validation.Type.DANGER, "Too short", preferences)));

Customizing

By default, JInputValidator uses PatternFly 4 colors and Font Awesome icons for the various states.

These values can be overridden by providing a Preferences object to JInputValidatorPreferences.getPreferences(Preferences preferences) containing the following keys:

  • font The path of the font to use for the visual verification. This must be a path that is loadable as a resource.
  • danger.color The color to render the danger indicator in.
  • danger.icon The Unicode characters for the danger indicator.
  • information.color The color to render the information indicator in.
  • information.icon The Unicode characters for the information indicator.
  • success.color The color to render the success indicator in.
  • sucess.icon The Unicode characters for the success indicator.
  • unknown.color The color to render the unknown indicator in.
  • unknown.icon The Unicode characters for the unknown indicator.
  • warning.color The color to render the warning indicator in.
  • warning.icon The Unicode characters for the warning indicator.

Once you have the JInputValidatorPreferences object, it can be passed to the constructor of a JInputValidator.

If your application already uses Preferences for other purposes, you can set the above keys in the package com.alexandriasoftware.swing to override the defaults as long as your application reads its preferences before creating the first JInputValidator object.

License

JInputValidator is released under the Apache 2.0 License

jinputvalidator's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar rhwood avatar step-security-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jinputvalidator's Issues

Information text not formatted

It became a problem when the string used as information about the Validation Type become more big. It takes along the lines but I want to wrap at somes part of string.
I tried HTML format string and Text Alignment, it doesn't work

And I also want to ask if there is no a library as yours but for android developers, I like it and I want to use it for android app

Use CompoundBorder

The validate currently replaces the component’s border, drawing the validation icon as part of the inherited border. It should use a CompoundBorder so the component’s border is untouched, and the validation only manipulates its own order.

Preferences should inherit from default preferences

Currently the JInputValidatorPreferences do not inherit from the default instance. They should, so that overriding preferences

  • do not need to specify all preferences
  • do not get the default default preferences instead of the application default preferences

Test Javadocs not created

Due to some change in a dependency or maven itself, the generation of test javadocs is failing. The cause needs to be tracked down and fixes monitored so this can be re-enabled.

Helper for adding error message to existing HTML tool tip text

Need to add helpers that would allow a JInputValidator to provide a getToolTipText() that strips off <html> and </html> tags for inclusion in an expanded error message in a Validation. A helper that prepends or appends the error message to an existing tool tip would also help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.