⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)List.java	1.93 02/09/12 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package javax.microedition.lcdui;/** * A <code>Screen</code> containing list of choices. Most of its * behavior is common with * class {@link ChoiceGroup ChoiceGroup}, and their common API. The * different <code>List</code> types in particular, are defined in * interface {@link Choice * Choice}.  When a <code>List</code> is present on the display, the * user can interact with * it by selecting elements and possibly by traversing and scrolling among * them.  Traversing and scrolling operations do not cause application-visible * events. The system notifies the application only when a {@link Command * Command} is invoked by notifying its {@link CommandListener}.  The * <code>List</code> * class also supports a select command that may be invoked specially * depending upon the capabilities of the device. * * <p>The notion of a <em>select</em> operation on a <code>List</code> * element is central * to the user's interaction with the <code>List</code>.  On devices * that have a dedicated * hardware &quot;select&quot; or &quot;go&quot; key, the select * operation is implemented with * that key.  Devices that do not have a dedicated key must provide another * means to do the select operation, for example, using a soft key.  The * behavior of the select operation within the different types of lists is * described in the following sections.</p> * * <p><code>List</code> objects may be created with <code>Choice</code> types of * {@link Choice#EXCLUSIVE}, {@link Choice#MULTIPLE}, and * {@link Choice#IMPLICIT}.  The <code>Choice</code> type {@link Choice#POPUP} * is not allowed on <code>List</code> objects.</p> * * <h3>Selection in <code>EXCLUSIVE</code> and <code>MULTIPLE</code> Lists</h3> * * <p>The select operation is not associated with a * <code>Command</code> object, so the * application has no means of setting a label for it or being notified when * the operation is performed.  In <code>Lists</code> of type * <code>EXCLUSIVE</code>, the select * operation selects the target element and deselects the previously selected * element.  In <code>Lists</code> of type <code>MULTIPLE</code>, the * select operation toggles the * selected state of the target element, leaving the selected state of other * elements unchanged.  Devices that implement the select operation using a * soft key will need to provide a label for it.  The label should be something * similar to &quot;Select&quot; for <code>Lists</code> of type * <code>EXCLUSIVE</code>, and it should be something * similar to &quot;Mark&quot; or &quot;Unmark&quot; for * <code>Lists</code> of type <code>MULTIPLE</code>.</p> * * <h3>Selection in <code>IMPLICIT</code> Lists</h3> * * <p>The select operation is associated with a <code>Command</code> * object referred to as * the <em>select command</em>.  When the user performs the select operation, * the system will invoke the select command by notifying the * <code>List's</code> {@link * CommandListener CommandListener}.  The default select command is the * system-provided command <code>SELECT_COMMAND</code>.  The select * command may be modified * by the application through use of the {@link #setSelectCommand(Command * command) setSelectCommand} method.  Devices that implement the select * operation using a soft key will use the label from the select command.  If * the select command is <code>SELECT_COMMAND</code>, the device may * choose to provide its * own label instead of using the label attribute of * <code>SELECT_COMMAND</code>. * Applications should generally provide their own select command to replace * <code>SELECT_COMMAND</code>.  This allows applications to provide a * meaningful label, * instead of relying on the one provided by the system for * <code>SELECT_COMMAND</code>. * The implementation must <em>not</em> invoke the select command if there are * no elements in the <code>List</code>, because if the * <code>List</code> is empty the selection does * not exist.  In this case the implementation should remove or disable the * select command if it would appear explicitly on a soft button or in a menu. * Other commands can be invoked normally when the <code>List</code> * is empty.</p> * * <h3>Use of <code>IMPLICIT</code> Lists</h3> * * <p> <code>IMPLICIT</code> <code>Lists</code> can be used to * construct menus by providing operations * as <code>List</code> elements.  The application provides a * <code>Command</code> that is used to * select a <code>List</code> element and then defines this * <code>Command</code> to be used as the * select command.  The application must also register a * <code>CommandListener</code> that * is called when the user selects or activates the <code>Command</code>:</p> * * <TABLE BORDER="2"> * <TR> * <TD ROWSPAN="1" COLSPAN="1"> *    <pre><code> *     String[] elements = { ... }; //Menu items as List elements *     List menuList = new List("Menu", List.IMPLICIT, elements, null); *     Command selectCommand = new Command("Open", Command.ITEM, 1); *     menuList.setSelectCommand(selectCommand); *     menuList.setCommandListener(...);     </code></pre> * </TD> * </TR> * </TABLE> * * <p>The listener can query the <code>List</code> to determine which * element is selected * and then perform the corresponding action.  Note that setting a command as * the select command adds it to the <code>List</code> as a side effect.</p> * * <p> The select command should be considered as a <em>default operation</em> * that takes place when a select key is pressed.  For example, a * <code>List</code> * displaying email headers might have three operations: read, reply, and * delete. Read is considered to be the default operation.  </p> * * <TABLE BORDER="2"> * <TR> * <TD ROWSPAN="1" COLSPAN="1"> *    <pre><code> *     List list = new List("Email", List.IMPLICIT, headers); *     readCommand = new Command("Read", Command.ITEM, 1); *     replyCommand = new Command("Reply", Command.ITEM, 2); *     deleteCommand = new Command("Delete", Command.ITEM, 3); *     list.setSelectCommand(readCommand); *     list.addCommand(replyCommand); *     list.addCommand(deleteCommand); *     list.setCommandListener(...);     </code></pre> * </TD> * </TR> * </TABLE> * <p>On a device with a dedicated select key, pressing this key will invoke * <code>readCommand</code>.  On a device without a select key, the user is * still able to invoke the read command, since it is also provided as an * ordinary <code>Command</code>.</p> * * <p> It should be noted that this kind of default operation must be used * carefully, and the usability of the resulting user interface must always * kept in mind. The default operation should always be the most intuitive * operation on a particular List.  </p> * * @since MIDP 1.0 */public class List extends Screen implements Choice {    /**     * The default select command for <code>IMPLICIT</code> <code>Lists</code>.     * Applications using an <code>IMPLICIT</code> <code>List</code>     * should set their own select command     * using      * {@link #setSelectCommand(Command command) setSelectCommand}.     *      * <p>     * The field values of <code>SELECT_COMMAND</code> are:<br>     * - <code>label = &quot;&quot;</code> (an empty string)<br>     * - <code>type = SCREEN</code><br>     * - <code>priority = 0</code><br>     * </p>     * <p>(It would be more appropriate if the type were     * <code>ITEM</code>, but the type of     * <code>SCREEN</code> is retained for historical purposes.)</p>     * <p>     * The application should not use these values for recognizing     * the <code>SELECT_COMMAND</code>. Instead, object identities of     * the <code>Command</code> and     * <code>Displayable</code> (<code>List</code>) should be used.     * </p>     *      * <p><code>SELECT_COMMAND</code> is treated as an ordinary     * <code>Command</code> if it is used with other <code>Displayable</code>     * types.</p>     */    public final static Command SELECT_COMMAND =        new Command("", Command.SCREEN, 0);    // private members //    /**     * An internal Form to render this List (basically, a List is     * just a Form with a choiceGroup in it     */    private Form form;    // SYNC NOTE: The List constructor establishes 'cg' as non-null    // and which remains constant for the lifetime of this object.    // All public api calls are delegated to the 'cg' object and    // therefore no synchronization is necessary.    /**     * An internal choicegroup to handle the selections     */    private ChoiceGroup cg;    /**     * This is an internal Command which represents the callback     * to a selection event of an IMPLICIT list. By default, this     * command is the predefined List.SELECT_COMMAND. This can be     * overridden however using the setSelectCommand().     */    private Command selectCommand = SELECT_COMMAND;    // constructors //    /**     * Creates a new, empty <code>List</code>, specifying its title     * and the type of the     * list.      * @param title the screen's title (see {@link Displayable Displayable})     * @param listType one of <code>IMPLICIT</code>, <code>EXCLUSIVE</code>,     * or <code>MULTIPLE</code>     * @throws IllegalArgumentException if <code>listType</code> is not     * one of     * <code>IMPLICIT</code>,     * <code>EXCLUSIVE</code>, or <code>MULTIPLE</code>     * @see Choice     */    public List(String title, int listType) {        this(title, listType, new String[] {}, new Image[] {});    }    /**     * Creates a new <code>List</code>, specifying its title, the type     * of the <code>List</code>, and     * an array of <code>Strings</code> and <code>Images</code> to be     * used as its initial contents.     *     * <p>The <code>stringElements</code> array must be non-null and     * every array element     * must also be non-null.  The length of the     * <code>stringElements</code> array     * determines the number of elements in the <code>List</code>.     * The <code>imageElements</code> array     * may be <code>null</code> to indicate that the <code>List</code>     * elements have no images.  If the     * <code>imageElements</code> array is non-null, it must be the     * same length as the     * <code>stringElements</code> array.  Individual elements of the     * <code>imageElements</code> array     * may be <code>null</code> in order to indicate the absence of an     * image for the     * corresponding <code>List</code> element. Non-null elements of the     * <code>imageElements</code> array may refer to mutable or     * immutable images.</p>     *     * @param title the screen's title (see {@link Displayable Displayable})     * @param listType one of <code>IMPLICIT</code>, <code>EXCLUSIVE</code>,     * or <code>MULTIPLE</code>     * @param stringElements set of strings specifying the string parts of the     * <code>List</code> elements     * @param imageElements set of images specifying the image parts of     * the <code>List</code> elements     *     * @throws NullPointerException if <code>stringElements</code> is     * <code>null</code>     * @throws NullPointerException if the <code>stringElements</code>     * array contains any null elements     * @throws IllegalArgumentException if the <code>imageElements</code>     * array is non-null     * and has a different length from the <code>stringElements</code> array     * @throws IllegalArgumentException if <code>listType</code> is not one      * of <code>IMPLICIT</code>,     * <code>EXCLUSIVE</code>, or <code>MULTIPLE</code>     *     * @see Choice#EXCLUSIVE     * @see Choice#MULTIPLE     * @see Choice#IMPLICIT     */    public List(String title, int listType, String[] stringElements,		Image[] imageElements) {        super(title);

⌨️ 快捷键说明

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