📄 display.java
字号:
/* * @(#)Display.java 1.192 02/10/15 * * Copyright (c) 1999-2002 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package javax.microedition.lcdui;import java.util.*;import java.io.*;/* This is used to implement the communication between MIDlet and Display */import javax.microedition.midlet.MIDlet;import javax.microedition.lcdui.game.GameCanvas;import javax.microedition.io.Connector;import com.sun.midp.midlet.MIDletState;import com.sun.midp.midlet.MIDletStateMap;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midlet.Scheduler;import com.sun.midp.io.j2me.storage.File;import com.sun.midp.io.j2me.storage.RandomAccessStream;import com.sun.midp.main.Configuration;import com.sun.midp.lcdui.*;import com.sun.midp.security.*;/** * <code>Display</code> represents the manager of the display and * input devices of the * system. It includes methods for retrieving properties of the device and * for requesting that objects be displayed on the device. Other methods that * deal with device attributes are primarily used with {@link Canvas Canvas} * objects and are thus defined there instead of here. <p> * * There is exactly one instance of Display per {@link * javax.microedition.midlet.MIDlet MIDlet} and the application can get a * reference to that instance by calling the {@link * #getDisplay(javax.microedition.midlet.MIDlet) getDisplay()} method. The * application may call the <code>getDisplay()</code> method at any time * during course of * its execution. The <code>Display</code> object * returned by all calls to <code>getDisplay()</code> will remain the * same during this * time. <p> * * A typical application will perform the following actions in response to * calls to its <code>MIDlet</code> methods: * <UL> * <LI><STRONG>startApp</STRONG> - the application is moving from the * paused state to the active state. * Initialization of objects needed while the application is active should be * done. The application may call * {@link #setCurrent(Displayable) setCurrent()} for the first screen if that * has not already been done. Note that <code>startApp()</code> can be * called several * times if <code>pauseApp()</code> has been called in between. This * means that one-time * initialization * should not take place here but instead should occur within the * <code>MIDlet's</code> * constructor. * </LI> * <LI><STRONG>pauseApp</STRONG> - the application may pause its threads. * Also, if it is * desirable to start with another screen when the application is re-activated, * the new screen should be set with <code>setCurrent()</code>.</LI> * <LI><STRONG>destroyApp</STRONG> - the application should free resources, * terminate threads, etc. * The behavior of method calls on user interface objects after * <code>destroyApp()</code> has returned is undefined. </li> * </UL> * <p> * * <P>The user interface objects that are shown on the display device are * contained within a {@link Displayable Displayable} object. At any time the * application may have at most one <code>Displayable</code> object * that it intends to be * shown on the display device and through which user interaction occurs. This * <code>Displayable</code> is referred to as the <em>current</em> * <code>Displayable</code>. </p> * * <P>The <code>Display</code> class has a {@link * #setCurrent(Displayable) setCurrent()} * method for setting the current <code>Displayable</code> and a * {@link #getCurrent() * getCurrent()} method for retrieving the current * <code>Displayable</code>. The * application has control over its current <code>Displayable</code> * and may call * <code>setCurrent()</code> at any time. Typically, the application * will change the * current <code>Displayable</code> in response to some user action. * This is not always the * case, however. Another thread may change the current * <code>Displayable</code> in * response to some other stimulus. The current * <code>Displayable</code> will also be * changed when the timer for an {@link Alert Alert} elapses. </P> * * <p> The application's current <code>Displayable</code> may not * physically be drawn on the * screen, nor will user events (such as keystrokes) that occur necessarily be * directed to the current <code>Displayable</code>. This may occur * because of the presence * of other <code>MIDlet</code> applications running simultaneously on * the same device. </p> * * <P>An application is said to be in the <em>foreground</em> if its current * <code>Displayable</code> is actually visible on the display device * and if user input * device events will be delivered to it. If the application is not in the * foreground, it lacks access to both the display and input devices, and it is * said to be in the <em>background</em>. The policy for allocation of these * devices to different <code>MIDlet</code> applications is outside * the scope of this * specification and is under the control of an external agent referred to as * the <em>application management software</em>. </p> * * <P>As mentioned above, the application still has a notion of its current * <code>Displayable</code> even if it is in the background. The * current <code>Displayable</code> is * significant, even for background applications, because the current * <code>Displayable</code> is always the one that will be shown the * next time the * application is brought into the foreground. The application can determine * whether a <code>Displayable</code> is actually visible on the * display by calling {@link * Displayable#isShown isShown()}. In the case of <code>Canvas</code>, * the {@link * Canvas#showNotify() showNotify()} and {@link Canvas#hideNotify() * hideNotify()} methods are called when the <code>Canvas</code> is * made visible and is * hidden, respectively.</P> * * <P> Each <code>MIDlet</code> application has its own current * <code>Displayable</code>. This means * that the {@link #getCurrent() getCurrent()} method returns the * <code>MIDlet's</code> * current <code>Displayable</code>, regardless of the * <code>MIDlet's</code> foreground/background * state. For example, suppose a <code>MIDlet</code> running in the * foreground has current * <code>Displayable</code> <em>F</em>, and a <code>MIDlet</code> * running in the background has current * <code>Displayable</code> <em>B</em>. When the foreground * <code>MIDlet</code> calls <code>getCurrent()</code>, it * will return <em>F</em>, and when the background <code>MIDlet</code> * calls <code>getCurrent()</code>, it * will return <em>B</em>. Furthermore, if either <code>MIDlet</code> * changes its current * <code>Displayable</code> by calling <code>setCurrent()</code>, this * will not affect the any other * <code>MIDlet's</code> current <code>Displayable</code>. </p> * * <P>It is possible for <code>getCurrent()</code> to return * <code>null</code>. This may occur at startup * time, before the <code>MIDlet</code> application has called * <code>setCurrent()</code> on its first * screen. The <code>getCurrent(</code>) method will never return a * reference to a * <code>Displayable</code> object that was not passed in a prior call * to <code>setCurrent()</code> call * by this <code>MIDlet</code>. </p> * * <a name="systemscreens"></a> * <h3>System Screens</h3> * * <P> Typically, the * current screen of the foreground <code>MIDlet</code> will be * visible on the display. * However, under certain circumstances, the system may create a screen that * temporarily obscures the application's current screen. These screens are * referred to as <em>system screens.</em> This may occur if the system needs * to show a menu of commands or if the system requires the user to edit text * on a separate screen instead of within a text field inside a * <code>Form</code>. Even * though the system screen obscures the application's screen, the notion of * the current screen does not change. In particular, while a system screen is * visible, a call to <code>getCurrent()</code> will return the * application's current * screen, not the system screen. The value returned by * <code>isShown()</code> is <code>false</code> * while the current <code>Displayable</code> is obscured by a system * screen. </p> * * <p> If system screen obscures a canvas, its * <code>hideNotify()</code> method is called. * When the system screen is removed, restoring the canvas, its * <code>showNotify()</code> * method and then its <code>paint()</code> method are called. If the * system screen was used * by the user to issue a command, the <code>commandAction()</code> * method is called after * <code>showNotify()</code> is called. </p> * * <p>This class contains methods to retrieve the prevailing foreground and * background colors of the high-level user interface. These methods are * useful for creating <CODE>CustomItem</CODE> objects that match the user * interface of other items and for creating user interfaces within * <CODE>Canvas</CODE> that match the user interface of the rest of the * system. Implementations are not restricted to using foreground and * background colors in their user interfaces (for example, they might use * highlight and shadow colors for a beveling effect) but the colors returned * are those that match reasonably well with the implementation's color * scheme. An application implementing a custom item should use the * background color to clear its region and then paint text and geometric * graphics (lines, arcs, rectangles) in the foreground color.</p> * * @since MIDP 1.0 */public class Display {/* * ************* public member variables */ /** * Image type for <code>List</code> element image. * * <P>The value of <code>LIST_ELEMENT</code> is <code>1</code>.</P> * * @see #getBestImageWidth(int imageType) * @see #getBestImageHeight(int imageType) * @since MIDP 2.0 */ public static final int LIST_ELEMENT = 1; /** * Image type for <code>ChoiceGroup</code> element image. * * <P>The value of <code>CHOICE_GROUP_ELEMENT</code> is <code>2</code>.</P> * * @see #getBestImageWidth(int imageType) * @see #getBestImageHeight(int imageType) * @since MIDP 2.0 */ public static final int CHOICE_GROUP_ELEMENT = 2; /** * Image type for <code>Alert</code> image. * * <P>The value of <code>ALERT</code> is <code>3</code>.</P> * * @see #getBestImageWidth(int imageType) * @see #getBestImageHeight(int imageType) * @since MIDP 2.0 */ public static final int ALERT = 3; /** * A color specifier for use with <code>getColor</code>. * <code>COLOR_BACKGROUND</code> specifies the background color of * the screen. * The background color will always contrast with the foreground color. * * <p> * <code>COLOR_BACKGROUND</code> has the value <code>0</code>. * * @see #getColor * @since MIDP 2.0 */ public static final int COLOR_BACKGROUND = 0; /** * A color specifier for use with <code>getColor</code>. * <code>COLOR_FOREGROUND</code> specifies the foreground color, * for text characters * and simple graphics on the screen. Static text or user-editable * text should be drawn with the foreground color. The foreground color * will always constrast with background color. * * <p> <code>COLOR_FOREGROUND</code> has the value <code>1</code>. * * @see #getColor * @since MIDP 2.0 */ public static final int COLOR_FOREGROUND = 1; /** * A color specifier for use with <code>getColor</code>. * <code>COLOR_HIGHLIGHTED_BACKGROUND</code> identifies the color for the * focus, or focus highlight, when it is drawn as a * filled in rectangle. The highlighted * background will always constrast with the highlighted foreground. * * <p> * <code>COLOR_HIGHLIGHTED_BACKGROUND</code> has the value <code>2</code>. * * @see #getColor * @since MIDP 2.0 */ public static final int COLOR_HIGHLIGHTED_BACKGROUND = 2; /** * A color specifier for use with <code>getColor</code>. * <code>COLOR_HIGHLIGHTED_FOREGROUND</code> identifies the color for text * characters and simple graphics when they are highlighted. * Highlighted * foreground is the color to be used to draw the highlighted text * and graphics against the highlighted background. * The highlighted foreground will always constrast with * the highlighted background. * * <p> * <code>COLOR_HIGHLIGHTED_FOREGROUND</code> has the value <code>3</code>. * * @see #getColor * @since MIDP 2.0 */ public static final int COLOR_HIGHLIGHTED_FOREGROUND = 3; /** * A color specifier for use with <code>getColor</code>. * <code>COLOR_BORDER</code> identifies the color for boxes and borders * when the object is to be drawn in a * non-highlighted state. The border color is intended to be used with * the background color and will contrast with it. * The application should draw its borders using the stroke style returned * by <code>getBorderStyle()</code>. * * <p> <code>COLOR_BORDER</code> has the value <code>4</code>. * * @see #getColor * @since MIDP 2.0 */ public static final int COLOR_BORDER = 4; /** * A color specifier for use with <code>getColor</code>. * <code>COLOR_HIGHLIGHTED_BORDER</code> * identifies the color for boxes and borders when the object is to be * drawn in a highlighted state. The highlighted border color is intended * to be used with the background color (not the highlighted background * color) and will contrast with it. The application should draw its * borders using the stroke style returned <code>by getBorderStyle()</code>. * * <p> <code>COLOR_HIGHLIGHTED_BORDER</code> has the value <code>5</code>. * * @see #getColor * @since MIDP 2.0 */ public static final int COLOR_HIGHLIGHTED_BORDER = 5;/* * ************* protected member variables */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -