⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screen.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		// 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
				//#endif
			//#endif
			this.screenHeight = this.fullScreenHeight; 
		//#else
			//# this.screenHeight = getHeight();
		//#endif
		this.originalScreenHeight = this.screenHeight;
		
		//#ifdef polish.ScreenWidth:defined
			//#= this.screenWidth = ${ polish.ScreenWidth };
		//#else
			this.screenWidth = getWidth();
		//#endif
						
		// creating standard container:
		if (createDefaultContainer) {
			this.container = new Container( true );
			this.container.screen = this;
		}
		this.style = style;
		this.forwardCommandListener = new ForwardCommandListener();
		//#ifndef tmp.menuFullScreen
			//# super.setCommandListener(this.forwardCommandListener);
		//#endif
		//#ifdef tmp.useExternalMenuBar
			//#style menubar, menu, default
			//# this.menuBar = new MenuBar( this );
		//#endif
		setTitle( title );
	}
		
	/**
	 * Initialises this screen before it is painted for the first time.
	 */
	private void init() {
		//#debug
de.enough.polish.util.Debug.debug("debug", "de.enough.polish.ui.Screen", 389, "Initialising screen ", this );
		boolean startAnimationThread = false;
		if (StyleSheet.animationThread == null) {
			StyleSheet.animationThread = new AnimationThread();
			startAnimationThread = true;
		}
		//#ifdef polish.Screen.initCode:defined
			//#include ${polish.Screen.initCode}
		//#endif
		if (this.style != null) {
			setStyle( this.style );
		}
		//#ifdef polish.useDynamicStyles
			// check if this screen has got a style:
			if (this.style == null) {
				this.cssSelector = createCssSelector();
				setStyle( StyleSheet.getStyle( this ) );
			} else {
				this.cssSelector = this.style.name;
			}
		//#endif
		//#ifdef tmp.menuFullScreen
			//#ifdef tmp.useExternalMenuBar
				//# int availableScreenWidth = this.screenWidth - (this.marginLeft + this.marginRight);
				//# this.menuBarHeight = this.menuBar.getItemHeight( availableScreenWidth, availableScreenWidth );
				//#if !tmp.useScrollBar
					//# int scrollWidth = this.menuBar.contentHeight + this.menuBar.paddingTop + this.menuBar.paddingBottom;
					//#if polish.css.scrollindicator-up-image
						//# if (this.scrollIndicatorUpImage != null) {
							//# scrollWidth = this.scrollIndicatorUpImage.getWidth(); 
						//# }
					//#elif polish.css.scrollindicator-down-image
						//# if (this.scrollIndicatorDownImage != null) {
							//# scrollWidth = this.scrollIndicatorDownImage.getWidth(); 
						//# }
					//#endif
					//# this.scrollIndicatorWidth = scrollWidth;
					//# this.scrollIndicatorX = this.screenWidth / 2 - this.scrollIndicatorWidth / 2;
					//# this.scrollIndicatorY = (this.fullScreenHeight - (this.menuBar.marginBottom + this.menuBar.paddingBottom + this.menuBar.contentHeight)) + ((this.menuBar.contentHeight - this.scrollIndicatorWidth)/2);
				//#endif
				//# //System.out.println("without ExternalMenu: scrollIndicatorY=" + this.scrollIndicatorY + ", screenHeight=" + this.screenHeight + ", FullScreenHeight=" + this.fullScreenHeight );	
				//# //System.out.println("Screen.init: menuBarHeight=" + this.menuBarHeight + " scrollIndicatorWidth=" + this.scrollIndicatorWidth );
			//#else
				//#ifdef polish.css.style.menu
					Style menustyle = StyleSheet.menuStyle;
				//#else
					//# Style menustyle = this.style;
				//#endif
				if (menustyle != null) {
					Integer colorInt = null;
					if (this.style != null) {
						colorInt = this.style.getIntProperty(16);
					}
					if (colorInt == null) {
						colorInt = menustyle.getIntProperty(16);
					}
					if (colorInt != null) {
						this.menuBarColor = colorInt.intValue();
					}
					this.menuFontColor = menustyle.getFontColor();
					if (menustyle.font != null) {
						this.menuFont = menustyle.font;
					} else {
						this.menuFont = Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM );				
					}			
				} else {
					this.menuFont = Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM );
				}
				int localMenuBarHeight = this.menuFont.getHeight();
				//#ifdef polish.Menu.PaddingBottom:defined
					//#= localMenuBarHeight += ${polish.Menu.PaddingBottom};  
				//#endif
				//#ifdef polish.Menu.PaddingTop:defined
					//#= localMenuBarHeight += ${polish.Menu.PaddingTop};  
				//#endif
				//#if !polish.Menu.PaddingBottom:defined && !polish.Menu.PaddingTop:defined
					localMenuBarHeight += 2;
				//#endif
				//#if !tmp.useScrollBar
					int scrollWidth = localMenuBarHeight;
					//#if polish.css.scrollindicator-up-image
						//# if (this.scrollIndicatorUpImage != null) {
							//# scrollWidth = this.scrollIndicatorUpImage.getWidth(); 
						//# }
					//#elif polish.css.scrollindicator-down-image
						//# if (this.scrollIndicatorDownImage != null) {
							//# scrollWidth = this.scrollIndicatorDownImage.getWidth(); 
						//# }
					//#endif
					this.scrollIndicatorWidth = scrollWidth;
					this.scrollIndicatorX = this.screenWidth / 2 - this.scrollIndicatorWidth / 2;
					this.scrollIndicatorY = (this.fullScreenHeight - localMenuBarHeight) + (localMenuBarHeight -  this.scrollIndicatorWidth)/2;
				//#endif
				//System.out.println("without ExternalMenu: scrollIndicatorY=" + this.scrollIndicatorY + ", screenHeight=" + this.screenHeight + ", FullScreenHeight=" + this.fullScreenHeight + ", localMenuBarHeight=" + localMenuBarHeight);	
				//#ifdef polish.Menu.MarginBottom:defined 
					//#= localMenuBarHeight += ${polish.Menu.MarginBottom};
					//#= this.scrollIndicatorY -=  ${polish.Menu.MarginBottom};
				//#endif
				//#ifdef polish.Menu.MarginTop:defined 
					//#= localMenuBarHeight += ${polish.Menu.MarginTop};
				//#endif
				this.menuBarHeight = localMenuBarHeight;
			//#endif
			int diff = this.originalScreenHeight - this.screenHeight;
			this.originalScreenHeight = this.fullScreenHeight - this.menuBarHeight;
			this.screenHeight = this.originalScreenHeight - diff;
			// set position of scroll indicator:
		//#elif polish.vendor.Siemens && !tmp.useScrollBar
			//# // set the position of scroll indicator for Siemens devices 
			//# // on the left side, so that the menu-indicator is visible:
			//# int scrollWidth = 12;
			//#if polish.css.scrollindicator-up-image
				//# if (this.scrollIndicatorUpImage != null) {
					//# scrollWidth = this.scrollIndicatorUpImage.getWidth(); 
				//# }
			//#elif polish.css.scrollindicator-down-image 
				//# if (this.scrollIndicatorDownImage != null) {
					//# scrollWidth = this.scrollIndicatorDownImage.getWidth(); 
				//# }
			//#endif
			//# this.scrollIndicatorWidth = scrollWidth;
			//# this.scrollIndicatorX = 0;
			//# this.scrollIndicatorY = this.screenHeight - (this.scrollIndicatorWidth + 1);
		//#elif !tmp.useScrollBar
			//# // set position of scroll indicator:
			//# int scrollWidth = 12;
			//#if polish.css.scrollindicator-up-image
				//# if (this.scrollIndicatorUpImage != null) {
					//# scrollWidth = this.scrollIndicatorUpImage.getWidth(); 
				//# }
			//#elif polish.css.scrollindicator-down-image 
				//# if (this.scrollIndicatorDownImage != null) {
					//# scrollWidth = this.scrollIndicatorDownImage.getWidth(); 
				//# }
			//#endif
			//# this.scrollIndicatorWidth = scrollWidth;
			//# this.scrollIndicatorX = this.screenWidth - this.scrollIndicatorWidth;
			//# this.scrollIndicatorY = this.screenHeight - (this.scrollIndicatorWidth + 1);
		//#endif
			
		//System.out.println("final: scrollIndicatorY=" + this.scrollIndicatorY + ", screenHeight=" + this.screenHeight + ", FullScreenHeight=" + this.fullScreenHeight );	
		if (this.container != null) {
			this.container.screen = this;
		}
		calculateContentArea( 0, 0, this.screenWidth, this.screenHeight );
		
		// start the animmation thread if necessary: 
		if (startAnimationThread) {
			StyleSheet.animationThread.start();
		}
		this.isInitialised = true;
	}
	
	/**
	 * Calculates and sets the content area for this screen.
	 * Usually no items are painted outside of the specified area.
	 * This method knows about the title, subtitle, infoarea and ticker
	 * and adjusts the content area accordingly
	 * 
	 * @param x left start of the content area, might later be adjusted by an external scrollindicator
	 * @param y top start of the content area, is adjusted by the top margin, title height, subtitle height, 
	 *        info height and maybe ticker height (when the ticker should be painted at the top).
	 * @param width width of the content area, might later be adjusted by an external scrollindicator
	 * @param height height of the content area, is adjusted by the title height, subtitle height, 
	 *        info height and ticker height.
	 */
	protected void calculateContentArea( int x, int y, int width, int height ) {
		//#debug
de.enough.polish.util.Debug.debug("debug", "de.enough.polish.ui.Screen", 557, "calculateContentArea(" + x + ", " + y + ", " + width + ", " + height + ")");
		
		x += this.marginLeft;
		width -= this.marginLeft + this.marginRight;
		y += this.marginTop;
		height -= this.marginTop; // + this.marginBottom;
		//#if !polish.css.title-position || !tmp.usingTitle
			int topHeight = this.titleHeight + this.subTitleHeight + this.infoHeight;
		//#else
			//# int topHeight = this.subTitleHeight + this.infoHeight;
			//# if (this.paintTitleAtTop) {
				//# topHeight += this.titleHeight;
			//# } else {
				//# height -= this.titleHeight;
			//# }
		//#endif
		y += topHeight;
		//#ifndef polish.skipTicker			
			//# int tickerHeight = 0;
			//# if (this.ticker != null) {
				//# tickerHeight = this.ticker.getItemHeight( width, width );
			//# } 	
			//# height -= topHeight + tickerHeight;
		//#else
			height -= topHeight;	
		//#endif
		//#if tmp.useScrollBar
			//# if ( this.container != null ) {
				//# this.scrollBar.scrollBarHeight = height;
				//# //System.out.println("calculateContentArea for " + this + ": container.isInitialised=" + this.container.isInitialised );
				//# int scrollBarWidth = this.scrollBar.getItemWidth(width, width);
				//# int containerHeight = this.container.getItemHeight(width - scrollBarWidth, width - scrollBarWidth);
				//# if (containerHeight > height) {
					//# //System.out.println("calculateContentArea for" + this + ": scrollBar is required for containerHeight of " + containerHeight + ", availableHeight=" + height );					
					//# width -= scrollBarWidth;
				//# } else {
					//# //System.out.println("calculateContentArea for" + this + ": scrollBar is NOT required for containerHeight of " + containerHeight + ", availableHeight=" + height );					
					//# this.container.requestFullInit();
				//# }
			//# }
		//#endif
			
		// now set the content coordinates:	
		this.contentX = x;
		//#ifndef polish.skipTicker			
			//#if tmp.paintTickerAtTop
				//# y += tickerHeight;
			//#elif polish.css.ticker-position && !polish.TickerPosition:defined
				//# if (this.paintTickerAtTop) {
					//# y += tickerHeight;
				//# }
			//#endif
		//#endif
		this.contentY = y;
		this.contentWidth = width;
		this.contentHeight = height;
		//#debug
de.enough.polish.util.Debug.debug("debug", "de.enough.polish.ui.Screen", 614, "calculateContentArea: x=" + this.contentX + ", y=" + this.contentY + ", width=" + this.contentWidth + ", height=", this.contentHeight);
		if (this.container != null) {
			this.container.setVerticalDimensions( y, y + height );
		}
	}
	
	

	/**
	 * Initialises this screen and informs all items about being painted soon.
	 */
	public void showNotify() {
		//#debug
de.enough.polish.util.Debug.debug("debug", "de.enough.polish.ui.Screen", 627, "showNotify " + this + " isInitialised=", this.isInitialised);
		try {
			//#ifdef polish.Screen.showNotifyCode:defined
				//#include ${polish.Screen.showNotifyCode}
			//#endif
			//#if tmp.fullScreen && polish.midp2 && polish.Bugs.fullScreenInShowNotify
				//# super.setFullScreenMode( true );
				//#ifdef polish.FullCanvasHeight:defined
					//#= this.fullScreenHeight = ${polish.FullCanvasHeight};
				//#else
					//# this.fullScreenHeight = getHeight();
				//#endif
				//# this.screenHeight = this.fullScreenHeight - this.menuBarHeight;
				//# this.originalScreenHeight = this.screenHeight;
				//# this.scrollIndicatorY = this.screenHeight + 1; //- this.scrollIndicatorWidth - 1;
			//#endif
			if (!this.isInitialised) {
				init();
			}
			//#if polish.css.repaint-previous-screen
				//# if (this.repaintPreviousScreen) {
					//# Displayable currentDisplayable = StyleSheet.display.getCurrent();
					//#if polish.Screen.dontBufferPreviousScreen
						//# if ( currentDisplayable != this && currentDisplayable instanceof AccessibleCanvas) {
							//# this.previousScreen = (AccessibleCanvas) currentDisplayable;							
							//#if !polish.Bugs.noTranslucencyWithDrawRgb
								//#if polish.color.overlay:defined
									//#= this.previousScreenOverlayBackground = new TranslucentSimpleBackground( ${polish.color.overlay} );
								//#else
									//# this.previousScreenOverlayBackground = new TranslucentSimpleBackground( 0xAA000000 );
								//#endif
							//#endif
						//# }
					//#else
						//# if ( currentDisplayable != this && currentDisplayable instanceof AccessibleCanvas ) {
							//# if (this.previousScreenImage == null) {
								//#if tmp.fullScreen
									//# this.previousScreenImage = Image.createImage( this.screenWidth, this.fullScreenHeight);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -