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

📄 stringitem.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//#condition polish.usePolishGui// generated by de.enough.doc2java.Doc2Java (www.enough.de) on Sat Dec 06 15:06:43 CET 2003/* * Copyright (c) 2004-2005 Robert Virkus / Enough Software * * 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 de.enough.polish.util.BitMapFont;import de.enough.polish.util.BitMapFontViewer;import de.enough.polish.util.TextUtil;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;/** * An item that can contain a string. *  * A <code>StringItem</code> is display-only; the user * cannot edit the contents. Both the label and the textual content of a * <code>StringItem</code> may be modified by the application. The * visual representation * of the label may differ from that of the textual contents. *  * @author Robert Virkus, robert@enough.de */public class StringItem extends Item{	protected String text;	protected String[] textLines;	protected int textColor;	protected Font font;	//#ifdef polish.css.font-bitmap		protected BitMapFont bitMapFont;		protected BitMapFontViewer bitMapFontViewer;	//#endif	//#ifdef polish.css.text-wrap		protected boolean useSingleLine;		protected boolean clipText;		protected int xOffset;		private int textWidth;		private boolean isHorizontalAnimationDirectionRight;		private boolean isSkipHorizontalAnimation;	//#endif	//#ifdef polish.css.text-horizontal-adjustment		protected int textHorizontalAdjustment;	//#endif	//#ifdef polish.css.text-vertical-adjustment		protected int textVerticalAdjustment;	//#endif	//#ifdef polish.css.text-effect		protected TextEffect textEffect;	//#endif	/**	 * Creates a new <code>StringItem</code> object.  Calling this	 * constructor is equivalent to calling	 * 	 * <pre><code>	 * StringItem(label, text, Item.PLAIN, null);     	 * </code></pre>	 * 	 * @param label the Item label	 * @param text the text contents	 * @see #StringItem(String, String, int, Style)	 */	public StringItem( String label, String text)	{		this( label, text, PLAIN );	}	/**	 * Creates a new <code>StringItem</code> object.  Calling this	 * constructor is equivalent to calling	 * 	 * <pre><code>	 * StringItem(label, text, Item.PLAIN, style);     	 * </code></pre>	 * 	 * @param label the Item label	 * @param text the text contents	 * @param style the style	 * @see #StringItem(String, String, int, Style)	 */	public StringItem( String label, String text, Style style )	{				this( label, text, PLAIN, style );		if(style == null){			System.out.println("null");		}else{			System.out.println("123");		}	}			/**	 * Creates a new <code>StringItem</code> object with the given label,	 * textual content, and appearance mode.	 * Either label or text may be present or <code>null</code>.	 * 	 * <p>The <code>appearanceMode</code> parameter	 * (see <a href="Item.html#appearance">Appearance Modes</a>)	 * is a hint to the platform of the application's intended use	 * for this <code>StringItem</code>.  To provide hyperlink- or	 * button-like behavior,	 * the application should associate a default <code>Command</code> with this	 * <code>StringItem</code> and add an	 * <code>ItemCommandListener</code> to this	 * <code>StringItem</code>.	 * 	 * <p>Here is an example showing the use of a	 * <code>StringItem</code> as a button: </p>	 * <pre><code>	 * StringItem strItem = new StringItem("Default: ", "Set", Item.BUTTON);	 * strItem.setDefaultCommand(	 * new Command("Set", Command.ITEM, 1);	 * // icl is ItemCommandListener	 * strItem.setItemCommandListener(icl);     	 * </code></pre>	 * 	 * @param label the StringItem's label, or null if no label	 * @param text the StringItem's text contents, or null if the contents are initially empty	 * @param appearanceMode the appearance mode of the StringItem, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON	 * @throws IllegalArgumentException if appearanceMode invalid	 * @since  MIDP 2.0	 */	public StringItem( String label, String text, int appearanceMode)	{		this( label, text, appearanceMode, null );	}	/**	 * Creates a new <code>StringItem</code> object with the given label,	 * textual content, and appearance mode.	 * Either label or text may be present or <code>null</code>.	 * 	 * <p>The <code>appearanceMode</code> parameter	 * (see <a href="Item.html#appearance">Appearance Modes</a>)	 * is a hint to the platform of the application's intended use	 * for this <code>StringItem</code>.  To provide hyperlink- or	 * button-like behavior,	 * the application should associate a default <code>Command</code> with this	 * <code>StringItem</code> and add an	 * <code>ItemCommandListener</code> to this	 * <code>StringItem</code>.	 * 	 * <p>Here is an example showing the use of a	 * <code>StringItem</code> as a button: </p>	 * <pre><code>	 * StringItem strItem = new StringItem("Default: ", "Set", Item.BUTTON);	 * strItem.setDefaultCommand(	 * new Command("Set", Command.ITEM, 1);	 * // icl is ItemCommandListener	 * strItem.setItemCommandListener(icl);     	 * </code></pre>	 * 	 * @param label the StringItem's label, or null if no label	 * @param text the StringItem's text contents, or null if the contents are initially empty	 * @param appearanceMode the appearance mode of the StringItem, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON	 * @param style the style for this item	 * @throws IllegalArgumentException if appearanceMode invalid	 * @since  MIDP 2.0	 */	public StringItem( String label, String text, int appearanceMode, Style style )	{		super( label, LAYOUT_DEFAULT, appearanceMode, style );		this.text = text;	}			//#if polish.css.text-effect || polish.css.text-wrap	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#animate()	 */	public boolean animate() {		boolean animated = super.animate();		//#if polish.css.text-effect 			if (this.textEffect != null) {				animated |= this.textEffect.animate();			}		//#endif		//#if polish.css.text-wrap			if (this.useSingleLine && this.clipText) {				if (this.isSkipHorizontalAnimation) {					this.isSkipHorizontalAnimation = false;				} else {					if (this.isHorizontalAnimationDirectionRight) {						this.xOffset++;						if (this.xOffset >= 0) {							this.isHorizontalAnimationDirectionRight = false;						}					} else {						this.xOffset--;						if (this.xOffset + this.textWidth < this.contentWidth) {							this.isHorizontalAnimationDirectionRight = true;						}					}					animated = true;					this.isSkipHorizontalAnimation = true;				}			}		//#endif		return animated;	}	//#endif		//#if polish.css.text-wrap	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#defocus(de.enough.polish.ui.Style)	 */	protected void defocus(Style originalStyle) {		super.defocus(originalStyle);		if (this.clipText) {			this.xOffset = 0;		}	}		//#endif	//#ifdef polish.css.text-effect	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#hideNotify()	 */	protected void hideNotify() {		if (this.textEffect != null) {			this.textEffect.hideNotify();		}		super.hideNotify();	}	//#endif	//#ifdef polish.css.text-effect	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#showNotify()	 */	protected void showNotify() {		if (this.textEffect != null) {			this.textEffect.showNotify();		}		super.showNotify();	}	//#endif		/**	 * Gets the text contents of the <code>StringItem</code>, or	 * <code>null</code> if the <code>StringItem</code> is	 * empty.	 * 	 * @return a string with the content of the item	 * @see #setText(java.lang.String)	 */	public String getText()	{		return this.text;	}	/**	 * Sets the text contents of the <code>StringItem</code>. 	 * If text	 * is <code>null</code>,	 * the <code>StringItem</code>	 * is set to be empty.	 * 	 * @param text the new content	 * @see #getText()	 */	public void setText( String text)	{		setText( text, null );	}		/**	 * Sets the text contents of the <code>StringItem</code> along with a style. 	 * If text is <code>null</code>,	 * the <code>StringItem</code>	 * is set to be empty.	 * 	 * @param text the new content	 * @param style the new style, is ignored when null	 * @see #getText()	 */	public void setText( String text, Style style)	{		//#debug		System.out.println("StringItem: setText( \"" + text + "\" )");		if ( style != null ) {

⌨️ 快捷键说明

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