com.michaelbaranov.microba.calendar

Class DatePicker


public class DatePicker
extends CalendarPane

A concrete implementation of JComponent. Capable of displaying and selecting dates, much like an editable combo-box with a calendar dropdown.

This implementatin allows for specifying time component along with the date. Make sure that: 1) keepTime property is true; 2) stripTime is false; 3) dateFormat has time fields;

Author:
Michael Baranov

Field Summary

static int
PICKER_STYLE_BUTTON
A constant for the "pickerStyle" property.
static int
PICKER_STYLE_FIELD_AND_BUTTON
A constant for the "pickerStyle" property.
static String
PROPERTY_NAME_DATE_FORMAT
The name of a "dateFormat" property.
static String
PROPERTY_NAME_DROPDOWN_FOCUSABLE
The name of a "popupFocusable" property.
static String
PROPERTY_NAME_FIELD_EDITABLE
The name of a "fieldEditable" property.
static String
PROPERTY_NAME_KEEP_TIME
The name of a "keepTime" property.
static String
PROPERTY_NAME_PICKER_STYLE
The name of a "pickerStyle" property.

Constructor Summary

DatePicker()
Constructor.
DatePicker(Date initialDate)
Constructor.
DatePicker(Date initialDate, DateFormat dateFormat)
Constructor.
DatePicker(Date initialDate, DateFormat dateFormat, Locale locale)
Constructor.
DatePicker(Date initialDate, DateFormat dateFormat, Locale locale, TimeZone zone)
Constructor.
DatePicker(Date initialDate, int dateStyle)
Constructor.
DatePicker(Date initialDate, int dateStyle, Locale locale)
Constructor.
DatePicker(Date initialDate, int dateStyle, Locale locale, TimeZone zone)
Constructor.

Method Summary

boolean
commitEdit()
DateFormat
getDateFormat()
Returns the date format.
int
getPickerStyle()
Returns current visual style of the picker control.
String
getUIClassID()
void
hidePopup()
Hides the calendar dropdown without selecting a date.
boolean
isDropdownFocusable()
Is the dropdown focusable?

If not focusable, the dropdown calendar will lack some keyboard input capabilities.

boolean
isFieldEditable()
Is the edit field of the control editable by the user?

If not editable, the user can not type in the date and can only use calendar drop-down to select dates.

boolean
isKeepTime()
Does UI try to preserve time components entered in the edit field?

If true and if the date format has some time fields (hours, minutes, seconds, fraction of second), the UI tries to respect the time fields' values entered by user as much as possible.

void
revertEdit()
void
setDateFormat(DateFormat dateFormat)
Sets the date format constant defined by DateFormat and updates the control to reflect new date style.
void
setDropdownFocusable(boolean popupFocusable)
Enables or disables focusability of the dropdown calendar.
void
setFieldEditable(boolean fieldEditable)
Enables or disables editing of the edit field by the user.
void
setKeepTime(boolean keepTime)
Determines if the UI should try to preserve time components entered in the edit field.
void
setPickerStyle(int pickerStyle)
Sets the current visual style of the picker control.
void
showButtonOnly(boolean buttonOnly)
A shortucut method to switch picker style between PICKER_STYLE_FIELD_AND_BUTTON and PICKER_STYLE_BUTTON
void
showPopup()
Displays the calendar dropdown.

Field Details

PICKER_STYLE_BUTTON

public static final int PICKER_STYLE_BUTTON
A constant for the "pickerStyle" property.
Field Value:
288

PICKER_STYLE_FIELD_AND_BUTTON

public static final int PICKER_STYLE_FIELD_AND_BUTTON
A constant for the "pickerStyle" property.
Field Value:
272

PROPERTY_NAME_DATE_FORMAT

public static final String PROPERTY_NAME_DATE_FORMAT
The name of a "dateFormat" property.

PROPERTY_NAME_DROPDOWN_FOCUSABLE

public static final String PROPERTY_NAME_DROPDOWN_FOCUSABLE
The name of a "popupFocusable" property.

PROPERTY_NAME_FIELD_EDITABLE

public static final String PROPERTY_NAME_FIELD_EDITABLE
The name of a "fieldEditable" property.

PROPERTY_NAME_KEEP_TIME

public static final String PROPERTY_NAME_KEEP_TIME
The name of a "keepTime" property.

PROPERTY_NAME_PICKER_STYLE

public static final String PROPERTY_NAME_PICKER_STYLE
The name of a "pickerStyle" property.

Constructor Details

DatePicker

public DatePicker()
Constructor.

DatePicker

public DatePicker(Date initialDate)
Constructor.

DatePicker

public DatePicker(Date initialDate,
                  DateFormat dateFormat)
Constructor.

DatePicker

public DatePicker(Date initialDate,
                  DateFormat dateFormat,
                  Locale locale)
Constructor.

DatePicker

public DatePicker(Date initialDate,
                  DateFormat dateFormat,
                  Locale locale,
                  TimeZone zone)
Constructor.

DatePicker

public DatePicker(Date initialDate,
                  int dateStyle)
Constructor.

DatePicker

public DatePicker(Date initialDate,
                  int dateStyle,
                  Locale locale)
Constructor.

DatePicker

public DatePicker(Date initialDate,
                  int dateStyle,
                  Locale locale,
                  TimeZone zone)
Constructor.

Method Details

commitEdit

public boolean commitEdit()

getDateFormat

public DateFormat getDateFormat()
Returns the date format.

Returns:
current date format

getPickerStyle

public int getPickerStyle()
Returns current visual style of the picker control.

NOTE: do not confuse with getStyle().

Returns:
current visual style constant.

getUIClassID

public String getUIClassID()

hidePopup

public void hidePopup()
Hides the calendar dropdown without selecting a date.

isDropdownFocusable

public boolean isDropdownFocusable()
Is the dropdown focusable?

If not focusable, the dropdown calendar will lack some keyboard input capabilities.

Returns:
true if the dropdown is focusable, false otherwise

isFieldEditable

public boolean isFieldEditable()
Is the edit field of the control editable by the user?

If not editable, the user can not type in the date and can only use calendar drop-down to select dates.

Returns:
true if the edit field is editable, false otherwise

isKeepTime

public boolean isKeepTime()
Does UI try to preserve time components entered in the edit field?

If true and if the date format has some time fields (hours, minutes, seconds, fraction of second), the UI tries to respect the time fields' values entered by user as much as possible.

Note: to be able to receive time portion of the date, make sure isStripTime() is false (the dafualt).

Returns:
true if the UI respects time fields, false otherwise
See Also:
setKeepTime(boolean), setStripTime(boolean), isStripTime()

revertEdit

public void revertEdit()

setDateFormat

public void setDateFormat(DateFormat dateFormat)
Sets the date format constant defined by DateFormat and updates the control to reflect new date style.

Parameters:
dateFormat - the date format constant to set

setDropdownFocusable

public void setDropdownFocusable(boolean popupFocusable)
Enables or disables focusability of the dropdown calendar.

If not focusable, the dropdown calendar will lack some keyboard input capabilities.

Parameters:
popupFocusable - the focusable value to set

setFieldEditable

public void setFieldEditable(boolean fieldEditable)
Enables or disables editing of the edit field by the user.

If not editable, the user can not type in the date and can only use calendar drop-down to select dates.

Parameters:
fieldEditable - the editable value to set

setKeepTime

public void setKeepTime(boolean keepTime)
Determines if the UI should try to preserve time components entered in the edit field.

If true and if the date format has some time fields (hours, minutes, seconds, fraction of second), the UI tries to respect the time fields' values entered by user as much as possible.

Note: to be able to receive time portion of the date, make sure isStripTime() is false (the dafualt).

Parameters:
keepTime - true to make the UI respects time fields, false otherwise
See Also:
isKeepTime(), setStripTime(boolean), isStripTime()

setPickerStyle

public void setPickerStyle(int pickerStyle)
Sets the current visual style of the picker control.

The control is then updated to reflect the new style.

NOTE: do not confuse with getStyle().

Parameters:
pickerStyle - the style to set

showButtonOnly

public void showButtonOnly(boolean buttonOnly)
Parameters:
buttonOnly - true to set PICKER_STYLE_BUTTON, false to set PICKER_STYLE_FIELD_AND_BUTTON

showPopup

public void showPopup()
Displays the calendar dropdown.