JClass DesktopViews 6.3.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
All Implemented Interfaces:
JCValidator, Serializable
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
 
Fields inherited from interface com.klg.jclass.field.validate.JCValidator
DOWN, UP
 
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(com.klg.jclass.field.validate.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.
 int getLastValidInputCharPosition(String text)
          Returns the last valid input character in text.
 String getMask()
          Returns the current mask.
 String getMaskChars()
          Returns the mask characters used.
 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(com.klg.jclass.field.validate.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.

Parameters:
allow_null -
default_value -
invalid_chars -
locale -
mask -
match_picklist -
num_match -
picklist -
place_holder_chars -
valid_chars -
Method Detail

getSupportedClasses

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

Returns:

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.

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

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.

Parameters:
num_mask_match -
See Also:
getNumMaskMatch()

getNumMaskMatch

public int getNumMaskMatch()
Returns the number of characters to match with the mask.

Returns:
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.

Parameters:
mask -
See Also:
setMaskChars(java.lang.String), getMask()

getMask

public String getMask()
Returns the current mask.

Returns:
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.

Parameters:
place_holder_chars -
See Also:
getPlaceHolderChars()

getPlaceHolderChars

public String getPlaceHolderChars()
Returns the placeholder String.

Returns:
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.

Parameters:
mask_chars -
See Also:
getMaskChars()

getMaskChars

public String getMaskChars()
Returns the mask characters used.

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

getParsedMask

public String getParsedMask()
Returns a String with only literals in the correct position.

Returns:
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.

Specified by:
inRange in class AbstractValidator
Parameters:
value -
Returns:

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.

Parameters:
actual_position -
buffer -
string_position -
Returns:

getNextCursorPosition

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

Parameters:
current_position -
direction -
Returns:

changeText

public void changeText(com.klg.jclass.field.validate.TextEvent e)
Processes all changes in the text field. It will validate the text if a mask is used.

Specified by:
changeText in interface JCValidator
Overrides:
changeText in class AbstractValidator
Parameters:
e -

setCursor

public void setCursor(com.klg.jclass.field.validate.TextCursorEvent e)
Moves the cursor to a valid cursor position.

Specified by:
setCursor in interface JCValidator
Specified by:
setCursor in class AbstractValidator
Parameters:
e -

getLastValidInputCharPosition

public int getLastValidInputCharPosition(String text)
Returns the last valid input character in text. Skips any characters from the end that match the placeHolderChars by counting the length backward.

Parameters:
text -
Returns:
last valid input character in text

parse

public Object parse(Class class_type,
                    String text)
Validates the text after the text field loses focus.

Specified by:
parse in interface JCValidator
Specified by:
parse in class AbstractValidator
Parameters:
class_type -
text -
Returns:

validate

public boolean validate(Object obj)
Validates the value in the field.

Specified by:
validate in interface JCValidator
Overrides:
validate in class AbstractValidator
Parameters:
obj -
Returns:

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 incorrect. The parseAndValidate method in this class must call the validate method in this class.

Parameters:
obj -
Returns:

format

public String format(Object obj)
Formats the text.

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

getFirstValidCursorPosition

public int getFirstValidCursorPosition()
Returns the first valid cursor position in the text field.

Specified by:
getFirstValidCursorPosition in interface JCValidator
Specified by:
getFirstValidCursorPosition in class AbstractValidator
Returns:
first valid cursor position in the text field

formatForEdit

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

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

hasEditFormat

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

Specified by:
hasEditFormat in interface JCValidator
Specified by:
hasEditFormat in class AbstractValidator
Returns:
true if the validator has a different edit format

addIncrement

protected Object addIncrement(Object current)
Specified by:
addIncrement in class AbstractValidator

subtractIncrement

protected Object subtractIncrement(Object current)
Specified by:
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.

Specified by:
convertToSupported in class AbstractValidator
Parameters:
obj -
Returns:
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: The object passed in is not modified but only used as a reference.

Specified by:
convertFromSupported in class AbstractValidator
Parameters:
from -
class_type -
Returns:
See Also:
convertToSupported(java.lang.Object)

getDefaultValue

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

Returns:
default value for the field

setDefaultValue

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

Parameters:
default_value -

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