choicegroup.java

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

JAVA
940
字号
     */    public void delete(int elementNum) {	        synchronized (Display.LCDUILock) {            checkIndex(elementNum);	    --numOfEls;            // setup new elements array            if (elementNum != numOfEls) {                System.arraycopy(cgElements, elementNum + 1, cgElements,                                 elementNum, numOfEls - elementNum);            }            // free some memory... (efficient for very large arrays)             if (cgElements.length > (GROW_FACTOR * 10) &&		cgElements.length / numOfEls >= 2) {                CGElement[] newArray = new CGElement[numOfEls + GROW_FACTOR];                System.arraycopy(cgElements, 0, newArray, 0, numOfEls);                cgElements = newArray;                newArray = null;            }                    cgElements[numOfEls] = null;            // notify l&f            choiceGroupLF.lDelete(elementNum);        } // synchronized    }    /**     * Deletes all elements from this <code>ChoiceGroup</code>.     */    public void deleteAll() {        synchronized (Display.LCDUILock) {            cgElements = new CGElement[GROW_FACTOR]; // initial size            numOfEls = 0;            choiceGroupLF.lDeleteAll();        }    }    /**     * Sets the <code>String</code> and <code>Image</code> parts of the     * element referenced by <code>elementNum</code>,     * replacing the previous contents of the element.     *     * @param elementNum the index of the element to be set     * @param stringPart the string part of the new element     * @param imagePart the image part of the element, or <code>null</code>     * if there is no image part     * @throws IndexOutOfBoundsException if <code>elementNum</code> is invalid     * @throws NullPointerException if <code>stringPart</code> is     * <code>null</code>     */    public void set(int elementNum, String stringPart, Image imagePart) {        synchronized (Display.LCDUILock) {            checkIndex(elementNum);            checkNull(stringPart);            cgElements[elementNum].set(stringPart, imagePart);            choiceGroupLF.lSet(elementNum, stringPart, imagePart);        }    }    /**     * Gets a boolean value indicating whether this element is selected.     *     * @param elementNum the index of the element to be queried     *     * @return selection state of the element     *     * @throws IndexOutOfBoundsException if <code>elementNum</code> is invalid     */    public boolean isSelected(int elementNum) {        synchronized (Display.LCDUILock) {            checkIndex(elementNum);	    return choiceGroupLF.lIsSelected(elementNum);        }    }    /**     * Returns the index number of an element in the     * <code>ChoiceGroup</code> that is     * selected. For <code>ChoiceGroup</code> objects of type     * <code>EXCLUSIVE</code> and <code>POPUP</code>     * there is at most one element selected, so     * this method is useful for determining the user's choice.     * Returns <code>-1</code> if     * there are no elements in the <code>ChoiceGroup</code>.     *     * <p>For <code>ChoiceGroup</code> objects of type     * <code>MULTIPLE</code>, this always     * returns <code>-1</code> because no     * single value can in general represent the state of such a     * <code>ChoiceGroup</code>.     * To get the complete state of a <code>MULTIPLE</code>     * <code>Choice</code>, see {@link     * #getSelectedFlags getSelectedFlags}.</p>     *     * @return index of selected element, or <code>-1</code> if none     * @see #setSelectedIndex     */    public int getSelectedIndex() {        synchronized (Display.LCDUILock) {	    return choiceGroupLF.lGetSelectedIndex();	}    }    /**     * Queries the state of a <code>ChoiceGroup</code> and returns the state of     * all elements in the     * boolean array     * <code>selectedArray_return</code>. <strong>Note:</strong> this     * is a result parameter.     * It must be at least as long as the size     * of the <code>ChoiceGroup</code> as returned by <code>size()</code>.     * If the array is longer, the extra     * elements are set to <code>false</code>.     *     * <p>For <code>ChoiceGroup</code> objects of type     * <code>MULTIPLE</code>, any     * number of elements may be selected and set to true in the result     * array.  For <code>ChoiceGroup</code> objects of type     * <code>EXCLUSIVE</code> and <code>POPUP</code>     * exactly one element will be selected, unless there are     * zero elements in the <code>ChoiceGroup</code>. </p>     *     * @return the number of selected elements in the <code>ChoiceGroup</code>     *     * @param selectedArray_return array to contain the results     * @throws IllegalArgumentException if <code>selectedArray_return</code>     * is shorter than the size of the <code>ChoiceGroup</code>     * @throws NullPointerException if <code>selectedArray_return</code>     * is null     * @see #setSelectedFlags     */    public int getSelectedFlags(boolean[] selectedArray_return) {        checkFlag(selectedArray_return);        synchronized (Display.LCDUILock) {	    int numSelected = 0;	    if (numOfEls > 0) {                numSelected = 		    choiceGroupLF.lGetSelectedFlags(selectedArray_return);            }	    for (int i = numOfEls; i < selectedArray_return.length; i++) {		selectedArray_return[i] = false;	    }	    return numSelected;        }    }    /**     * For <code>ChoiceGroup</code> objects of type     * <code>MULTIPLE</code>, this simply sets an     * individual element's selected state.     *     * <P>For <code>ChoiceGroup</code> objects of type     * <code>EXCLUSIVE</code> and <code>POPUP</code>, this can be used only to     * select an element.  That is, the <code> selected </code> parameter must     * be <code> true </code>. When an element is selected, the previously     * selected element is deselected. If <code> selected </code> is <code>     * false </code>, this call is ignored.</P>     *     * <p>For both list types, the <code>elementNum</code> parameter     * must be within     * the range     * <code>[0..size()-1]</code>, inclusive. </p>     *     * @param elementNum the number of the element. Indexing of the     * elements is zero-based     * @param selected the new state of the element <code>true=selected</code>,     * <code>false=not</code> selected     * @throws IndexOutOfBoundsException if <code>elementNum</code> is invalid     * @see #getSelectedIndex     */    public void setSelectedIndex(int elementNum, boolean selected) {        checkIndex(elementNum);        synchronized (Display.LCDUILock) {            choiceGroupLF.lSetSelectedIndex(elementNum, selected);        } // synchronized    }    /**     * Attempts to set the selected state of every element in the     * <code>ChoiceGroup</code>. The array     * must be at least as long as the size of the     * <code>ChoiceGroup</code>. If the array is     * longer, the additional values are ignored. <p>     *     * For <code>ChoiceGroup</code> objects of type     * <code>MULTIPLE</code>, this sets the selected     * state of every     * element in the <code>Choice</code>. An arbitrary number of     * elements may be selected.     * <p>     *     * For <code>ChoiceGroup</code> objects of type     * <code>EXCLUSIVE</code> and <code>POPUP</code>, exactly one array     * element must have the value <code>true</code>. If no element is     * <code>true</code>,     * the first element     * in the <code>Choice</code> will be selected. If two or more     * elements are <code>true</code>, the     * implementation will choose the first <code>true</code> element     * and select it. <p>     *     * @param selectedArray an array in which the method collect the     * selection status     * @throws IllegalArgumentException if <code>selectedArray</code>     * is shorter than the size of the <code>ChoiceGroup</code>     * @throws NullPointerException if the <code>selectedArray</code>     * is <code>null</code>     * @see #getSelectedFlags     */    public void setSelectedFlags(boolean[] selectedArray) {        synchronized (Display.LCDUILock) {            checkFlag(selectedArray);            if (numOfEls == 0) {                return;            }            if (choiceType == Choice.MULTIPLE) {                for (int i = 0; i < numOfEls; i++) {                    cgElements[i].setSelected(selectedArray[i]);                }                choiceGroupLF.lSetSelectedFlags(selectedArray);            } else {                for (int i = 0; i < numOfEls; i++) {                    if (selectedArray[i]) {                        choiceGroupLF.lSetSelectedIndex(i, true);                        return;                    }                }                choiceGroupLF.lSetSelectedIndex(0, true);            }        } // synchronized    }    /**     * Sets the application's preferred policy for fitting     * <code>Choice</code> element     * contents to the available screen space. The set policy applies for all     * elements of the <code>Choice</code> object.  Valid values are     * {@link #TEXT_WRAP_DEFAULT}, {@link #TEXT_WRAP_ON},     * and {@link #TEXT_WRAP_OFF}. Fit policy is a hint, and the     * implementation may disregard the application's preferred policy.     *     * @param fitPolicy preferred content fit policy for choice elements     * @throws IllegalArgumentException if <code>fitPolicy</code> is invalid     * @see #getFitPolicy     */    public void setFitPolicy(int fitPolicy) {        if (fitPolicy < TEXT_WRAP_DEFAULT || fitPolicy > TEXT_WRAP_OFF) {            throw new IllegalArgumentException();        }        synchronized (Display.LCDUILock) {            if (this.fitPolicy != fitPolicy) {                this.fitPolicy = fitPolicy;                choiceGroupLF.lSetFitPolicy(fitPolicy);            }        }    }    /**     * Gets the application's preferred policy for fitting     * <code>Choice</code> element     * contents to the available screen space.  The value returned is the     * policy that had been set by the application, even if that value had     * been disregarded by the implementation.     *     * @return one of {@link #TEXT_WRAP_DEFAULT}, {@link #TEXT_WRAP_ON}, or     * {@link #TEXT_WRAP_OFF}     * @see #setFitPolicy     */    public int getFitPolicy() {        // SYNC NOTE: return of atomic value, no locking necessary        return fitPolicy;    }    /**     * Sets the application's preferred font for     * rendering the specified element of this <code>Choice</code>.     * An element's font is a hint, and the implementation may disregard     * the application's preferred font.     *     * <p> The <code>elementNum</code> parameter must be within the range     * <code>[0..size()-1]</code>, inclusive.</p>     *     * <p> The <code>font</code> parameter must be a valid <code>Font</code>     * object or <code>null</code>. If the <code>font</code> parameter is     * <code>null</code>, the implementation must use its default font     * to render the element.</p>     *     * @param elementNum the index of the element, starting from zero     * @param font the preferred font to use to render the element     * @throws IndexOutOfBoundsException if <code>elementNum</code> is invalid     * @see #getFont     */    public void setFont(int elementNum, Font font) {        synchronized (Display.LCDUILock) {            checkIndex(elementNum);

⌨️ 快捷键说明

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