dateeditor.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,806 行 · 第 1/4 页
JAVA
1,806 行
*/ void show() { // refresh the edit date to value stored in DateField each time editDate = Calendar.getInstance(); Date date = lf.df.getDate(); if (date != null) { editDate.setTime(date); } selectedDate = hilightedDate = editDate.get(Calendar.DATE); amSelected = amHilighted = false; if (editDate.get(Calendar.AM_PM) == Calendar.AM) { amSelected = true; amHilighted = true; } switch (mode) { case DateField.DATE: case DateField.DATE_TIME: focusOn = MONTH_POPUP; break; case DateField.TIME: focusOn = HOURS_POPUP; break; default: Logging.report(Logging.ERROR, LogChannels.LC_HIGHUI, "DateEditor.show(), mode=" +mode); break; } popUpOpen = true; ScreenLFImpl sLF = (ScreenLFImpl)lf.df.owner.getLF(); sLF.lGetCurrentDisplay().showPopup(this); } /** * Hide all sub-popups triggered by this date editor. */ void hideAllPopups() { if (monthPopup != null) monthPopup.hide(); if (yearPopup != null) yearPopup.hide(); if (hoursPopup != null) hoursPopup.hide(); if (minutesPopup != null) minutesPopup.hide(); popUpOpen = false; } // *********** private ************ // /** * Populate the date components. */ protected void populateDateComponents() { // populate MONTHS[] MONTHS = new String[DateFieldLFImpl.MONTH_NAMES.length]; for (int i = 0; i < DateFieldLFImpl.MONTH_NAMES.length; i++) { MONTHS[i] = DateFieldLFImpl.MONTH_NAMES[i].substring(0, 3); } monthPopup = new DEPopupLayer(this, MONTHS, editDate.get(Calendar.MONTH), true); // populate YEARS[] int selectedIndex = createYearStrings(editDate.get(Calendar.YEAR) - 10); yearPopup = new DEPopupLayer(this, YEARS, selectedIndex, false); } /** * Recreates years string given a start year. * @param startYear the first year to be added to the YEARS array * @return selected year in the newly created array */ protected int createYearStrings(int startYear) { int selectedIndex = 0; int year = startYear; YEARS = new String[22]; YEARS[0] = Resource.getString(ResourceConstants.LCDUI_DF_YEAR_BEFORE); YEARS[21] = Resource.getString(ResourceConstants.LCDUI_DF_YEAR_AFTER); for (int i = 1; i < 21; i++) { if (year == editDate.get(Calendar.YEAR)) { selectedIndex = i; } YEARS[i] = Integer.toString(year++); } return selectedIndex; } /** * Populate the time components. */ protected void populateTimeComponents() { int selectedIndex = 0; // populate HOURS[] String[] hours; if (lf.CLOCK_USES_AM_PM) { HOURS = new int[12]; hours = new String[12]; selectedIndex = editDate.get(Calendar.HOUR) - 1; if (selectedIndex < 0) { selectedIndex = 11; } for (int i = 0; i < 12; i++) { HOURS[i] = i + 1; hours[i] = Integer.toString(i + 1); } } else { HOURS = new int[24]; hours = new String[24]; selectedIndex = editDate.get(Calendar.HOUR_OF_DAY); for (int i = 0; i < 24; i++) { HOURS[i] = i; hours[i] = Integer.toString(i); } } hoursPopup = new DEPopupLayer(this, hours, selectedIndex, true); // populate MINUTES[] selectedIndex = 0; MINUTES = new int[60]; String[] minutes = new String[60]; int minute = editDate.get(Calendar.MINUTE); for (int i = 0; i < 60; i++) { if (i == minute) { selectedIndex = i; } MINUTES[i] = i; minutes[i] = Integer.toString(i); } minutesPopup = new DEPopupLayer(this, minutes, selectedIndex, true); } /** * Set popup location and bounds * * @param popup popup to relocate * @param image background image of popup * @param bounds relative bounds of the popup layer */ protected void setPopupLocation( DEPopupLayer popup, Image image, int []bounds) { int x = this.bounds[X] + bounds[X]; int y = this.bounds[Y] + bounds[Y]; int w = image.getWidth(); int h = image.getHeight(); popup.setElementSize( w - 4, DateEditorSkin.FONT_POPUPS.getHeight()); popup.setBounds(x, y + h, w, DateEditorSkin.HEIGHT_POPUPS); popup.updateScrollIndicator(); bounds[W]= w; bounds[H]= h; } /** * Set month popup location using upper left corner coordinate of the * DateEditor layer and relative coordinates of the popup anchor. */ protected void setMonthPopupLocation() { setPopupLocation(monthPopup, DateEditorSkin.IMAGE_MONTH_BG, month_bounds); } /** * Set year popup location using upper left corner coordinate of the * DateEditor layer and relative coordinates of the popup anchor. */ protected void setYearPopupLocation() { setPopupLocation(yearPopup, DateEditorSkin.IMAGE_YEAR_BG, year_bounds); } /** * Set hours popup location using upper left corner coordinate of the * DateEditor layer and relative coordinates of the popup anchor. */ protected void setHoursPopupLocation() { setPopupLocation(hoursPopup, DateEditorSkin.IMAGE_TIME_BG, hours_bounds); } /** * Set minutes popup location using upper left corner coordinate of the * DateEditor layer and relative coordinates of the popup anchor. */ protected void setMinutesPopupLocation() { setPopupLocation(minutesPopup, DateEditorSkin.IMAGE_TIME_BG, minutes_bounds); } /** * Draws month popup content. * @param g The Graphics object to paint to */ protected void drawMonthComponent(Graphics g) { Image bgImg; int w = 0; if (ScreenSkin.RL_DIRECTION) { bgImg = DateEditorSkin.IMAGE_MONTH_HE_BG; } else { bgImg = DateEditorSkin.IMAGE_MONTH_BG; } if (bgImg != null) { g.drawImage(bgImg, 0, 0, Graphics.LEFT | Graphics.TOP); w = bgImg.getWidth(); int h = bgImg.getHeight(); if (focusOn == MONTH_POPUP) { g.setColor(DateEditorSkin.COLOR_TRAVERSE_IND); g.drawRect(-2, -2, w + 3, h + 3); } } g.setFont(DateEditorSkin.FONT_POPUPS); g.setColor(0); int textOffset = 3; w = DateEditorSkin.IMAGE_MONTH_BG.getWidth(); if (ScreenSkin.RL_DIRECTION) { textOffset = w - textOffset; } g.drawString(MONTHS[editDate.get(Calendar.MONTH)], textOffset, 0, ScreenSkin.TEXT_ORIENT | Graphics.TOP); } /** * Draws year popup content. * @param g The Graphics object to paint to */ protected void drawYearComponent(Graphics g) { Image bgImg; int w = 0; if (ScreenSkin.RL_DIRECTION) { bgImg = DateEditorSkin.IMAGE_YEAR_HE_BG; } else { bgImg = DateEditorSkin.IMAGE_YEAR_BG; } if (bgImg != null) { g.drawImage(bgImg, 0, 0, Graphics.LEFT | Graphics.TOP); w = bgImg.getWidth(); int h = bgImg.getHeight(); if (focusOn == YEAR_POPUP) { g.setColor(DateEditorSkin.COLOR_TRAVERSE_IND); g.drawRect(-2, -2, w + 3, h + 3); } } int textOffset = 3; if (ScreenSkin.RL_DIRECTION) { textOffset = w - textOffset; } g.setFont(DateEditorSkin.FONT_POPUPS); g.setColor(0); g.drawString(Integer.toString(editDate.get(Calendar.YEAR)), textOffset, 0, ScreenSkin.TEXT_ORIENT | Graphics.TOP); } /** * Draws hours popup content. * @param g The Graphics object to paint to */ protected void drawHoursComponent(Graphics g) { Image bgImg; if (ScreenSkin.RL_DIRECTION) { bgImg = DateEditorSkin.IMAGE_TIME_HE_BG; } else { bgImg = DateEditorSkin.IMAGE_TIME_BG; } if (bgImg != null) { g.drawImage(bgImg, 0, 0, Graphics.LEFT | Graphics.TOP); int w = bgImg.getWidth(); int h = bgImg.getHeight(); if (focusOn == HOURS_POPUP) { g.setColor(DateEditorSkin.COLOR_TRAVERSE_IND); g.drawRect(-2, -2, w + 3, h + 3); } } g.setFont(DateEditorSkin.FONT_POPUPS); g.setColor(0); int hour; if (lf.CLOCK_USES_AM_PM) { hour = editDate.get(Calendar.HOUR) == 0 ? 12 : editDate.get(Calendar.HOUR) % 12; } else { hour = editDate.get(Calendar.HOUR_OF_DAY); } int textOffset = 3; int w = bgImg.getWidth(); if (ScreenSkin.RL_DIRECTION) { textOffset = w - textOffset; } g.drawString(DateFieldLFImpl.twoDigits(hour), textOffset, 0, ScreenSkin.TEXT_ORIENT | Graphics.TOP); } /** * Draws minutes popup content. * @param g The Graphics object to paint to */ protected void drawMinutesComponent(Graphics g) { Image bgImg; if (ScreenSkin.RL_DIRECTION) { bgImg = DateEditorSkin.IMAGE_TIME_HE_BG; } else { bgImg = DateEditorSkin.IMAGE_TIME_BG; } if (bgImg != null) { g.drawImage(bgImg, 0, 0, Graphics.LEFT | Graphics.TOP); int w = bgImg.getWidth(); int h = bgImg.getHeight(); if (focusOn == MINUTES_POPUP) { g.setColor(DateEditorSkin.COLOR_TRAVERSE_IND); g.drawRect(-2, -2, w + 3, h + 3); } } int textOffset = 3; int w = bgImg.getWidth(); if (ScreenSkin.RL_DIRECTION) { textOffset = w - textOffset; } g.setFont(DateEditorSkin.FONT_POPUPS); g.setColor(0); g.drawString(DateFieldLFImpl.twoDigits(editDate.get(Calendar.MINUTE)), textOffset, 0, ScreenSkin.TEXT_ORIENT | Graphics.TOP); } /** * Draw the date components. * @param g The Graphics object to paint to */ protected void drawDateComponents(Graphics g) { g.translate(month_bounds[X], month_bounds[Y]); drawMonthComponent(g); g.translate(-month_bounds[X], -month_bounds[Y]); g.translate(year_bounds[X], year_bounds[Y]); drawYearComponent(g); g.translate(-year_bounds[X], -year_bounds[Y]); g.translate(calendar_bounds[X], calendar_bounds[Y]); paintCalendar(g); g.translate(-calendar_bounds[X], -calendar_bounds[Y]); } /** * Draw the time components. * @param g The Graphics object to paint to */ protected void drawTimeComponents(Graphics g) { g.translate(hours_bounds[X], hours_bounds[Y]); drawHoursComponent(g); g.translate(-hours_bounds[X], -hours_bounds[Y]); g.translate(minutes_bounds[X], minutes_bounds[Y]); drawMinutesComponent(g); g.translate(-minutes_bounds[X], -minutes_bounds[Y]); g.translate(ampm_bounds[X], ampm_bounds[Y]); paintAmPm(g); g.translate(-ampm_bounds[X], -ampm_bounds[Y]); } /** * Paint the Calendar background * @param g The Graphics context to paint to */ protected void paintCalBg(Graphics g) { if (DateEditorSkin.IMAGE_CAL_BG == null || DateEditorSkin.IMAGE_DAYS == null) { return; } g.drawImage(DateEditorSkin.IMAGE_CAL_BG, 0, 0, Graphics.LEFT | Graphics.TOP); // paint days of week int wBg = DateEditorSkin.IMAGE_DAYS.getWidth(); int hBg = DateEditorSkin.IMAGE_DAYS.getHeight(); int w = wBg / 7; int o = Resource.getFirstDayOfWeek(); int xBg = 5; int x = (o - 1) * w; for (int i = 0; i < 7; i++) { g.drawRegion(DateEditorSkin.IMAGE_DAYS, x, 0, w, hBg, Sprite.TRANS_NONE, xBg, 0, Graphics.TOP | Graphics.HCENTER); xBg += w; x += w; if ( x >= wBg ) { x -= wBg; } } } /** * Paint the Calendar. * @param g The Graphics context to paint to */ protected void paintCalendar(Graphics g) { if (DateEditorSkin.IMAGE_CAL_BG == null || DateEditorSkin.IMAGE_DAYS == null || DateEditorSkin.IMAGE_DATES == null) { return; } paintCalBg(g); if (DateEditorSkin.IMAGE_DATES == null) { return; } g.translate(2, 0); int o = DateEditorSkin.IMAGE_CAL_BG.getWidth() / 7; int rowH = 11; int h = DateEditorSkin.IMAGE_DATES.getHeight() / 31; int w = DateEditorSkin.IMAGE_DATES.getWidth(); // draw calendar int x = 5 + ((dayOffset - 1) * o); int y = h + 4;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?