StocksMonitor 1.5.0

hirondelle.stocks.portfolio
Class RegexInputVerifier

Object
  extended by InputVerifier
      extended by RegexInputVerifier

final class RegexInputVerifier
extends InputVerifier

Verifies user input into a JTextComponent versus a regular expression.

This class is likely useful for a wide number of simple input needs. See the Pattern class for details regarding regular expressions.

The main(java.lang.String...) method is provided as a developer tool for testing regular expressions versus user input, but the principal use of this class is to be passed to JComponent.setInputVerifier(javax.swing.InputVerifier).

Upon detection of invalid input, this class takes the following actions :

The user of this class is encouraged to always place conditions on data entry in the tooltip for the corresponding field.


Nested Class Summary
(package private) static class RegexInputVerifier.UseToolTip
          Enumeration compels the caller to use a style which reads clearly.
 
Field Summary
(package private) static String ERROR_MESSAGE_START
          The text which begins all error messages.
(package private) static RegexInputVerifier FLOATING_POINT
          Convenience object for input of decimals numbers, eg -23.23321, 100.25.
(package private) static RegexInputVerifier INTEGER
          Convenience object for input of integers: ...-2,-1,0,1,2...
(package private) static RegexInputVerifier MONEY
          Convenience object for input of money values, eg -23, 100.25.
(package private) static RegexInputVerifier NON_NEGATIVE_FLOATING_POINT
          Convenience object for input of non-negative decimals numbers, eg 23.23321, 100.25.
(package private) static RegexInputVerifier NON_NEGATIVE_INTEGER
          Convenience object for input of these integers: 0,1,2...
(package private) static RegexInputVerifier NON_NEGATIVE_MONEY
          Convenience object for input of non-negative money values, eg 23, 100.25.
(package private) static RegexInputVerifier TEXT
          Convenience object for input of short amounts of text.
 
Constructor Summary
RegexInputVerifier(Pattern aPattern, RegexInputVerifier.UseToolTip aUseToolTip)
          Constructor.
 
Method Summary
static void main(String... aArgs)
          Developer test harness for verifying a regular expression, using a simple graphical interface and a RegexInputVerifier.
 boolean shouldYieldFocus(JComponent aComponent)
          Always returns true, in this implementation, such that focus can always transfer to another component whenever the validation fails.
 boolean verify(JComponent aComponent)
          Return true only if the untrimmed user input matches the regular expression provided to the constructor.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_MESSAGE_START

static final String ERROR_MESSAGE_START
The text which begins all error messages. The caller may examine their text fields for the presence of ERROR_MESSAGE_START, before processing input.

See Also:
Constant Field Values

INTEGER

static final RegexInputVerifier INTEGER
Convenience object for input of integers: ...-2,-1,0,1,2...

From 1 to 9 digits, possibly preceded by a minus sign. Corresponds approximately to the spec of Integer.parseInt. The limit on the number of digits is related to size of Integer.MAX_VALUE and Integer.MIN_VALUE.


NON_NEGATIVE_INTEGER

static final RegexInputVerifier NON_NEGATIVE_INTEGER
Convenience object for input of these integers: 0,1,2...

As in INTEGER, but with no leading minus sign.


TEXT

static final RegexInputVerifier TEXT
Convenience object for input of short amounts of text.

Text contains from 1 to 75 non-whitespace characters.


FLOATING_POINT

static final RegexInputVerifier FLOATING_POINT
Convenience object for input of decimals numbers, eg -23.23321, 100.25.

Possible leading minus sign, 1 to 10 digits before the decimal, and 1 to 10 digits after the decimal.


NON_NEGATIVE_FLOATING_POINT

static final RegexInputVerifier NON_NEGATIVE_FLOATING_POINT
Convenience object for input of non-negative decimals numbers, eg 23.23321, 100.25.

As in FLOATING_POINT, but no leading minus sign.


MONEY

static final RegexInputVerifier MONEY
Convenience object for input of money values, eg -23, 100.25.

Possible leading minus sign, from 1 to 15 leading digits, and optionally a decimal place and two decimals.


NON_NEGATIVE_MONEY

static final RegexInputVerifier NON_NEGATIVE_MONEY
Convenience object for input of non-negative money values, eg 23, 100.25.

As in MONEY, except no leading minus sign

Constructor Detail

RegexInputVerifier

RegexInputVerifier(Pattern aPattern,
                   RegexInputVerifier.UseToolTip aUseToolTip)
Constructor.

Parameters:
aPattern - regular expression against which all user input will be verified; aPattern.pattern satisfies Util.textHasContent(java.lang.String).
aUseToolTip - indicates if the tooltip text should be appended to error messages displayed to the user.
Method Detail

shouldYieldFocus

public boolean shouldYieldFocus(JComponent aComponent)
Always returns true, in this implementation, such that focus can always transfer to another component whenever the validation fails.

If super.shouldYieldFocus returns false, then notify the user of an error.

Overrides:
shouldYieldFocus in class InputVerifier
Parameters:
aComponent - is a JTextComponent.

verify

public boolean verify(JComponent aComponent)
Return true only if the untrimmed user input matches the regular expression provided to the constructor.

Specified by:
verify in class InputVerifier
Parameters:
aComponent - must be a JTextComponent.

main

public static void main(String... aArgs)
Developer test harness for verifying a regular expression, using a simple graphical interface and a RegexInputVerifier.

Use of the GUI is straightforward :

(For running this test harness, RegexInputVerifier needs to be a public class; after testing is finished, it is probably a good idea to change the scope to package-private, since the services of this class are used only by the user interface layer.)


StocksMonitor 1.5.0

Copyright Hirondelle Systems - License - Generated 2008Jul12.10.53