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

📄 screen.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
						//# Integer yInteger = this.style.getIntProperty(54);
						//# if (yInteger != null) {
							//# this.foregroundY = yInteger.intValue();
						//# }
					//#endif
				//# } catch (IOException e) {
					//#debug error
					//# System.out.println("Unable to load foreground-image [" + foregroundImageUrl + "]: " + e);
				//# }
			//# }
		//#endif
		//#if polish.css.clip-screen-info
			//# Boolean clipScreenInfoBool = style.getBooleanProperty( 87 );
			//# if (clipScreenInfoBool != null) {
				//# this.clipScreenInfo = clipScreenInfoBool.booleanValue();
			//# }
		//#endif	
		//#if polish.css.menubar-style  && tmp.useExternalMenuBar
			//# Style menuBarStyle = (Style) style.getObjectProperty(117);
			//# if (menuBarStyle != null) {
				//# this.menuBar.setStyle( menuBarStyle );
			//# }
		//#endif

		//#ifndef polish.skipTicker
			//#if polish.css.ticker-position
				//# Integer tickerPositionInt = style.getIntProperty(114);
				//# if (tickerPositionInt == null && this.ticker != null && this.ticker.style != null) {
					//# tickerPositionInt = this.ticker.style.getIntProperty(114);
				//# }
				//# if (tickerPositionInt != null) {
					//# this.paintTickerAtTop = (tickerPositionInt.intValue() == POSITION_TOP);
				//# }
			//#endif
		//#endif
		//#if polish.css.repaint-previous-screen
			Boolean repaintPreviousScreenBool = style.getBooleanProperty(116);
			if (repaintPreviousScreenBool != null) {
				this.repaintPreviousScreen = repaintPreviousScreenBool.booleanValue();
			}
		//#endif
		//#if polish.css.separate-menubar
			//# Boolean separateMenubarBool = style.getBooleanProperty(-1);
			//# if (separateMenubarBool != null) {
				//# this.separateMenubar = separateMenubarBool.booleanValue();
			//# }
		//#endif
		//#if tmp.menuFullScreen
			//#if polish.css.background-bottom
				//# Integer backgroundBottomInt = style.getIntProperty(153);
				//# if (backgroundBottomInt != null) {
					//# this.excludeMenuBarForBackground = backgroundBottomInt.intValue() == 1; 
				//# }
			//#endif
		//#endif
		//#ifdef tmp.usingTitle
			//#if polish.css.background-top	
				//# Integer backgroundTopInt = style.getIntProperty(154);
				//# if (backgroundTopInt != null) {
					//# this.excludeTitleForBackground = backgroundTopInt.intValue() == 1; 
				//# }
			//#endif
		//#endif
	}
	
	/**
	 * Animates this Screen.
	 * All embedded items are also animated.
	 * 
	 * @return true when at least one animated item needs a redraw/repaint.
	 */
	public boolean animate() {
		if (!this.isInitialized) {
			return false;
		}
			synchronized (this.paintLock) {
			try {
				boolean animated = false;
				if (this.background != null) {
					animated = this.background.animate();
				}
				//#ifdef tmp.menuFullScreen
					//#ifdef tmp.useExternalMenuBar
						//# animated = animated | this.menuBar.animate();
					//#else
						//# if (this.menuOpened) {
							//# animated = animated | this.menuContainer.animate();
						//# } else
					//#endif
				//#endif
				if (this.container != null) {
					animated = animated | this.container.animate();
				}
				//#ifdef tmp.usingTitle
					if (this.title != null) {
						animated = animated | this.title.animate();
					}
				//#endif
				//#ifndef polish.skipTicker
					//# if (this.ticker != null) {
						//# animated = animated | this.ticker.animate();
					//# }
				//#endif
				//#if polish.ScreenInfo.enable
					//# if (ScreenInfo.item != null && ScreenInfo.isVisible()) {
						//# animated = animated | ScreenInfo.item.animate();
					//# }
				//#endif
				return animated;
			} catch (Exception e) {
				//#debug error
				//# System.out.println("animate() threw an exception" + e );
				return false;
			}
		}
	}
	
	/**
	 * Paints the screen.
	 * When you subclass Screen you should override paintScreen(Graphics g) instead, if possible.
	 * 
	 * @param g the graphics context.
	 * @see #paintScreen(Graphics)
	 */
	public void paint(Graphics g) {
		//System.out.println("Painting screen "+ this + ", background == null: " + (this.background == null));
		synchronized (this.paintLock ) {
			//#if polish.Bugs.losesFullScreen
				//# super.setFullScreenMode( true );
			//#endif
			//#if tmp.fullScreenInPaint
				//# if (!this.isInFullScreenMode) {
					//# super.setFullScreenMode( true );
					//# this.isInFullScreenMode = true;
					//#if tmp.menuFullScreen
						//#ifdef polish.FullCanvasHeight:defined
							//#= this.fullScreenHeight = ${polish.FullCanvasHeight};
						//#else
							//# this.fullScreenHeight = getHeight();
						//#endif
						//# this.screenHeight = this.fullScreenHeight - this.menuBarHeight;
						//# this.originalScreenHeight = this.screenHeight;
						//#if tmp.useScrollIndicator
							//# this.scrollIndicatorY = this.screenHeight + 1; //- this.scrollIndicatorWidth - 1 - this.menuBarHeight;
						//#endif
					//#endif
				//# }
			//#endif
			//#if !tmp.menuFullScreen
				int translateY = g.getTranslateY();
				if (translateY != 0 && this.screenHeight == this.originalScreenHeight) {
					this.screenHeight -= translateY;
					//#if tmp.useScrollIndicator 
						this.scrollIndicatorY -= translateY;
					//#endif
					//#debug
					//# System.out.println("Adjusting screenheight from " + this.originalScreenHeight + " to " + this.screenHeight );
					if (this.container != null) {
						int y = translateY;
						calculateContentArea( 0, y, this.screenWidth, this.screenHeight - y );
					}
				}
			//#endif
			//#if tmp.fullScreen && polish.FullCanvasSize:defined && polish.Bugs.setClipForFullScreenNeeded
				//# g.translate( -g.getTranslateX(), -g.getTranslateY() );
				//#= g.setClip( 0, 0, ${polish.FullCanvasWidth}, ${polish.FullCanvasHeight} );
			//#endif
			//#if polish.debug.error
			//# try {
			//#endif
				//#if polish.css.repaint-previous-screen
					//#if polish.Screen.dontBufferPreviousScreen
						//# if (this.repaintPreviousScreen && this.previousScreen != null) {
							//# this.previousScreen.paint(g);
							//#if !polish.Bugs.noTranslucencyWithDrawRgb
								//# this.previousScreenOverlayBackground.paint(0, 0, this.screenWidth, this.screenHeight, g);
							//#endif
						//# }
					//#else
						if (this.repaintPreviousScreen && this.previousScreenImage != null) {
							g.drawImage(this.previousScreenImage, 0, 0, Graphics.TOP | Graphics.LEFT );
							//#if !polish.Bugs.noTranslucencyWithDrawRgb
								this.previousScreenOverlayBackground.paint(0, 0, this.screenWidth, this.screenHeight, g);
							//#endif
						}
					//#endif
				//#endif
				int sWidth = this.screenWidth - this.marginLeft - this.marginRight;
				int leftBorder = this.marginLeft;
				int rightBorder = leftBorder + sWidth;
				if (this.isLayoutHorizontalShrink) {
					int contWidth = this.contentWidth;
					if (this.container != null) {
						contWidth = this.container.getItemWidth(sWidth, sWidth); 
						//#ifdef tmp.usingTitle
							if (this.title != null && this.title.itemWidth > contWidth ) {
								this.titleHeight = this.title.getItemHeight( contWidth, contWidth );
							}
						//#endif
					}
					sWidth = contWidth;
					//System.out.println("is horizontal shrink - from sWidth=" + (this.screenWidth - this.marginLeft - this.marginRight) + ", to=" + sWidth );					
					if (this.isLayoutRight) {
						leftBorder = rightBorder - sWidth;
					} else if (this.isLayoutCenter) {
						leftBorder = (this.screenWidth - sWidth) / 2;
						rightBorder = this.screenWidth - leftBorder;
					} else {
						rightBorder = this.screenWidth - sWidth;
					}
					//System.out.println("leftBorder=" + leftBorder + ", rightBorder=" + rightBorder );
				}
				
				//#ifdef tmp.menuFullScreen
					//# int sHeight = this.fullScreenHeight - this.marginTop - this.marginBottom;
				//#else
					int sHeight = this.screenHeight - this.marginTop - this.marginBottom;
				//#endif
				int topBorder = this.marginTop;
				if (this.isLayoutVerticalShrink) {
					int contHeight = this.contentHeight;
					if (this.container != null) {
						contHeight = this.container.getItemHeight(sWidth, sWidth); 
					}
//					//#if tmp.menuFullScreen
//						sHeight = contHeight + this.titleHeight + this.menuBarHeight;
//					//#else
						sHeight = contHeight + this.titleHeight;
//					//#endif
					//System.out.println("isLayoutVerticalShrink - sHeight: from=" + (this.fullScreenHeight - this.marginTop - this.marginBottom) + ", to=" + sHeight + ", contentHeight=" + this.contentHeight + ", topBorder=" + topBorder );
					if (this.isLayoutBottom) {
//						//#ifdef tmp.menuFullScreen
//							topBorder = this.fullScreenHeight - (this.marginBottom + sHeight + 1);
//						//#else
							topBorder = this.screenHeight - (this.marginBottom + sHeight + 1);
//						//#endif
						//System.out.println("bottom -> topBorder=" + topBorder + ", contY=>" + (topBorder + this.titleHeight) );
					} else if (this.isLayoutVCenter) {
//						//#ifdef tmp.menuFullScreen
//							topBorder = (this.fullScreenHeight - (this.marginBottom + this.marginBottom))/2 - sHeight/2;
//						//#else
							topBorder = (this.screenHeight - (this.marginBottom + this.marginTop + sHeight))/2;
//						//#endif						 
						//System.out.println("vcenter -> topBorder=" + topBorder + ", contY=>" + (topBorder + this.titleHeight) );
					}
				}

				// paint background:
				if (this.background != null) {
					int backgroundHeight = sHeight;
					int backgroundY = topBorder;
					//#ifdef tmp.menuFullScreen
						//# if (this.excludeMenuBarForBackground) {
							//# backgroundHeight = this.screenHeight - this.marginTop - this.marginBottom + 1;
						//# }
					//#endif
					//#ifdef tmp.usingTitle
						if (this.excludeTitleForBackground) {
							backgroundHeight -= this.titleHeight;
							backgroundY += this.titleHeight;
						}
					//#endif
					// System.out.println("Screen (" + this + ": painting background at leftBorder=" + leftBorder + ", backgroundY=" + backgroundY);
					this.background.paint(leftBorder, backgroundY, sWidth, backgroundHeight, g);
				} else {
					//System.out.println("Screen (" + this + ": clearing area...");
					int backgroundHeight = sHeight;
					int backgroundY = topBorder;
					//#ifdef tmp.menuFullScreen
						//# if (this.excludeMenuBarForBackground) {
							//# backgroundHeight = this.screenHeight - this.marginTop - this.marginBottom + 1;
						//# }
					//#endif
					//#ifdef tmp.usingTitle
						if (this.excludeTitleForBackground) {
							backgroundHeight -= this.titleHeight;
							backgroundY += this.titleHeight;
						}
					//#endif
					g.setColor( 0xFFFFFF );
					g.fillRect( leftBorder, backgroundY, sWidth, backgroundHeight );
				}
				
				int topHeight = topBorder;
				//#ifdef tmp.usingTitle
					//#if polish.css.title-position
						//# if (this.paintTitleAtTop) {
					//#endif
							// paint title:
							if (this.title != null && this.showTitleOrMenu) {
								this.title.paint( leftBorder, topBorder, leftBorder, rightBorder, g);
								topHeight += this.titleHeight;
							}
					//#if polish.css.title-position
						//# }
					//#endif
				//#endif
				if (this.subTitle != null) {
					this.subTitle.paint( leftBorder, topHeight, leftBorder, rightBorder, g );
					this.subTitle.relativeY = topHeight;
					topHeight += this.subTitleHeight;
				}
				//#ifndef polish.skipTicker			
					//#if tmp.paintTickerAtTop
						//# if (this.ticker != null) {
							//# this.ticker.paint( leftBorder, topHeight, leftBorder, rightBorder, g);
							//# topHeight += this.ticker.itemHeight;
						//# }
					//#elif polish.css.ticker-position && !polish.TickerPosition:defined
						//# if (this.paintTickerAtTop && this.ticker != null) {
							//# this.ticker.paint( leftBorder, topHeight, leftBorder, rightBorder, g);
							//# topHeight += this.ticker.itemHeight;
						//# }
					//#endif
				//#endif
	
				int infoItemY = topHeight;
				//#if polish.clip-screen-info
					//# if (this.showInfoItem && this.clipScreenInfo) {			
						//# topHeight += this.infoHeight;
					//# }
				//#endif
				//System.out.println("topHeight=" + topHeight + ", contentY=" + contentY);
				
				// protect the title, ticker and the full-screen-menu area:
	//			int clipHeight = this.screenHeight - topHeight;
	//			//#if tmp.menuFullScreen
	//				int cHeight = this.fullScreenHeight - topHeight - this.marginBottom;
	//				if (cHeight < clipHeight) {
	//					clipHeight = cHeight;
	//				}

⌨️ 快捷键说明

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