DateFieldLFImplpublic class DateFieldLFImpl extends ItemLFImpl implements DateFieldLFThis is the Look & Feel implementation for DateField. |
Fields Summary |
---|
static final String[] | MONTH_NAMESStatic array holding the names of the 12 months. | static final boolean | CLOCK_USES_AM_PMFlag to signal the clock representation uses AM and PM notation.
This is dummy right now, and always set to true since there is
not easy to find out from the system if the clock is using a
12-hour or 24-hour mode. | DateField | dfDateField associated with this view. | private Calendar | currentDateCurrent date being handled by this datefield impl. | int | modeCurrent input mode being handled by this datefield impl. | private boolean | traversedInA flag indicating a prior call to uCallTraverse() | DateEditor | editorThe editor for this DateField. |
Constructors Summary |
---|
DateFieldLFImpl(DateField dateField)Creates DateFieldLF for the passed in DateField object.
super(dateField);
DateFieldResources.load();
DateEditorResources.load();
df = dateField;
if (editor == null) {
editor = new DateEditor(this);
}
|
Methods Summary |
---|
static java.lang.String | ampmString(java.util.Calendar calendar)Get the am/pm text given a Calendar.
if (!CLOCK_USES_AM_PM) {
return null;
}
return (calendar.get(Calendar.AM_PM) == Calendar.AM) ?
Resource.getString(ResourceConstants.LCDUI_DF_AM) :
Resource.getString(ResourceConstants.LCDUI_DF_PM);
| static java.lang.String | dayOfWeekString(java.util.Calendar calendar)Get the localized day of the week text given a Calendar.
String str;
switch (calendar.get(Calendar.DAY_OF_WEEK)) {
case Calendar.SUNDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_SUN);
break;
case Calendar.MONDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_MON);
break;
case Calendar.TUESDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_TUE);
break;
case Calendar.WEDNESDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_WED);
break;
case Calendar.THURSDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_THU);
break;
case Calendar.FRIDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_FRI);
break;
case Calendar.SATURDAY:
str = Resource.getString(ResourceConstants.LCDUI_DF_SAT);
break;
default:
str = Integer.toString(calendar.get(Calendar.DAY_OF_WEEK));
break;
}
return str;
| void | drawButtonBG(Graphics g, int x, int y, int w, int h)Draw background of button
if (DateFieldSkin.IMAGE_BUTTON_BG != null) {
CGraphicsUtil.draw9pcsBackground(g, x, y, w, h,
DateFieldSkin.IMAGE_BUTTON_BG);
}
| boolean | equateNLA()Determine if this Item should have a newline after it
if (super.equateNLA()) {
return true;
}
return ((df.layout & Item.LAYOUT_2) != Item.LAYOUT_2);
| boolean | equateNLB()Determine if this Item should have a newline before it
if (super.equateNLB()) {
return true;
}
return ((df.layout & Item.LAYOUT_2) != Item.LAYOUT_2);
| static java.lang.String | getHourString(java.util.Calendar calendar)Get the hour given a Calendar, based on a 12-hour or 24-hour clock.
if (CLOCK_USES_AM_PM) {
int hour = calendar.get(Calendar.HOUR);
return (hour == 0) ? "12" : "" + hour;
} else {
return Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
}
| boolean | lCallTraverse(int dir, int viewportWidth, int viewportHeight, int[] visRect)Called by the system to traverse this DateField.
super.lCallTraverse(dir, viewportWidth, viewportHeight, visRect);
visRect[X] = 0;
visRect[Y] = 0;
visRect[HEIGHT] = bounds[HEIGHT];
visRect[WIDTH] = bounds[WIDTH];
if (!editor.isPopupOpen()) {
if (!traversedIn) {
traversedIn = true;
return true;
}
}
return false;
| void | lCallTraverseOut()Called by the system to indicate traversal has left this Item.
super.lCallTraverseOut();
traversedIn = false;
if (editor.isPopupOpen()) {
editor.hideAllPopups();
getCurrentDisplay().hidePopup(editor);
}
| void | lGetContentSize(int[] size, int availableWidth)Sets the content size in the passed in array.
Content is calculated based on the availableWidth.
size[WIDTH] and size[HEIGHT] should be set by this method.
Font f = DateFieldSkin.FONT;
size[HEIGHT] = f.getHeight() + (2 * DateFieldSkin.PAD_V);
int mode = df.mode;
size[WIDTH] =
f.stringWidth(toString(df.currentDate, mode, df.initialized)) +
(2 * DateFieldSkin.PAD_H);
switch (mode) {
case DateField.DATE:
if (DateFieldSkin.IMAGE_ICON_DATE != null) {
size[WIDTH] += DateFieldSkin.IMAGE_ICON_DATE.getWidth();
}
if (size[WIDTH] < DateEditorSkin.WIDTH_DATE) {
size[WIDTH] = DateEditorSkin.WIDTH_DATE;
}
break;
case DateField.TIME:
if (DateFieldSkin.IMAGE_ICON_TIME != null) {
size[WIDTH] += DateFieldSkin.IMAGE_ICON_TIME.getWidth();
}
if (size[WIDTH] < DateEditorSkin.WIDTH_TIME) {
size[WIDTH] = DateEditorSkin.WIDTH_TIME;
}
break;
case DateField.DATE_TIME:
if (DateFieldSkin.IMAGE_ICON_DATETIME != null) {
size[WIDTH] +=
DateFieldSkin.IMAGE_ICON_DATETIME.getWidth();
}
if (size[WIDTH] < DateEditorSkin.WIDTH_DATETIME) {
size[WIDTH] = DateEditorSkin.WIDTH_DATETIME;
}
break;
default:
// for safety/completeness.
Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI,
"DateFieldLFImpl: mode=" + mode);
break;
}
if (size[WIDTH] > availableWidth) {
size[WIDTH] = availableWidth;
}
| public java.util.Date | lGetDate()Gets the date currently set on the date field widget.
This method is called by Date only if Date is initialized.
return new java.util.Date(df.currentDate.getTime().getTime());
| void | lPaintContent(Graphics g, int width, int height)Paints the content area of this DateField.
Graphics is translated to contents origin.
currentDate = df.currentDate;
mode = df.mode;
// draw background
if (DateFieldSkin.IMAGE_BG != null) {
CGraphicsUtil.draw9pcsBackground(g, 0, 0, width, height,
DateFieldSkin.IMAGE_BG);
} else {
// draw widget instead of using images
CGraphicsUtil.drawDropShadowBox(g, 0, 0, width, height,
DateFieldSkin.COLOR_BORDER,
DateFieldSkin.COLOR_BORDER_SHD,
DateFieldSkin.COLOR_BG);
}
// draw icon
int iconWidth = 0;
switch (mode) {
case DateField.DATE:
if (DateFieldSkin.IMAGE_ICON_DATE != null) {
iconWidth = DateFieldSkin.IMAGE_ICON_DATE.getWidth();
int yOffset = height -
DateFieldSkin.IMAGE_ICON_DATE.getHeight();
if (yOffset > 0) {
yOffset = (int)(yOffset / 2);
} else {
yOffset = 0;
}
drawButtonBG(g, width - iconWidth, 0, iconWidth, height);
g.drawImage(DateFieldSkin.IMAGE_ICON_DATE,
width - iconWidth, yOffset,
Graphics.LEFT | Graphics.TOP);
}
break;
case DateField.TIME:
if (DateFieldSkin.IMAGE_ICON_TIME != null) {
iconWidth = DateFieldSkin.IMAGE_ICON_TIME.getWidth();
int yOffset = height -
DateFieldSkin.IMAGE_ICON_DATE.getHeight();
if (yOffset > 0) {
yOffset = (int)(yOffset / 2);
} else {
yOffset = 0;
}
drawButtonBG(g, width - iconWidth, 0, iconWidth, height);
g.drawImage(DateFieldSkin.IMAGE_ICON_TIME,
width - iconWidth, yOffset,
Graphics.LEFT | Graphics.TOP);
}
break;
case DateField.DATE_TIME:
if (DateFieldSkin.IMAGE_ICON_DATETIME != null) {
iconWidth = DateFieldSkin.IMAGE_ICON_DATETIME.getWidth();
int yOffset = height -
DateFieldSkin.IMAGE_ICON_DATE.getHeight();
if (yOffset > 0) {
yOffset = (int)(yOffset / 2);
} else {
yOffset = 0;
}
drawButtonBG(g, width - iconWidth, 0, iconWidth, height);
g.drawImage(DateFieldSkin.IMAGE_ICON_DATETIME,
width - iconWidth, yOffset,
Graphics.LEFT | Graphics.TOP);
}
break;
default:
// for safety/completeness.
Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI,
"DateFieldLFImpl: mode=" + mode);
break;
}
// we clip in case our text is too long
g.clipRect(DateFieldSkin.PAD_H, DateFieldSkin.PAD_V,
width - (2 * DateFieldSkin.PAD_H) - iconWidth,
height - (2 * DateFieldSkin.PAD_V));
g.translate(DateFieldSkin.PAD_H, DateFieldSkin.PAD_V);
// paint value
g.setFont(DateFieldSkin.FONT);
g.setColor(DateFieldSkin.COLOR_FG);
g.drawString(toString(currentDate, mode, df.initialized),
0, 0, Graphics.LEFT | Graphics.TOP);
g.translate(-DateFieldSkin.PAD_H, -DateFieldSkin.PAD_V);
if (editor.isPopupOpen() && editor.isSizeChanged()) {
setPopupLocation();
}
| public void | lSetDate(java.util.Date date)Notifies Look & Feel of a date change in the corresponding DateField.
lRequestPaint();
| public void | lSetInputMode(int mode)Notifies Look & Feel of a new input mode set in the corresponding
DateField.
lRequestInvalidate(true, true);
| void | saveDate(java.util.Date date)Called from the Date Editor to save the selected Date.
synchronized (Display.LCDUILock) {
df.setDateImpl(date);
lSetDate(date);
}
| private void | setPopupLocation()Set location of popup layer
ScreenLFImpl sLF = (ScreenLFImpl)df.owner.getLF();
// decide where to show popup: above, below or in
// the middle of the screen (if both above/below don't
// work out)
int[] avalibleBounds = sLF.lGetCurrentDisplay().getBodyLayerBounds();
int x = bounds[X] + contentBounds[X] + DateFieldSkin.PAD_V - sLF.viewable[X];
int y = bounds[Y] + contentBounds[Y] - sLF.viewable[Y];
if (y - DateEditorSkin.HEIGHT >= 0) {
// can fit above
y -= DateEditorSkin.HEIGHT - DateFieldSkin.PAD_V - avalibleBounds[Y];
} else if (y + contentBounds[HEIGHT] + DateEditorSkin.HEIGHT + 2 * DateFieldSkin.PAD_V < avalibleBounds[HEIGHT]) {
// can fit below
y += contentBounds[HEIGHT] + 2 * DateFieldSkin.PAD_V + avalibleBounds[Y];
} else {
// fit in the middle of screen
y = avalibleBounds[Y] + (avalibleBounds[HEIGHT] / 2) -
(DateEditorSkin.HEIGHT / 2);
}
editor.setLocation(x, y);
| boolean | shouldSkipTraverse()Indicate whether or not traversing should occur.
return false;
| static java.lang.String | toString(java.util.Calendar currentDate, int mode, boolean initialized)Translate the mode of a DateField into a readable string.
String str = null;
if (!initialized) {
switch (mode) {
case DateField.DATE:
str = Resource.getString(ResourceConstants.LCDUI_DF_DATE);
break;
case DateField.TIME:
str = Resource.getString(ResourceConstants.LCDUI_DF_TIME);
break;
case DateField.DATE_TIME:
str = Resource.getString(
ResourceConstants.LCDUI_DF_DATETIME);
break;
default:
// for safety/completeness.
Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI,
"DateFieldLFImpl: mode=" + mode);
break;
}
} else {
switch (mode) {
case DateField.DATE:
str = Resource.getDateString(
dayOfWeekString(currentDate),
"" + currentDate.get(Calendar.DATE),
MONTH_NAMES[currentDate.get(Calendar.MONTH)].
substring(0, 3),
Integer.toString(currentDate.get(Calendar.YEAR)));
break;
case DateField.TIME:
str = Resource.getTimeString(getHourString(currentDate),
"" + twoDigits(currentDate.get(Calendar.MINUTE)),
"" + currentDate.get(Calendar.SECOND),
ampmString(currentDate));
break;
case DateField.DATE_TIME:
str = Resource.getDateTimeString(
dayOfWeekString(currentDate),
Integer.toString(currentDate.get(Calendar.DATE)),
MONTH_NAMES[currentDate.get(Calendar.MONTH)].
substring(0, 3),
Integer.toString(currentDate.get(Calendar.YEAR)),
getHourString(currentDate),
twoDigits(currentDate.get(Calendar.MINUTE)),
Integer.toString(currentDate.get(Calendar.SECOND)),
ampmString(currentDate));
break;
default:
// for safety/completeness.
Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI,
"DateFieldLFImpl: mode=" + mode);
break;
}
}
return str;
| static java.lang.String | twoDigits(int n)A utility method to return a numerical digit as two digits
if it is less than 10 (used to display time in 2 digits
if required, eg. 6:09pm).
if (n == 0) {
return "00";
} else if (n < 10) {
return "0" + n;
} else {
return "" + n;
}
| void | uCallKeyPressed(int keyCode)Called by the system to signal a key press.
if (keyCode != Constants.KEYCODE_SELECT) {
return;
}
synchronized (Display.LCDUILock) {
if (!editor.isPopupOpen()) {
setPopupLocation();
editor.show();
} else {
editor.hideAllPopups();
getCurrentDisplay().hidePopup(editor);
}
} // synchronized
uRequestPaint();
| void | uCallSizeChanged(int w, int h)Called by the system to indicate the size available to this Item
has changed
super.uCallSizeChanged(w,h);
synchronized (Display.LCDUILock) {
editor.setSizeChanged();
}
|
|