|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.wotonomy.ui.swing.util.TextInputRangeChecker
public class TextInputRangeChecker
This class will actively check the inputs of 2 numbers in seperate text components. The number in the text components represent an upper and lower bound to some range. This class checks to make sure the user inputs values in the lower bound text field that are less than the value of the upper bound and vice versa for the upper bound text field. This class will also check to make sure the bounds fall within a given range if specified. The checks are automatically performed when the focus is lost on either component. If the inputs are correct then no event occurs. If the inputs are not correct, then a dialog message is displayed stating the reason why the bounds are invalid, and the original correct value is restored into the text components.
Field Summary | |
---|---|
protected static int |
LOWER
|
protected static int |
NONE
|
protected static int |
UPPER
|
Constructor Summary | |
---|---|
TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent,
javax.swing.text.JTextComponent anUpperTextComponent)
Constructor with some of the settable parameters. |
|
TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent,
javax.swing.text.JTextComponent anUpperTextComponent,
double aMaxRange)
Constructor with some of the settable parameters. |
|
TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent,
javax.swing.text.JTextComponent anUpperTextComponent,
java.lang.String lowerTextName,
java.lang.String upperTextName)
Constructor with some of the settable parameters. |
|
TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent,
javax.swing.text.JTextComponent anUpperTextComponent,
java.lang.String lowerTextName,
java.lang.String upperTextName,
double aMaxRange)
Constructor with all the settable parameters. |
Method Summary | |
---|---|
void |
addFocusListener(java.awt.event.FocusListener aListener)
Adds the listener to the lists of focus listener maintened by this object. |
protected void |
displayMessage(java.lang.String message,
java.awt.Component parent)
Creates a JOptionPane to display the reason why the bounds failed validation. |
protected void |
fireFocusEvent(java.awt.event.FocusEvent e)
Fires a focus lost event if the validation was successfull. |
void |
focusGained(java.awt.event.FocusEvent e)
Method used to be notified when one of the text components has gained its focus. |
void |
focusLost(java.awt.event.FocusEvent e)
Method used to be notified when one of the text components has lost its focus. |
double |
getLastValidatedLowerNumber()
Returns the last valid value of the lower bound. |
double |
getLastValidatedUpperNumber()
Returns the last valid value of the upper bound. |
protected double |
getNumber(javax.swing.text.JTextComponent aComponent)
Gets the number represented in the text component. |
boolean |
performCheck()
Allows the caller to perform the validation of the bounds programatically. |
protected boolean |
validate(java.lang.Object aComponent)
Validates the bounds inputed by the user. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int NONE
protected static final int LOWER
protected static final int UPPER
Constructor Detail |
---|
public TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent, javax.swing.text.JTextComponent anUpperTextComponent)
aLowerTextComponent
- A text component for the lower bound.anUpperTextComponent
- A text component for the upper bound.public TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent, javax.swing.text.JTextComponent anUpperTextComponent, java.lang.String lowerTextName, java.lang.String upperTextName)
aLowerTextComponent
- A text component for the lower bound.anUpperTextComponent
- A text component for the upper bound.lowerTextName
- The name of the lower bound, eg - start year.upperTextName
- The name of the upper bound, eg - end year.
is used.public TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent, javax.swing.text.JTextComponent anUpperTextComponent, double aMaxRange)
aLowerTextComponent
- A text component for the lower bound.anUpperTextComponent
- A text component for the upper bound.aMaxRange
- The range the bounds muist fall between, if 0 then no range
is used.public TextInputRangeChecker(javax.swing.text.JTextComponent aLowerTextComponent, javax.swing.text.JTextComponent anUpperTextComponent, java.lang.String lowerTextName, java.lang.String upperTextName, double aMaxRange)
aLowerTextComponent
- A text component for the lower bound.anUpperTextComponent
- A text component for the upper bound.lowerTextName
- The name of the lower bound, eg - start year.upperTextName
- The name of the upper bound, eg - end year.aMaxRange
- The range the bounds muist fall between, if 0 then no range
is used.Method Detail |
---|
public boolean performCheck()
public void addFocusListener(java.awt.event.FocusListener aListener)
aListener
- A Focus Listener to receive Focus Events.public double getLastValidatedLowerNumber()
public double getLastValidatedUpperNumber()
public void focusGained(java.awt.event.FocusEvent e)
focusGained
in interface java.awt.event.FocusListener
public void focusLost(java.awt.event.FocusEvent e)
focusLost
in interface java.awt.event.FocusListener
protected void fireFocusEvent(java.awt.event.FocusEvent e)
protected boolean validate(java.lang.Object aComponent)
aComponent
- The component to use to display a dialog window, if neccessray.
If null, then the parent window of the text componets will be used.
protected void displayMessage(java.lang.String message, java.awt.Component parent)
protected double getNumber(javax.swing.text.JTextComponent aComponent)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |