datefieldlfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 659 行 · 第 1/2 页
JAVA
659 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package javax.microedition.lcdui;import java.util.Calendar;import java.util.Date;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.configurator.Constants;import com.sun.midp.chameleon.*;import com.sun.midp.chameleon.skins.DateFieldSkin;import com.sun.midp.chameleon.skins.resources.DateFieldResources;import com.sun.midp.chameleon.skins.DateEditorSkin;import com.sun.midp.chameleon.skins.ScreenSkin;import com.sun.midp.chameleon.skins.resources.DateEditorResources;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;/** * This is the Look & Feel implementation for DateField. */class DateFieldLFImpl extends ItemLFImpl implements DateFieldLF { /** * Creates DateFieldLF for the passed in DateField object. * @param dateField the DateField object associated with this view */ DateFieldLFImpl(DateField dateField) { super(dateField); DateFieldResources.load(); DateEditorResources.load(); df = dateField; if (editor == null) { editor = new DateEditor(this); } } // ***************************************************** // Package private methods // ***************************************************** /** * Notifies Look & Feel of a date change in the corresponding DateField. * @param date - the new Date set in the DateField */ public void lSetDate(java.util.Date date) { lRequestPaint(); } /** * Notifies Look & Feel of a new input mode set in the corresponding * DateField. * @param mode the new input mode set in the DateField. */ public void lSetInputMode(int mode) { lRequestInvalidate(true, true); } /** * Gets the date currently set on the date field widget. * This method is called by Date only if Date is initialized. * @return the date this widget is currently set to */ public Date lGetDate() { return new java.util.Date(df.currentDate.getTime().getTime()); } // ***************************************************** // Package private methods // ***************************************************** /** * Indicate whether or not traversing should occur. * * @return <code>true</code> if traversing should be skipped; * </code>false</code>, if the field is editable. */ boolean shouldSkipTraverse() { return false; } /** * 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. * @param size The array that holds Item content size and location * in Item internal bounds coordinate system. * @param availableWidth The width available for this Item */ void lGetContentSize(int size[], int availableWidth) { 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; } } /** * Determine if this Item should have a newline after it * * @return true if it should have a newline after */ boolean equateNLA() { if (super.equateNLA()) { return true; } return ((df.layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** * Determine if this Item should have a newline before it * * @return true if it should have a newline before */ boolean equateNLB() { if (super.equateNLB()) { return true; } return ((df.layout & Item.LAYOUT_2) != Item.LAYOUT_2); } /** * Called from the Date Editor to save the selected Date. * * @param date The Date object to which current date should be set. */ void saveDate(java.util.Date date) { synchronized (Display.LCDUILock) { df.setDateImpl(date); lSetDate(date); } } /** * Paints the content area of this DateField. * Graphics is translated to contents origin. * @param g The graphics where DateField content should be painted * @param width The width available for the Item's content * @param height The height available for the Item's content */ void lPaintContent(Graphics g, int width, int height) { 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; int btnOffset = 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; } if (!ScreenSkin.RL_DIRECTION) { btnOffset = width - iconWidth; } drawButtonBG(g, btnOffset, 0, iconWidth, height); g.drawImage(DateFieldSkin.IMAGE_ICON_DATE, btnOffset, 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; } if (!ScreenSkin.RL_DIRECTION) { btnOffset = width - iconWidth; } drawButtonBG(g, btnOffset, 0, iconWidth, height); g.drawImage(DateFieldSkin.IMAGE_ICON_TIME, btnOffset, 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; } if (!ScreenSkin.RL_DIRECTION) { btnOffset = width - iconWidth; } drawButtonBG(g, btnOffset, 0, iconWidth, height); g.drawImage(DateFieldSkin.IMAGE_ICON_DATETIME, btnOffset, yOffset, Graphics.LEFT | Graphics.TOP); } break; default: // for safety/completeness. Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "DateFieldLFImpl: mode=" + mode); break; } int textOffset = DateFieldSkin.PAD_H; if (ScreenSkin.RL_DIRECTION) { textOffset = width - DateFieldSkin.PAD_H; } // we clip in case our text is too long g.clipRect(ScreenSkin.RL_DIRECTION ? DateFieldSkin.PAD_H + iconWidth : DateFieldSkin.PAD_H, DateFieldSkin.PAD_V, width - (2 * DateFieldSkin.PAD_H) - iconWidth, height - (2 * DateFieldSkin.PAD_V)); if (!ScreenSkin.RL_DIRECTION) { g.translate(DateFieldSkin.PAD_H, DateFieldSkin.PAD_V); textOffset = 0; } // paint value g.setFont(DateFieldSkin.FONT); g.setColor(DateFieldSkin.COLOR_FG); g.drawString(toString(currentDate, mode, df.initialized), textOffset, 0, ScreenSkin.TEXT_ORIENT | Graphics.TOP); if (!ScreenSkin.RL_DIRECTION) { g.translate(-DateFieldSkin.PAD_H, -DateFieldSkin.PAD_V); } if (editor.isPopupOpen() && editor.isSizeChanged()) { setPopupLocation(); } } /** * Draw background of button * @param g Graphics * @param x x coordinate * @param y y coordinate
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?