JClass DesktopViews 6.3.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
All Implemented Interfaces:
JCValidator, Serializable
Direct Known Subclasses:
JCDateValidator, JCTimeValidator

public class JCDateTimeValidator
extends JCStringValidator

The JCDateTimeValidator is used to validate calendar objects.

See Also:
Serialized Form

Nested Class Summary
 class JCDateTimeValidator.DateChooser
           
 class JCDateTimeValidator.DateTimeChooser
           
 class JCDateTimeValidator.DateTimePopup
           
 class JCDateTimeValidator.TimeSpin
           
protected  class JCDateTimeValidator.WorkingCalendar
           
 
Field Summary
protected  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  String default_format
           
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, 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_SUBFIELD, SPIN_WRAP, UPPERCASE, valid_chars
 
Fields inherited from interface com.klg.jclass.field.validate.JCValidator
DOWN, UP
 
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.
 com.klg.jclass.field.validate.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(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, getLastValidInputCharPosition, 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

See Also:
Constant Field Values

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

See Also:
Constant Field Values

MEDIUM

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

See Also:
Constant Field Values

SHORT

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

See Also:
Constant Field Values

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 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

default_format

protected String default_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.

Parameters:
allow_null -
default_detail -
default_value -
edit_formats -
format -
locale -
mask_input -
place_holder_chars -

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.

Parameters:
allow_null -
default_detail -
default_value -
edit_formats -
format -
locale -
mask_input -
millenniumThreshold -
place_holder_chars -
Method Detail

getSupportedClasses

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

Overrides:
getSupportedClasses in class JCStringValidator
Returns:

getDefaultFormat

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

Parameters:
l -
Returns:

getDefaultFormat

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

Returns:

getDefaultDetail

public int getDefaultDetail()
Returns the detail level of the default format.

Returns:
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), or SHORT.

Parameters:
detail -
See Also:
getDefaultDetail()

getDefaultEditFormats

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

Parameters:
l -
Returns:

getDefaultEditFormats

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

Returns:

getEditFormats

public String[] getEditFormats()
Returns the list of editFormats used to attempt to parse user input.

Returns:
list of editFormats
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.

Parameters:
formats -
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.

Specified by:
inferSubField in interface JCValidator
Overrides:
inferSubField in class AbstractValidator
Parameters:
selection_start -
selection_end -

getIncrement

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

Returns:

setIncrement

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

Parameters:
increment -

getIncrementField

public int getIncrementField()
Returns the incrementField operated on by the currently set increment value.

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

Parameters:
field -
See Also:
Calendar.set(int, int)

getMilleniumThreshold

public int getMilleniumThreshold()
Returns millenium threshold.

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
Parameters:
locale -
See Also:
AbstractValidator.setLocale(java.util.Locale)

getTimeZone

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

Returns:

setTimeZone

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

Parameters:
zone -

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
Parameters:
value -
Returns:

addEditFormat

public void addEditFormat(String edit_format)
Adds the specified format to the edit format list.

Parameters:
edit_format -
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.

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

Parameters:
mask_input -
See Also:
setFormat(java.lang.String)

getFormat

public String getFormat()
Returns the mask currently being used to display the date/time values.

Returns:
mask currently being used
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

Parameters:
format -

parse

public Object parse(Class class_type,
                    String text)
Validates the specified text, and returns a new Object if successful.

Specified by:
parse in interface JCValidator
Overrides:
parse in class JCStringValidator
Parameters:
class_type - sets which class object the text should be converted to
text - text to be converted to an object
Returns:

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 JClass Field.
Note: Objects that are inherently immutable do not need to be copied, and hence return the passed in value as the implementation.

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

validate

public boolean validate(Object obj)
Validates the given object.

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

internal_validate

protected boolean internal_validate(JCDateTimeValidator.WorkingCalendar cal)

format

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

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

isLeap

public static boolean isLeap(int year)
Checks whether the given year is a leap year.

Parameters:
year - the year to check (for example, 1997)
Returns:

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 (for example, 1997)
month - the month (0 to 11)
day - the day of the month (0 to 31)
Returns:

daysInMonth

public static int daysInMonth(int month,
                              int year)
Calculates the number of days in a given month.

Parameters:
year - the year to use (for example, 1997)
month - the month (0 to 11)
Returns:

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 (for example, 1997)
day_of_year - the day of the year (1 to 366)
Returns:

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: YEAR must be the actual year, or rather "tm_year + 1900".

Parameters:
year -
day_of_year -
Returns:

daysInYear

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

Parameters:
year -
Returns:
days in a year

dayOfWeek

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

Parameters:
year -
month -
day -
Returns:

weekOfYear

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

Parameters:
year - year
day_of_year - day
Returns:
1 based week of year

weekOfMonth

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

Parameters:
year - year
month - month
day - day
Returns:
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
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.

Overrides:
convertFromSupported in class JCStringValidator
Parameters:
from -
class_type -
Returns:
See Also:
convertToSupported(java.lang.Object)

getDefaultValue

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

Specified by:
getDefaultValue in interface JCValidator
Overrides:
getDefaultValue in class JCStringValidator
Returns:
default value for the field

setDefaultValue

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

Overrides:
setDefaultValue in class JCStringValidator
Parameters:
default_value -

createPopupComponent

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

Specified by:
createPopupComponent in interface JCValidator
Overrides:
createPopupComponent in class AbstractValidator
Returns:

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