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

📄 choiceitem.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			}
			return defaultCheckSelected;
		} else {
			if (defaultRadioSelected == null ) {
				defaultRadioSelected = Image.createImage(11, 11);
				Graphics g = defaultRadioSelected.getGraphics();
				g.setColor( this.boxColor );
				g.fillRect(0, 0, 12, 12 );
				g.setColor( 0xFFFFFF );
				g.fillArc(1, 1, 9, 9, 0, 360 );
				g.setColor( this.boxColor );
				g.fillArc(3, 3, 5, 5, 0, 360 );
			}
			return defaultRadioSelected;
		}
	}

	/**
	 * Creates a plain image
	 * @return the image for a plain item
	 */
	private Image createPlain() {
		if (this.isMultiple) {
			if (defaultCheckPlain == null ) {
				defaultCheckPlain = Image.createImage(12, 12);
				Graphics g = defaultCheckPlain.getGraphics();
				g.setColor( this.boxColor );
				g.drawRect(0, 0, 11, 11 );
				g.drawRect(1, 1, 9, 9 );
			}
			return defaultCheckPlain;
		} else {
			if (defaultRadioPlain == null ) {
				defaultRadioPlain = Image.createImage(11, 11);
				Graphics g = defaultRadioPlain.getGraphics();
				g.setColor( this.boxColor );
				g.fillRect(0, 0, 12, 12 );
				g.setColor( 0xFFFFFF );
				g.fillArc(1, 1, 9, 9, 0, 360 );
			}
			return defaultRadioPlain;
		}
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#paintContent(int, int, int, int, javax.microedition.lcdui.Graphics)
	 */
	public void paintContent(int x, int y, int leftBorder, int rightBorder, Graphics g) {
		if (this.drawBox) {
			if ( this.boxImage != null) {
				g.drawImage( this.boxImage, x, y + this.yBoxAdjust, Graphics.TOP | Graphics.LEFT );
			}
			x += this.boxWidth;
			leftBorder += this.boxWidth;
			y += this.yAdjust;
		}
		super.paintContent(x, y, leftBorder, rightBorder, g);
	}
	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)
	 */
	public void setStyle(Style style) {
		super.setStyle(style);
		if (this.drawBox) {
			Style parentStyle = null;
			if (this.parent != null) {
				parentStyle = this.parent.style;
			}
			//#ifdef polish.css.radiobox-selected
				//# if (this.choiceType == Choice.EXCLUSIVE) {
					//# String url = style.getProperty( 11);
					//# if (url == null && parentStyle != null) {
						//# url = parentStyle.getProperty( 11);
					//# }
					//# loadImage( url, false );
				//# }
			//#endif
			//#ifdef polish.css.radiobox-plain
				//# if (this.choiceType == Choice.EXCLUSIVE) {
					//# String plainName = style.getProperty( 12);
					//# if ("none".equals(plainName)) {
						//# this.drawNoPlain = true;
					//# } else {
						//# if (plainName == null && parentStyle != null) {
							//# plainName = parentStyle.getProperty( 12);
						//# }
						//# loadImage( plainName, true );
					//# }
				//# }
			//#endif
			//#ifdef polish.css.checkbox-selected
				//# if (this.choiceType == Choice.MULTIPLE) {
					//# String url = style.getProperty( 9);
					//# if (url == null && parentStyle != null) {
						//# url = parentStyle.getProperty( 9);
					//# }
					//# loadImage( url, false );
				//# }
			//#endif
			//#ifdef polish.css.checkbox-plain
				//# if (this.choiceType == Choice.MULTIPLE) {
					//# String plainName = style.getProperty( 10);
					//# if ("none".equals(plainName)) {
						//# this.drawNoPlain = true;
					//# } else {
						//# if (plainName == null && parentStyle != null) {
							//# plainName = parentStyle.getProperty( 10);
						//# }
						//# loadImage( plainName, true );
					//# }
				//# }
			//#endif
			//#ifdef polish.css.choice-color
				//# Color color = style.getColorProperty(8);
				//# if (color == null && parentStyle != null) {
					//# color = parentStyle.getColorProperty(8);
				//# }
				//# if (color != null) {
					//# this.boxColor = color.getColor();
				//# }
			//#endif
	
		} // if draw box
	}
	
	private void loadImage( String name, boolean isPlain ) {
		if (name == null) {
			return;
		}
		//#ifdef polish.images.backgroundLoad
			//# if (isPlain) {
				//# this.plainImgName = name;
			//# } else {
				//# this.selectedImgName = name;
			//# }
		//#endif
		try {
			if (isPlain) {
				this.plain = StyleSheet.getImage( name, this, true );
			} else {
				this.selected = StyleSheet.getImage( name, this, true );
			}
		} catch (IOException e) {
			//#debug error
			//# System.out.println("Unable to load image [" + name + "]" + e );
		}
		
	}


	//#ifdef polish.images.backgroundLoad
	//# /* (non-Javadoc)
	 //# * @see de.enough.polish.ui.ImageConsumer#setImage(java.lang.String, javax.microedition.lcdui.Image)
	 //# */
	//# public void setImage(String name, Image image) {
		//# if (!this.drawBox) {
			//# super.setImage( name, image );
		//# } else if (name.equals(this.selectedImgName)) {
			//# this.selected = image;
		//# } else if (name.equals(this.plainImgName)) {
			//# this.plain = image;
		//# } else {
			//# setImage( image );
		//# }
		//# this.isInitialized = false;
		//# /*
		//# this.isInitialised = false;
		//# repaint();
		//# */
	//# }
	//#endif

	/**
	 * Selects or deselects this item.
	 * 
	 * @param select true when this item should be selected
	 */
	public void select(boolean select ) {
		this.isSelected = select;
		if (select) {
			this.boxImage = this.selected;
		} else {
			this.boxImage = this.plain;
		}
		/*
		 * if this is enabled, the navigation in Lists does not work anymore...
		if (this.isInitialised) {
			this.isInitialised = false;
			repaint();
		}*/
	}
	
	/**
	 * Changes the selected-state to the opposite state.
	 */
	public void toggleSelect() {
		select( !this.isSelected );
	}

	/**
	 * Sets the preferred font.
	 * This setting is ignored, since the J2ME Polish implementation
	 * uses the CSS settings.
	 *  
	 * @param font the preferred font
	 */
	public void setPreferredFont(Font font) {
		this.preferredFont = font;
	}

	/**
	 * @param lastItem the item to use the values from for adjustoing
	 */
	public void adjustProperties(Item lastItem) {
		this.relativeY = lastItem.relativeY;
	}
	
	/**
	 * Sets the image representing the "not selected" state of this choice item.
	 * 
	 * @param image the image representing the "not selected" state
	 */
	public void setPlainImage( Image image ) {
		this.plain = image;
	}

	/**
	 * Gets the image representing the "not selected" state of this choice item.
	 * 
	 * @return the image representing the "not selected" state
	 */
	public Image getPlainImage() {
		return this.plain;
	}

	/**
	 * Sets the image representing the "selected" state of this choice item.
	 * 
	 * @param image the image representing the "selected" state
	 */
	public void setSelectedImage( Image image ) {
		this.selected = image;
	}
	
	/**
	 * Gets the image representing the "selected" state of this choice item.
	 * 
	 * @return the image representing the "selected" state
	 */
	public Image getSelectedImage() {
		return this.selected;
	}


}

⌨️ 快捷键说明

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