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

📄 screen.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	//			//#endif
//				System.out.println("paintScreen with clipping " + g.getClipX() + ", " + g.getClipY() + ", " + g.getClipWidth() + ", " + g.getClipHeight() + " before clipRect");
//				int clipX = g.getClipX();
//				int clipY = g.getClipY();
//				int clipWidth = g.getClipWidth();
//				int clipHeight = g.getClipHeight();
				g.setClip(leftBorder, topHeight, sWidth, this.screenHeight - topHeight  );
				//g.clipRect(leftBorder, topHeight, sWidth, this.screenHeight - topHeight  );
	
				// paint content:
				//System.out.println("starting to paint content of screen");
				paintScreen( g );
				//System.out.println("done painting content of screen");
//				System.out.println("paintScreen with clipping " + g.getClipX() + ", " + g.getClipY() + ", " + g.getClipWidth() + ", " + g.getClipHeight() );
//				g.setColor( 0xff0000 );
//				g.drawRect(g.getClipX() + 1 , g.getClipY() + 1 , g.getClipWidth() - 2 ,  g.getClipHeight() - 2);
				
				//#if tmp.useScrollBar
					//# if (this.container != null && this.container.itemHeight > this.contentHeight) {
						//# // paint scroll bar: - this.container.yOffset
						//#debug
						//# System.out.println("Screen/ScrollBar: container.contentY=" + this.container.contentY + ", container.internalY=" +  this.container.internalY + ", container.yOffset=" + this.container.yOffset + ", container.height=" + this.container.availableHeight + ", container.relativeY=" + this.container.relativeY);
//# 						
						//# int scrollX = sWidth + this.marginLeft 
									//# - this.scrollBar.initScrollBar(sWidth, this.contentHeight, this.container.itemHeight, this.container.yOffset, this.container.internalY, this.container.internalHeight, this.container.focusedIndex, this.container.size() );
						//# //TODO allow scroll bar on the left side
						//# this.scrollBar.relativeX = scrollX;
						//# this.scrollBar.relativeY = this.contentY;
						//# this.scrollBar.paint( scrollX, this.contentY, scrollX, rightBorder, g);
					//# }
				//#endif
				
				// allow painting outside of the screen again:
				//g.setClip( clipX, clipY, clipWidth, clipHeight );
				//#ifdef tmp.menuFullScreen
				 	//# g.setClip(0, 0, this.screenWidth, this.fullScreenHeight );
				//#else
				 	g.setClip(0, 0, this.screenWidth, this.originalScreenHeight );
				//#endif
				 
				// paint info element:
				if (this.showInfoItem) {			
					this.infoItem.paint( this.marginLeft, infoItemY, this.marginLeft, rightBorder, g );
				}
	 	
				int bottomY = this.contentY + this.contentHeight;
				//#ifndef polish.skipTicker			
					//#if tmp.paintTickerAtBottom
						//# if (this.ticker != null) {
							//# this.ticker.paint( this.marginLeft, bottomY, this.marginLeft, rightBorder, g);
							//# bottomY += this.ticker.itemHeight;
						//# }
					//#elif polish.css.ticker-position && !polish.TickerPosition:defined
						//# if (!this.paintTickerAtTop && this.ticker != null) {
							//# this.ticker.paint( this.marginLeft, bottomY, this.marginLeft, rightBorder, g);
							//# bottomY += this.ticker.itemHeight;
						//# }
					//#endif
				//#endif
				//#if tmp.usingTitle && polish.css.title-position
						//# if (!this.paintTitleAtTop) {
							//# // paint title:
							//# if (this.title != null && this.showTitleOrMenu) {
								//# this.title.paint( leftBorder, bottomY, leftBorder, rightBorder, g);
								//# //bottomY += this.titleHeight;
							//# }
						//# }
				//#endif
				
				// paint border:
				if (this.border != null) {
					this.border.paint(leftBorder, topBorder-1, sWidth, sHeight, g );
				}
				
				//#if polish.ScreenInfo.enable
					//# ScreenInfo.paint( g, topHeight, this.screenWidth );
				//#endif
					
				// paint menu in full-screen mode:
				int menuLeftX = 0;
				int menuRightX = this.screenWidth;
				int menuY = this.screenHeight; // + this.marginBottom;
				//#if polish.css.separate-menubar
					//# if (!this.separateMenubar) {
						//# menuLeftX = leftBorder;
						//# menuRightX = rightBorder;
						//# menuY = this.screenHeight - this.marginBottom;
					//# }
				//#endif
				//#ifdef tmp.menuFullScreen
					//#ifdef tmp.useExternalMenuBar
						//# this.menuBar.paint(menuLeftX, menuY, menuLeftX, menuRightX, g);
						//#if tmp.useScrollIndicator
							//# if (this.menuBar.isOpened) {
								//# this.paintScrollIndicator = this.menuBar.paintScrollIndicator;
								//# this.paintScrollIndicatorUp = this.menuBar.canScrollUpwards;
								//# this.paintScrollIndicatorDown = this.menuBar.canScrollDownwards;
							//# }
						//#endif
					//#else
						//# if (this.menuOpened) {
							//# topHeight -= this.infoHeight;
							//# int menuHeight = this.menuContainer.getItemHeight(this.screenWidth, this.screenWidth);
							//# int y = this.originalScreenHeight - (menuHeight + 1);
							//# if (y < topHeight) {
								//#if tmp.useScrollIndicator
								//# this.paintScrollIndicator = true;
								//# this.paintScrollIndicatorUp = (this.menuContainer.yOffset != 0);
								//# this.paintScrollIndicatorDown = ( (this.menuContainer.focusedIndex != this.menuContainer.size() - 1)
										//# && (this.menuContainer.yOffset + menuHeight > this.originalScreenHeight - topHeight)) ;
								//#endif
								//# y = topHeight; 
							//#if tmp.useScrollIndicator
							//# } else {
								//# this.paintScrollIndicator = false;
							//#endif
							//# }
							//# this.menuContainer.setScrollHeight(this.originalScreenHeight-topHeight);
							//# g.setClip(0, topHeight, this.screenWidth, this.originalScreenHeight - topHeight );
							//# this.menuContainer.paint(menuLeftX, y, menuLeftX, menuLeftX + this.screenWidth, g);
						 	//# g.setClip(0, 0, this.screenWidth, this.fullScreenHeight );
						//# } 
						//#if !polish.doja
							//# if (this.showTitleOrMenu || this.menuOpened) {
								//# // clear menu-bar:
								//# if (this.menuBarColor != Item.TRANSPARENT) {
									//# g.setColor( this.menuBarColor );
									//# //TODO check use menuY instead of this.originalScreenHeight?
									//# g.fillRect(menuLeftX, this.originalScreenHeight, menuRightX,  this.menuBarHeight );
								//# }
								//# g.setColor( this.menuFontColor );
								//# g.setFont( this.menuFont );
								//# String menuText = this.menuLeftString;
								//# if (menuText != null) {
									//#ifdef polish.MenuBar.MarginLeft:defined
										//#= menuLeftX += ${polish.MenuBar.MarginLeft};
									//#elifdef polish.MenuBar.PaddingLeft:defined
										//#= menuLeftX += ${polish.MenuBar.PaddingLeft};
									//#else
										//# menuLeftX += 2;
									//#endif
									//#ifdef polish.MenuBar.MarginTop:defined
										//#= g.drawString(menuText, menuX, this.originalScreenHeight + ${polish.MenuBar.MarginTop}, Graphics.TOP | Graphics.LEFT );
									//#else
										//# g.drawString(menuText, menuLeftX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.LEFT );
									//#endif
//# 									
								//# }
								//# menuText = this.menuRightString;
								//# if (menuText != null) {
									//#ifdef polish.MenuBar.MarginRight:defined
										//#= menuRightX -= ${polish.MenuBar.MarginRight};
									//#elifdef polish.MenuBar.PaddingRight:defined
										//#= menuRightX -= ${polish.MenuBar.PaddingRight};
									//#elifdef polish.MenuBar.MarginLeft:defined
										//# menuRightX -= 2;
									//#endif
//# 
									//#ifdef polish.MenuBar.MarginTop:defined
										//#= g.drawString(menuText, menuRightX, this.originalScreenHeight + ${polish.MenuBar.MarginTop}, Graphics.TOP | Graphics.RIGHT );
									//#else
										//# g.drawString(menuText, menuRightX, this.originalScreenHeight + 2, Graphics.TOP | Graphics.RIGHT );
									//#endif
									//#ifdef polish.hasPointerEvents
										//# this.menuRightCommandX = menuRightX - this.menuFont.stringWidth( menuText );
									//#endif
								//# }
							//# } // if this.showTitleOrMenu || this.menuOpened
						//#endif
					//#endif
				//#endif
						
				//#if tmp.useScrollIndicator
					// paint scroll-indicator in the middle of the menu:					
					if (this.paintScrollIndicator) {
						g.setColor( this.scrollIndicatorColor );
						int x = this.scrollIndicatorX;
						int y = this.scrollIndicatorY;
						//System.out.println("paint: this.scrollIndicatorY=" + this.scrollIndicatorY);
						int width = this.scrollIndicatorWidth;
						int halfWidth = width / 2;
						if (this.paintScrollIndicatorUp) {
							//#if polish.css.scrollindicator-up-image
								//# if (this.scrollIndicatorUpImage != null) {
									//# g.drawImage(this.scrollIndicatorUpImage, x, y, Graphics.LEFT | Graphics.TOP );
								//# } else {
							//#endif						
								//#ifdef polish.midp2
									//# g.fillTriangle(x, y + halfWidth-1, x + width, y + halfWidth-1, x + halfWidth, y );
								//#else
									g.drawLine( x, y + halfWidth-1, x + width, y + halfWidth-1 );
									g.drawLine( x, y + halfWidth-1, x + halfWidth, y );
									g.drawLine( x + width, y + halfWidth-1, x + halfWidth, y );
								//#endif
							//#if polish.css.scrollindicator-up-image
								//# }
							//#endif
						}
						if (this.paintScrollIndicatorDown) {
							//#if polish.css.scrollindicator-down-image
								//# if (this.scrollIndicatorDownImage != null) {
									//#if polish.css.scrollindicator-down-image
										//# if (this.scrollIndicatorUpImage != null) {
											//# y += this.scrollIndicatorUpImage.getHeight() + 1;
										//# } else {
											//# y += halfWidth;
										//# }
									//#else
										//# y += halfWidth;
									//#endif
									//# g.drawImage(this.scrollIndicatorDownImage, x, y, Graphics.LEFT | Graphics.TOP );
								//# } else {
							//#endif						
								//#ifdef polish.midp2
									//# g.fillTriangle(x, y + halfWidth+1, x + width, y + halfWidth+1, x + halfWidth, y + width );
								//#else
									g.drawLine( x, y + halfWidth+1, x + width, y + halfWidth+1 );
									g.drawLine( x, y + halfWidth+1, x + halfWidth, y + width );
									g.drawLine(x + width, y + halfWidth+1, x + halfWidth, y + width );
								//#endif
							//#if polish.css.scrollindicator-down-image
								//# }
							//#endif
						}
					}
				//#endif
				//#ifdef polish.css.foreground-image
					//# if (this.foregroundImage != null) {
						//# g.drawImage( this.foregroundImage, this.foregroundX, this.foregroundY, Graphics.TOP | Graphics.LEFT  );
					//# }
				//#endif
			
			//#if polish.debug.error
			//# } catch (RuntimeException e) {
				//#debug error
				//# System.out.println( "unable to paint screen (" + getClass().getName() + "):" + e );
			//# }
			//#endif
		}
	}
	
	/**
	 * Paints the screen.
	 * This method also needs to set the protected variables
	 * paintScrollIndicator, paintScrollIndicatorUp and paintScrollIndicatorDown.
	 * 
	 * @param g the graphics on which the screen should be painted
	 * @see #contentX
	 * @see #contentY
	 * @see #contentWidth
	 * @see #contentHeight
	 * @see #paintScrollIndicator
	 * @see #paintScrollIndicatorUp
	 * @see #paintScrollIndicatorDown
	 */
	protected void paintScreen( Graphics g ) {
		int y = this.contentY;
		int x = this.contentX;
		int height = this.contentHeight;
		int width = this.contentWidth;
		int containerHeight = this.container.getItemHeight( width, width);
		//#if tmp.useScrollIndicator
			this.paintScrollIndicator = false; // defaults to false
		//#endif
		if (containerHeight > this.container.availableHeight ) {
			//#if tmp.useScrollIndicator
				this.paintScrollIndicator = true;
				this.paintScrollIndicatorUp = (this.container.yOffset != 0);
					//&& (this.container.focusedIndex != 0);
				this.paintScrollIndicatorDown = (  
						( (this.container.focusedIndex != this.container.size() - 1) 
								|| (this.container.focusedItem != null && this.container.focusedItem.itemHeight > this.container.availableHeight) )
						 && (this.container.getScrollYOffset() + containerHeight > this.container.availableHeight) );
			//#endif
		} else if (this.isLayoutVCenter) {
			/*
			//#debug
			//# System.out.println("Screen: adjusting y from [" + y + "] to [" + ( y + (height - containerHeight) / 2) + "] - containerHeight=" + containerHeight);
			*/
			if (this.isLayoutVerticalShrink) {
				y = g.getClipY();
			} else {
				y += ((height - containerHeight) / 2);
			}
		} else if (this.isLayoutBottom) {
			if (this.isLayoutVerticalShrink) {
				y = g.getClipY();
			} else {
				y += (height - containerHeight);
			}
//			System.out.println("content: y=" + y + ", contentY=" + this.contentY + ", contentHeight="+ this.contentHeight + ", containerHeight=" + containerHeight);
		}
		int containerWidth = this.container.itemWidth;
		if (this.isLayoutCenter) {
			int diff = (width - containerWidth) / 2;
			x += diff;
			width -= (width - containerWidth);
		} else if (this.isLayoutRight) {
			int diff = width - containerWidth;
			x += diff;
			width -= diff;
		}
		this.container.relativeX = x;
		this.container.relativeY = y;
		//System.out.println("content: x=" + x + ", rightBorder=" + (x + width) );
		this.container.paint( x, y, x, x + width, g );
	}
	
	//#ifdef tmp.usingTitle
	/**
	 * Gets the title of the Screen. 
	 * Returns null if there is no title.
	 * 
	 * @return the title of this screen
	 */
	public String getTitle()
	{
		if (this.title == null) {
			return null;
		} else if ( !(this.title instanceof StringItem ) ) {
			return null;
		} else {
			return ((StringItem)this.title).getText();
		}
	}
	//#endif

	

⌨️ 快捷键说明

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