displayablelfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,140 行 · 第 1/3 页
JAVA
1,140 行
/* * * * 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; */import javax.microedition.lcdui.game.GameCanvas;import com.sun.midp.lcdui.EventConstants;import com.sun.midp.lcdui.GameMap;import com.sun.midp.lcdui.GameCanvasLFImpl;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.configurator.Constants;/** * The look and feel implementation of <code>Displayable</code> based * on platform widget. */abstract class DisplayableLFImpl implements DisplayableLF { /** Static initializer. */ static { initialize0(); } /** * Native class initializer. */ private static native void initialize0(); /** * Creates <code>DisplayableLF</code> for the passed in * <code>Displayable</code>. * * @param d the <code>Displayable</code> object associated with this * look & feel. */ DisplayableLFImpl(Displayable d) { owner = d; width = Display.WIDTH; height = Display.HEIGHT; } /** * Native finalizer to delete native resources. */ private native void finalize(); // ************************************************************ // public methods - DisplayableLF interface implementation // ************************************************************ /** * Implement public API isShown(). * * @return true if current <code>DisplayableLF</code> is interactive * with user. */ public boolean lIsShown() { return (currentDisplay != null) && currentDisplay.isShown(this); } /** * Get the width in pixels this <code>Displayable</code> is using. * * @return width of the area available to the application */ public int lGetWidth() { return width; } /** * Get the height in pixels this <code>Displayable</code> is using. * * @return height of the area available to the application */ public int lGetHeight() { return height; } /** * Notifies <code>Displayable</code>'s look & feel object of * a title change. * * SYNC NOTE: The caller of this method handles synchronization. * * @param oldTitle the old title, or <code>null</code> for no title * @param newTitle the new title, or <code>null</code> for no title */ public void lSetTitle(String oldTitle, String newTitle) { // No updates are necessary if we are in a full screen mode if (owner.isInFullScreenMode) { return; } // No update needed if title string is the same object if (oldTitle == newTitle) { return; } // No update needed if title strings have same content if (oldTitle != null && newTitle != null && oldTitle.equals(newTitle)) { return; } // Update only if we have native resource created if (nativeId != INVALID_NATIVE_ID) { setTitle0(nativeId, newTitle); } } /** * Notifies <code>Displayable</code>'s look & feel object of * a ticker change. * * SYNC NOTE: The caller of this method handles synchronization. * * @param oldTicker the old ticker, or <code>null</code> for no ticker * @param newTicker the new ticker, or <code>null</code> for no ticker */ public void lSetTicker(Ticker oldTicker, Ticker newTicker) { // This method will not be called if oldTicker and // newTicker are the same (that includes both being null) if (owner.ticker != null) { owner.ticker.tickerLF.lSetOwner(this); } updateNativeTicker(oldTicker, newTicker); } /** * Notifies look & feel object of a command addition * to the <code>Displayable</code>. * * SYNC NOTE: The caller of this method handles synchronization. * * @param cmd the command that was added * @param i the index of the added command in * <code>Displayable.commands[]</code> array */ public void lAddCommand(Command cmd, int i) { updateCommandSet(); } /** * Notifies look &s; feel object of a command removal * from the <code>Displayable</code>. * * SYNC NOTE: The caller of this method handles synchronization. * * @param cmd the command that was removed * @param i the index of the removed command in * <code>Displayable.commands[]</code> array */ public void lRemoveCommand(Command cmd, int i) { updateCommandSet(); } /** * Updates command set if this <code>Displayable</code> is visible. * * SYNC NOTE: Caller must hold LCDUILock around this call. */ public void updateCommandSet() { if (state == SHOWN && currentDisplay != null) { currentDisplay.updateCommandSet(); } } /** * Return the <code>Display</code> instance in which the LF is * currently shown. * * @return the <code>Display</code> instance in which the LF is shown. * <code>Null</code> if not shown. */ public Display lGetCurrentDisplay() { return currentDisplay; } /** * Called to get the key mask of all the keys that were pressed. * Implement an interface function for <code>CanvasLF</code> only. * * @return keyMask The key mask of all the keys that were pressed. */ public int uGetKeyMask() { synchronized (Display.LCDUILock) { // don't release currently pressed keys int savedMaskCopy = stickyKeyMask | currentKeyMask; stickyKeyMask = 0; return savedMaskCopy; } } /** * Set the display instance the <code>Displayable</code> is associated * with. * Caller should hold LCDUILock around this call. * * @param d <code>Display</code> instance in which this * <code>DisplayableLF</code> is visible. * <code>null</code> if this <code>DisplayableLF</code> is * no longer visible. */ public void lSetDisplay(Display d) { // ASSERT(d == null || currentDisplay == null) currentDisplay = d; } /** * Return the associated Displayable object. * * SYNC NOTE: Since the <code>Displayable</code> and * <code>DisplayableLFImpl</code> has 1-to-1 mapping, this function * can be called from in or outside of LCDUILock. * * @return the public model object this LF is associated with. */ public Displayable lGetDisplayable() { return owner; } /** * Notifies look & feel object of a full screen mode change. * * @param mode <code>true</code>, if canvas should be displayed * without title, ticker, etc.; <code>false</code> otherwise */ public void uSetFullScreenMode(boolean mode) { boolean requestRepaint = false; synchronized (Display.LCDUILock) { if (lIsShown()) { // currentDisplay is not null when lIsShown is true currentDisplay.lSetFullScreen(mode); if (mode) { setTicker(null); } else if (owner.ticker != null) { setTicker(owner.ticker); } updateCommandSet(); requestRepaint = true; } } if (currentDisplay != null) { // This may call into app code, so do it outside LCDUILock uCallSizeChanged(currentDisplay.width, currentDisplay.height); } else { uCallSizeChanged(Display.WIDTH, Display.HEIGHT); } // app's sizeChanged has to be called before repaint synchronized (Display.LCDUILock) { if (requestRepaint) { lRequestPaint(); } } } /** * Prepare to show this LF on physical screen. * This function will set correct screen mode screen mode * then call lCallShow. */ public void uCallShow() { boolean copyDefferedSizeChange; synchronized (Display.LCDUILock) { // Assure correct screen mode currentDisplay.lSetFullScreen(owner.isInFullScreenMode); // display dimentions may change as the resulr of lSetFullScreen width = currentDisplay.width; height = currentDisplay.height; if (owner.isInFullScreenMode) { setTicker(null); } else if (owner.ticker != null) { setTicker(owner.ticker); } copyDefferedSizeChange = defferedSizeChange; defferedSizeChange = false; } if (copyDefferedSizeChange) { synchronized (Display.calloutLock) { try { owner.sizeChanged(width, height); } catch (Throwable t) { Display.handleThrowable(t); } } } synchronized (Display.LCDUILock) { // Do the internal show preparation lCallShow(); if (pendingInvalidate || copyDefferedSizeChange) { lRequestInvalidate(); } } } /** * Prepare to show this LF on physical screen. This is the * internal version of showNotify() function as defined in MIDP spec. * It is called immediately prior to this LF being made visible * on the display. The LF should load any resource that is * needed, layout. App's paint() should NOT be called in this function. * Instead, it should be in the uCallPaint() that will be called on this * LF shortly after. * * This function sets this DisplayableLF to SHOWN state. */ void lCallShow() { // This will suppress drags, repeats and ups until a // corresponding down is seen. sawPointerPress = sawKeyPress = false; if (state != SHOWN) { // Create native resource first // since the title and ticker may depend on it createNativeResource(); } // Start to paint the ticker updateNativeTicker(null, owner.ticker); // set mapping between GameCanvas and DisplayAccess // set Game key event flag based on value passed in // GameCanvas constructor. if (owner instanceof GameCanvas) { GameMap.registerDisplayAccess(owner, currentDisplay.accessor); stickyKeyMask = currentKeyMask = 0; } else { // set the keymask to -1 when // the displayable is not a GameCanvas. stickyKeyMask = currentKeyMask = -1; } state = SHOWN; } // lCallShow() /** * Get the current vertical scroll position. * * @return int The vertical scroll position on a scale of 0-100 */ public int getVerticalScrollPosition() { // SYNC NOTE: return of atomic value return 0; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?