itemlfimpl.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,226 行 · 第 1/3 页

JAVA
1,226
字号
/* *    * * 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.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.configurator.Constants;/** * Look and feel implementation for <code>Item</code> based on  * platform widgets. * * SYNC NOTE: Only functions with prefix 'uCall' handle locking internally. * Its the caller's responsibility to hold LCDUILock around calls to the * rest of functions. */abstract class ItemLFImpl implements ItemLF {    /**     * Creates look and feel for the passed in <code>Item</code>.     *     * @param item the <code>Item</code> for which the look &amp; feel      *             should be created     */    ItemLFImpl(Item item) {        this.item = item;        actualBoundsInvalid = new boolean[] {true, true, true, true};        bounds = new int[] {0, 0, 0, 0};    }    // *****************************************************    //  Public methods - ItemLF interface implementation    // *****************************************************        /**     * Returns the locked width of the Item, or -1 if it's not locked     * @return locked width plus adornment width, or -1 if it's not locked     */    int lGetLockedWidth() {		if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {	    Logging.report(Logging.INFORMATION,			   LogChannels.LC_HIGHUI_ITEM_LAYOUT,			   " ItemLFImpl  -  lGetLockedWidth: " + 			   item.lockedWidth);	}	return item.lockedWidth;    }    /**     * Returns the locked height of the Item, or -1 if it's not locked     * @return locked height plus adornment height, or -1 if it's not locked     */    protected int lGetLockedHeight() {	if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {	    Logging.report(Logging.INFORMATION,			   LogChannels.LC_HIGHUI_ITEM_LAYOUT,			   " ItemLFImpl  -  lGetLockedHeight: " + 			   item.lockedHeight);	}	return item.lockedHeight;    }    /**     * PLACE HOLDER     * 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) {	return lGetPreferredWidth(height);    }    /**     * PLACE HOLDER     * 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) {	return lGetPreferredHeight(width);    }    /**     * PLACE HOLDER     * Used by the Form Layout to set the size of this Item     * @return the minimum width that includes cell spacing     */    int lGetAdornedMinimumWidth() {	return lGetMinimumWidth();    }    /**     * PLACE HOLDER     * Used by the Form Layout to set the size of this Item     * @return the minimum height that includes cell spacing     */    int lGetAdornedMinimumHeight() {	return lGetMinimumHeight();    }        /**     * Get the preferred width of this <code>Item</code>.     *     * @param h tentative locked height.     * 		Ignored here and item.lockedHeight is used always.     *     * @return the preferred width     */    public int lGetPreferredWidth(int h) {		// note: h is not used!	lGetRequestedSizes();	return preferredWidth;    }    /**     * Get the preferred height of this <code>Item</code>.     *     * @param w tentative locked width.     * 		Ignored here and preferred width is used always.     *     * @return the preferred height     */    public int lGetPreferredHeight(int w) {	// note: w is not used	lGetRequestedSizes();	return preferredHeight;    }    /**     * Get the minimum width of this <code>Item</code>.     *     * @return the minimum width     */    public int lGetMinimumWidth() {	lGetRequestedSizes(); // Make sure cached sizes are up to date	return minimumWidth;    }    /**     * Get the minimum height of this <code>Item</code>.     *     * @return the minimum height     */    public int lGetMinimumHeight() {	lGetRequestedSizes();	return minimumHeight;    }     /**     * Notifies L&amp;F of a label change in the corresponding      * <code>Item</code>.     *     * @param label the new label string     */    public void lSetLabel(String label) {	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {	    setLabel0(nativeId, label);	}        lRequestInvalidate(true, true);    }    /**     * Notifies L&amp;F of a layout change in the corresponding      * <code>Item</code>.     *     * @param layout the new layout descriptor     */    public void lSetLayout(int layout) {        lRequestInvalidate(true, true);    }    /**     * Notifies L&amp;F of a command addition in the corresponding      * <code>Item</code>.     *     * @param cmd the newly added command     * @param i the index of the added command in the <code>Item</code>'s     *          commands[] array     */    public void lAddCommand(Command cmd, int i) {        if (item.owner != null) {            ((DisplayableLFImpl)item.owner.getLF()).updateCommandSet();        }    }    /**     * Notifies L&amp;F of a command removal in the corresponding     * <code>Item</code>.     *     * @param cmd the newly removed command     * @param i the index of the removed command in the <code>Item</code>'s     *          commands[] array     */    public void lRemoveCommand(Command cmd, int i) {        if (item.owner != null) {            ((DisplayableLFImpl)item.owner.getLF()).updateCommandSet();        }    }    /**     * Notifies L&amp;F of a preferred size change in the corresponding     * <code>Item</code>.     *     * @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) {        if (width == bounds[WIDTH] && height == bounds[HEIGHT]) {            // no need to invalidate            return;        }        lRequestInvalidate(width != bounds[WIDTH],			   height != bounds[HEIGHT]);    }    /**     * Notifies L&amp;F of the default command change in the corresponding     * <code>Item</code>.     *     * @param cmd the newly set default command     * @param i index of this new command in the <code>ChoiceGroup</code>'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 <code>null</code>.     *     * @param oldOwner old owner screen before this change. New owner     *                 can be found in <code>Item</code> model.     */    public void lSetOwner(Screen oldOwner) {	// Currently Item has no owner	if (item.owner == null) {	    // Hide native resource	    lHideNativeResource();	    // Free any native resource	    deleteNativeResource();	    // do app notification	    if (visibleInViewport) {		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;	    cachedWidth = INVALID_SIZE;	    hasFocus = false;	}    }    /**     * 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    // *****************************************************    /**     * Create native resource of this <code>Item</code>.     * After this call, <code>Item.nativeId</code> should have had the     * created native resource id.     *     * @param ownerId native <code>MidpDisplayable*</code> of the owner screen     */    abstract void createNativeResource(int ownerId);    /**     * Delete native resource of this <code>Item</code>.     * After this call, <code>Item.nativeId</code> should have been reset to     * <code>DisplayableLFImpl.INVALID_NATIVE_ID</code>.     */    void deleteNativeResource() {	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {	    delete0(nativeId);	    nativeId = DisplayableLFImpl.INVALID_NATIVE_ID;	}    }    /**     * Create a temporary native resource of this <code>Item</code> whose     * id must be deleted before caller function returns.     */    protected void createTempNativeResource() {        int ownerId = (item.owner == null)			    ? DisplayableLFImpl.INVALID_NATIVE_ID			    : ((DisplayableLFImpl)item.owner.getLF()).nativeId;	createNativeResource(ownerId);    }    /**     * Paint the content of this <code>Item</code>.     * This function simply calls lCallPaint() after obtaining LCDUILock.     *     * @param g the <code>Graphics</code> object to be used for rendering     *          the item     * @param w current width of the item in pixels     * @param h current height of the item in pixels     */    void uCallPaint(Graphics g, int w, int h) {	synchronized (Display.LCDUILock) {	    lCallPaint(g, w, h);	}    }    /**     * Paint the content of this <code>Item</code>.     * The default implementation does nothing.     *     * @param g the <code>Graphics</code> object to be used for rendering     *          the item     * @param w current width of the item in pixels     * @param h current height of the item in pixels     */    void lCallPaint(Graphics g, int w, int h) {}    /**     * Determine if this <code>Item</code> should horizontally shrink.     *     * @return <code>true</code> if it should horizontally shrink     */    boolean shouldHShrink() {        return ((item.layout & Item.LAYOUT_SHRINK) == Item.LAYOUT_SHRINK);    }    /**     * Determine if this <code>Item</code> should horizontally expand.     *     * @return <code>true</code> if it should horizontally expand     */    boolean shouldHExpand() {        return ((item.layout & Item.LAYOUT_EXPAND) == Item.LAYOUT_EXPAND);    }    /**     * Determine if this <code>Item</code> should vertically shrink.     *     * @return <code>true</code> if it should vertically shrink     */    boolean shouldVShrink() {        return ((item.layout & Item.LAYOUT_VSHRINK) == Item.LAYOUT_VSHRINK);    }    /**     * Determine if this <code>Item</code> should vertically expand.     *     * @return <code>true</code> if it should vertically expand     */    boolean shouldVExpand() {        return ((item.layout & Item.LAYOUT_VEXPAND) == Item.LAYOUT_VEXPAND);    }    /**     * Determine if this <code>Item</code> should have a newline after it.     *     * @return <code>true</code> if it should have a newline after

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?