customitemlfimpl.java

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

JAVA
1,337
字号
/* *    * * 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  javax.microedition.lcdui.KeyConverter; */import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.configurator.Constants;// **************************************************************************//  Package Private - These are all methods which delegate calls to//                    CustomItem application code, locking on the calloutLock//                    before doing so// **************************************************************************/** * This is the look and feel implementation for <code>CustomItem</code>. */class CustomItemLFImpl extends ItemLFImpl implements CustomItemLF {    /**     * Creates <code>CustomItemLF</code> associated with the passed in      * <code>CustomItem</code>.     *     * @param ci the <code>CustomItem</code> associated with this      *           look &amp; feel.     */    CustomItemLFImpl(CustomItem ci) {        super(ci);        dirtyRegion = new int[4];        resetDirtyRegion();        customItem = ci;    }    // **********************************************************    //  CustItemLF interface implementation    // ***********************************************************    /**     * Notifies L&amp;F that repaint of the entire custom item is needed.     */    public void lRepaint() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_REPAINT,                           ">>> CustomItemLFImpl -- lRepaint()");        }                // content area is empty no repaint is needed        if (contentImageData == null) {            return;        }        setDirtyRegionFull();        try {            int pad = getItemPad();            // We prune off the label area when doing a complete repaint            lRequestPaint(pad,                          pad + getLabelHeight(bounds[WIDTH]),                          contentImageData.getWidth(),                          contentImageData.getHeight());        } catch (Exception e) {            Display.handleThrowable(e);        }    }    /**     * Notifies L&amp;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 width the width of the dirty region     * @param height the height of the dirty region     */    public void lRepaint(int x, int y, int width, int height) {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_REPAINT,                           ">>> CustomItemLFImpl -- lRepaint(" + x +                            "," + y + "," + width + "," + height + ")");        }        try {            // Content area is empty there is no need to do anything            if (contentImageData == null) {                return;            }            int pad = getItemPad();            // int lH = getLabelHeight(bounds[WIDTH]);            // no need to do anything if the repaint region            // is complete outside the content area                        if (x >= bounds[WIDTH] - 2*pad ||                 y >= bounds[HEIGHT] - 2*pad /* - lH */ ||                x + width <= 0 || y + height <= 0) {                return;            }            // passed in region is expressed in the same coordinate system            // as the dirtyRegion; join those 2 regions            if (x <= 0) {                dirtyRegion[X1] = 0;            } else {                // when dirty region is unset the following will be true                // and dirtyRegion[X1] will be correctly set                if (dirtyRegion[X1] > x) {                    dirtyRegion[X1] = x;                }            }            if (y <= 0) {                dirtyRegion[Y1] = 0;            } else {                // when dirty region is unset the following will be true                // and dirtyRegion[Y1] will be correctly set                if (dirtyRegion[Y1] > y) {                    dirtyRegion[Y1] = y;                }            }            if (x + width >= bounds[WIDTH] - pad) {                dirtyRegion[X2] = bounds[WIDTH] - pad;            } else {                // when dirty region is unset the following will be true                // and dirtyRegion[X2] will be correctly set                if (x + width > dirtyRegion[X2]) {                    dirtyRegion[X2] = x + width;                }            }            if (y + height >= bounds[HEIGHT] - pad) {                dirtyRegion[Y2] = bounds[HEIGHT] - pad;            } else {                // when dirty region is unset the following will be true                // and dirtyRegion[Y2]  will be correctly set                if (y + height > dirtyRegion[Y2]) {                    dirtyRegion[Y2] = y + height;                }            }            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {                Logging.report(Logging.INFORMATION,                               LogChannels.LC_HIGHUI_ITEM_REPAINT,                               "after join ..... \t\t dirtyRegion (" +                                   dirtyRegion[X1] + "," +                                   dirtyRegion[Y1] + ") - (" +                                   dirtyRegion[X2] + "," +                                   dirtyRegion[Y2] + ")");            }            // obsolete - can use any number...            super.lRequestPaint(0, 0, 0, 0);            /*            // repaint should be requested in Item's coordinate            // system (translate by padding and labelHeight)            super.lRequestPaint(dirtyRegion[X1] + pad,                                dirtyRegion[Y1] + pad + lH,                                dirtyRegion[X2] - dirtyRegion[X1] + 1,                                dirtyRegion[Y2] - dirtyRegion[Y1] + 1);            */        } catch (Exception e) {            Display.handleThrowable(e);        }    }    /**     * Notifies L&amp;F that <code>CustomItem</code> was invalidated.     */    public void lInvalidate() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           ">>> CustomItemLFImpl -- lInvalidate()");        }        setDirtyRegionFull();        lRequestInvalidate(true, true);    }    /**     * Get the preferred width of this <code>Item</code>, including      * the preferred content width and room for the label.      * This is the callback for <code>Item</code>'s public      * getPreferredWidth() method.     *     * @param h the height to base the width size on     *     * @return the preferred width     */    private int uCallPreferredWidth(int h) {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           "CustomItem -- uCallPreferredWidth h=" + h);        }        // SYNC NOTE: Call into app code. Must not hold LCDUILock.        int pW = customItem.uGetContentSize(CustomItem.SIZE_PREF_WIDTH, h);        // preferred width should be at least the minimum allowed,        // this is checked and fixed at Item level        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           "\t -- uCallPreferredWidth item returned " +                           pW);        }        synchronized (Display.LCDUILock) {            // if width is not locked item.lockedWidth will be -1            // which means that all available width can be used            int lw = getLabelWidth(item.lockedWidth);            // if label is wider than customItem body, we're allowed            // to make the body wider.            if (lw > pW) {                pW = lw;            }            if (pW > 0) {                pW += 2 * getItemPad();            }        }        return pW;    }    /**     * Get the preferred height of this <code>Item</code>, including the      * preferred content height and room for the label.      * This is the callback for <code>Item</code>'s public      * getPreferredHeight() method.     *     * @param w the width to base the height size on     *     * @return the preferred height     */    private int uCallPreferredHeight(int w) {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           "CustomItem -- uCallPreferredHeight w=" + w);        }        // SYNC NOTE: Call into app code. Must not hold LCDUILock.        int pH = customItem.uGetContentSize(CustomItem.SIZE_PREF_HEIGHT, w);        // preferred height should be at least the minimum allowed,        // this is checked and fixed at Item level        synchronized (Display.LCDUILock) {            pH += getLabelHeight(w);            if (pH > 0) {                pH += 2 * getItemPad();            }        }        return pH;    }    /**     * Get the minimum width of this <code>Item</code>, including the      * minimum content width and room for the label.      * This is the callback for <code>Item</code>'s public      * getMinimumWidth() method.     *     * @return the minimum width     */    private int uCallMinimumWidth() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           "CustomItemLFImpl -- uCallMinimumWidth");        }        // SYNC NOTE: Call into app code. Must not hold LCDUILock.        int mW = customItem.uGetContentSize(CustomItem.SIZE_MIN_WIDTH, 0);                synchronized (Display.LCDUILock) {            int lw = getLabelWidth(-1);                        // if label is wider than customItem body, we're allowed            // to make the body wider.            if (lw > mW) {                mW = lw;            }                        if (mW > 0) {                mW += 2 * getItemPad();            }        }                return mW;    }    /**     * Get the minimum height of this <code>Item</code>, including the      * minimum content height and room for the label.      * This is the callback for <code>Item</code>'s public      * getMinimumHeight() method.     *     * @return the minimum height     */    private int uCallMinimumHeight() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           "CustomItemLFImpl -- uCallMinimumHeight");        }        // SYNC NOTE: Call into app code. Must not hold LCDUILock.        int mH = customItem.uGetContentSize(CustomItem.SIZE_MIN_HEIGHT, 0);        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                           LogChannels.LC_HIGHUI_ITEM_LAYOUT,                           "CustomItem -- uCallMinimumHeight ret: " + mH);        }        synchronized (Display.LCDUILock) {            mH += getLabelHeight(-1);            if (mH > 0) {                mH += 2 * getItemPad();            }        }        return mH;    }    /**     * Get minimum and preferred sizes from <code>CustomItem</code>      * subclass and cache the result in super class.     */    public void uCallSizeRefresh() {        if (isRequestedSizesValid()) {            return;        }        int mw = uCallMinimumWidth();        if (mw < 0) mw = 0;        int mh = uCallMinimumHeight();        if (mh < 0) mh = 0;                int pw = uCallPreferredWidth(item.lockedHeight);        if (pw < mw) pw = mw;        int ph = uCallPreferredHeight(pw);        synchronized (Display.LCDUILock) {            // NOTE: When the item should shrink, the minimum size is used,            // and the minimum size is calculated with the label            // on the same line            if (shouldHShrink() &&                item.label != null &&                item.label.length() > 0) {                mh += DEFAULT_LABEL_HEIGHT;            }            if (ph < mh) ph = mh;            // Cache the result in ItemLFImpl            lSetRequestedSizes(mw, mh, pw, ph);        }    }    /**     * Overriding <code>ItemLFImpl</code>.     * 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) {        super.lSetLabel(label);    }    // JAVADOC COMMENT ELIDED    public int lGetInteractionModes() {        // removed support for traversal.        // (MIDlets should use low level key events instead)        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;    }    // *****************************************************    //  Package private methods    // *****************************************************    /**     * Calculate minimum and preferred width and height of this item and      * store the result in instance variables     * minimumWidth, minimumHeight, preferredWidth and preferredHeight.     *     * Override the version in <code>ItemLFImpl</code> to do nothing.

⌨️ 快捷键说明

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