customitemlfimpl.java

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

JAVA
699
字号
/* *    * * 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.configurator.Constants;import com.sun.midp.chameleon.skins.ScreenSkin;// **************************************************************************//  Package Private - These are all methods which delegate calls to//                    CustomItem application code, locking on the calloutLock//                    before doing so// **************************************************************************/*** This is the Look &amps; Feel implementation for CustomItem.*/class CustomItemLFImpl extends ItemLFImpl implements CustomItemLF {    /**     * Creates CustomItemLF associated with the passed in CustomItem.     * @param ci the CustomItem associated with this look&amps;feel.     */    CustomItemLFImpl(CustomItem ci) {        super(ci);        customItem = ci;    }    // **********************************************************    //  CustItemLF interface implementation    // ***********************************************************    /**     * Notifies L&F that repaint of the entire custom item is needed     */    public void lRepaint() {        lRepaint(0, 0, contentBounds[WIDTH], contentBounds[HEIGHT]);    }    /**     * Notifies L&F that repaint of the specified region is needed.     *     * @param x the x coordinate of the origin of the dirty region     * @param y the y coordinate of the origin of the dirty region     * @param w the width of the dirty region     * @param h the height of the dirty region     */    public void lRepaint(int x, int y, int w, int h) {        try {            if (x > contentBounds[WIDTH] || y > contentBounds[HEIGHT] ||                x + w <= 0 || y + w <= 0 || w <= 0 || h <= 0) {                return;            }            if (x < 0) {                w += x;                x = 0;            }            if (x + w > contentBounds[WIDTH]) {                w = contentBounds[WIDTH] - x;            }            if (y < 0) {                h += y;                y = 0;            }            if (y + h > contentBounds[HEIGHT]) {                h = contentBounds[HEIGHT] - y;            }            lRequestPaint(x + contentBounds[X] + ScreenSkin.PAD_FORM_ITEMS,                          y + contentBounds[Y] + ScreenSkin.PAD_FORM_ITEMS,                          w, h);        } catch (Exception e) {            Display.handleThrowable(e);        }    }    /**     * Notifies L&F that Custom Item was invalidated.     */    public void lInvalidate() {        lRequestInvalidate(true, true);    }    // JAVADOC COMMENT ELIDED    public int lGetInteractionModes() {        int result = customItem.TRAVERSE_HORIZONTAL |                customItem.TRAVERSE_VERTICAL |                customItem.KEY_PRESS |                customItem.KEY_RELEASE;        if (Constants.REPEAT_SUPPORTED) {            result = result | customItem.KEY_REPEAT;        }        if (Constants.POINTER_SUPPORTED) {            result = result | customItem.POINTER_PRESS |                customItem.POINTER_RELEASE;        }        if (Constants.MOTION_SUPPORTED) {            result = result | customItem.POINTER_DRAG;        }        return result;    }    /**     * Refresh the cached preferred and minimum sizes of this CustomItem.     */    public void uCallSizeRefresh() {        if (isRequestedSizesValid()) {            return;        }        int mw = uCallMinimumWidth();        if (mw < 0) mw = 0;        int mh = uCallMinimumHeight();        if (mh < 0) mh = 0;        int pw = item.lockedWidth == -1 ?            uCallPreferredWidth(item.lockedHeight) : item.lockedWidth;        if (pw < mw) pw = mw;        int ph = uCallPreferredHeight(pw);        if (ph < mh) ph = mh;        // Cache the result in ItemLFImpl        synchronized (Display.LCDUILock) {            minimumWidth = mw;            minimumHeight = mh;            preferredWidth = pw;            preferredHeight = ph;            cachedWidth = super.lGetAvailableWidth();        }    }    /**     * Get the preferred width of this Item, including the preferred     * content width and room for the label. This is the callback     * for Item's public getPreferredWidth() method.     *     * @param h the height to base the width size on     * @return the preferred width     */    private int uCallPreferredWidth(int h) {        // SYNC NOTE: call into app code. Must not hold LCDUILock.        int pw = customItem.uGetContentSize(CustomItem.SIZE_PREF_WIDTH, h);        int ph = h == -1 ?            customItem.uGetContentSize(CustomItem.SIZE_PREF_HEIGHT, pw) : h;        synchronized (Display.LCDUILock) {            if (cachedWidth != INVALID_SIZE ||                contentBounds[WIDTH] != pw || contentBounds[HEIGHT] != ph) {                contentBounds[WIDTH]  = pw;                contentBounds[HEIGHT] = ph;                cachedWidth = INVALID_SIZE;            }            // Note that content size had to be calculated outside of            // the LCDUILock that is why it is set here and            // lGetContentSize is left empty            return super.lGetPreferredWidth(h);        }    }    /**     * Get the preferred height of this Item, including the preferred     * content height and room for the label. This is the callback     * for Item's public getPreferredHeight() method.     *     * @param w the width to base the height size on     * @return the preferred height     */    private int uCallPreferredHeight(int w) {        // SYNC NOTE: call into app code. Must not hold LCDUILock.        int prefH = customItem.uGetContentSize(CustomItem.SIZE_PREF_HEIGHT, w);        int prefW = customItem.uGetContentSize(CustomItem.SIZE_PREF_WIDTH,                                               prefH);        if (prefW > w) prefW = w;        synchronized (Display.LCDUILock) {            if (cachedWidth != INVALID_SIZE ||                contentBounds[WIDTH] != prefW ||                contentBounds[HEIGHT] != prefH) {                contentBounds[WIDTH] = prefW;                contentBounds[HEIGHT] = prefH;                cachedWidth = INVALID_SIZE;            }            // Note that content size had to be calculated outside of            // the LCDUILock that is why it is set here and            // lGetContentSize is left empty            return super.lGetPreferredHeight(w);        }    }    /**     * Get the minimum width of this Item, including the minimum     * content width and room for the label. This is the callback     * for Item's public getMinimumWidth() method.     *     * @return the minimum width     */    private int uCallMinimumWidth() {        // SYNC NOTE: call into app code. Must not hold LCDUILock.        int mw = customItem.uGetContentSize(CustomItem.SIZE_MIN_WIDTH, 0);        int ph = customItem.uGetContentSize(CustomItem.SIZE_PREF_HEIGHT, mw);        synchronized (Display.LCDUILock) {            if (cachedWidth != INVALID_SIZE ||                contentBounds[WIDTH] != mw || contentBounds[HEIGHT] != ph) {                contentBounds[WIDTH] = mw;                contentBounds[HEIGHT] = ph;                cachedWidth = INVALID_SIZE;            }            // Note that content size had to be calculated outside of            // the LCDUILock that is why it is set here and            // lGetContentSize is left empty            return super.lGetPreferredWidth(-1);        }    }    /**     * Get the minimum height of this Item, including the minimum     * content height and room for the label. This is the callback     * for Item's public getMinimumHeight() method.     *     * @return the minimum height     */    private int uCallMinimumHeight() {        // SYNC NOTE: call into app code. Must not hold LCDUILock.        int minH  = customItem.uGetContentSize(CustomItem.SIZE_MIN_HEIGHT, 0);        int prefW = customItem.uGetContentSize(CustomItem.SIZE_PREF_WIDTH,                                               minH);        synchronized (Display.LCDUILock) {            if (cachedWidth != INVALID_SIZE ||                contentBounds[WIDTH] != prefW ||                contentBounds[HEIGHT] != minH) {                contentBounds[WIDTH]  = prefW;                contentBounds[HEIGHT] = minH;                cachedWidth = INVALID_SIZE;            }            // Note that content size had to be calculated outside of            // the LCDUILock that is why it is set here and            // lGetContentSize is left empty            return super.lGetPreferredHeight(-1);        }    }    // *****************************************************    //  Package private methods    // *****************************************************    /**      * Get the preferred width of this time.      * @param h tentative height      * @return cached size      */     public int lGetPreferredWidth(int h) {         // argument h is ignored since we are only using the cached value         return preferredWidth;     }     /**      * Get the preferred height of this time.      * @param w tentative width      * @return cached size      */     public int lGetPreferredHeight(int w) {         // argument w is ignored since we are only using the cached value         return preferredHeight;     }    /**     * Get the minimum width of this time.     * @return cached size     */    public int lGetMinimumWidth() {        return minimumWidth;    }    /**     * Get the minimum height of this time.     * @return cached size     */    public int lGetMinimumHeight() {        return minimumHeight;    }    /**     * Determine if this Item should not be traversed to     *     * @return true if this Item should not be traversed to     */    boolean shouldSkipTraverse() {        return false;    }    /**     * Called by the system to indicate the size available to this Item     * has changed     *     * @param w the new width of the item's content area     * @param h the new height of the item's content area     */    void uCallSizeChanged(int w, int h) {        super.uCallSizeChanged(w,h);        int prefH = customItem.uGetContentSize(CustomItem.SIZE_PREF_HEIGHT, w);        int prefW = customItem.uGetContentSize(CustomItem.SIZE_PREF_WIDTH, h);        if (prefW > w) {            prefW = w;        }        if (prefH > h) {            prefH = h;        }        synchronized (Display.LCDUILock) {            contentBounds[WIDTH] = prefW;            contentBounds[HEIGHT] = prefH;

⌨️ 快捷键说明

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