📄 display.java
字号:
} screenGraphics.reset(x1, y1, x2, y2); current.callPaint(screenGraphics, target); refresh(x1, y1, x2, y2); } /** * Return the key code that corresponds to the specified game * action on the device. gameAction must be a defined game action * (Canvas.UP, Canvas.DOWN, Canvas.FIRE, etc.) * <B>Post-conditions:</B><BR> The key code of the key that * corresponds to the specified action is returned. The return * value will be -1 if the game action is invalid or not supported * by the device. * * @param gameAction The game action to obtain the key code for. * @return the key code. */ static int getKeyCode(int gameAction) { return eventHandler.getKeyCode(gameAction); } /** * get the current vertical scroll position. * @return the vertical scroll position. */ int getVerticalScrollPosition() { // SYNC NOTE: No need to lock here because 'current' // can only be null once, at startup, so we don't care // if 'current' changes values, just that it isn't null if (current != null) { return current.getVerticalScrollPosition(); } else { return 0; } } /** * get the current vertical scroll proportion. * @return the vertical scroll proportion. */ int getVerticalScrollProportion() { // SYNC NOTE: No need to lock here because 'current' // can only be null once, at startup, so we don't care // if 'current' changes values, just that it isn't null if (current != null) { return current.getVerticalScrollProportion(); } else { return 100; } } /** * Return the game action associated with the given key code on * the device. keyCode must refer to a key that is mapped as a * game key on the device The game action of the key is returned. * The return value will be 0 if the key is not mapped to a game * action or not present on the device. * * @param keyCode the key code * @return the corresponding game action (UP, DOWN, LEFT, RIGHT, FIRE, etc.) */ static int getGameAction(int keyCode) { return eventHandler.getGameAction(keyCode); } /** * returns 0 if keyCode is not a system key. Otherwise, returns * one of the EventHandler.SYSTEM_KEY_ constants. * @param keyCode get the system equivalent key. * @return translated system key or zero if it is not a system key. */ static int getSystemKey(int keyCode) { return eventHandler.getSystemKey(keyCode); } /** * Gets an informative key string for a key. The string returned * should resemble the text physically printed on the key. For * example, on a device with function keys F1 through F4, calling * this method on the keycode for the F1 key will return the * string "F1". A typical use for this string will be to compose * help text such as "Press F1 to proceed." * * <p>There is no direct mapping from game actions to key * names. To get the string name for a game action, the * application must call * * <p><code>getKeyName(getKeyCode(GAME_A))</code> * @param keyCode the key code being requested * @return a string name for the key, or null if no name is available */ static String getKeyName(int keyCode) { return eventHandler.getKeyName(keyCode); } /** * Update the system's account of abstract commands * * SYNC NOTE: Calls to this method should be synchronized * on the LCDUILock */ void updateCommandSet() { Command[] screenCommands = current.getCommands(); int screenComCount = current.getCommandCount(); for (int i = 0; i < screenComCount; i++) { screenCommands[i].setInternalID(i); } Item curItem = current.getCurrentItem(); if (curItem == null) { eventHandler.updateCommandSet(null, 0, screenCommands, screenComCount); } else { Command[] itemCommands = curItem.getCommands(); int itemComCount = curItem.getCommandCount(); for (int i = 0; i < itemComCount; i++) { itemCommands[i].setInternalID(i + screenComCount); } eventHandler.updateCommandSet(itemCommands, itemComCount, screenCommands, screenComCount); } } /** * is the current display visible. * @param d displayble instance to check, if current and visible. * @return true, if the Display is visible and the object is current. */ boolean isShown(Displayable d) { // SYNC NOTE: calls to isShown() should be synchronized on // the LCDUILock. return hasForeground && !paintSuspended && (current == d); } /** * This is a utility method used to handle any Throwables * caught while calling application code. The default * implementation will simply call printStackTrace() on * the Throwable. Note, the parameter must be non-null or * this method will generate a NullPointerException. * * @param t The Throwable caught during the call into * application code. */ static void handleThrowable(Throwable t) { t.printStackTrace(); } /** * set the current vertical scroll position and proportion. * @param scrollPosition vertical scroll position. * @param scrollProportion vertical scroll proportion. */ native void setVerticalScroll(int scrollPosition, int scrollProportion); /** * set the input, mode. * @param mode type of input to accept. */ native void setInputMode(int mode); /** * Control the drawing of the trusted MIDlet * icon in native. * @param drawTrusted true if the icon should be drawn, * false if it should not. */ private native void drawTrustedIcon(boolean drawTrusted); /** * See if we're using the display's Graphics object. * @param gfx Graphics object to compare to <code>screenGraphics</code>. * @return true if <code>gfx</code> equals <code>screenGraphics</code>, * false otherwise. */ static boolean isGraphicsDisplay(Graphics gfx) { return screenGraphics == gfx; }/* * ************* private methods */ /** * get the class that handle I/O event stream for this display. * @return handle to the event handler for this display */ private static EventHandler getEventHandler() { String n = Configuration.getProperty( "com.sun.midp.lcdui.eventHandler"); try { return (EventHandler) (Class.forName(n)).newInstance(); } catch (Exception e) { } if (Configuration.getProperty("microedition.configuration") != null) { try { return (EventHandler) (Class.forName( "com.sun.midp.lcdui.AutomatedEventHandler")).newInstance(); } catch (Exception e) { } try { return (EventHandler) (Class.forName( "com.sun.midp.lcdui.DefaultEventHandler")).newInstance(); } catch (Exception e) { } throw new Error("Unable to establish EventHandler"); } try { return (EventHandler) (Class.forName( "com.sun.midp.lcdui.AWTEventHandler")).newInstance(); } catch (Exception e) { } throw new Error("Unable to establish EventHandler"); } /** * Registers a new Displayable object to this Display. This means that * it is now the current Displayable object, eligible to receive input * events, and eligible to paint. If necessary, showNotify() is called * on this Displayable and hideNotify() is called on the Displayable * being replaced. This method is used to initialize a Displayable as * a result of either: * - a SCREEN change timerEvent() * - a call to resumePainting() * - a change in foreground status of this Display (results in a call * to resumePainting()) * * @param newCurrent The Displayable to take effect as the new * "current" Displayable * @param fgChange If True, then this call to registerNewCurrent() is a * result of this Display being moved to the foreground, * i.e. setForeground(true) */ private void registerNewCurrent(Displayable newCurrent, boolean fgChange) { // If this Display is not in the foreground, simply record // the new Displayable and return. When this Display resumes // the foreground, this method will be called again. Displayable currentCopy = null; // SYNC NOTE: The implementation of callShowNotify() will // use LCDUILock to lock around its internal handling. // Canvas will override callShowNotify() to first call // super(), and then obtain a lock // on calloutLock around a call to the applications // showNotify() method. if (newCurrent != null) { newCurrent.callShowNotify(Display.this); } synchronized (LCDUILock) { if (fgChange) { hasForeground = true; if (newCurrent == null) { /* * At least clear the screen so the last display, which * could be destroyed (like the Selector) is not still * showing. */ screenGraphics.reset(0, 0, WIDTH, HEIGHT); screenGraphics.setColor(Display.ERASE_COLOR); screenGraphics.fillRect(0, 0, WIDTH, HEIGHT); refresh(0, 0, WIDTH, HEIGHT); eventHandler.updateCommandSet(null, 0, null, 0); /* * Without a displayable, we can shortcircuit the rest * of the call and simply return. */ return; } } // This will suppress drags, repeats and ups until a // corresponding down is seen. accessor.sawPointerPress = accessor.sawKeyPress = false; // We re-set our suspended state to false. paintSuspended = false; // We make a copy of the current Displayable to call // hideNotify() when we're done currentCopy = current; current = newCurrent; // set mapping between GameCanvas and DisplayAccess // set Game key event flag based on value passed in // GameCanvas constructor. if (current instanceof GameCanvas) { GameMap.register(current, accessor); stickyKeyMask = currentKeyMask = 0; } else { // set the keymask to -1 when // the displayable is not a GameCanvas. stickyKeyMask = currentKeyMask = -1; } setVerticalScroll( current.getVerticalScrollPosition(), current.getVerticalScrollProportion()); // Next, update the command set updateCommandSet(); } // synchronized // SYNC NOTE: The implementation of callHideNotify() // will use LCDUILock to lock around its internal handling. // Canvas will override callHideNotify(), first calling // super(), and then obtaining calloutLock around a call // to the application's hideNotify() method. // NOTE: the reason we test for currentCopy != current is // for cases when the Display has interrupted its suspension // by a system screen to immediately return to its "current" // Displayable. In this case, currentCopy == current, and // we've just called showNotify() above (no need to call // hideNotify()) if (currentCopy != null && currentCopy != current) { currentCopy.callHideNotify(Display.this); } repaint(0, 0, WIDTH, HEIGHT, null); } // registerNewCurrent() /** * run the serially repainted operations. */ private void getCallSerially() { java.util.Vector q = null; synchronized (LCDUILock) { q = currentQueue; currentQueue = (q == queue1) ? queue2 : queue1; } // SYNC NOTE: w
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -