📄 screen.java
字号:
//#condition polish.usePolishGui/* * Created on 12-Mar-2004 at 21:46:17. * * This file is part of J2ME Polish. * * J2ME Polish is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * J2ME Polish 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 for more details. * * You should have received a copy of the GNU General Public License * along with J2ME Polish; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Commercial licenses are also available, please * refer to the accompanying LICENSE.txt or visit * http://www.j2mepolish.org for details. */package de.enough.polish.ui;import java.io.IOException;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import de.enough.polish.ui.backgrounds.TranslucentSimpleBackground;import de.enough.polish.util.ArrayList;import de.enough.polish.util.Locale;//#ifdef polish.Screen.imports:defined //#include ${polish.Screen.imports}//#endif/** * The common superclass of all high-level user interface classes. * * The contents displayed and their interaction with the user are defined by * subclasses. * * <P>Using subclass-defined methods, the application may change the contents * of a <code>Screen</code> object while it is shown to the user. If * this occurs, and the * <code>Screen</code> object is visible, the display will be updated * automatically. That * is, the implementation will refresh the display in a timely fashion without * waiting for any further action by the application. For example, suppose a * <code>List</code> object is currently displayed, and every element * of the <code>List</code> is * visible. If the application inserts a new element at the beginning of the * <code>List</code>, it is displayed immediately, and the other * elements will be * rearranged appropriately. There is no need for the application to call * another method to refresh the display.</P> * * <P>It is recommended that applications change the contents of a * <code>Screen</code> only * while it is not visible (that is, while another * <code>Displayable</code> is current). * Changing the contents of a <code>Screen</code> while it is visible * may result in * performance problems on some devices, and it may also be confusing if the * <code>Screen's</code> contents changes while the user is * interacting with it.</P> * * <P>In MIDP 2.0 the four <code>Screen</code> methods that defined * read/write ticker and * title properties were moved to <code>Displayable</code>, * <code>Screen's</code> superclass. The * semantics of these methods have not changed.</P> * <HR> * * @since MIDP 1.0 * */public abstract class Screen//#if polish.Bugs.needsNokiaUiForSystemAlerts && !polish.SystemAlertNotUsed //#define tmp.needsNokiaUiForSystemAlerts//#endif//#if polish.hasCommandKeyEvents || (polish.key.LeftSoftKey:defined && polish.key.RightSoftKey:defined) //#define tmp.hasCommandKeyEvents//#endif//#if polish.useFullScreen //#if (polish.midp2 && !tmp.needsNokiaUiForSystemAlerts) && (!polish.useMenuFullScreen || tmp.hasCommandKeyEvents) //#define tmp.fullScreen //# extends Canvas //#elif polish.classes.fullscreen:defined //#define tmp.fullScreen //#= extends ${polish.classes.fullscreen} //#endif//#endif//#if !tmp.fullScreen extends Canvas//#endifimplements AccessibleCanvas{ private final static int POSITION_TOP = 0; private final static int POSITION_LEFT = 1; //#if tmp.fullScreen || polish.midp1 || (polish.usePolishTitle == true) //#define tmp.usingTitle protected Item title; private boolean excludeTitleForBackground; //#ifdef polish.css.title-style private Style titleStyle; //#endif //#if polish.css.title-position private boolean paintTitleAtTop = true; //#endif //#if polish.Vendor.Motorola || polish.Bugs.ignoreTitleCall //#define tmp.ignoreMotorolaTitleCall private boolean ignoreMotorolaTitleCall = true; //#endif //#endif //#ifdef polish.Vendor.Siemens // Siemens sometimes calls hideNotify directly // after showNotify for some reason. // So hideNotify checks how long the screen // has been shown - if not long enough, // the call will be ignored. private long showNotifyTime; //#endif private Item subTitle; protected int subTitleHeight; protected int titleHeight; protected Background background; protected Border border; protected Style style; /** the screen height minus the ticker height and the height of the menu bar */ protected int screenHeight; /** the screen height minus the height of the menu bar */ protected int originalScreenHeight; protected final int screenWidth; //#ifndef polish.skipTicker private Ticker ticker; //#if polish.Ticker.Position:defined //#if top == ${ lowercase(polish.Ticker.Position) } //#define tmp.paintTickerAtTop //#else //#define tmp.paintPositionAtBottom //#endif //#elif polish.css.ticker-position private boolean paintTickerAtTop; //#else //#define tmp.paintPositionAtBottom //#endif //#endif protected String cssSelector; private ForwardCommandListener forwardCommandListener; protected Container container; private boolean isLayoutCenter; private boolean isLayoutRight; private boolean isLayoutVCenter; private boolean isLayoutBottom; private boolean isLayoutHorizontalShrink; private boolean isLayoutVerticalShrink; private boolean isInitialised; //#if polish.ScreenChangeAnimation.forward:defined protected Command lastTriggeredCommand; //#endif //#if (polish.useMenuFullScreen && tmp.fullScreen) || polish.needsManualMenu //#define tmp.menuFullScreen /** the real, complete height of the screen - this includes title, subtitle, content and menubar */ protected int fullScreenHeight; protected int menuBarHeight; private boolean excludeMenuBarForBackground; //#ifdef polish.key.ReturnKey:defined private Command backCommand; //#endif private Command okCommand; //#if polish.MenuBar.useExtendedMenuBar || polish.classes.MenuBar:defined //#if polish.classes.MenuBar:defined //#= private final ${polish.classes.MenuBar} menuBar; //#else private final MenuBar menuBar; //#endif //#define tmp.useExternalMenuBar //#else //#ifdef polish.key.LeftSoftKey:defined //#= private final static int LEFT_SOFT_KEY = ${polish.key.LeftSoftKey}; //#else private final static int LEFT_SOFT_KEY = -6; //#endif //#ifdef polish.key.RightSoftKey:defined //#= private final static int RIGHT_SOFT_KEY = ${polish.key.RightSoftKey}; //#else private final static int RIGHT_SOFT_KEY = -7; //#endif private Command menuSingleLeftCommand; private Command menuSingleRightCommand; private Container menuContainer; private ArrayList menuCommands; private boolean menuOpened; private Font menuFont; private int menuFontColor = 0; private int menuBarColor = 0xFFFFFF; //#ifdef polish.hasPointerEvents private int menuRightCommandX; private int menuLeftCommandX; //#endif //#endif //#endif /** The Gauge Item which should be animated by this screen */ Item gauge; /** The currently focused items which has item-commands */ private Item focusedItem; //#if polish.useScrollBar || polish.classes.ScrollBar:defined //#define tmp.useScrollBar //#if polish.classes.ScrollBar:defined //#style scrollbar? //#= protected final ${polish.classes.ScrollBar} scrollBar = new ${polish.classes.ScrollBar}(); //#else //#style scrollbar? protected final ScrollBar scrollBar = new ScrollBar(); //#endif //#if polish.css.scrollbar-position protected boolean paintScrollBarOnRightSide = true; //#endif //#else private boolean paintScrollIndicator; private boolean paintScrollIndicatorUp; private boolean paintScrollIndicatorDown; private int scrollIndicatorColor; private int scrollIndicatorX; // left x position of scroll indicator private int scrollIndicatorY; // top y position of scroll indicator private int scrollIndicatorWidth; // width and height of the indicator //#if polish.css.scrollindicator-up-image || polish.css.scrollindicator-down-image private Image scrollIndicatorUpImage; private Image scrollIndicatorDownImage; //#endif //#endif //#if tmp.usingTitle || tmp.menuFullScreen private boolean showTitleOrMenu = true; //#endif /** an info text which is shown e.g. when some content is added to textfields */ private StringItem infoItem; /** determines whether the info text should be shown */ private boolean showInfoItem; protected int infoHeight; //#if tmp.fullScreen && polish.midp2 && polish.Bugs.fullScreenInPaint //#define tmp.fullScreenInPaint private boolean isInFullScreenMode; //#endif //#ifdef polish.css.foreground-image private Image foregroundImage; private int foregroundX; private int foregroundY; //#endif //#if polish.css.clip-screen-info private boolean clipScreenInfo; //#endif //#if polish.blackberry public boolean keyPressedProcessed; //#endif protected int contentX; protected int contentY; protected int contentWidth; protected int contentHeight; private int marginLeft; private int marginRight; private int marginTop; private int marginBottom; //#if polish.css.separate-menubar private boolean separateMenubar = true; //#endif //#if polish.css.repaint-previous-screen private boolean repaintPreviousScreen; //#if polish.Screen.dontBufferPreviousScreen private AccessibleCanvas previousScreen; //#else private Image previousScreenImage; //#endif //#if !polish.Bugs.noTranslucencyWithDrawRgb private Background previousScreenOverlayBackground; //#endif //#endif protected ScreenStateListener screenStateListener; private boolean isScreenChangeDirtyFlag; private final Object paintLock = new Object(); private int containerX; protected int containerY; /** * Creates a new screen, this constructor can be used together with the //#style directive. * * @param title the title, or null for no title * @param createDefaultContainer true when the default container should be created. */ public Screen( String title, boolean createDefaultContainer ) { this( title, null, createDefaultContainer ); } /** * Creates a new screen, this constructor can be used together with the //#style directive. * * @param title the title, or null for no title * @param style the style of this screen * @param createDefaultContainer true when the default container should be created. */ public Screen( String title, boolean createDefaultContainer, Style style ) { this( title, style, createDefaultContainer ); } /** * Creates a new screen * * @param title the title, or null for no title * @param style the style of this screen * @param createDefaultContainer true when the default container should be created. */ public Screen( String title, Style style, boolean createDefaultContainer ) { super(); //#if !(polish.Bugs.fullScreenInShowNotify || polish.Bugs.fullScreenInPaint || tmp.needsNokiaUiForSystemAlerts) //#if tmp.fullScreen && polish.midp2 //# super.setFullScreenMode( true ); //#endif //#endif // get the screen dimensions: // this is a bit complicated, since Nokia's FullCanvas fucks // up when calling super.getHeight(), so we need to use hardcoded values... //#ifdef tmp.menuFullScreen //#if polish.needsManualMenu && !tmp.fullScreen this.fullScreenHeight = getHeight(); //#else //#if tmp.needsNokiaUiForSystemAlerts //#ifdef polish.NokiaFullCanvasHeight:defined //#= this.fullScreenHeight = ${ polish.NokiaFullCanvasHeight }; //#else //# this.fullScreenHeight = getHeight(); //#endif //#else //#ifdef polish.FullCanvasHeight:defined //#= this.fullScreenHeight = ${ polish.FullCanvasHeight }; //#else //# this.fullScreenHeight = getHeight(); //#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -