de.enough.polish.ui
Class DateField

java.lang.Object
  extended by de.enough.polish.ui.Item
      extended by de.enough.polish.ui.StringItem
          extended by de.enough.polish.ui.DateField
All Implemented Interfaces:
ItemCommandListener, javax.microedition.lcdui.CommandListener

public class DateField
extends StringItem
implements ItemCommandListener, javax.microedition.lcdui.CommandListener

A DateField is an editable component for presenting date and time (calendar) information that may be placed into a Form. Value for this field can be initially set or left unset. If value is not set then the UI for the field shows this clearly. The field value for "not initialized state" is not valid value and getDate() for this state returns null.

Instance of a DateField can be configured to accept date or time information or both of them. This input mode configuration is done by DATE, TIME or DATE_TIME static fields of this class. DATE input mode allows to set only date information and TIME only time information (hours, minutes). DATE_TIME allows to set both clock time and date values.

In TIME input mode the date components of Date object must be set to the "zero epoch" value of January 1, 1970.

Calendar calculations in this field are based on default locale and defined time zone. Because of the calculations and different input modes date object may not contain same millisecond value when set to this field and get back from this field.


Since:
MIDP 1.0
Author:
Robert Virkus, robert@enough.de

Field Summary
static int DATE
          Input mode for date information (day, month, year).
static int DATE_TIME
          Input mode for date (day, month, year) and time (minutes, hours) information.
static int TIME
          Input mode for time information (hours and minutes).
 
Fields inherited from class de.enough.polish.ui.StringItem
animateTextWrap, bitMapFont, bitMapFontViewer, clipText, font, text, textColor, textEffect, textHorizontalAdjustment, textLines, textVerticalAdjustment, textWrapDirection, textWrapSpeed, useSingleLine, xOffset
 
Fields inherited from class de.enough.polish.ui.Item
_bbField, _bbFieldAdded, appearanceMode, background, backgroundHeight, backgroundWidth, backgroundYOffset, border, borderWidth, BUTTON, colSpan, commands, completeBackground, completeBackgroundPadding, completeBorder, contentHeight, contentWidth, contentX, contentY, cssSelector, defaultCommand, focusedStyle, HORIZONTAL, HYPERLINK, includeLabel, INTERACTIVE, internalHeight, internalWidth, internalX, internalY, isFocused, isInitialized, isInvisible, isLayoutCenter, isLayoutExpand, isLayoutRight, isPressed, isShown, isStyleInitialised, itemCommandListener, itemHeight, itemWidth, label, labelStyle, layout, LAYOUT_2, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_DEFAULT, LAYOUT_EXPAND, LAYOUT_LEFT, LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE, LAYOUT_RIGHT, LAYOUT_SHRINK, LAYOUT_TOP, LAYOUT_VCENTER, LAYOUT_VEXPAND, LAYOUT_VSHRINK, marginBottom, marginLeft, marginRight, marginTop, maximumHeight, maximumWidth, minimumHeight, minimumWidth, NO_POSITION_SET, opacity, opacityPaintNormally, opacityRgbData, paddingBottom, paddingHorizontal, paddingLeft, paddingRight, paddingTop, paddingVertical, parent, PLAIN, preferredHeight, preferredWidth, preserveViewType, relativeX, relativeY, rowSpan, screen, style, TRANSPARENT, useSingleRow, VERTICAL, view
 
Constructor Summary
DateField(java.lang.String label, int mode)
          Creates a DateField object with the specified label and mode.
DateField(java.lang.String label, int mode, Style style)
          Creates a DateField object with the specified label and mode.
DateField(java.lang.String label, int mode, java.util.TimeZone timeZone)
          Creates a date field in which calendar calculations are based on specific TimeZone object and the default calendaring system for the current locale.
DateField(java.lang.String label, int mode, java.util.TimeZone timeZone, Style style)
          Creates a date field in which calendar calculations are based on specific TimeZone object and the default calendaring system for the current locale.
 
Method Summary
 boolean animate()
          Animates this item.
 void commandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Displayable box)
           
 void commandAction(javax.microedition.lcdui.Command c, Item item)
          Called by the system to indicate that a command has been invoked on a particular item.
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this item.
protected  void defocus(Style originalStyle)
          Removes the focus from this item.
 void fieldChanged(Field field, int context)
           
 java.util.Date getDate()
          Returns date value of this field.
 int getInputMode()
          Gets input mode for this date field.
protected  boolean handleKeyPressed(int keyCode, int gameAction)
          Handles the key-pressed event.
protected  void initContent(int firstLineWidth, int lineWidth)
          Initialises this item.
 void paintContent(int x, int y, int leftBorder, int rightBorder, javax.microedition.lcdui.Graphics g)
          Paints the content of this item.
 void setDate(java.util.Date date)
          Sets a new value for this field.
 void setInputMode(int mode)
          Set input mode for this date field.
 void setItemCommandListener(ItemCommandListener l)
          Sets a listener for Commands to this Item, replacing any previous ItemCommandListener.
 void setStyle(Style style)
          Sets the style of this item.
 
Methods inherited from class de.enough.polish.ui.StringItem
animate, getFont, getFontHeight, getText, hideNotify, releaseResources, setFont, setText, setText, setTextColor, showNotify, stringWidth, toString
 
Methods inherited from class de.enough.polish.ui.Item
addCommand, addCommand, addCommands, addRelativeToBackgroundRegion, addRelativeToBackgroundRegion, addRelativeToContentRegion, containsCommand, focus, getAbsoluteX, getAbsoluteY, getAppearanceMode, getAttribute, getAttributes, getBackgroundHeight, getBackgroundWidth, getBackgroundX, getBackgroundY, getContentHeight, getContentWidth, getContentX, getContentY, getDefaultCommand, getFocusedStyle, getItemAt, getItemCommandListener, getItemCommands, getItemHeight, getItemStateListener, getItemWidth, getLabel, getLabelItem, getLayout, getMinimumHeight, getMinimumWidth, getParent, getPreferredHeight, getPreferredWidth, getScreen, getStyle, handleCommand, handleKeyReleased, handleKeyRepeated, handlePointerPressed, handlePointerReleased, init, initStyle, isInContentArea, isInItemArea, isInItemArea, isInitialized, isVisible, notifyItemPressedEnd, notifyItemPressedStart, notifyStateChanged, paint, paintBackground, paintBackgroundAndBorder, paintBorder, removeCommand, repaint, repaint, repaintFully, requestInit, setAppearanceMode, setAttribute, setDefaultCommand, setItemCommandListener, setItemStateListener, setLabel, setLayout, setParent, setParent, setPreferredSize, setVisible, show, showCommands
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATE

public static final int DATE
Input mode for date information (day, month, year). With this mode this DateField presents and allows only to modify date value. The time information of date object is ignored.

Value 1 is assigned to DATE.

See Also:
Constant Field Values

TIME

public static final int TIME
Input mode for time information (hours and minutes). With this mode this DateField presents and allows only to modify time. The date components should be set to the "zero epoch" value of January 1, 1970 and should not be accessed.

Value 2 is assigned to TIME.

See Also:
Constant Field Values

DATE_TIME

public static final int DATE_TIME
Input mode for date (day, month, year) and time (minutes, hours) information. With this mode this DateField presents and allows to modify both time and date information.

Value 3 is assigned to DATE_TIME.

See Also:
Constant Field Values
Constructor Detail

DateField

public DateField(java.lang.String label,
                 int mode)
Creates a DateField object with the specified label and mode. This call is identical to DateField(label, mode, null).

Parameters:
label - item label
mode - the input mode, one of DATE, TIME or DATE_TIME
Throws:
java.lang.IllegalArgumentException - if the input mode's value is invalid

DateField

public DateField(java.lang.String label,
                 int mode,
                 Style style)
Creates a DateField object with the specified label and mode. This call is identical to DateField(label, mode, null).

Parameters:
label - item label
mode - the input mode, one of DATE, TIME or DATE_TIME
style - the CSS style for this item
Throws:
java.lang.IllegalArgumentException - if the input mode's value is invalid

DateField

public DateField(java.lang.String label,
                 int mode,
                 java.util.TimeZone timeZone)
Creates a date field in which calendar calculations are based on specific TimeZone object and the default calendaring system for the current locale. The value of the DateField is initially in the "uninitialized" state. If timeZone is null, the system's default time zone is used.

Parameters:
label - item label
mode - the input mode, one of DATE, TIME or DATE_TIME
timeZone - a specific time zone, or null for the default time zone
Throws:
java.lang.IllegalArgumentException - if the input mode's value is invalid

DateField

public DateField(java.lang.String label,
                 int mode,
                 java.util.TimeZone timeZone,
                 Style style)
Creates a date field in which calendar calculations are based on specific TimeZone object and the default calendaring system for the current locale. The value of the DateField is initially in the "uninitialized" state. If timeZone is null, the system's default time zone is used.

Parameters:
label - item label
mode - the input mode, one of DATE, TIME or DATE_TIME
timeZone - a specific time zone, or null for the default time zone
style - the CSS style for this item
Throws:
java.lang.IllegalArgumentException - if the input mode's value is invalid
Method Detail

getDate

public java.util.Date getDate()
Returns date value of this field. Returned value is null if field value is not initialized. The date object is constructed according the rules of locale specific calendaring system and defined time zone. In TIME mode field the date components are set to the "zero epoch" value of January 1, 1970. If a date object that presents time beyond one day from this "zero epoch" then this field is in "not initialized" state and this method returns null. In DATE mode field the time component of the calendar is set to zero when constructing the date object.

Returns:
date object representing time or date depending on input mode
See Also:
setDate(java.util.Date)

setDate

public void setDate(java.util.Date date)
Sets a new value for this field. null can be passed to set the field state to "not initialized" state. The input mode of this field defines what components of passed Date object is used.

In TIME input mode the date components must be set to the "zero epoch" value of January 1, 1970. If a date object that presents time beyond one day then this field is in "not initialized" state. In TIME input mode the date component of Date object is ignored and time component is used to precision of minutes.

In DATE input mode the time component of Date object is ignored.

In DATE_TIME input mode the date and time component of Date are used but only to precision of minutes.

Parameters:
date - new value for this field
See Also:
getDate()

getInputMode

public int getInputMode()
Gets input mode for this date field. Valid input modes are DATE, TIME and DATE_TIME.

Returns:
input mode of this field
See Also:
setInputMode(int)

setInputMode

public void setInputMode(int mode)
Set input mode for this date field. Valid input modes are DATE, TIME and DATE_TIME.

Parameters:
mode - the input mode, must be one of DATE, TIME or DATE_TIME
Throws:
java.lang.IllegalArgumentException - if an invalid value is specified
See Also:
getInputMode()

paintContent

public void paintContent(int x,
                         int y,
                         int leftBorder,
                         int rightBorder,
                         javax.microedition.lcdui.Graphics g)
Description copied from class: Item
Paints the content of this item. The background has already been painted and the border will be added after this method returns.

Overrides:
paintContent in class StringItem
Parameters:
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
g - the Graphics on which this item should be painted.

initContent

protected void initContent(int firstLineWidth,
                           int lineWidth)
Description copied from class: Item
Initialises this item. The implementation needs to calculate and set the contentWidth and contentHeight fields. The implementation should take the fields preferredWidth and preferredHeight into account.

Overrides:
initContent in class StringItem
Parameters:
firstLineWidth - the maximum width of the first line
lineWidth - the maximum width of any following lines
See Also:
Item.contentWidth, Item.contentHeight, Item.preferredWidth, Item.preferredHeight

createCssSelector

protected java.lang.String createCssSelector()
Description copied from class: Item
Retrieves the CSS selector for this item. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the item and not by a predefined style-name. With the #style preprocessing command styles are set fix, this method yields in a faster GUI and is recommended. When in a style-sheet dynamic styles are used, e.g. "Form>p", than the selector of the item is needed.
This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles
The returned selector needs to be in lower case.

Overrides:
createCssSelector in class StringItem
Returns:
the appropriate CSS selector for this item. The selector needs to be in lower case.

setStyle

public void setStyle(Style style)
Description copied from class: Item
Sets the style of this item.

Overrides:
setStyle in class StringItem
Parameters:
style - the new style for this item.

animate

public boolean animate()
Description copied from class: Item
Animates this item. Subclasses can override this method to create animations. The default implementation returns false

Overrides:
animate in class Item
Returns:
true when this item has been animated.
See Also:
Item.animate(long, ClippingRegion)

defocus

protected void defocus(Style originalStyle)
Description copied from class: Item
Removes the focus from this item.

Overrides:
defocus in class StringItem
Parameters:
originalStyle - the original style which will be restored.

handleKeyPressed

protected boolean handleKeyPressed(int keyCode,
                                   int gameAction)
Description copied from class: Item
Handles the key-pressed event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed. The default implementation just handles the FIRE game-action when a default-command and an item-command-listener have been registered.

Overrides:
handleKeyPressed in class Item
Parameters:
keyCode - the code of the pressed key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key has been handled / recognized

commandAction

public void commandAction(javax.microedition.lcdui.Command cmd,
                          javax.microedition.lcdui.Displayable box)
Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener

setItemCommandListener

public void setItemCommandListener(ItemCommandListener l)
Description copied from class: Item
Sets a listener for Commands to this Item, replacing any previous ItemCommandListener. A null reference is allowed and has the effect of removing any existing listener. When no listener is registered, J2ME Polish notifies the command-listener of the current screen, when an item command has been selected.

It is illegal to call this method if this Item is contained within an Alert.

Overrides:
setItemCommandListener in class Item
Parameters:
l - the new listener, or null.

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          Item item)
Description copied from interface: ItemCommandListener
Called by the system to indicate that a command has been invoked on a particular item.

Specified by:
commandAction in interface ItemCommandListener
Parameters:
c - the Command that was invoked
item - the Item on which the command was invoked

fieldChanged

public void fieldChanged(Field field,
                         int context)