JClass 4.5.0 API
Documentation

com.klg.jclass.field.validate
Class JCDateTimeValidator

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

public class JCDateTimeValidator
extends JCStringValidator

The JCDateTimeValidator is used to validate calendar objects.

See Also:
Serialized Form

Inner Class Summary
protected  class JCDateTimeValidator.DateTimeChooser
           
 
Field Summary
protected  com.klg.jclass.field.validate.JCDateTimeValidator.WorkingCalendar cal
           
protected  Vector compiled_edit_formats
           
protected  com.klg.jclass.field.validate.DateFormat compiled_format
           
protected  String date_format
           
protected  int default_detail
           
protected  Object defaultValue
           
protected  Vector edit_formats
           
static int FULL
          Detail level of the default format for date/time validators.
protected  int increment_field
           
static int LONG
          Detail level of the default format for date/time validators.
protected  boolean mask_input
           
static int MEDIUM
          Detail level of the default format for date/time validators.
protected  int millenium_threshold
           
protected  String original_format
           
static int SHORT
          Detail level of the default format for date/time validators.
protected  int spin_policy
           
protected  Class[] supportedClasses
           
protected  DateFormatSymbols symbols
           
protected  TimeZone tz
           
 
Fields inherited from class com.klg.jclass.field.validate.JCStringValidator
compiled_mask_ch, compiled_mask_sym, defaultValue, mask, mask_chars, mask_length, num_editable_pos, num_mask_match, 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
JCDateTimeValidator()
          Creates a JCDateTimeValidator.
JCDateTimeValidator(Locale locale, String format, String place_holder_chars, String[] edit_formats, boolean mask_input, int default_detail, boolean allow_null, Object default_value)
          Creates a JCDateTimeValidator with the values specified.
JCDateTimeValidator(Locale locale, String format, String place_holder_chars, String[] edit_formats, boolean mask_input, int default_detail, boolean allow_null, Object default_value, int millenniumThreshold)
          Creates a JCDateTimeValidator with the values specified.
 
Method Summary
 void addEditFormat(String edit_format)
          Adds the specified format to the edit format list.
protected  Object addIncrement(Object current)
           
 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)
          Creates a new instance of the object with the same value.
 PopupFieldEditor createPopupComponent()
          Returns the popup component for this validator.
static int dayOfMonthOfYear(int year, int day_of_year)
          Calculates the month, day_of_month, given year and day_of_year; returns day.
static int dayOfWeek(int year, int month, int day)
          Returns the 1 based day of week.
static int dayOfYear(int year, int month, int day)
          Calculates the day of year from month, day, and year.
static int daysInMonth(int month, int year)
          Calculates the number of days in a given month.
static int daysInYear(int year)
          Returns how many days in a year.
 String format(Object obj)
          Generates a String representation of the given object.
 int getDefaultDetail()
          Returns the detail level of the default format.
 String[] getDefaultEditFormats()
          Sets/restores the default EditFormats for the validator.
 String[] getDefaultEditFormats(Locale l)
          Gets the default EditFormats for the validator.
 String getDefaultFormat()
          Gets the default Mask for the validator.
 String getDefaultFormat(Locale l)
          Gets the default Mask for the validator given a specific locale.
 Object getDefaultValue()
          Returns the default value for the field.
 String[] getEditFormats()
          Returns the list of editFormats used to attempt to parse user input.
 String getFormat()
          Returns the mask currently being used to display the date/time values.
 int getIncrement()
          Gets the number by which to spin the values in numeric spin fields.
 int getIncrementField()
          Returns the incrementField operated on by the currently set increment value.
 boolean getMaskInput()
          Gets the flag that controls whether or not to force the user to input data that exactly matches the format.
 int getMilleniumThreshold()
          Returns millenium threshold.
protected  Class[] getSupportedClasses()
          Creates a list of classes supported by the validator.
 TimeZone getTimeZone()
          Gets the time zone to be used by the validator.
 void inferSubField(int selection_start, int selection_end)
          Infers the sub-field in the currently selected region that will be selected.
 boolean inRange(Object value)
          Checks if the value is in the valid range.
protected  boolean internal_validate(com.klg.jclass.field.validate.JCDateTimeValidator.WorkingCalendar cal)
           
static boolean isLeap(int year)
          Checks whether the given year is a leap year.
static int monthOfYear(int year, int day_of_year)
          Calculates the month, given the year and day_of_year; returns month.
 Object parse(Class class_type, String text)
          Validates the specified text, and returns a new Object if successful.
 void setDefaultDetail(int detail)
          Specifies the detail level of the default format.
 void setDefaultValue(Object default_value)
          Sets the default value for the field.
 void setEditFormats(String[] formats)
          Sets the list of editFormats used in the attempt to parse user input.
 void setFormat(String format)
          Sets the format to use to display the date/time values.
 void setIncrement(int increment)
          Sets the number by which to spin the values in numeric spin fields.
 void setIncrementField(int field)
          Sets the value of the incrementField operated on by the increment.
 void setLocale(Locale locale)
          Sets the default locale.
 void setMaskInput(boolean mask_input)
          Sets the flag that controls whether or not to force the user to input data that exactly matches the format.
 void setMilleniumThreshold(int threshold)
          Sets the MilleniumThreshold, which is a value used for interpreting 2 digit years.
 void setTimeZone(TimeZone zone)
          Sets the time zone to be used by the validator.
protected  Object subtractIncrement(Object current)
           
 boolean validate(Object obj)
          Validates the given object.
static int weekOfMonth(int year, int month, int day)
          Returns the 1 based week of month.
static int weekOfYear(int year, int day_of_year)
          Returns the 1 based week of year.
 
Methods inherited from class com.klg.jclass.field.validate.JCStringValidator
changeText, compileMask, formatForEdit, getFirstValidCursorPosition, getMask, getMaskChars, getNextCursorPosition, getNumMaskMatch, getParsedMask, getPlaceHolderChars, hasEditFormat, internalValidate, isValidChar, setCursor, setMask, setMaskChars, setNumMaskMatch, setPlaceHolderChars
 
Methods inherited from class com.klg.jclass.field.validate.AbstractValidator
calculateSpinability, checkValidInvalid, compareValues, convertCase, getAllowNull, getCasePolicy, getInvalidChars, getItem, getLocale, getMatchPickList, getMax, getMin, getNextValue, getPickList, getPickListIndex, getPreviousValue, getSpinPolicy, getValidChars, isClassSupported, isValidChar, setAllowNull, setCasePolicy, setInvalidChars, 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

FULL

public static final int FULL
Detail level of the default format for date/time validators. Example: Fri, Apr 30, 1999 01:33:05 PM EST

LONG

public static final int LONG
Detail level of the default format for date/time validators. Example: Apr 30, 1999 01:34:21 PM EST

MEDIUM

public static final int MEDIUM
Detail level of the default format for date/time validators. Example: Apr 30, 1999 01:35:08 PM

SHORT

public static final int SHORT
Detail level of the default format for date/time validators. Example: 04/30/99 01:35 PM

supportedClasses

protected Class[] supportedClasses

mask_input

protected boolean mask_input

date_format

protected String date_format

compiled_format

protected com.klg.jclass.field.validate.DateFormat compiled_format

tz

protected TimeZone tz

cal

protected com.klg.jclass.field.validate.JCDateTimeValidator.WorkingCalendar cal

symbols

protected DateFormatSymbols symbols

edit_formats

protected Vector edit_formats

compiled_edit_formats

protected Vector compiled_edit_formats

increment_field

protected int increment_field

millenium_threshold

protected int millenium_threshold

default_detail

protected int default_detail

spin_policy

protected int spin_policy

original_format

protected String original_format

defaultValue

protected Object defaultValue
Constructor Detail

JCDateTimeValidator

public JCDateTimeValidator()
Creates a JCDateTimeValidator.

JCDateTimeValidator

public JCDateTimeValidator(Locale locale,
                           String format,
                           String place_holder_chars,
                           String[] edit_formats,
                           boolean mask_input,
                           int default_detail,
                           boolean allow_null,
                           Object default_value)
Creates a JCDateTimeValidator with the values specified.

JCDateTimeValidator

public JCDateTimeValidator(Locale locale,
                           String format,
                           String place_holder_chars,
                           String[] edit_formats,
                           boolean mask_input,
                           int default_detail,
                           boolean allow_null,
                           Object default_value,
                           int millenniumThreshold)
Creates a JCDateTimeValidator with the values specified.
Method Detail

getSupportedClasses

protected Class[] getSupportedClasses()
Creates a list of classes supported by the validator.
Overrides:
getSupportedClasses in class JCStringValidator

getDefaultFormat

public String getDefaultFormat(Locale l)
Gets the default Mask for the validator given a specific locale.

getDefaultFormat

public String getDefaultFormat()
Gets the default Mask for the validator.

getDefaultDetail

public int getDefaultDetail()
Returns the detail level of the default format.
See Also:
setDefaultDetail(int)

setDefaultDetail

public void setDefaultDetail(int detail)
Specifies the detail level of the default format. Has no effect when the format property has been changed. Valid values are: FULL, LONG, MEDIUM (default), SHORT
See Also:
getDefaultDetail()

getDefaultEditFormats

public String[] getDefaultEditFormats(Locale l)
Gets the default EditFormats for the validator.

getDefaultEditFormats

public String[] getDefaultEditFormats()
Sets/restores the default EditFormats for the validator.

getEditFormats

public String[] getEditFormats()
Returns the list of editFormats used to attempt to parse user input.
See Also:
setEditFormats(java.lang.String[])

setEditFormats

public void setEditFormats(String[] formats)
Sets the list of editFormats used in the attempt to parse user input.
See Also:
getDefaultEditFormats(java.util.Locale), getEditFormats(), addEditFormat(java.lang.String)

inferSubField

public void inferSubField(int selection_start,
                          int selection_end)
Infers the sub-field in the currently selected region that will be selected. If there is no selected region then the selected region is equal to the cursor position.
Overrides:
inferSubField in class AbstractValidator

getIncrement

public int getIncrement()
Gets the number by which to spin the values in numeric spin fields.

setIncrement

public void setIncrement(int increment)
Sets the number by which to spin the values in numeric spin fields.

getIncrementField

public int getIncrementField()
Returns the incrementField operated on by the currently set increment value.
See Also:
Calendar.set(int, int)

setIncrementField

public void setIncrementField(int field)
Sets the value of the incrementField operated on by the increment.
See Also:
Calendar.set(int, int)

getMilleniumThreshold

public int getMilleniumThreshold()
Returns millenium threshold.
See Also:
setMilleniumThreshold(int)

setMilleniumThreshold

public void setMilleniumThreshold(int threshold)
Sets the MilleniumThreshold, which is a value used for interpreting 2 digit years. Any 2 digit date less than the threshold is considered to be after the year 2000 while any value greater than or equal to the threshold is considered to be after the year 1900. The default is 69 so that, for example, '96 --> 1996 and '10 == 2010.
Parameters:
threshold - valid values are 0 through 100

addIncrement

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

subtractIncrement

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

setLocale

public void setLocale(Locale locale)
Sets the default locale.
Overrides:
setLocale in class AbstractValidator
See Also:
AbstractValidator.setLocale(java.util.Locale)

getTimeZone

public TimeZone getTimeZone()
Gets the time zone to be used by the validator.

setTimeZone

public void setTimeZone(TimeZone zone)
Sets the time zone to be used by the validator.

inRange

public boolean inRange(Object value)
Checks if the value is in the valid range. The default is true for the DateTime validator. This method is used internally. You should not have to call it.
Overrides:
inRange in class JCStringValidator

addEditFormat

public void addEditFormat(String edit_format)
Adds the specified format to the edit format list.
See Also:
setEditFormats(java.lang.String[])

getMaskInput

public boolean getMaskInput()
Gets the flag that controls whether or not to force the user to input data that exactly matches the format.
See Also:
getFormat()

setMaskInput

public void setMaskInput(boolean mask_input)
Sets the flag that controls whether or not to force the user to input data that exactly matches the format. When using this flag, be sure that the date format mask is non-ambiguous (for example, 'hh' instead of 'h').
See Also:
setFormat(java.lang.String)

getFormat

public String getFormat()
Returns the mask currently being used to display the date/time values.
See Also:
setFormat(java.lang.String)

setFormat

public void setFormat(String format)
Sets the format to use to display the date/time values. The format should be of the form:
Symbol(s) Meaning
y Year within the current century (1 or 2 digits)
yy Year within the current century (2 digits)
yyyy Year including century (4 digits)
M numeric month of year (1 or 2 digits)
MM numeric month of year (2 digits)
MMM abbreviated month name
MMMM full month name
EEEE Day of the Week (full name)
EE Day of the Week (abbreviated)
d numeric day of month (1 or 2 digits)
dd numeric day of month (2 digits)
h hour of day (1-12) (1 or 2 digits)
hh hour of day (1-12) (2 digits)
H hour of day (0-23) (1 or 2 digits)
HH hour of day (0-23) (2 digits)
m minute (1 or 2 digits)
mm minute (2 digits)
s second (1 or 2 digits)
ss second (2 digits)
a AM/PM representation
p AM/PM representation
z time zone abbreviation
zz time zone abbreviation
zzzz time zone (full name)
D Day in year (1, 2, or 3 digits)
DDD Day in year (3 digits)
\\ Next character is a literal


parse

public Object parse(Class class_type,
                    String text)
Validates the specified text, and returns a new Object if successful.
Overrides:
parse in class JCStringValidator
Parameters:
c - sets which class object the text should be converted to
text - text to be converted to an object

copyValue

public Object copyValue(Object value)
Creates a new instance of the object with the same 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 Field Note objects that are inherently immutable do not need to be copied and hence just return the passed in value as the implementation.
Overrides:
copyValue in class JCStringValidator

validate

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

internal_validate

protected boolean internal_validate(com.klg.jclass.field.validate.JCDateTimeValidator.WorkingCalendar cal)

format

public String format(Object obj)
Generates a String representation of the given object.
Overrides:
format in class JCStringValidator

isLeap

public static boolean isLeap(int year)
Checks whether the given year is a leap year.
Parameters:
year - The year to check. i.e. "1997"

dayOfYear

public static int dayOfYear(int year,
                            int month,
                            int day)
Calculates the day of year from month, day, and year.
Parameters:
year - The year i.e. 1997
month - The month (0 to 11)
day - The day of the month (0 to 31)

daysInMonth

public static int daysInMonth(int month,
                              int year)
Calculates the number of days in a given month.
Parameters:
year - The year to use. i.e. "1997"
month - The month (0 to 11)

monthOfYear

public static int monthOfYear(int year,
                              int day_of_year)
Calculates the month, given the year and day_of_year; returns month.
Parameters:
year - The year to use. i.e. "1997"
day_of_year - The day of the year (1 to 366)

dayOfMonthOfYear

public static int dayOfMonthOfYear(int year,
                                   int day_of_year)
Calculates the month, day_of_month, given year and day_of_year; returns day. NOTE that YEAR must be the actual year or rather "tm_year + 1900".

daysInYear

public static int daysInYear(int year)
Returns how many days in a year. NOTE that YEAR must be the actual year, or rather "tm_year + 1900".

dayOfWeek

public static int dayOfWeek(int year,
                            int month,
                            int day)
Returns the 1 based day of week.

weekOfYear

public static int weekOfYear(int year,
                             int day_of_year)
Returns the 1 based week of year.

weekOfMonth

public static int weekOfMonth(int year,
                              int month,
                              int day)
Returns the 1 based week of month.

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
Overrides:
convertToSupported in class JCStringValidator
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
Overrides:
convertFromSupported in class JCStringValidator
See Also:
convertToSupported(java.lang.Object)

getDefaultValue

public Object getDefaultValue()
Returns the default value for the field.
Overrides:
getDefaultValue in class JCStringValidator

setDefaultValue

public void setDefaultValue(Object default_value)
Sets the default value for the field.
Overrides:
setDefaultValue in class JCStringValidator

createPopupComponent

public PopupFieldEditor createPopupComponent()
Returns the popup component for this validator.
Overrides:
createPopupComponent in class AbstractValidator

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