displayablelfimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 1,171 行 · 第 1/3 页
JAVA
1,171 行
/* * * * 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.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.chameleon.skins.*;/*** This is the look & feel implementation for Displayable.*/class DisplayableLFImpl implements DisplayableLF { /** * Creates DisplayableLF for the passed in Displayable. * @param d the Displayable object associated with this * look &s; feel. */ DisplayableLFImpl(Displayable d) { owner = d; resetViewport(); } // ************************************************************ // public methods - DisplayableLF interface implementation // ************************************************************ /** * Returns the width of the area available to the application. * @return width of the area available to the application */ public int lGetWidth() { // NOTE: If we update the viewport size in all cases we change // the displayable's size then we needn't to update it inside // the method. So we need to investigate removing // 'resetViewport()' below. resetViewport(); return viewport[WIDTH]; } /** * Returns the height of the area available to the application. * @return height of the area available to the application */ public int lGetHeight() { // NOTE: If we update the viewport size in all cases we change // the displayable's size then we needn't to update it inside // the method. So we need to investigate removing // 'resetViewport()' below. resetViewport(); return viewport[HEIGHT]; } /** * Notifies Displayable'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) { Display d = lGetCurrentDisplay(); if (d != null) { d.lSetTitle(this, newTitle); } // Displayable area size may be affected by the presence or // absence of the title so we need to update the viewport resetViewport(); } /** * Notifies Displayable'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) { Display d = lGetCurrentDisplay(); if (d != null) { d.lSetTicker(this, newTicker); } if (newTicker != null) { newTicker.tickerLF.lSetOwner(this); } // Displayable area size may be affected by the presence or // absence of the ticker so we need to update the viewport resetViewport(); } /** * 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 Displayable.commands[] * array */ public void lAddCommand(Command cmd, int i) { updateCommandSet(); } /** * Notifies look & 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 Displayable.commands[] * array */ public void lRemoveCommand(Command cmd, int i) { updateCommandSet(); } /** * Updates command set if this Displayable is visible. * * SYNC NOTE: Caller should hold LCDUILock. */ public void updateCommandSet() { if (state == SHOWN && currentDisplay != null) { currentDisplay.updateCommandSet(); } } /** * Return the Display instance in which the LF is currently shown. * @return the current Display. */ public Display lGetCurrentDisplay() { return currentDisplay; } /** * Implement public API isShown(). * @return true if current DisplayableLF is interactive with user. */ public boolean lIsShown() { return !(currentDisplay == null) && currentDisplay.isShown(this); } /** * Notifies look and feel object of a full screen mode change. * If true, this DisplayableLF will take up as much screen real estate * as possible. * * @param mode - if true displayable should be displayed * without title, ticker, etc.; if false - otherwise */ public void uSetFullScreenMode(boolean mode) { boolean requestRepaint = false; synchronized (Display.LCDUILock) { if (lIsShown()) { // IMPL_NOTE: Notify MainWindow of screen mode change // currentDisplay is not null when lIsShown is true currentDisplay.lSetFullScreen(mode); layout(); updateCommandSet(); requestRepaint = true; } else { // Layout needs to happen even if the canvas is not visible // so that correct width and height could be returned // in getWidth() and getHeight() layout(); } } // app's sizeChanged has to be called before repaint synchronized (Display.LCDUILock) { if (requestRepaint) { lRequestPaint(); } } } /** * \Need revisit Move this to CanvasLFImpl. * Called to get key mask of all the keys that were pressed. * @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; } } /** * Return the associated Displayable object. * @return the Displayable. */ public Displayable lGetDisplayable() { return owner; } /** * Set the display instance the Displayable is associated with. * Caller should hold LCDUILock around this call. * * @param d Display instance in which this DisplayableLF is visible. * null if this DisplayableLF is no longer visible. */ public void lSetDisplay(Display d) { // ASSERT(d == null || currentDisplay == null) currentDisplay = d; } /** * Prepare to show this LF on physical screen. * This function simply calls lCallShow() after obtaining LCDUILock. */ public void uCallShow() { boolean copyDefferedSizeChange; if (Logging.REPORT_LEVEL <= Logging.INFORMATION) { Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI_FORM_LAYOUT, "# in DisplayableLFImpl: uCallShow"); } synchronized (Display.LCDUILock) { // Assure correct screen mode currentDisplay.lSetFullScreen(owner.isInFullScreenMode); copyDefferedSizeChange = defferedSizeChange; defferedSizeChange = false; } if (copyDefferedSizeChange) { synchronized (Display.calloutLock) { try { owner.sizeChanged(viewport[WIDTH], viewport[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() { if (Logging.REPORT_LEVEL <= Logging.INFORMATION) { Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI_FORM_LAYOUT, "# in DisplayableLFImpl: lCallShow"); } // This will suppress drags, repeats and ups until a // corresponding down is seen. sawPointerPress = sawKeyPress = false; // IMPL_NOTE: Move this to CanvasLFImpl // 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; } // IMPL_NOTES: should be remove after interface will be fixed currentDisplay.setVerticalScroll(getVerticalScrollPosition(), getVerticalScrollProportion()); state = SHOWN; } // lCallShow() /** * Get the current vertical scroll position * * @return int The vertical scroll position on a scale of 0-100 */ public int getVerticalScrollPosition() { return 0; } /** * Get the current vertical scroll proportion * * @return ing The vertical scroll proportion on a scale of 0-100 */ public int getVerticalScrollProportion() { // SYNC NOTE: return of atomic value return 100; } /** * Remove this displayable from physical screen. * This function simply calls lCallHide() after obtaining LCDUILock. */ public void uCallHide() { if (Logging.REPORT_LEVEL <= Logging.INFORMATION) { Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI_FORM_LAYOUT, "# in DisplayableLFImpl: uCallHide"); } synchronized (Display.LCDUILock) { lCallHide(); } } /** * Remove this displayable from physical screen. * The displayable should unload any resource that was allocated. It's not * required to clean the physical screen before this function returns. * This function could be called while a LF is in "freeze" mode.<p> * * This function simply sets this DisplayableLF to HIDDEN state. */ void lCallHide() { if (Logging.REPORT_LEVEL <= Logging.INFORMATION) { Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI_FORM_LAYOUT, "# in DisplayableLFImpl: lCallHide"); } state = HIDDEN; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?