itemlfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,522 行 · 第 1/4 页
JAVA
1,522 行
/* * * * 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 com.sun.midp.lcdui.Text;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.configurator.Constants;import com.sun.midp.chameleon.skins.ScreenSkin;/*** This is the look &s; feel implementation for Item.*/abstract class ItemLFImpl implements ItemLF { /** * Creates look and feel for the passed in item * @param item the Item for which the Look and feel should be created */ ItemLFImpl(Item item) { this.item = item; actualBoundsInvalid = new boolean[] {true, true, true, true}; bounds = new int[] {0, 0, 0, 0}; target = new int[4]; labelBounds = new int[] {0, 0, 0, 0}; contentBounds = new int[] {0, 0, 0, 0}; } // ***************************************************** // Public methods - ItemLF interface implementation // ***************************************************** /** * Get the minimum width of this Item * * @return the minimum width */ public int lGetMinimumWidth() { // IMPL_NOTE minimum width should be less than preferred return lGetPreferredWidth(-1); } /** * Get the preferred width of this Item * * @param h the tentative content height in pixels, or -1 if a * tentative height has not been computed * @return the preferred width */ public int lGetPreferredWidth(int h) { int availableWidth = lGetAvailableWidth(); if (cachedWidth == INVALID_SIZE || cachedWidth != availableWidth) { lGetLabelSize(labelBounds, availableWidth); lGetContentSize(contentBounds, availableWidth); cachedWidth = availableWidth; } // no content if (contentBounds[HEIGHT] == 0) { return labelBounds[WIDTH]; } // no label if (labelBounds[HEIGHT] == 0) { return contentBounds[WIDTH]; } if (labelAndContentOnSameLine(labelBounds[HEIGHT]) && (labelBounds[WIDTH] + getHorizontalPad() + contentBounds[WIDTH] <= availableWidth)) { return labelBounds[WIDTH] + getHorizontalPad() + contentBounds[WIDTH]; } return (labelBounds[WIDTH] > contentBounds[WIDTH] ? labelBounds[WIDTH] : contentBounds[WIDTH]); } /** * Get the minimum height of this Item * * @return the minimum height */ public int lGetMinimumHeight() { // minimum height will be reached if we give item the most width return lGetPreferredHeight(-1); } /** * Get the preferred height of this Item * * @param w the tentative content width in pixels, or -1 if a * tentative width has not been computed * @return the preferred height */ public int lGetPreferredHeight(int w) { if (w == -1) { w = lGetAvailableWidth(); } if (cachedWidth == INVALID_SIZE || cachedWidth != w) { lGetLabelSize(labelBounds, w); lGetContentSize(contentBounds, w); cachedWidth = w; } // no content if (contentBounds[HEIGHT] == 0) { return labelBounds[HEIGHT]; } // no label if (labelBounds[HEIGHT] == 0) { return contentBounds[HEIGHT]; } if (labelAndContentOnSameLine(labelBounds[HEIGHT]) && (labelBounds[WIDTH] + getHorizontalPad() + contentBounds[WIDTH] <= w)) { return labelBounds[HEIGHT] < contentBounds[HEIGHT] ? contentBounds[HEIGHT] : labelBounds[HEIGHT]; } return labelBounds[HEIGHT] + getVerticalPad() + contentBounds[HEIGHT]; } /** * Returns if the pointer location (x, y, w.r.t. the Form origin) * is within the bounds of the 'clickable' area of this * ItemLFImpl. We exclude non-interactive areas such as the * label. <p> * * Most items can use this method. The only case that needs * overriding is the ChoiceGroupPopupLFImpl. */ boolean itemContainsPointer(int x, int y) { int contentX = bounds[X] + contentBounds[X] + ScreenSkin.PAD_FORM_ITEMS - 2; int contentY = bounds[Y] + contentBounds[Y] + ScreenSkin.PAD_FORM_ITEMS - 2; int myX = x - contentX; int myY = y - contentY; return (myX >= 0 && myX <= contentBounds[WIDTH] + ScreenSkin.PAD_FORM_ITEMS - 2 && myY >= 0 && myY <= contentBounds[HEIGHT] + ScreenSkin.PAD_FORM_ITEMS - 2); } /** * Returns if the pointer location (x, y, w.r.t. the Form origin) * is within the bounds of the 'clickable' area of this * ItemLFImpl. We exclude non-interactive areas such as the * label. <p> * * Most items can use this method. The only case that needs * overriding is the ChoiceGroupPopupLFImpl. */ int itemAcceptPointer(int x, int y) { int contentX = bounds[X] + contentBounds[X] + ScreenSkin.PAD_FORM_ITEMS - 2; int contentY = bounds[Y] + contentBounds[Y] + ScreenSkin.PAD_FORM_ITEMS - 2; int myX = x - contentX; int myY = y - contentY; if ((myX >= -ScreenSkin.TOUCH_RADIUS) && (myX <= contentBounds[WIDTH] + ScreenSkin.PAD_FORM_ITEMS - 2 + ScreenSkin.TOUCH_RADIUS)) { if ((myY < -ScreenSkin.TOUCH_RADIUS || myY > contentBounds[HEIGHT] + ScreenSkin.PAD_FORM_ITEMS - 2 + ScreenSkin.TOUCH_RADIUS)) { return -1; } else { if (myY >= 0 && myY <= contentBounds[HEIGHT] + ScreenSkin.PAD_FORM_ITEMS - 2 ) { return 0; } else { return Math.max(Math.abs(myY),Math.abs(myY - contentBounds[HEIGHT] + ScreenSkin.PAD_FORM_ITEMS - 2)); } } } return -1; } ItemLFImpl findNearestItem(ItemLFImpl secondItem, int x) { int x1 = bounds[X] + contentBounds[WIDTH]; int x2 = secondItem.bounds[X]; if ((x - x1) <= (x2 - x)) { return this; } else { return secondItem ; } } /** * Notifies L&F of a label change in the corresponding Item. * @param label the new label string */ public void lSetLabel(String label) { int[] oldBounds = new int[]{labelBounds[X],labelBounds[Y],labelBounds[WIDTH],labelBounds[HEIGHT]}; lGetLabelSize(labelBounds, lGetAvailableWidth()); if (labelBounds[X] == oldBounds[X] && labelBounds[Y] == oldBounds[Y] && labelBounds[WIDTH] == oldBounds[WIDTH] && labelBounds[HEIGHT] == oldBounds[HEIGHT]) { lRequestPaint(labelBounds[X],labelBounds[Y],labelBounds[WIDTH],labelBounds[HEIGHT]); } else { lRequestInvalidate(true,true); } } /** * Notifies L&F of a layout change in the corresponding Item. * @param layout the new layout descriptor */ public void lSetLayout(int layout) { lRequestInvalidate(true, true); } /** * Notifies L&F of a command addition in the corresponding Item. * @param cmd the newly added command * @param i the index of the added command in the Item's * commands[] array */ public void lAddCommand(Command cmd, int i) { if (item.owner != null) { ((DisplayableLFImpl)item.owner.getLF()).updateCommandSet(); } } /** * Notifies L&F of a command removal in the corresponding Item. * @param cmd the newly removed command * @param i the index of the removed command in the Item's * commands[] array */ public void lRemoveCommand(Command cmd, int i) { if (item.owner != null) { ((DisplayableLFImpl)item.owner.getLF()).updateCommandSet(); } } /** * Notifies L&F of a preferred size change in the corresponding Item. * @param width the value to which the width is locked, or * <code>-1</code> if it is unlocked * @param height the value to which the height is locked, or * <code>-1</code> if it is unlocked */ public void lSetPreferredSize(int width, int height) { // the "preferred size" is in "inner bounds" (contents) terms if (width == getInnerBounds(WIDTH) && height == getInnerBounds(HEIGHT)) { /* no need to invalidate */ return; } lRequestInvalidate(width != getInnerBounds(WIDTH), height != getInnerBounds(HEIGHT)); } /** * Notifies L&F of the default command change in the corresponding Item. * @param cmd the newly set default command * @param i index of this new command in the ChoiceGroup's commands array */ public void lSetDefaultCommand(Command cmd, int i) {} /** * Notify this itemLF that its owner screen has changed. * Clear internal state if its new owner is null. * * @param oldOwner old owner screen before this change. New owner * can be found in Item model. */ public void lSetOwner(Screen oldOwner) { if (item.owner == null) { // Hide it if (visible) { // IMPL_NOTE: We are holding LCDUILock and this // will call into app code on CustomItem. // Need to schedule an event to do that. uCallHideNotify(); } // the deleted item may be added later, so we // have to invalidate it. actualBoundsInvalid[X] = true; actualBoundsInvalid[Y] = true; actualBoundsInvalid[WIDTH] = true; actualBoundsInvalid[HEIGHT] = true; hasFocus = false; } } /** * Called by the system to indicate the content has been scrolled * inside of the form * * @param w the new width of the viewport of the screen * @param h the new height of the viewport of the screen */ public void uCallScrollChanged(int newViewportX, int newViewportY) { // do nothing by default. } /** * Return whether the cached requested sizes are valid. * * @return <code>true</code> if the cached requested sizes are up to date. * <code>false</code> if they have been invalidated. */ public final boolean isRequestedSizesValid() { return (cachedWidth != INVALID_SIZE); } // ***************************************************** // Package private methods // ***************************************************** /** * Used by the Form Layout to set the size of this Item * * @param height the tentative content height in pixels * @return the preferred width */ int lGetAdornedPreferredWidth(int height) { if (height > 2 * ScreenSkin.PAD_FORM_ITEMS) { height -= 2 * ScreenSkin.PAD_FORM_ITEMS; } else { height = -1; } return lGetPreferredWidth(height) + 2 * ScreenSkin.PAD_FORM_ITEMS; } /** * Used by the Form Layout to set the size of this Item * * @param width the tentative content width in pixels * @return the preferred height */ int lGetAdornedPreferredHeight(int width) { if (width > 2 * ScreenSkin.PAD_FORM_ITEMS) { width -= 2 * ScreenSkin.PAD_FORM_ITEMS; } else { width = -1; } return lGetPreferredHeight(width) + 2 * ScreenSkin.PAD_FORM_ITEMS; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?