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

📄 item.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		//# protected int colSpan = 1;
	//#endif
	//#if polish.css.rowspan
		//# protected int rowSpan;
	//#endif
	//#if polish.css.include-label
		//# protected boolean includeLabel;
	//#endif
	/** The vertical offset for the background, can be used for smoother scrolling, for example */ 
	protected int backgroundYOffset;

	
	protected Item() {
		this( null, LAYOUT_DEFAULT, PLAIN, null );
	}
	
	protected Item( Style style ) {
		this( null, LAYOUT_DEFAULT, PLAIN, style );
	}
	
	protected Item( String label, int layout) {
		this( label, layout, PLAIN, null );
	}

	/**
	 * Creates a new Item.
	 * 
	 * @param label the label of this item
	 * @param layout the layout of this item
	 * @param appearanceMode the mode of this item, either Item.PLAIN, Item.BUTTON or Item.HYPERLINK
	 * @param style the style of this item - contains the background, border etc.
	 */
	protected Item(String label, int layout, int appearanceMode, Style style) {
		this.style = style;
		this.layout = layout;
		this.appearanceMode = appearanceMode;
		if (label != null && label.length() != 0) {
			setLabel( label );
		}
		if (style == null) {
			this.layout = layout;
		} else {
			this.style = style;
			this.isStyleInitialised = false;
		}
	}

	/**
	 * Sets the label of the <code>Item</code>. If <code>label</code>
	 * is <code>null</code>, specifies that this item has no label.
	 * 
	 * <p>It is illegal to call this method if this <code>Item</code>
	 * is contained within  an <code>Alert</code>.</p>
	 * 
	 * @param label - the label string
	 * @throws IllegalStateException - if this Item is contained  within an Alert
	 * @see #getLabel()
	 */
	public void setLabel( String label)
	{
		if (this.label == null) {
			this.label = new StringItem( null, label, this.labelStyle );
			this.label.parent = this.parent;
		} else {
			this.label.setText( label );
		}
		if (this.isInitialised) {
			this.isInitialised = false;
			repaint();
		}
	}

	/**
	 * Gets the label of this <code>Item</code> object.
	 * 
	 * @return the label string
	 * @see #setLabel(java.lang.String)
	 */
	public String getLabel()
	{
		if (this.label == null) {
			return null;
		} else {
			return this.label.getText();
		}
	}
	
	/**
	 * Retrieves the label item that is used by this item.\
	 * 
	 * @return the item or null when no item is used.
	 */
	public Item getLabelItem() {
		return this.label;
	}

	/**
	 * Gets the layout directives used for placing the item.
	 * 
	 * @return a combination of layout directive values
	 * @see #setLayout(int)
	 * @since  MIDP 2.0
	 */
	public int getLayout()
	{
		return this.layout;
	}

	/**
	 * Sets the layout directives for this item.
	 * 
	 * <p>It is illegal to call this method if this <code>Item</code>
	 * is contained within an <code>Alert</code>.</p>
	 * 
	 * @param layout - a combination of layout directive values for this item
	 * @throws IllegalArgumentException - if the value of layout is not a bit-wise OR combination of layout directives
	 * @throws IllegalStateException - if this Item is contained within an Alert
	 * @see #getLayout()
	 * @since  MIDP 2.0
	 */
	public void setLayout(int layout)
	{
		this.layout = layout;
	}

	/**
	 * Returns the appearance mode of this <code>Item</code>.
	 * See <a href="Item.html#appearance">Appearance Modes</a>.
	 * 
	 * @return the appearance mode value, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON
	 * @since  MIDP 2.0
	 */
	public int getAppearanceMode()
	{
		return this.appearanceMode;
	}
	
	/**
	 * Sets the appearance mode of this item.
	 * 
	 * @param appearanceMode the mode value, one of Item.PLAIN, Item.HYPERLINK, or Item.BUTTON
	 */
	public void setAppearanceMode( int appearanceMode ) {
		this.appearanceMode = appearanceMode;
	}
	
	/**
	 * Retrieves the style of this item.
	 * 
	 * @return the style of this item.
	 */
	public Style getStyle() {
		return this.style;
	}
	
	/**
	 * Sets the style of this item.
	 * 
	 * @param style the new style for this item.
	 * @throws NullPointerException when style is null
	 */
	public void setStyle( Style style ) {
		//#debug
de.enough.polish.util.Debug.debug("debug", "de.enough.polish.ui.Item", 868, "setting style - with background: ", (style.background != null));
		this.isInitialised = false;
		this.isStyleInitialised = true;
		this.style = style;
		if (style != StyleSheet.defaultStyle) {
			this.layout = style.layout;
		}
		// horizontal styles: center -> right -> left
		if ( ( this.layout & LAYOUT_CENTER ) == LAYOUT_CENTER ) {
			this.isLayoutCenter = true;
			this.isLayoutRight = false;
		} else {
			this.isLayoutCenter = false;
			if ( ( this.layout & LAYOUT_RIGHT ) == LAYOUT_RIGHT ) {
				this.isLayoutRight = true;
			} else {
				this.isLayoutRight = false;
			}
		}
		//System.out.println(" style [" + style.name + "]: right: " + this.isLayoutRight + " center: " + this.isLayoutCenter);
		// vertical styles: vcenter -> bottom -> top
		// expanding layouts:
		if ( ( this.layout & LAYOUT_EXPAND ) == LAYOUT_EXPAND ) {
			this.isLayoutExpand = true;
		} else {
			this.isLayoutExpand = false;
		}
		this.background = style.background;
		this.border = style.border;
		if (this.border != null) {
			this.borderWidth = this.border.borderWidth;
		} else if (this.background != null){
			this.borderWidth = this.background.borderWidth;
		} else {
			this.borderWidth = 0;
		}
		this.paddingLeft = style.paddingLeft;
		this.paddingRight = style.paddingRight;
		this.paddingTop = style.paddingTop;
		this.paddingBottom = style.paddingBottom;
		this.paddingVertical = style.paddingVertical;
		this.paddingHorizontal = style.paddingHorizontal;
		this.marginLeft = style.marginLeft;
		this.marginRight = style.marginRight;
		this.marginTop = style.marginTop;
		this.marginBottom = style.marginBottom;
		//#ifdef polish.css.before
			//# String beforeUrlStr = style.getProperty(190); 
			//# if (beforeUrlStr != null) {
				//# if ( !beforeUrlStr.equals(this.beforeUrl) ) {
					//# try {
						//# this.beforeImage = StyleSheet.getImage(beforeUrlStr, null, true );
						//# this.beforeWidth = this.beforeImage.getWidth() + this.paddingHorizontal;
						//# this.beforeHeight = this.beforeImage.getHeight();
					//# } catch (IOException e) {
						//# this.beforeUrl = null;
						//# this.beforeImage = null;
						//# this.beforeWidth = 0;
						//# this.beforeHeight = 0;						
					//# }
				//# }
			//# } else {
				//# this.beforeImage = null;
				//# this.beforeWidth = 0;
				//# this.beforeHeight = 0;
			//# }
			//# this.beforeUrl = beforeUrlStr;
		//#endif
		//#ifdef polish.css.after
			//# String afterUrlStr = style.getProperty(191);
			//# if (afterUrlStr != null) {
				//# if ( !afterUrlStr.equals(this.afterUrl) ) {
					//# try {
						//# this.afterImage = StyleSheet.getImage(afterUrlStr, null, true );
						//# this.afterWidth = this.afterImage.getWidth() + this.paddingHorizontal;
						//# this.afterHeight = this.afterImage.getHeight();
					//# } catch (IOException e) {
						//# this.afterUrl = null;
						//# this.afterWidth = 0;
						//# this.afterHeight = 0;
						//# this.afterImage = null;
					//# }
				//# }
			//# } else {
				//# this.afterWidth = 0;
				//# this.afterHeight = 0;
				//# this.afterImage = null;
			//# }
			//# this.afterUrl = afterUrlStr;
		//#endif
		//#ifdef polish.css.label-style
			Style labStyle = (Style) style.getObjectProperty(3);
			if (labStyle != null) {
				this.labelStyle = labStyle;
			} else if (this.labelStyle == null || this.isFocused) {
				this.labelStyle = StyleSheet.labelStyle;
			}
		//#else
			//# this.labelStyle = StyleSheet.labelStyle;
		//#endif
		if (this.label != null) {
			this.label.setStyle( this.labelStyle );			
		}
		//#ifdef polish.css.min-width
			//# Integer minWidthInt = style.getIntProperty(58);
			//# if (minWidthInt != null) {
				//# this.minimumWidth = minWidthInt.intValue();
			//# }
		//#endif
		//#ifdef polish.css.max-width
			//# Integer maxWidthInt  = style.getIntProperty(59);
			//# if (maxWidthInt != null) {
				//# this.maximumWidth = maxWidthInt.intValue();
			//# }
		//#endif
		//#ifdef polish.css.min-height
			//# Integer minHeightInt = style.getIntProperty(144);
			//# if (minHeightInt != null) {
				//# this.minimumHeight = minHeightInt.intValue();
			//# }
		//#endif
		//#ifdef polish.css.max-height
			//# Integer maxHeightInt  = style.getIntProperty(145);
			//# if (maxHeightInt != null) {
				//# this.maximumHeight = maxHeightInt.intValue();
			//# }
		//#endif
		//#ifdef polish.css.focused-style
			//Object object = style.getObjectProperty("focused-style");
			//if (object != null) {
			//	System.out.println("focused-type: " + object.getClass().getName());
			//}
			Style focused = (Style) style.getObjectProperty(1);
			if (focused != null) {
				this.focusedStyle = focused;
//				if (this instanceof ChoiceGroup) {
//					System.out.println("Setting focused style for choicegroup!");
//				}
			}
		//#endif
		//#if polish.css.colspan
			//# Integer colSpanInt = style.getIntProperty(106);
			//# if ( colSpanInt != null ) {
				//# this.colSpan = colSpanInt.intValue();
			//# }
		//#endif	
		//#if polish.css.include-label
			//# Boolean includeLabelBool = style.getBooleanProperty(132);
			//# if (includeLabelBool != null) {
				//# this.includeLabel = includeLabelBool.booleanValue();
			//# }
		//#endif
		
	}
	
	/**
	 * Retrieves the complete width of this item.
	 * Note that the width can dynamically change,
	 * e.g. when a StringItem gets a new text.
	 * 
	 * @param firstLineWidth the maximum width of the first line 
	 * @param lineWidth the maximum width of any following lines
	 * @return the complete width of this item.
	 */
	public int getItemWidth( int firstLineWidth, int lineWidth ) {
		if (!this.isInitialised || this.itemWidth > lineWidth) {
			init( firstLineWidth, lineWidth );
		}
		return this.itemWidth;
	}

	/**
	 * Retrieves the complete height of this item.
	 * Note that the width can dynamically change,
	 * e.g. when a new style is set.
	 * 
	 * @param firstLineWidth the maximum width of the first line 
	 * @param lineWidth the maximum width of any following lines
	 * @return the complete heigth of this item.
	 */
	public int getItemHeight( int firstLineWidth, int lineWidth ) {
		if (!this.isInitialised || this.itemWidth > lineWidth) {
			init( firstLineWidth, lineWidth );
		}
		return this.itemHeight;
	}

	/**
	 * Adds a context sensitive <code>Command</code> to the item.

⌨️ 快捷键说明

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