|
StocksMonitor 1.5.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
ObjectInputVerifier
RegexInputVerifier
final class RegexInputVerifier
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 |
|---|
static final String ERROR_MESSAGE_START
static final RegexInputVerifier INTEGER
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.
static final RegexInputVerifier NON_NEGATIVE_INTEGER
As in INTEGER, but with no leading minus sign.
static final RegexInputVerifier TEXT
Text contains from 1 to 75 non-whitespace characters.
static final RegexInputVerifier FLOATING_POINT
Possible leading minus sign, 1 to 10 digits before the decimal, and 1 to 10 digits after the decimal.
static final RegexInputVerifier NON_NEGATIVE_FLOATING_POINT
As in FLOATING_POINT, but no leading minus sign.
static final RegexInputVerifier MONEY
Possible leading minus sign, from 1 to 15 leading digits, and optionally a decimal place and two decimals.
static final RegexInputVerifier NON_NEGATIVE_MONEY
As in MONEY, except no leading minus sign
| Constructor Detail |
|---|
RegexInputVerifier(Pattern aPattern,
RegexInputVerifier.UseToolTip aUseToolTip)
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 |
|---|
public boolean shouldYieldFocus(JComponent aComponent)
If super.shouldYieldFocus returns false, then notify the user of an error.
shouldYieldFocus in class InputVerifieraComponent - is a JTextComponent.public boolean verify(JComponent aComponent)
verify in class InputVerifieraComponent - must be a JTextComponent.public static void main(String... aArgs)
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 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||