Class DatePicker
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- com.michaelbaranov.microba.common.MicrobaComponent
-
- com.michaelbaranov.microba.calendar.CalendarPane
-
- com.michaelbaranov.microba.calendar.DatePicker
-
- All Implemented Interfaces:
CalendarColors
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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 java.lang.String
PROPERTY_NAME_DATE_FORMAT
The name of a "dateFormat" property.static java.lang.String
PROPERTY_NAME_DROPDOWN_FOCUSABLE
The name of a "popupFocusable" property.static java.lang.String
PROPERTY_NAME_FIELD_EDITABLE
The name of a "fieldEditable" property.static java.lang.String
PROPERTY_NAME_KEEP_TIME
The name of a "keepTime" property.static java.lang.String
PROPERTY_NAME_PICKER_STYLE
The name of a "pickerStyle" property.-
Fields inherited from class com.michaelbaranov.microba.calendar.CalendarPane
PROPERTY_NAME_DATE, PROPERTY_NAME_FOCUS_LOST_BEHAVIOR, PROPERTY_NAME_HOLIDAY_POLICY, PROPERTY_NAME_LOCALE, PROPERTY_NAME_RESOURCES, PROPERTY_NAME_SHOW_NONE_BTN, PROPERTY_NAME_SHOW_NUMBER_WEEK, PROPERTY_NAME_SHOW_TODAY_BTN, PROPERTY_NAME_STRIP_TIME, PROPERTY_NAME_STYLE, PROPERTY_NAME_VETO_POLICY, PROPERTY_NAME_ZONE, STYLE_CLASSIC, STYLE_MODERN
-
Fields inherited from class com.michaelbaranov.microba.common.MicrobaComponent
PROPERTY_NAME_COLOR_OVERRIDE_MAP
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface com.michaelbaranov.microba.calendar.CalendarColors
COLOR_CALENDAR_GRID_BACKGROUND_DISABLED, COLOR_CALENDAR_GRID_BACKGROUND_ENABLED, COLOR_CALENDAR_GRID_FOCUS, COLOR_CALENDAR_GRID_FOREGROUND_DISABLED, COLOR_CALENDAR_GRID_FOREGROUND_ENABLED, COLOR_CALENDAR_GRID_HOLIDAY_FOREGROUND_DISABLED, COLOR_CALENDAR_GRID_HOLIDAY_FOREGROUND_ENABLED, COLOR_CALENDAR_GRID_RESTRICTED, COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_DISABLED, COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_ENABLED, COLOR_CALENDAR_GRID_WEEKEND_FOREGROUND_DISABLED, COLOR_CALENDAR_GRID_WEEKEND_FOREGROUND_ENABLED, COLOR_CALENDAR_HEADER_BACKGROUND_DISABLED, COLOR_CALENDAR_HEADER_BACKGROUND_ENABLED, COLOR_CALENDAR_HEADER_FOREGROUND_DISABLED, COLOR_CALENDAR_HEADER_FOREGROUND_ENABLED, COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_DISABLED, COLOR_CALENDAR_HEADER_FOREGROUND_WEEKEND_ENABLED
-
-
Constructor Summary
Constructors Constructor Description DatePicker()
Constructor.DatePicker(java.util.Date initialDate)
Constructor.DatePicker(java.util.Date initialDate, int dateStyle)
Constructor.DatePicker(java.util.Date initialDate, int dateStyle, java.util.Locale locale)
Constructor.DatePicker(java.util.Date initialDate, int dateStyle, java.util.Locale locale, java.util.TimeZone zone)
Constructor.DatePicker(java.util.Date initialDate, java.text.DateFormat dateFormat)
Constructor.DatePicker(java.util.Date initialDate, java.text.DateFormat dateFormat, java.util.Locale locale)
Constructor.DatePicker(java.util.Date initialDate, java.text.DateFormat dateFormat, java.util.Locale locale, java.util.TimeZone zone)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
commitEdit()
Forces the control to commit current user's edit.java.text.DateFormat
getDateFormat()
Returns the date format.int
getPickerStyle()
Returns current visual style of the picker control.java.lang.String
getUIClassID()
void
hidePopup()
Hides the calendar dropdown without selecting a date.boolean
isDropdownFocusable()
Is the dropdown focusable?boolean
isFieldEditable()
Is the edit field of the control editable by the user?boolean
isKeepTime()
Does UI try to preserve time components entered in the edit field?void
revertEdit()
Forces the control to revert current user's edit to reflect current control's date.void
setDateFormat(java.text.DateFormat dateFormat)
Sets the date format constant defined byDateFormat
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 betweenPICKER_STYLE_FIELD_AND_BUTTON
andPICKER_STYLE_BUTTON
void
showPopup()
Displays the calendar dropdown.-
Methods inherited from class com.michaelbaranov.microba.calendar.CalendarPane
addActionListener, addCommitListener, commitOrRevert, fireActionEvent, fireCommitEvent, getDate, getFocusLostBehavior, getHolidayPolicy, getLocale, getResources, getStyle, getVetoPolicy, getZone, isShowNoneButton, isShowNumberOfWeek, isShowTodayButton, isStripTime, observeMonth, removeActionListener, removeCommitListener, setDate, setFocusLostBehavior, setHolidayPolicy, setLocale, setResources, setShowNoneButton, setShowNumberOfWeek, setShowTodayButton, setStripTime, setStyle, setVetoPolicy, setZone, stripTime
-
Methods inherited from class com.michaelbaranov.microba.common.MicrobaComponent
getColorOverrideMap, getUI, setColorOverrideMap, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
PROPERTY_NAME_DATE_FORMAT
public static final java.lang.String PROPERTY_NAME_DATE_FORMAT
The name of a "dateFormat" property.- See Also:
- Constant Field Values
-
PROPERTY_NAME_FIELD_EDITABLE
public static final java.lang.String PROPERTY_NAME_FIELD_EDITABLE
The name of a "fieldEditable" property.- See Also:
- Constant Field Values
-
PROPERTY_NAME_KEEP_TIME
public static final java.lang.String PROPERTY_NAME_KEEP_TIME
The name of a "keepTime" property.- See Also:
- Constant Field Values
-
PROPERTY_NAME_PICKER_STYLE
public static final java.lang.String PROPERTY_NAME_PICKER_STYLE
The name of a "pickerStyle" property.- See Also:
- Constant Field Values
-
PROPERTY_NAME_DROPDOWN_FOCUSABLE
public static final java.lang.String PROPERTY_NAME_DROPDOWN_FOCUSABLE
The name of a "popupFocusable" property.- See Also:
- Constant Field Values
-
PICKER_STYLE_FIELD_AND_BUTTON
public static final int PICKER_STYLE_FIELD_AND_BUTTON
A constant for the "pickerStyle" property.- See Also:
- Constant Field Values
-
PICKER_STYLE_BUTTON
public static final int PICKER_STYLE_BUTTON
A constant for the "pickerStyle" property.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DatePicker
public DatePicker()
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate)
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate, int dateStyle)
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate, java.text.DateFormat dateFormat)
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate, int dateStyle, java.util.Locale locale)
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate, java.text.DateFormat dateFormat, java.util.Locale locale)
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate, int dateStyle, java.util.Locale locale, java.util.TimeZone zone)
Constructor.
-
DatePicker
public DatePicker(java.util.Date initialDate, java.text.DateFormat dateFormat, java.util.Locale locale, java.util.TimeZone zone)
Constructor.
-
-
Method Detail
-
getUIClassID
public java.lang.String getUIClassID()
- Overrides:
getUIClassID
in classCalendarPane
-
getDateFormat
public java.text.DateFormat getDateFormat()
Returns the date format.- Returns:
- current date format
- See Also:
setDateFormat(DateFormat)
-
setDateFormat
public void setDateFormat(java.text.DateFormat dateFormat)
Sets the date format constant defined byDateFormat
and updates the control to reflect new date style.- Parameters:
dateFormat
- the date format constant to set- See Also:
getDateFormat()
,DateFormat
-
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- See Also:
setFieldEditable(boolean)
-
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- See Also:
isFieldEditable()
-
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- See Also:
setDropdownFocusable(boolean)
-
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- See Also:
isDropdownFocusable()
-
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
CalendarPane.isStripTime()
isfalse
(the dafualt).- Returns:
true
if the UI respects time fields,false
otherwise- See Also:
setKeepTime(boolean)
,CalendarPane.setStripTime(boolean)
,CalendarPane.isStripTime()
-
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
CalendarPane.isStripTime()
isfalse
(the dafualt).- Parameters:
keepTime
-true
to make the UI respects time fields,false
otherwise- See Also:
isKeepTime()
,CalendarPane.setStripTime(boolean)
,CalendarPane.isStripTime()
-
getPickerStyle
public int getPickerStyle()
Returns current visual style of the picker control.NOTE: do not confuse with
CalendarPane.getStyle()
.- Returns:
- current visual style constant.
-
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
CalendarPane.getStyle()
.- Parameters:
pickerStyle
- the style to set- See Also:
PICKER_STYLE_BUTTON
,PICKER_STYLE_FIELD_AND_BUTTON
-
showButtonOnly
public void showButtonOnly(boolean buttonOnly)
A shortucut method to switch picker style betweenPICKER_STYLE_FIELD_AND_BUTTON
andPICKER_STYLE_BUTTON
- Parameters:
buttonOnly
-true
to setPICKER_STYLE_BUTTON
,false
to setPICKER_STYLE_FIELD_AND_BUTTON
-
showPopup
public void showPopup()
Displays the calendar dropdown.
-
hidePopup
public void hidePopup()
Hides the calendar dropdown without selecting a date.
-
commitEdit
public boolean commitEdit()
Description copied from class:CalendarPane
Forces the control to commit current user's edit. The opertaion may fail because the date in the control may be restricted by current veto policy. If successfull, the current date of the control may change, aCommitEvent
is fired.- Overrides:
commitEdit
in classCalendarPane
- Returns:
true
if successful,false
otherwise- See Also:
CalendarPane.revertEdit()
,CalendarPane.getFocusLostBehavior()
,CalendarPane.setFocusLostBehavior(int)
-
revertEdit
public void revertEdit()
Description copied from class:CalendarPane
Forces the control to revert current user's edit to reflect current control's date. The current date of the control may change, aCommitEvent
is fired.- Overrides:
revertEdit
in classCalendarPane
- See Also:
CalendarPane.revertEdit()
,CalendarPane.getFocusLostBehavior()
,CalendarPane.setFocusLostBehavior(int)
-
-