JClass 4.5.0 API
Documentation

com.klg.jclass.field.validate
Class JCStringValidator

java.lang.Object
  |
  +--com.klg.jclass.field.validate.AbstractValidator
        |
        +--com.klg.jclass.field.validate.JCStringValidator
Direct Known Subclasses:
JCDateTimeValidator, JCIPAddressValidator

public class JCStringValidator
extends AbstractValidator

This class validates objects of type String.

See Also:
Serialized Form

Field Summary
protected  char[] compiled_mask_ch
           
protected  int[] compiled_mask_sym
           
protected  Object defaultValue
           
protected  String mask
           
protected  String mask_chars
           
protected  int mask_length
           
protected  int num_editable_pos
           
protected  int num_mask_match
           
protected  String place_holder_chars
           
 
Fields inherited from class com.klg.jclass.field.validate.AbstractValidator
abstractInitializing, allow_null, AS_IS, case_policy, increment, invalid_chars, li, locale, LOWERCASE, match_picklist, max, min, NOT_FOUND, picklist, SPIN_FIELD, spin_policy, SPIN_SUBFIELD, SPIN_WRAP, supportedClasses, UPPERCASE, valid_chars
 
Constructor Summary
JCStringValidator()
          Constructs a JCStringValidator.
JCStringValidator(Locale locale, String mask, int num_match, String place_holder_chars, ListModel picklist, boolean match_picklist, String valid_chars, String invalid_chars, boolean allow_null, Object default_value)
          Constructs a JCStringValidator with the values specified.
 
Method Summary
protected  Object addIncrement(Object current)
           
 void changeText(TextEvent e)
          Processes all changes in the text field.
protected  void compileMask()
          This routine compiles the mask into 2 arrays.
 Object convertFromSupported(Object from, Class class_type)
          Converts the supported type to the type supported by the validator.
 Object convertToSupported(Object obj)
          Converts the specified type (if possible) to the type supported by the validator.
 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
 String format(Object obj)
          Formats the text.
 String formatForEdit(Object obj)
          Generates a String representation of the given object for use in edit mode.
 Object getDefaultValue()
          Returns the default value for the field.
 int getFirstValidCursorPosition()
          Returns the first valid cursor position in the text field.
 String getMask()
          Returns the current mask.
 String getMaskChars()
          Returns the mask characters used.
protected  int getNextCursorPosition(int current_position, boolean direction)
          Gets the next non-literal cursor position.
 int getNumMaskMatch()
          Returns the number of characters to match with the mask.
 String getParsedMask()
          Returns a string with only literals in the correct position.
 String getPlaceHolderChars()
          Returns the placeholder string.
protected  Class[] getSupportedClasses()
          Creates a list of classes supported by the validator.
 boolean hasEditFormat()
          Returns true if the validator has a different edit format.
 boolean inRange(Object value)
          Checks if the value is in the valid range.
protected  boolean internalValidate(Object obj)
          This does the actual validation for the validate method.
protected  boolean isValidChar(StringBuffer buffer, int string_position, int actual_position)
          This function checks to see if the character entered is valid.
 Object parse(Class class_type, String text)
          Validates the text after the text field loses focus.
 void setCursor(TextCursorEvent e)
          Moves the cursor to a valid cursor position.
 void setDefaultValue(Object default_value)
          Sets the default value for the field.
 void setMask(String mask)
          Sets the mask to be used.
 void setMaskChars(String mask_chars)
          Sets the mask characters to be used.
 void setNumMaskMatch(int num_mask_match)
          Sets the number of characters to match with the mask from left to right.
 void setPlaceHolderChars(String place_holder_chars)
          Sets the placeholder string, which specifies the characters to use instead of an empty mask.
protected  Object subtractIncrement(Object current)
           
 boolean validate(Object obj)
          Validates the value in the field.
 
Methods inherited from class com.klg.jclass.field.validate.AbstractValidator
calculateSpinability, checkValidInvalid, compareValues, convertCase, createPopupComponent, getAllowNull, getCasePolicy, getInvalidChars, getItem, getLocale, getMatchPickList, getMax, getMin, getNextValue, getPickList, getPickListIndex, getPreviousValue, getSpinPolicy, getValidChars, inferSubField, isClassSupported, isValidChar, setAllowNull, setCasePolicy, setInvalidChars, setLocale, setMatchPickList, setMax, setMin, setPickList, setRange, setSpinPolicy, setValidChars, spinDown, spinUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compiled_mask_sym

protected int[] compiled_mask_sym

compiled_mask_ch

protected char[] compiled_mask_ch

mask_length

protected int mask_length

num_editable_pos

protected int num_editable_pos

mask

protected String mask

place_holder_chars

protected String place_holder_chars

mask_chars

protected String mask_chars

num_mask_match

protected int num_mask_match

defaultValue

protected Object defaultValue
Constructor Detail

JCStringValidator

public JCStringValidator()
Constructs a JCStringValidator.

JCStringValidator

public JCStringValidator(Locale locale,
                         String mask,
                         int num_match,
                         String place_holder_chars,
                         ListModel picklist,
                         boolean match_picklist,
                         String valid_chars,
                         String invalid_chars,
                         boolean allow_null,
                         Object default_value)
Constructs a JCStringValidator with the values specified.
Method Detail

getSupportedClasses

protected Class[] getSupportedClasses()
Creates a list of classes supported by the validator.

copyValue

public 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
Overrides:
copyValue in class AbstractValidator

setNumMaskMatch

public void setNumMaskMatch(int num_mask_match)
Sets the number of characters to match with the mask from left to right. This number does not include any literals. If the value is negative, the entire mask will be matched.
See Also:
getNumMaskMatch()

getNumMaskMatch

public int getNumMaskMatch()
Returns the number of characters to match with the mask.
See Also:
setNumMaskMatch(int)

setMask

public void setMask(String mask)
Sets the mask to be used. # - Any digit, minus sign, comma, decimal point, or plus sign
See Also:
setMaskChars(java.lang.String), getMask()

getMask

public String getMask()
Returns the current mask.
See Also:
setMask(java.lang.String)

setPlaceHolderChars

public void setPlaceHolderChars(String place_holder_chars)
Sets the placeholder string, which specifies the characters to use instead of an empty mask. If this string is null, or an empty character exists after the number of characters provided then the field uses a space character.
See Also:
getPlaceHolderChars()

getPlaceHolderChars

public String getPlaceHolderChars()
Returns the placeholder string.
See Also:
setPlaceHolderChars(java.lang.String)

setMaskChars

public void setMaskChars(String mask_chars)
Sets the mask characters to be used. The default is: "#@HULA*^\\". # - Any digit, minus sign, comma, decimal point, or plus sign
See Also:
getMaskChars()

getMaskChars

public String getMaskChars()
Returns the mask characters used.
See Also:
setMaskChars(java.lang.String)

getParsedMask

public String getParsedMask()
Returns a string with only literals in the correct position.
See Also:
setMask(java.lang.String)

inRange

public boolean inRange(Object value)
Checks if the value is in the valid range.
Overrides:
inRange in class AbstractValidator

compileMask

protected void compileMask()
This routine compiles the mask into 2 arrays. One array keeps track of the valid characters at certain positions and the other array keeps track of the actual literals that need to be printed.

isValidChar

protected boolean isValidChar(StringBuffer buffer,
                              int string_position,
                              int actual_position)
This function checks to see if the character entered is valid. It compares it to the mask specified.

getNextCursorPosition

protected int getNextCursorPosition(int current_position,
                                    boolean direction)
Gets the next non-literal cursor position.

changeText

public void changeText(TextEvent e)
Processes all changes in the text field. It will validate the text if a mask is used.
Overrides:
changeText in class AbstractValidator

setCursor

public void setCursor(TextCursorEvent e)
Moves the cursor to a valid cursor position.
Overrides:
setCursor in class AbstractValidator
Tags copied from interface: JCValidator
Parameters:
text - the current text
prev_position - the previous position of the cursor
new_position - the new position of the cursor
Returns:
Returns the actual position that was set

parse

public Object parse(Class class_type,
                    String text)
Validates the text after the text field loses focus.
Overrides:
parse in class AbstractValidator
Tags copied from class: AbstractValidator
Parameters:
text - text to be converted to an object

validate

public boolean validate(Object obj)
Validates the value in the field.
Overrides:
validate in class AbstractValidator
Tags copied from class: AbstractValidator
Parameters:
obj - object to be checked

internalValidate

protected boolean internalValidate(Object obj)
This does the actual validation for the validate method. We need an internal method because parseAndValidate called any subclass' validate method which is wrong. The parseAndValidate method in this class must call the validate method in this class.

format

public String format(Object obj)
Formats the text.
Overrides:
format in class AbstractValidator

getFirstValidCursorPosition

public int getFirstValidCursorPosition()
Returns the first valid cursor position in the text field.
Overrides:
getFirstValidCursorPosition in class AbstractValidator

formatForEdit

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

hasEditFormat

public boolean hasEditFormat()
Returns true if the validator has a different edit format.
Overrides:
hasEditFormat in class AbstractValidator

addIncrement

protected Object addIncrement(Object current)
Overrides:
addIncrement in class AbstractValidator

subtractIncrement

protected Object subtractIncrement(Object current)
Overrides:
subtractIncrement in class AbstractValidator

convertToSupported

public 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 Object convertFromSupported(Object from,
                                   Class class_type)
Converts the supported type to the type supported by the validator. Note that the object passed in is not modified but only used as a reference
See Also:
convertToSupported(java.lang.Object)

getDefaultValue

public Object getDefaultValue()
Returns the default value for the field.

setDefaultValue

public void setDefaultValue(Object default_value)
Sets the default value for the field.

Copyright© 1999-2000 KL Group Inc.
All rights reserved.