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

📄 iconitem.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				//# if (useScaledImage) {
					//#ifdef polish.Bugs.drawRgbOrigin
						//# scaleX += g.getTranslateX();
						//# scaleY += g.getTranslateY();						
					//#endif
					//# if (scaleX < 0) {
						//# scaleX = 0;
					//# }
					//# if (scaleY < 0) {
						//# scaleY = 0;
					//# }
					//# g.drawRGB(sData, 0, sWidth, scaleX, scaleY, sWidth, sHeight, true );
				//# }
			//#endif		
			//#if polish.css.icon-horizontal-adjustment
				//# x -= this.horizontalAdjustment;
			//#endif
			//#if polish.css.icon-vertical-adjustment
				//# y -= this.verticalAdjustment;
			//#endif
		}
		super.paintContent(x, y, leftBorder, rightBorder, g);
	}
	
	/**
	 * Retrieves the image of this item.
	 * 
	 * @return the image of this icon.
	 */
	public Image getImage() {
		return this.image;
	}
	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)
	 */
	public void setStyle(Style style) {
		super.setStyle(style);
		//#ifdef polish.css.icon-image-align
			Integer align = style.getIntProperty(7);
			if (align == null) {
				// keep align setting
			} else {
				switch (align.intValue()) {
					case 0: this.imageAlign = Graphics.LEFT; break; 
					case 1: this.imageAlign = Graphics.RIGHT; break; 
					case 2: this.imageAlign = Graphics.TOP; break; 
					case 3: this.imageAlign = Graphics.BOTTOM; break; 
					case 4: this.imageAlign = Graphics.HCENTER | Graphics.VCENTER; break; 
				}
			}
		//#endif
		//#ifdef polish.css.icon-image
			String imageName = style.getProperty(6);
			if (imageName != null) {
				Item item = this;
				Item container = this.parent;
				while ((container != null) 
						&& !(container instanceof Container) 
						&& (container.parent != null)) 
				{
					item = container;
					container = container.parent;
				}
				if (container instanceof Container) {
					imageName = ((Container) container).parseIndexUrl( imageName, item );
				}
				//#if polish.debug.error
					//# else if ( imageName.indexOf( "%INDEX%") != -1) {
						//# throw new IllegalStateException("IconItem cannot resolve %INDEX% in url since parent is not a container: " + container );
					//# }
				//#endif
				try {
					Image img = StyleSheet.getImage(imageName, this, true);
					if (img != null) {
						this.image = img;
						//#if polish.midp2 && polish.css.scale-factor
							//# this.rgbData = null;
							//# this.scaleData = null;
						//#endif
					}
				} catch (IOException e) {
					//#debug error
					//# System.out.println("unable to load image [" + imageName + "]" + e);
				}
			}
		//#endif
		//#if polish.css.icon-vertical-adjustment
			//# Integer verticalAdjustmentInt = style.getIntProperty(82);
			//# if (verticalAdjustmentInt != null) {
				//# this.verticalAdjustment = verticalAdjustmentInt.intValue();
			//# }
		//#endif
		//#if polish.css.icon-horizontal-adjustment
			//# Integer horizontalAdjustmentInt = style.getIntProperty(81);
			//# if (horizontalAdjustmentInt != null) {
				//# this.horizontalAdjustment = horizontalAdjustmentInt.intValue();
			//# }
		//#endif

		//#if polish.midp2	
			//#ifdef polish.css.scale-factor
				//# Integer scaleFactorInt = style.getIntProperty( 60 );
				//# if (scaleFactorInt != null) {
					//# this.scaleFactor = scaleFactorInt.intValue();
				//# }
			//#endif
			//#ifdef polish.css.scale-steps
				//# Integer scaleStepsInt = style.getIntProperty( 61 );
				//# if (scaleStepsInt != null) {
					//# this.scaleSteps = scaleStepsInt.intValue();
				//# }
			//#endif
		//#endif	
		//#if polish.css.icon-inactive
			//# Boolean inactiveBool = style.getBooleanProperty(111);
			//# if (inactiveBool != null) {
				//# if (inactiveBool.booleanValue()) {
					//# this.appearanceMode = Item.PLAIN;
				//# } else {
					//# this.appearanceMode = Item.INTERACTIVE;								
				//# }
			//# }
		//#endif

	}

	/**
	 * Loads the specified image.
	 * 
	 * @param url the local URL of the image
	 */
	public void setImage( String url ) {
		try {
			Image img = StyleSheet.getImage(url, this, false);
			if (img != null) {
				setImage( img );
			}
		} catch (IOException e) {
			//#debug error
			//# System.out.println("unable to load image [" + url + "]" + 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) {
		//# this.image = image;
		//# //System.out.println("image [" + name + "] has been set.");
		//# if (this.isInitialized) {
			//# this.isInitialized = false;
			//# repaint();
		//# }
	//# }
	//#endif
	
	/**
	 * Sets the image for this icon.
	 * 
	 * @param image the image for this icon, when null is given, no image is painted.
	 */
	public void setImage( Image image ) {
		setImage( image, null );
	}
	
	/**
	 * Sets the image for this icon.
	 * 
	 * @param img the image for this icon, when null is given, no image is painted.
	 * @param style the new style of this item, is ignored when null
	 */
	public void setImage(Image img, Style style) {
		if (style != null) {
			setStyle( style );
		}
		this.image = img;
		//#if polish.midp2 && polish.css.scale-factor
			//# this.rgbData = null;
			//# this.scaleData = null;
		//#endif
		if (this.isInitialized) {	
			this.isInitialized = false;
			repaint();
		}
	}

	
	/**
	 * Sets the image align for this icon.
	 * 
	 * @param imageAlign either Graphics.TOP, Graphics.LEFT, Graphics.BOTTOM or Graphics.RIGHT
	 */
	public void setImageAlign( int imageAlign ) {
		this.imageAlign = imageAlign;
		this.isInitialized = false;
	}
	
	//#if polish.midp2 && polish.css.scale-factor
	//# /* (non-Javadoc)
	 //# * @see de.enough.polish.ui.Item#hideNotify()
	 //# */
	//# public boolean animate() {
		//# boolean animated = super.animate();
		//# if (this.scaleFactor != 0) {
			//# if (this.scaleFinished || this.image == null) {
				//# return animated;
			//# }
			//# int imgWidth = this.image.getWidth();
			//# int imgHeight = this.image.getHeight();
			//# if (this.rgbData == null) {
				//# this.rgbData = new int[ imgWidth * imgHeight ];
				//# this.image.getRGB(this.rgbData, 0, imgWidth, 0, 0, imgWidth, imgHeight );
			//# }
			//# int step = this.currentStep;
			//# if (this.scaleDown) {
				//# step--;
				//# if (step <= 0) {
					//# this.scaleFinished =  true;
					//# this.scaleData = null;
					//# return true;
				//# }
			//# } else {
				//# step++;
				//# if (step > this.scaleSteps) {
					//# this.scaleDown = true;
					//# return false;
				//# }
			//# }
			//# this.currentStep = step;
			//# int scaleWidth = imgWidth + ((imgWidth * this.scaleFactor * step) / (this.scaleSteps * 100));
			//# int scaleHeight = imgHeight + ((imgHeight * this.scaleFactor * step) / (this.scaleSteps * 100));
			//# //System.out.println("\nstep=" + step + ", scaleSteps=" + this.scaleSteps + "\nscaleWidth=" + this.scaleWidth + ", scaleHeight=" + this.scaleHeight + ", imgWidth=" + imgWidth + ", imgHeight=" + imgHeight + "\n");
			//# int[] scaledRgbData = ImageUtil.scale( scaleWidth, scaleHeight, imgWidth, 
					//# imgWidth, imgHeight, this.rgbData);
			//# Object[] localeScaleData = new Object[]{ scaledRgbData, new Integer( scaleWidth ) };
			//# // this operation is atomic:
			//# this.scaleData = localeScaleData;
			//# return true;
		//# }
		//# return animated;
//# 		
	//# }		
	//#endif

	//#if polish.midp2 && polish.css.scale-factor
	//# /* (non-Javadoc)
	 //# * @see de.enough.polish.ui.Item#defocus(de.enough.polish.ui.Style)
	 //# */
	//# protected void defocus(Style originalStyle) {
		//# super.defocus(originalStyle);
		//# this.scaleFinished = false;
		//# this.scaleDown = false;
		//# this.currentStep = 0;
		//# this.scaleData = null;
	//# }
	//#endif

	//#if polish.debug.enabled
		//# public String toString(){
			//# return "IconItem(" + this.text + ")/" + super.toString();
		//# }
	//#endif
		
	/**
	 * Releases all (memory intensive) resources such as images or RGB arrays of this item.
	 * The default implementation does release any background resources.
	 */
	public void releaseResources() {
		super.releaseResources();
		//#if polish.midp2 && polish.css.scale-factor
			//# this.scaleData = null;
		//#endif
		this.image = null;
		this.isStyleInitialised = false;
	}

	
//#ifdef polish.IconItem.additionalMethods:defined
	//#include ${polish.IconItem.additionalMethods}
//#endif

}

⌨️ 快捷键说明

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