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

📄 stringitem.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			this.textLines = null;
		}
		requestInit();
	}

	/**
	 * Sets the application's preferred font for
	 * rendering this <code>StringItem</code>.
	 * The font is a hint, and the implementation may disregard
	 * the application's preferred font.
	 * 
	 * <p> The <code>font</code> parameter must be a valid <code>Font</code>
	 * object or <code>null</code>. If the <code>font</code> parameter is
	 * <code>null</code>, the implementation must use its default font
	 * to render the <code>StringItem</code>.</p>
	 * 
	 * @param font - the preferred font to use to render this StringItem
	 * @see #getFont()
	 * @since  MIDP 2.0
	 */
	public void setFont( Font font)
	{
		this.font = font;
		this.isInitialized = false;
	}

	/**
	 * Gets the application's preferred font for
	 * rendering this <code>StringItem</code>. The
	 * value returned is the font that had been set by the application,
	 * even if that value had been disregarded by the implementation.
	 * If no font had been set by the application, or if the application
	 * explicitly set the font to <code>null</code>, the value is the default
	 * font chosen by the implementation.
	 * 
	 * @return the preferred font to use to render this StringItem
	 * @see #setFont(javax.microedition.lcdui.Font)
	 * @since  MIDP 2.0
	 */
	public Font getFont()
	{
		return this.font;
	}



	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#paintContent(int, int, javax.microedition.lcdui.Graphics)
	 */
	public void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
		if (this.text != null) {
			//#ifdef polish.css.text-vertical-adjustment
				//# y += this.textVerticalAdjustment;
			//#endif
			//#ifdef polish.css.font-bitmap
				//# if (this.bitMapFontViewer != null) {
					//# if (this.isLayoutCenter) {
						//# x = leftBorder + (rightBorder - leftBorder) / 2;
						//#ifdef polish.css.text-horizontal-adjustment
							//# x += this.textHorizontalAdjustment;
						//#endif
					//# } else if (this.isLayoutRight) {
						//# x = rightBorder;
						//#ifdef polish.css.text-horizontal-adjustment
							//# x += this.textHorizontalAdjustment;
						//#endif
					//# } 
					//#ifdef polish.css.text-vertical-adjustment
						//# y += this.textVerticalAdjustment;
					//#endif
					//# this.bitMapFontViewer.paint( x, y, g );
					//# return;
				//# }
			//#endif
				
			g.setFont( this.font );
			g.setColor( this.textColor );
			
			int lineHeight = this.font.getHeight() + this.paddingVertical; 
			int centerX = 0;
			if (this.isLayoutCenter) {
				centerX = leftBorder + (rightBorder - leftBorder) / 2;
				//#ifdef polish.css.text-horizontal-adjustment
					//# centerX += this.textHorizontalAdjustment;
				//#endif
//			} else if (!this.isLayoutRight) {
//				x = leftBorder;
			}
			//#ifdef polish.css.text-horizontal-adjustment
				//# x += this.textHorizontalAdjustment;
				//# leftBorder += this.textHorizontalAdjustment;
				//# rightBorder += this.textHorizontalAdjustment;
			//#endif
			//#if polish.css.text-wrap
				//# int clipX = 0;
				//# int clipY = 0;
				//# int clipWidth = 0;
				//# int clipHeight = 0;
				//# if (this.useSingleLine && this.clipText ) {
					//# clipX = g.getClipX();
					//# clipY = g.getClipY();
					//# clipWidth = g.getClipWidth();
					//# clipHeight = g.getClipHeight();
					//# g.clipRect( x, y, this.contentWidth, this.contentHeight );
				//# }
			//#endif
			//#if polish.css.text-effect
				//# if (this.textEffect != null) {
					//# this.textEffect.drawStrings( this.textLines, this.textColor, x, y, leftBorder, rightBorder, lineHeight, this.contentWidth, this.layout, g );
				//# } else {
			//#endif
					for (int i = 0; i < this.textLines.length; i++) {
						String line = this.textLines[i];
						int lineX = x;
						int lineY = y;
						int orientation;
						// adjust the painting according to the layout:
						if (this.isLayoutRight) {
							lineX = rightBorder;
							orientation = Graphics.TOP | Graphics.RIGHT;
							//g.drawString( line, rightBorder, y, Graphics.TOP | Graphics.RIGHT );
						} else if (this.isLayoutCenter) {
							lineX = centerX;
							orientation = Graphics.TOP | Graphics.HCENTER;
							//g.drawString( line, centerX, y, Graphics.TOP | Graphics.HCENTER );
						} else {
							orientation = Graphics.TOP | Graphics.LEFT;
							// left layout (default)
							//g.drawString( line, x, y, Graphics.TOP | Graphics.LEFT );
						}	
						//#if polish.css.text-wrap
							//# if (this.clipText) {
								//# // when clipping (and therefore a scrolling animation) is needed,
								//# // center and right layouts don't really make sense - this would
								//# // start and stop the scrolling at wrong places outside of the clipping area: 
								//# orientation = Graphics.TOP | Graphics.LEFT;
								//# lineX = x + this.xOffset;
							//# }
						//#endif
						g.drawString( line, lineX, lineY, orientation );
						x = leftBorder;
						y += lineHeight;
					}
			//#if polish.css.text-effect
				//# }
			//#endif
			//#if polish.css.text-wrap
				//# if (this.useSingleLine && this.clipText ) {
					//# g.setClip( clipX, clipY, clipWidth, clipHeight );
				//# }
			//#endif
		}
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#initItem()
	 */
	protected void initContent(int firstLineWidth, int lineWidth){
		if (this.text != null && this.font == null) {
			this.font = Font.getDefaultFont();
		}
		if (this.text == null) {
			this.contentHeight = 0;
			this.contentWidth = 0;
			return;
		}
		//#ifdef polish.css.font-bitmap
			//# if (this.bitMapFont != null) {
				//# int orientation = Graphics.LEFT;
				//# if (this.isLayoutCenter) {
					//# orientation = Graphics.HCENTER;
				//# } else if (this.isLayoutRight) {
					//# orientation = Graphics.RIGHT;
				//# }
				//# this.bitMapFontViewer = this.bitMapFont.getViewer( this.text );
				//# this.bitMapFontViewer.layout( firstLineWidth, lineWidth, this.paddingVertical, orientation );
				//# this.contentHeight = this.bitMapFontViewer.getHeight();
				//# this.contentWidth = this.bitMapFontViewer.getWidth();
				//# return;
			//# }
		//#endif
		//#if polish.css.text-wrap
			//# if ( this.useSingleLine ) {
				//# this.textLines = new String[]{ this.text };
				//# int myTextWidth = this.font.stringWidth(this.text);
				//# if (myTextWidth > lineWidth) {
					//# this.clipText = true;
					//# this.textWidth = myTextWidth;
					//# this.isHorizontalAnimationDirectionRight = false;
					//# this.contentWidth = lineWidth;
					//# //TODO do this only when no animation should be used
//# //					int numberOfChars = (this.text.length() * lineWidth) / myTextWidth - 1;
//# //					if (numberOfChars > 1) {
//# //						this.textLines = new String[] { this.text.substring( 0, numberOfChars ) + ".." };
//# //					}
				//# } else {
					//# this.clipText = false;
					//# this.contentWidth = myTextWidth;
				//# }
				//# this.contentHeight = this.font.getHeight();
			//# } else {
		//#endif
				String[] lines = TextUtil.wrap(this.text, this.font, firstLineWidth, lineWidth);
				int fontHeight = this.font.getHeight();
				this.contentHeight = (lines.length * (fontHeight + this.paddingVertical)) - this.paddingVertical;
				int maxWidth = 0;
				for (int i = 0; i < lines.length; i++) {
					String line = lines[i];
					int width = this.font.stringWidth(line);
					if (width > maxWidth) {
						maxWidth = width;
					}
				}
				this.contentWidth = maxWidth;
				this.textLines = lines;
		//#if polish.css.text-wrap
			//# }
		//#endif
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)
	 */
	public void setStyle(Style style) {
		super.setStyle(style);
		this.textColor = style.getFontColor();
		this.font = style.font;
		//#ifdef polish.css.font-bitmap
			//# String bitMapUrl = style.getProperty(38);
			//# if (bitMapUrl != null) {
				//#debug
				//# System.out.println("getting bitmapfont " + bitMapUrl );
				//# this.bitMapFont = BitMapFont.getInstance( bitMapUrl );
			//# } else {
				//# this.bitMapFont = null;
				//# this.bitMapFontViewer = null;
			//# }
		//#endif
		//#ifdef polish.css.text-horizontal-adjustment
			//# Integer textHorizontalAdjustmentInt = style.getIntProperty( 83 );
			//# if ( textHorizontalAdjustmentInt != null ) {
				//# this.textHorizontalAdjustment = textHorizontalAdjustmentInt.intValue();		
			//# }
		//#endif
		//#ifdef polish.css.text-vertical-adjustment
			//# Integer textVerticalAdjustmentInt = style.getIntProperty( 84 );
			//# if ( textVerticalAdjustmentInt != null ) {
				//# this.textVerticalAdjustment = textVerticalAdjustmentInt.intValue();		
			//# }
		//#endif
		//#ifdef polish.css.text-effect
			//# TextEffect effect = (TextEffect) style.getObjectProperty( 88 );
			//# if (effect != null) {
				//# this.textEffect = effect;
				//# effect.setStyle(style);
			//# } else {
				//# this.textEffect = null;
			//# }
		//#endif	
		//#ifdef polish.css.text-wrap
			//# Boolean textWrapBool = style.getBooleanProperty(150);
			//# if (textWrapBool != null) {
				//# this.useSingleLine = !textWrapBool.booleanValue();
			//# }
		//#endif	
	}

	//#ifdef polish.useDynamicStyles
	//# /* (non-Javadoc)
	 //# * @see de.enough.polish.ui.Item#getCssSelector()
	 //# */
	//# protected String createCssSelector() {
		//# if ( this.appearanceMode == BUTTON ) {
			//# return "button";
		//# } else if (this.appearanceMode == HYPERLINK ) {
			//# return "a";
		//# } else {
			//# return "p";
		//# }
	//# }
	//#endif
	
	//#if polish.debug.error || polish.keepToString
	//# public String toString() {
		//# return  "StringItem " + super.toString() + ": \"" + this.getText() + "\""; 
	//# }
	//#endif

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#releaseResources()
	 */
	public void releaseResources() {
		super.releaseResources();
		//#ifdef polish.css.text-effect
			 //# if ( this.textEffect != null ) {
				 //# this.textEffect.releaseResources();
			 //# }
		//#endif
	}

	

}

⌨️ 快捷键说明

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