customitem.java

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

JAVA
1,214
字号
/* *    * * 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; *//** * A CustomItem is customizable by subclassing to introduce new visual and * interactive elements into <code>Forms</code>.  * Subclasses are responsible for their visual * appearance including sizing and rendering and choice of colors, fonts and * graphics.  Subclasses are responsible for the user interaction mode by * responding to events generated by keys, pointer actions, and traversal * actions.  Finally, subclasses are responsible for calling {@link * Item#notifyStateChanged} to trigger notification of listeners that the * <code>CustomItem's</code> value has changed. * * <p>Like other <code>Items</code>, <code>CustomItems</code> * have the concept of <em>minimum</em> and * <em>preferred</em> sizes.  These pertain to the total area * of the <code>Item</code>, * which includes space for the content, label, borders, etc.  See <a * href="Item.html#sizes">Item Sizes</a> for a full discussion of the * areas and sizes of <code>Items</code>.</p> * * <p><code>CustomItem</code> subclasses also have the concept * of the <em>content</em> size, which is the size of only the * content area of the <code>CustomItem</code>.  The * content area is a rectangular area inside the total area occupied by the * <code>CustomItem</code>. * The content area is the area within which the <code>CustomItem</code> * subclass paints and receives input events.  It does not include space * consumed by labels and borders.  The implementation is responsible for * laying out, painting, and handling input events within the area * of the <code>Item</code> that is outside the content area.</p> * * <p>All coordinates passed between the implementation and * the <code>CustomItem</code> * subclass are relative to the item's content area, with the upper-left * corner of this area being located at <code>(0,0)</code>.  * Size information passed * between the implementation and the <code>CustomItem</code> subclass with the *  * {@link #getMinContentHeight getMinContentHeight}, * {@link #getMinContentWidth getMinContentWidth}, * {@link #getPrefContentHeight getPrefContentHeight}, * {@link #getPrefContentWidth getPrefContentWidth}, and * {@link #sizeChanged sizeChanged} *  * methods all refer to the size of the content area.  The implementation is * responsible for computing and maintaining the difference between the size * of the content area and the size of the total area of the * <code>Item</code> as reported by the Item size methods *  * {@link Item#getMinimumHeight Item.getMinimumHeight}, * {@link Item#getMinimumWidth Item.getMinimumWidth}, * {@link Item#getPreferredHeight Item.getPreferredHeight}, and * {@link Item#getPreferredWidth Item.getPreferredWidth}.</p> * * <p>The implementation may disregard sizing information returned from a * <code>CustomItem</code> if it exceeds limits imposed by the * implementation's user interface policy.  In  * this case, the implementation must always report the actual size granted to  * the <code>CustomItem</code> via the {@link #sizeChanged sizeChanged} * and the {@link #paint paint} methods. * For example, this situation may occur if the implementation * prohibits an <code>Item</code> from becoming wider than the screen.  If the * <code>CustomItem</code> subclass code returns a value from * <code>getMinContentWidth</code> that would result in the * <code>CustomItem</code> being wider than the screen, the implementation may  * assign a width smaller than the minimum width returned by * <code>getMinContentWidth</code>.</p> * * <p>The implementation is allowed to call the <code>CustomItem's</code>  * content size methods *  * {@link #getMinContentHeight getMinContentHeight}, * {@link #getMinContentWidth getMinContentWidth}, * {@link #getPrefContentHeight getPrefContentHeight}, and * {@link #getPrefContentWidth getPrefContentWidth}, *  * in any order with respect to other <code>CustomItem</code> methods. * For all of these methods, the <code>CustomItem</code> subclass code must * return values that are consistent with the current contents of the * <code>CustomItem</code>.  If the contents changes, it is not sufficient for * the <code>CustomItem</code> subclass code simply to begin returning * different values from the content size methods.  Instead, the subclass code * must call the {@link #invalidate invalidate} method whenever its contents * changes.  This indicates to the implementation that it may need to perform * its layout computation, which will call the content size methods to get new * values based on the <code>CustomItem's</code> new contents.</p> *  * <a name="interaction"></a> * <h2>Interaction Modes</h2> * <p>The <code>CustomItem</code> class is intended to allow  * edit-in-place on many items, * but it does not allow every conceivable interaction.  Desire for * flexibility has been balanced against a requirement that these APIs be * simple enough to master easily, along with a need to allow for * platform-specific variations in look-and-feel, all without sacrificing * interoperability.</p> * * <p>The general idea is that there are multiple interaction * &quot;modes&quot; and that the <code>Form</code>  * implementation can convey which * ones it supports.  The <code>CustomItem</code> can then choose to * support one or more interaction modes.  There is no requirement for a * <code>CustomItem</code> to implement all combinations of * all interaction modes. * Typically, a <code>CustomItem</code> will implement an  * approach (such as the separate * editing screen technique discussed below) that works on all platforms, * in addition to a highly interactive approach that relies on a particular * interaction mode.  At run time, the <code>CustomItem</code> * code can query the system * to determine whether this interaction mode is supported.  If it is, the * <code>CustomItem</code> can use it; otherwise, it will fall * back to the approach that works on all platforms. </p> * * <p><code>CustomItem</code> can always use item commands to invoke * a separate editing screen, * although components with a small number of discrete * states could simply respond by changing the state and * then causing an <code>notifyStateChanged</code> notification.  * A technique for using a * separate editing screen would be to load the value into another * <code>Displayable</code> object (such as a List) and then to call * {@link Display#setCurrent(Displayable)} on it. * When the user * issues a command (such as &quot;OK&quot;) to indicate that  * editing of this value is * complete, the listener can retrieve the value from that * <code>Displayable</code> object * and then call * {@link Display#setCurrentItem(Item)} to return to this item.</p> * * <a name="keypad"></a> * <h2>Keypad Input</h2> * * <p>The implementation may optionally support delivery of keypad events to * the <code>CustomItem</code>.  The implementation indicates * the level of support by * setting the <code>KEY_PRESS</code>, <code>KEY_RELEASE</code>, and * <code>KEY_REPEAT</code> bits in the value * returned by <code>getInteractionModes</code>.   * Events corresponding to these bits are * delivered through calls to the <code>keyPressed()</code>, * <code>keyReleased()</code>, and * <code>keyRepeated()</code> methods, respectively.   * If an implementation supports * <code>KEY_RELEASE</code> events, it must also support  * <code>KEY_PRESS</code> events.  If an * implementation supports <code>KEY_REPEAT</code> events, it must also  * support <code>KEY_PRESS</code> * and <code>KEY_RELEASE</code> events.  If supported,  * <code>KEY_RELEASE</code> events will generally * occur after a corresponding <code>KEY_PRESS</code> event is  * received, and <code>KEY_REPEAT</code> * events will generally occur between <code>KEY_PRESS</code> and  * <code>KEY_RELEASE</code> events. * However, it is possible for the <code>CustomItem</code> to receive * <code>KEY_RELEASE</code> or * <code>KEY_REPEAT</code> events without a corresponding  * <code>KEY_PRESS</code> if a key is down when * the <code>CustomItem</code> becomes visible.</p> * * <p>Key event methods are passed the <code>keyCode</code>  * indicating the key on which the * event occurred.  Implementations must provide means for the user to * generate events with key codes <code>Canvas.KEY_NUM0</code>  * through <code>Canvas.KEY_NUM9</code>, * <code>Canvas.KEY_STAR</code>, and <code>Canvas.KEY_POUND</code>. * Implementations may also deliver * key events for other keys, include device-specific keys.  * The set of keys * available to a <code>CustomItem</code> may differ depending * upon whether commands have been added to it.</p> * * <p>The application may map key codes to game actions through use of the * <code>getGameAction</code> method.   * If the implementation supports key events on * <code>CustomItems</code>, the implementation must provide a  * sufficient set of key codes * and a mapping to game actions such that all game actions are available to * <code>CustomItems</code>.</p> * * <p>The set of keys and the key events available to a  * <code>CustomItem</code> may differ * from what is available on a <code>Canvas</code>.   * In particular, on a system that * supports traversal, the system might use directional keys for traversal and * elect not to deliver these keys to <code>CustomItems</code>.  * The mapping between key * codes and game actions in a <code>CustomItem</code> may differ * from the mapping in a <code>Canvas</code>.  See * <a href="Canvas.html#keyevents">Key Events</a> * and * <a href="Canvas.html#gameactions">Game Actions</a> * on class <code>Canvas</code> for further information about key codes and game * actions.</p> * * <a name="pointer"></a> * <h2>Pointer Input</h2> * * <p>The implementation may optionally support delivery of pointer events * (such as taps with a stylus) to the <code>CustomItem</code>.   * The implementation * indicates the level of support by setting the <code>POINTER_PRESS</code>, * <code>POINTER_RELEASE</code>, and <code>POINTER_DRAG</code> bits * in the value returned by <code>getInteractionModes</code>.  * Events corresponding to these bits are delivered * through calls to the <code>pointerPressed()</code>,  * <code>pointerReleased()</code>, and * <code>pointerDragged()</code> methods, respectively.   * If an implementation supports * <code>POINTER_RELEASE</code> events, it must also support  * <code>POINTER_PRESS</code> events.  If an * implementation supports <code>POINTER_DRAG</code> events,  * it must also support * <code>POINTER_PRESS</code> and <code>POINTER_RELEASE</code> events.   * If supported, <code>POINTER_RELEASE</code> * events will generally occur after a corresponding  * <code>POINTER_PRESS</code> event is * received, and <code>POINTER_DRAG</code> events will generally occur between * <code>POINTER_PRESS</code> and <code>POINTER_RELEASE</code> events.   * However, it is possible for the * <code>CustomItem</code> to receive <code>POINTER_RELEASE</code>  * or <code>POINTER_DRAG</code> events without a * corresponding <code>POINTER_PRESS</code> if the pointer is  * down when the <code>CustomItem</code> becomes visible.</p> * * <p>The <code>(x,y)</code> location of the pointer event is  * reported with every pointer * event.  This location is expressed in the coordinate system of the * <code>CustomItem</code>, where <code>(0,0)</code> is the upper-left * corner of the <code>CustomItem</code>.  Under * certain circumstances, pointer events may occur outside the bounds of the * item. </p> * * <h2>Traversal</h2> * * <p>An implementation may support traversal <em>internal</em> to a * <code>CustomItem</code>, that is, the implementation  * may temporarily delegate the * responsibility for traversal to the item itself.  Even if there is only one * traversal location inside the <code>CustomItem</code>,  * the item may want support the * internal traversal protocol so that it can perform specialized * highlighting, animation, etc. when the user has traversed into it.</p> * * <p>The implementation indicates its support for traversal internal to a * <code>CustomItem</code> by setting one or both of the  * <code>TRAVERSE_HORIZONTAL</code> or * <code>TRAVERSE_VERTICAL</code> bits in the value returned by * <code>getInteractionModes()</code>. If * neither of these bits is set, the implementation is unwilling to let * <code>CustomItems</code> traverse internally, or the  * implementation does not support * traversal at all.  If the implementation does support traversal but has * declined to permit traversal internal to <code>CustomItems</code>, * the implementation * will supply its own highlighting outside the  * <code>CustomItem's</code> content area.</p> * * <p>The <code>CustomItem</code> need not support internal * traversal at all.  It can do * this by returning <code>false</code> to the initial call to the * <code>traverse</code> method.  (This is the default behavior if this method * hasn't been overridden by the <code>CustomItem</code>.)  * If this occurs, the system must * arrange for the user to be able to traverse onto and past this item.  The * system must also arrange for proper scrolling to take place, particularly * if the item exceeds the height of the screen, regardless of whether * internal traversal is occurring.</p> * * <p>An implementation may provide support for delivering keypad or pointer * events to <code>CustomItems</code> even if it has declined * to support delivering traverse events to <code>CustomItems</code>.   * If an implementation provides support for * delivering keypad or pointer events to <code>CustomItems</code>,

⌨️ 快捷键说明

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