formlfimpl.java

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

JAVA
1,792
字号
/* *    * * 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;import com.sun.midp.chameleon.skins.ScreenSkin;/** * Look and feel class for Form. * See DisplayableLF.java for naming convention. */class FormLFImpl extends ScreenLFImpl implements FormLF {    /**     * Creates FormLF associated with passed in form.     * FormLFImpl maintains an array of views associated with its items.     *      * @param form the Form object associated with this FormLF     * @param items the array of Items using which the passed in Form     *        was created     * @param numOfItems current number of elements     */    FormLFImpl(Form form, Item items[], int numOfItems) {                super(form);                // Initialize the in-out rect for Item traversal        visRect = new int[4];                if (items == null) {            itemLFs = new ItemLFImpl[GROW_SIZE];            // numOfLFs was initialized to 0            // so there is no need to update it        } else {            this.itemLFs = new ItemLFImpl[items.length > GROW_SIZE ?                                         items.length : GROW_SIZE];            for (int i = 0; i < numOfItems; i++) {                itemLFs[i] = (ItemLFImpl)items[i].getLF();            }                   // right now we have the same number of views as items            numOfLFs = numOfItems;        }            }            /**     * Creates FormLF for the passed in screen.     * Passed in ItemLF is added as the only itemLF present.     * This constructor is used by List and TextBox.     *      * @param screen the Screen object associated with this FormLFImpl     * @param item the Item to be added to this screen     */    FormLFImpl(Screen screen, Item item) {        super(screen);        itemLFs = new ItemLFImpl[1];        itemLFs[0] = (ItemLFImpl)item.getLF();        numOfLFs = 1;        visRect = new int[4];        if (screen instanceof TextBox && item instanceof TextField) {            TextField textField = (TextField)item;            ((TextFieldLFImpl)textField.textFieldLF).setBorder(false);        }    }    // ************************************************************    //  public methods - FormLF interface implementation    // ************************************************************    /**     * Set the current traversal location to the given Item.     * This call has no effect if the given Item is the     * current traversal item, or if the given Item is not     * part of this Form. Note that null can be passed in     * clear the previously set current item.     *     *     * @param i the Item to make the current traversal item     */     public void uItemMakeVisible(Item i) {        synchronized (Display.LCDUILock) {            if (i == null) {                pendingCurrentItem = null;            }            /**             * Display could be made visible using display.setCurrentItem()             * call. In those cases foregroung will be granted after there             * there is a screen change event and after uItemMakeVisible()             * is called. In such cases we need to set pendingCurrentItem and             * call uItemMakeVisible() again when the FormLF changes its             * state to SHOWN.             */            if (state != SHOWN) {                pendingCurrentItem = i;                return;            }        }        uScrollToItem(i);    }    /**     * Scrolls to the passed in Item.      * @param item The Item that should be shown on the screen.     */    private void uScrollToItem(Item item) {        if (item == null || item.owner != owner) {            return;        }        ItemLFImpl[] itemsCopy = null;        int itemsCopyCount = 0;        int traverseIndexCopy = -1;        ItemLFImpl itemLF = null;                synchronized (Display.LCDUILock) {            itemsCopy = new ItemLFImpl[numOfLFs];            itemsCopyCount = numOfLFs;            System.arraycopy(itemLFs, 0, itemsCopy, 0, numOfLFs);            traverseIndexCopy = traverseIndex;        }                int index = -1;                if (traverseIndexCopy != -1 && (itemsCopy[traverseIndexCopy].item == item)) {            index = traverseIndexCopy;        } else {            for (int i = 0; i < itemsCopyCount; i++) {                if (itemsCopy[i].item == item) {                    index = i;                    break;                }            }        }        // item is found        if (index > -1) {            itemLF = itemsCopy[index];            if (index != traverseIndexCopy) {                                // We record the present traverseItem because if it                // is valid, we will have to call traverseOut() on that                // item when we process the invalidate call.                if (traverseIndexCopy != -1) {                    try {                        itemsCopy[traverseIndexCopy].uCallTraverseOut();                    } catch (Throwable t) {                        if (Logging.REPORT_LEVEL <= Logging.WARNING) {                            Logging.report(Logging.WARNING, LogChannels.LC_HIGHUI,                                           "Throwable while traversing out");                        }                    }                }                                // If the item is not interactive, we just leave it                // visible on the screen, but set traverseIndex to -1                // so that any interactive item which is visible will                // be traversed to when the invalidate occurs                traverseIndexCopy = itemLF.shouldSkipTraverse() ? -1 : index;                                if (traverseIndexCopy > -1) {                    itemTraverse = uCallItemTraverse(itemsCopy[traverseIndexCopy], CustomItem.NONE);                }                                synchronized (Display.LCDUILock) {                    traverseIndex = traverseIndexCopy;                }                                        updateCommandSet();            }            // Ensure the item is visible at least partially            if (!itemPartiallyVisible(itemLF)) {                viewable[Y] = itemLF.bounds[Y];                if (viewable[Y] + viewport[HEIGHT] > viewable[HEIGHT]) {                    viewable[Y] = viewable[HEIGHT] - viewport[HEIGHT];                    uHideShowItems(itemsCopy);                }            }            // If complex item need extra scrolling we should make it            if (!itemCompletelyVisible(itemLF)) {                if (itemsCopy[traverseIndexCopy].lScrollToItem(viewport, visRect)) {                    if (alignForBounds(visRect)) {                        uHideShowItems(itemsCopy);                        setupScroll();                    }                }            }            uRequestPaint();        } // index > -1    }    /**     * Notifies look&feel object of an item deleted in the corresponding     * Form.     *      * @param itemNum - the index of the item set     * @param item - the item set in the corresponding Form     *     */    public void lSet(int itemNum, Item item) {        itemLFs[itemNum] = (ItemLFImpl)item.itemLF;        itemsModified = true;        // current optimization: the new item is marked invalid, so when        // the callInvalidate arrives, we'll know to update it and        // the minimum set of neighbor Items.        lRequestInvalidate();    }    /**     * Notifies look&feel object of an item inserted in the corresponding     * Form.     *      * @param itemNum - the index of the inserted item     * @param item - the item inserted in the corresponding Form     *     */    public void lInsert(int itemNum, Item item) {        if (itemLFs.length == numOfLFs) {            ItemLFImpl newItemLFs[] =                 new ItemLFImpl[numOfLFs + GROW_SIZE];            System.arraycopy(itemLFs, 0, newItemLFs, 0, itemNum);            System.arraycopy(itemLFs, itemNum, newItemLFs, itemNum + 1,                             numOfLFs - itemNum);            itemLFs = newItemLFs;        } else {            // if we're not appending            if (itemNum != numOfLFs) {                System.arraycopy(itemLFs, itemNum, itemLFs, itemNum + 1,                                 numOfLFs - itemNum);            }        }                itemLFs[itemNum] = (ItemLFImpl)((Form)owner).items[itemNum].getLF();                numOfLFs++;        itemsModified = true;        if (traverseIndex >= itemNum) {            traverseIndex++;        } else if (traverseIndex == -1) {            traverseIndex = itemNum;        }        lRequestInvalidate();    }    /**     * Notifies look&feel object of an item deleted in the corresponding     * Form.     *      * @param itemNum - the index of the deleted item     * @param deleteditem - the item deleted in the corresponding form     *     */    public void lDelete(int itemNum, Item deleteditem) {        // start optimization...        // if the previous item has new line after, or the next item has        // new line before, and it's not the last item,        // than we could just mark the next item as actualBoundsInvalid[Y]        if (itemNum < (numOfLFs-1)) {            if (((itemNum > 0) && (itemLFs[itemNum-1].equateNLA()) ||                itemLFs[itemNum+1].equateNLB()) &&                itemLFs[itemNum+1].isNewLine) {                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {                    Logging.report(Logging.INFORMATION,                                    LogChannels.LC_HIGHUI_FORM_LAYOUT,                                   "[F]setting actualBoundsInvalid[Y] #" +                                    (itemNum + 1));                    if (itemNum > 0) {                        Logging.report(Logging.INFORMATION,                                        LogChannels.LC_HIGHUI_FORM_LAYOUT,                                       "[F]  | itemLFs[itemNum-1] = " +                                       itemLFs[itemNum-1]);                    }                    Logging.report(Logging.INFORMATION,                                    LogChannels.LC_HIGHUI_FORM_LAYOUT,                                   "[F]  | itemLFs[itemNum] = " +                                   itemLFs[itemNum]);                    if (itemNum < numOfLFs-1) {                        Logging.report(Logging.INFORMATION,                                        LogChannels.LC_HIGHUI_FORM_LAYOUT,                                       "[F]  | itemLFs[itemNum+1] = "+                                       itemLFs[itemNum+1]);                    }                }                itemLFs[itemNum+1].actualBoundsInvalid[Y] = true;            } else {                itemLFs[itemNum+1].actualBoundsInvalid[X] = true;            }        }        if (traverseIndex == itemNum) {            lastTraverseItem = itemLFs[traverseIndex];        }        numOfLFs--;        itemsModified = true;        if (traverseIndex > 0 && traverseIndex >= itemNum) {             traverseIndex--;         } else if (0 == numOfLFs) {             traverseIndex = -1;         }        if (itemNum < numOfLFs) {            System.arraycopy(itemLFs, itemNum + 1, itemLFs, itemNum,                             numOfLFs - itemNum);        }                // Delete reference to the last item view         // that was left after array copy        itemLFs[numOfLFs] = null;                if (pendingCurrentItem == deleteditem) {            pendingCurrentItem = null;

⌨️ 快捷键说明

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