formlfimpl.java

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

JAVA
1,820
字号
/* * * 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 class for <code>Form</code>. */class FormLFImpl extends DisplayableLFImpl implements FormLF {    /**     * Creates <code>FormLF</code> associated with passed in form.     * <code>FormLFImpl</code> maintains an array of views associated     * with its items.     *     * @param form the <code>Form</code> object associated with this     *             <code>FormLF</code>     * @param items the array of Items using which the passed in     *              <code>Form</code> 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];        width -= Constants.VERT_SCROLLBAR_WIDTH;        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 <code>FormLF</code> for the passed in screen.     * Passed in <code>ItemLF</code> is added as the only itemLF present.     * This constructor is used by <code>List</code> and <code>TextBox</code>.     *     * @param screen the <code>Screen</code> object associated with this     *               <code>FormLFImpl</code>     * @param item the <code>Item</code> to be added to this screen     */    FormLFImpl(Screen screen, Item item) {        super(screen);        itemLFs = new ItemLFImpl[1];        itemLFs[0] = (ItemLFImpl)item.getLF();        numOfLFs = 1;        // Initialize the in-out rect for Item traversal        visRect = new int[4];    }    // ************************************************************    //  public methods - FormLF interface implementation    // ************************************************************    /**     * Returns the width in pixels of the displayable area available for     * items.     * The value may depend on how the device uses the screen and may be     * affected by the presence or absence of the ticker, title,     * or commands.     * The <code>Item</code>s of the <code>Form</code> are     * laid out to fit within this width.     *     * @return the width of the <code>Form</code> in pixels     */    public int lGetWidth() {	return width;    }    /**     * Returns the height in pixels of the displayable area available     * for items.     * This value is the height of the form that can be displayed without     * scrolling.     * The value may depend on how the device uses the screen and may be     * affected by the presence or absence of the ticker, title,     * or commands.     *     * @return the height of the displayable area of the     *         <code>Form</code> in pixels     */    public int lGetHeight() {	return height;    }    /**     * Set the current traversal location to the given <code>Item</code>.     * This call has no effect if the given <code>Item</code> is the     * current traversal item, or if the given <code>Item</code> is not     * part of this <code>Form</code>. Note that null can be passed in     * clear the previously set current item.     *     * @param item the <code>Item</code> 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;            }        }    }    /**     * Notifies look&amp;feel object of an item set in the corresponding     * <code>Form</code>.     *     * @param itemNum the index of the item set     * @param item the item set in the corresponding <code>Form</code>     */    public void lSet(int itemNum, Item item) {        itemLFs[itemNum] = (ItemLFImpl)item.getLF();        itemsModified = true;        // Focus index remains at the same location        lRequestInvalidate();    }    /**     * Notifies look&amp;feel object of an item inserted in the corresponding     * <code>Form</code>.     *     * @param itemNum the index of the inserted item     * @param item the item inserted in the corresponding <code>Form</code>     */    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)item.getLF();        numOfLFs++;        itemsModified = true;        // Focus remains on the same item        if (traverseIndex >= itemNum) {            traverseIndex++;        } else if (traverseIndex == -1) {            traverseIndex = itemNum;        }                lRequestInvalidate();    }    /**     * Notifies look&amp;feel object of an item deleted in the corresponding     * <code>Form</code>.     *     * @param itemNum the index of the deleted item     * @param deleteditem the item deleted in the corresponding form     */    public void lDelete(int itemNum, Item deleteditem) {        // 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,				   " setting actualBoundsInvalid[Y] #" +				   (itemNum + 1));		    if (itemNum > 0) {			Logging.report(Logging.INFORMATION,				       LogChannels.LC_HIGHUI_FORM_LAYOUT,				       " | itemLFs[itemNum-1] = "+				       itemLFs[itemNum - 1]);		    }		    Logging.report(Logging.INFORMATION,				   LogChannels.LC_HIGHUI_FORM_LAYOUT,				   " | itemLFs[itemNum] = " +				   itemLFs[itemNum]);                    if (itemNum < numOfLFs - 1) {			Logging.report(Logging.INFORMATION,				       LogChannels.LC_HIGHUI_FORM_LAYOUT,				       " | 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;        }        lRequestInvalidate();    }    /**     * Notifies look&amp;feel object that all items are deleted in     * the corresponding <code>Form</code>.     */    public void lDeleteAll() {        if (traverseIndex != -1) {            lastTraverseItem = itemLFs[traverseIndex];        }        // Dereference all ItemLFImpls so they can be GC'ed        while (numOfLFs > 0) {            itemLFs[--numOfLFs] = null;        }        traverseIndex = -1;        itemsModified = true;        pendingCurrentItem = null;        lRequestInvalidate();    }    /**     * This method is responsible for:     * (1) Re-validate the contents of this <code>Form</code>, possibly due     * to an individual item     * (2) setup the viewable/scroll position     * (3) repaint the currently visible <code>Item</code>s     */    public void uCallInvalidate() {        super.uCallInvalidate();        int new_width = currentDisplay.width;         int new_height = currentDisplay.height;         // It could be that setCurrentItem() was called and we        // have done an 'artificial' traversal. In this case, we        // manually call traverseOut() on the last traversed item        // if there is one.        if (lastTraverseItem != null) {            try {                lastTraverseItem.uCallTraverseOut();                            } catch (Throwable t) {                if (Logging.REPORT_LEVEL <= Logging.WARNING) {                    Logging.report(Logging.WARNING, LogChannels.LC_HIGHUI,                                  "Throwable while traversing out");                }            }            lastTraverseItem = null;            updateCommandSet();        }        synchronized (Display.LCDUILock) {            // Do nothing if paint is suspended in current Display            if (!lIsShown()) {                return;            }            // Do not reset the Form from the top since this is an update            resetToTop = false;        }        // Setup items and show form native resource        // SYNC NOTE:         // called without LCDUILock, since it may end up calling into a MIDlet        if (new_width != width || new_height != height) {            width = new_width;            height = new_height;            firstShown = true;        }        // IMPL NOTES: Remove this line after UDPATE_LAYOUT is fixed        firstShown = true;        // Update contents        uShowContents(false);        // SYNC NOTE:        // 1. We are on event dispatch thread, currentDisplay won't change.        // 2. We are on event dispatch thread, call paint synchronously.        // 3. Since we could call into app's functions, like traverse(),        //    showNotify() and paint(), do this outside LCDUILock block.        currentDisplay.callPaint(0, 0, width, height, null);        

⌨️ 快捷键说明

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