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

📄 item.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * When it is equal -9999 this item's internal position is not known.
	 * The internal position is useful for items that have a large content which
	 * needs to be scrolled, e.g. containers.  
	 */
	protected int internalX = -9999;
	/** the vertical position of this item's internal content relative to it's top edge */
	protected int internalY;
	/** The internal width of this item's content.  */
	protected int internalWidth;
	/** The internal height of this item's content.  */
	protected int internalHeight;
	public boolean isFocused;
	
	//#ifdef polish.css.before
		//# private String beforeUrl;
		//# private int beforeWidth;
		//# private int beforeHeight;
		//# private Image beforeImage;
	//#endif

	//#ifdef polish.css.after
		//# private String afterUrl;
		//# private int afterWidth;
		//# private int afterHeight;
		//# private Image afterImage;
	//#endif
	// label settings:
	protected Style labelStyle = StyleSheet.labelStyle;
	protected StringItem label;
	private boolean useSingleRow;
	//#if polish.blackberry
		//# public Field _bbField;
		//# public boolean _bbFieldAdded;
	//#endif
	protected Style focusedStyle;

	//#if polish.css.colspan
		//# 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;

	private HashMap attributes;

	//#ifdef polish.css.view-type
		protected ItemView view;
	//#endif

	
	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; // orginally used "this.parent", however that field might not be known at this moment.
		} else {
			this.label.setText( label );
		}
		if (this.isInitialized) {
			this.isInitialized = 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)
	{
		if (layout != this.layout) {
			this.layout = layout;
			if (this.isInitialized) {
				this.isInitialized = false;
				repaint();
			}
		}
	}

	/**
	 * 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
		//# System.out.println("setting style - with background: " + (style.background != null));
		this.isInitialized = 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;
			}
		}
		
		// vertical styles: vcenter -> bottom -> top
		// expanding layouts:
		if ( ( this.layout & LAYOUT_EXPAND ) == LAYOUT_EXPAND ) {
			this.isLayoutExpand = true;
		} else {
			this.isLayoutExpand = false;
		}
		//System.out.println( this + " style [" + style.name + "]: right: " + this.isLayoutRight + " center: " + this.isLayoutCenter + " expand: " + this.isLayoutExpand + " layout=" + Integer.toHexString(this.layout));
		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());

⌨️ 快捷键说明

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