JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.field.validate
Class AbstractValidator

java.lang.Object
  |
  +--com.klg.jclass.field.validate.AbstractValidator
All Implemented Interfaces:
JCValidator, Serializable
Direct Known Subclasses:
JCNumberValidator, JCStringValidator

public abstract class AbstractValidator
extends Object
implements JCValidator, Serializable

A base class for all validators.

See Also:
Serialized Form

Field Summary
protected  boolean abstractInitializing
           
protected  boolean allow_null
           
static int AS_IS
          Leaves characters as entered in the CasePolicy property.
protected  int case_policy
           
protected  Object increment
           
protected  String invalid_chars
           
protected  ResourceBundle li
           
protected  Locale locale
           
static int LOWERCASE
          Converts characters to lower case in the CasePolicy property.
protected  boolean match_picklist
           
protected  Object max
           
protected  Object min
           
static int NOT_FOUND
           
protected  ListModel picklist
           
static int SPIN_FIELD
          Allows spinning up and down between the maximum and minimum values.
protected  int spin_policy
           
static int SPIN_SUBFIELD
          Allows context sensitive spinning if it is allowed.
static int SPIN_WRAP
          Like spin field but allows continuous spinning.
protected  Class[] supportedClasses
           
static int UPPERCASE
          Converts characters to upper case in the CasePolicy property.
protected  String valid_chars
           
 
Fields inherited from interface com.klg.jclass.field.validate.JCValidator
DOWN, UP
 
Constructor Summary
AbstractValidator()
           
 
Method Summary
protected abstract  Object addIncrement(Object current)
           
 int calculateSpinability(Object current)
          Determines if the value in the field can be spun further.
 void changeText(com.klg.jclass.field.validate.TextEvent e)
          Changes the specified text from the start_position to the end_position by inserting/replacing it by rge specified new_text.
protected  StringBuffer checkValidInvalid(String text)
          Given a partially complete string, this routine looks through the list and constructs a String that matches as much as possible.
 boolean compareValues(Object v1, Object v2)
          Since we cannot always rely on an objects equals() method we must define our own compare method.
 char convertCase(char c)
          Returns the value of the character as filtered by the casePolicy of the validator.
abstract  Object convertFromSupported(Object from, Class class_type)
          Converts the supported type to the type supported by the validator.
abstract  Object convertToSupported(Object obj)
          Converts the specified type (if possible) to the type supported by the validator.
abstract  Object copyValue(Object value)
          Since the clone() method is protected in the Object class we cannot actually clone a generic object without knowing what it is; therefore the validator must provide this routine to do the copying for JCField.
 com.klg.jclass.field.validate.PopupFieldEditor createPopupComponent()
          Returns the popup component.
abstract  String format(Object obj)
          Generates a String representation of the given object.
abstract  String formatForEdit(Object obj)
          Generates a String representation of the given object for use in edit mode.
 boolean getAllowNull()
          Returns whether or not null is a valid value.
 int getCasePolicy()
          Returns the value of the casePolicy property.
abstract  int getFirstValidCursorPosition()
          Reports the first valid cursor position.
 String getInvalidChars()
          Returns a String of characters that are not allowed to be typed in the current field.
protected  String getItem(int i)
          Gets a String representation of the object at the specified position in to pick list.
 Locale getLocale()
          Returns the Locale used for formatting and parsing.
 boolean getMatchPickList()
          Returns the value of matchPickList.
 Object getMax()
          Returns the maximum possible value of the object checked by the validator.
 Object getMin()
          Returns the minimum possible value of the object checked by the validator.
protected  Object getNextValue(int current_index)
          Returns the next value in the pickList or "null" if we are already at the end of the list.
 ListModel getPickList()
          Gets the pick list.
 int getPickListIndex(Object obj)
          Checks to see if a given object is in the pick list.
protected  Object getPreviousValue(int current_index)
          Returns the previous value in the pickList or "null" if we are already at the beginning of the list.
 int getSpinPolicy()
          Returns the spin policy.
 String getValidChars()
          Returns a String of characters that are allowed to be typed in the current field.
abstract  boolean hasEditFormat()
          Returns true if the validator has a different edit format.
 void inferSubField(int s, int e)
          Infer the sub field we need to work on from the current selected region If there is no selected region then the selected region is equal to the cursor position we don't ever need to look at the cursor position This particular implementation is a stub meant to be overridden if a particular validator supports subfields
protected abstract  boolean inRange(Object value)
           
 boolean isClassSupported(Class c)
          Returns true if the class passed in is the native type that the validator is designed to support.
 boolean isValidChar(char c)
          Determines whether the character specified is allowed in the field.
abstract  Object parse(Class c, String text)
          Validates the current display string and returns a new Object if successful, or "null" if validation fails.
 void setAllowNull(boolean allow_null)
          Sets whether or not a null value is supplied.
 void setCasePolicy(int v)
          Sets the value of the casePolicy property.
abstract  void setCursor(com.klg.jclass.field.validate.TextCursorEvent e)
          Sets the cursor to the specified position.
 void setInvalidChars(String v)
          Sets a String of characters that are not allowed to be input in the current field.
 void setLocale(Locale locale)
          Sets the Locale used for formatting and parsing.
 void setMatchPickList(boolean v)
          Sets the value of matchPickList, which controls whether values must match those in the PickList of the validator or not.
 void setMax(Object max)
          Sets the maximum possible value of the object checked by the validator.
 void setMin(Object min)
          Sets the minimum possible value of the object checked by the validator.
 void setPickList(ListModel picklist)
          Sets the pick list.
 void setRange(Object min, Object max)
          Sets the max and min properties simultaneously.
 void setSpinPolicy(int spin_policy)
          Sets the value of SpinPolicy.
 void setValidChars(String v)
          Sets a String of characters which are allowed to be input in the current field.
 Object spinDown(Object current)
          If the validator has the ability to "spin" then this gives us the previous value.
 Object spinUp(Object current)
          If the validator has the ability to "spin" then this returns the next value.
protected abstract  Object subtractIncrement(Object current)
           
 boolean validate(Object obj)
          Validates the specified internal object and returns the Object if successful, or "null" if validation fails.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.klg.jclass.field.validate.JCValidator
getDefaultValue
 

Field Detail

AS_IS

public static final int AS_IS
Leaves characters as entered in the CasePolicy property.

See Also:
Constant Field Values

UPPERCASE

public static final int UPPERCASE
Converts characters to upper case in the CasePolicy property.

See Also:
Constant Field Values

LOWERCASE

public static final int LOWERCASE
Converts characters to lower case in the CasePolicy property.

See Also:
Constant Field Values

SPIN_FIELD

public static final int SPIN_FIELD
Allows spinning up and down between the maximum and minimum values. (Default for numeric validators.)

See Also:
Constant Field Values

SPIN_SUBFIELD

public static final int SPIN_SUBFIELD
Allows context sensitive spinning if it is allowed. (Default for date and time validators.)

See Also:
Constant Field Values

SPIN_WRAP

public static final int SPIN_WRAP
Like spin field but allows continuous spinning. A value wraps from its maximum value to its minimum when spinning in the “up” direction, and from minimum to maximum in the other direction. (Default for String validators.)

See Also:
Constant Field Values

NOT_FOUND

public static final int NOT_FOUND
See Also:
Constant Field Values

max

protected Object max

min

protected Object min

locale

protected Locale locale

increment

protected Object increment

allow_null

protected boolean allow_null

case_policy

protected int case_policy

invalid_chars

protected String invalid_chars

match_picklist

protected boolean match_picklist

valid_chars

protected String valid_chars

picklist

protected ListModel picklist

spin_policy

protected int spin_policy

abstractInitializing

protected boolean abstractInitializing

supportedClasses

protected Class[] supportedClasses

li

protected ResourceBundle li
Constructor Detail

AbstractValidator

public AbstractValidator()
Method Detail

changeText

public void changeText(com.klg.jclass.field.validate.TextEvent e)
Changes the specified text from the start_position to the end_position by inserting/replacing it by rge specified new_text.

Specified by:
changeText in interface JCValidator
Parameters:
e -

setCursor

public abstract void setCursor(com.klg.jclass.field.validate.TextCursorEvent e)
Sets the cursor to the specified position.

Specified by:
setCursor in interface JCValidator
Parameters:
e - the event triggering the repositioning of the cursor

parse

public abstract Object parse(Class c,
                             String text)
                      throws FieldParseException
Validates the current display string and returns a new Object if successful, or "null" if validation fails.

Specified by:
parse in interface JCValidator
Parameters:
text - text to be converted to an object
c - sets which class object the text should be converted to
Returns:
Throws:
FieldParseException

convertToSupported

public abstract Object convertToSupported(Object obj)
Converts the specified type (if possible) to the type supported by the validator. To reverse this operation use the convertFromSupported() method

See Also:
convertFromSupported(java.lang.Object, java.lang.Class)

convertFromSupported

public abstract Object convertFromSupported(Object from,
                                            Class class_type)
Converts the supported type to the type supported by the validator.

See Also:
convertToSupported(java.lang.Object)

validate

public boolean validate(Object obj)
Validates the specified internal object and returns the Object if successful, or "null" if validation fails.

Specified by:
validate in interface JCValidator
Parameters:
obj - object to be checked
Returns:

copyValue

public abstract Object copyValue(Object value)
Since the clone() method is protected in the Object class we cannot actually clone a generic object without knowing what it is; therefore the validator must provide this routine to do the copying for JCField.

Specified by:
copyValue in interface JCValidator
Parameters:
value -
Returns:

compareValues

public boolean compareValues(Object v1,
                             Object v2)
Since we cannot always rely on an objects equals() method we must define our own compare method. This default implementation calls equals(). If this is not sufficient then the subclass can override this method without having to subclass the data object.

Specified by:
compareValues in interface JCValidator
Parameters:
v1 -
v2 -
Returns:

format

public abstract String format(Object obj)
Generates a String representation of the given object.

Specified by:
format in interface JCValidator
Parameters:
obj -
Returns:

formatForEdit

public abstract String formatForEdit(Object obj)
Generates a String representation of the given object for use in edit mode.

Specified by:
formatForEdit in interface JCValidator
Parameters:
obj -
Returns:

hasEditFormat

public abstract boolean hasEditFormat()
Returns true if the validator has a different edit format.

Specified by:
hasEditFormat in interface JCValidator
Returns:

getFirstValidCursorPosition

public abstract int getFirstValidCursorPosition()
Reports the first valid cursor position.

Specified by:
getFirstValidCursorPosition in interface JCValidator
Returns:

getAllowNull

public boolean getAllowNull()
Returns whether or not null is a valid value.


setAllowNull

public void setAllowNull(boolean allow_null)
Sets whether or not a null value is supplied.


getSpinPolicy

public int getSpinPolicy()
Returns the spin policy.

See Also:
setSpinPolicy(int)

setSpinPolicy

public void setSpinPolicy(int spin_policy)
Sets the value of SpinPolicy.
Value Meaning
SPIN_FIELD Default value. Allow spinning up and down between the maximum and minimum
SPIN_SUBFIELD Allow context sensitive spinning if it is allowed
SPIN_WRAP Like spin field but allows spinning from max to min and min to max


inferSubField

public void inferSubField(int s,
                          int e)
Infer the sub field we need to work on from the current selected region If there is no selected region then the selected region is equal to the cursor position we don't ever need to look at the cursor position This particular implementation is a stub meant to be overridden if a particular validator supports subfields

Specified by:
inferSubField in interface JCValidator
Parameters:
s -
e -

getLocale

public Locale getLocale()
Returns the Locale used for formatting and parsing.


setLocale

public void setLocale(Locale locale)
Sets the Locale used for formatting and parsing.


getCasePolicy

public int getCasePolicy()
Returns the value of the casePolicy property.

See Also:
setCasePolicy(int)

setCasePolicy

public void setCasePolicy(int v)
Sets the value of the casePolicy property.

Parameters:
v - AS_IS, UPPERCASE, LOWERCASE

convertCase

public char convertCase(char c)
Returns the value of the character as filtered by the casePolicy of the validator.

Parameters:
c - value whose case is to be checked

getPickList

public ListModel getPickList()
Gets the pick list.

Specified by:
getPickList in interface JCValidator
Returns:
list of values the end user can pick from

setPickList

public void setPickList(ListModel picklist)
Sets the pick list.

Specified by:
setPickList in interface JCValidator
Parameters:
picklist -

getPickListIndex

public int getPickListIndex(Object obj)
Checks to see if a given object is in the pick list.

Specified by:
getPickListIndex in interface JCValidator
Parameters:
obj -
Returns:
returns the index into the list or NOTFOUND on failure

getMatchPickList

public boolean getMatchPickList()
Returns the value of matchPickList.

See Also:
setMatchPickList(boolean)

setMatchPickList

public void setMatchPickList(boolean v)
Sets the value of matchPickList, which controls whether values must match those in the PickList of the validator or not. The default is "true" but this property is only applicable if there actually are elements stored in the PickList


getNextValue

protected Object getNextValue(int current_index)
Returns the next value in the pickList or "null" if we are already at the end of the list.

Parameters:
current_index - index of the current item in the picklist

getPreviousValue

protected Object getPreviousValue(int current_index)
Returns the previous value in the pickList or "null" if we are already at the beginning of the list.

Parameters:
current_index - index of the current item in the picklist

getValidChars

public String getValidChars()
Returns a String of characters that are allowed to be typed in the current field.

See Also:
setValidChars(java.lang.String), isValidChar(char)

setValidChars

public void setValidChars(String v)
Sets a String of characters which are allowed to be input in the current field.

See Also:
isValidChar(char)

getInvalidChars

public String getInvalidChars()
Returns a String of characters that are not allowed to be typed in the current field.

See Also:
setInvalidChars(java.lang.String), isValidChar(char)

setInvalidChars

public void setInvalidChars(String v)
Sets a String of characters that are not allowed to be input in the current field.

See Also:
isValidChar(char)

isValidChar

public boolean isValidChar(char c)
Determines whether the character specified is allowed in the field. It does this by first searching the InvalidChars and then the ValidChars strings.

See Also:
setInvalidChars(java.lang.String), setValidChars(java.lang.String)

getMax

public Object getMax()
Returns the maximum possible value of the object checked by the validator.

See Also:
setMax(java.lang.Object)

setMax

public void setMax(Object max)
Sets the maximum possible value of the object checked by the validator.

See Also:
setRange(java.lang.Object, java.lang.Object), setMin(java.lang.Object)

getMin

public Object getMin()
Returns the minimum possible value of the object checked by the validator.

See Also:
setMin(java.lang.Object)

setMin

public void setMin(Object min)
Sets the minimum possible value of the object checked by the validator.

See Also:
setRange(java.lang.Object, java.lang.Object), setMax(java.lang.Object)

setRange

public void setRange(Object min,
                     Object max)
Sets the max and min properties simultaneously.


inRange

protected abstract boolean inRange(Object value)

getItem

protected String getItem(int i)
Gets a String representation of the object at the specified position in to pick list. This is a function since subclasses may override the simple toString() conversion that the base functionality specifies.


addIncrement

protected abstract Object addIncrement(Object current)

subtractIncrement

protected abstract Object subtractIncrement(Object current)

spinUp

public Object spinUp(Object current)
If the validator has the ability to "spin" then this returns the next value.

Specified by:
spinUp in interface JCValidator
Parameters:
current -
Returns:

spinDown

public Object spinDown(Object current)
If the validator has the ability to "spin" then this gives us the previous value.

Specified by:
spinDown in interface JCValidator
Parameters:
current -
Returns:

calculateSpinability

public int calculateSpinability(Object current)
Determines if the value in the field can be spun further.

Specified by:
calculateSpinability in interface JCValidator
Parameters:
current -
Returns:

checkValidInvalid

protected StringBuffer checkValidInvalid(String text)
Given a partially complete string, this routine looks through the list and constructs a String that matches as much as possible.

Returns:
a more (or the same) complete string or null if it does not match at all

isClassSupported

public boolean isClassSupported(Class c)
Returns true if the class passed in is the native type that the validator is designed to support.

Specified by:
isClassSupported in interface JCValidator
Parameters:
c -
Returns:
true if the object passed in is the native type

createPopupComponent

public com.klg.jclass.field.validate.PopupFieldEditor createPopupComponent()
Returns the popup component.

Specified by:
createPopupComponent in interface JCValidator
Returns:
the PopupFieldEditor

Copyright © 2004 Quest Software Inc..
All rights reserved.