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

📄 customitem.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * <code>getInteractionModes</code> method.	 * 	 * <p>keyRepeated() is suported by the J2ME Polish implementation when the native system forwards keyRepeated events to Canvas classes.</p>	 * 	 * @param keyCode - the key code of the key that has been repeated	 * @see #getInteractionModes()	 */	protected void keyRepeated(int keyCode)	{		//do nothing	}	/**	 * Called by the system when a pointer down action (for example, a pen	 * tap) has occurred within the item.  The <code>(x,y)</code>	 * coordinates are relative	 * to the origin of the item, and they will always indicate a location	 * within the item.  The implementation indicates support for delivery of	 * pointer press events by setting the <code>POINTER_PRESS</code>	 * bit in the value	 * returned by the <code>getInteractionModes</code> method.	 * 	 * @param x the x coordinate of the pointer down	 * @param y the y coordinate of the pointer down	 * @see #getInteractionModes()	 */	protected void pointerPressed(int x, int y)	{		//default implementation doesn't do anything	}	/**	 * Called by the system when a pointer up action (for example, a pen lift)	 * has occurred after a pointer down action had occurred within the item.	 * The <code>(x,y)</code> coordinates are relative to the origin	 * of the item.	 * Implementations should deliver a pointer release event to an item even	 * if the pointer has moved outside the item when the release occurs.  In	 * this case the <code>(x,y)</code> coordinates may indicate a	 * location outside the	 * bounds of the item.  The implementation indicates support for delivery	 * of pointer release events by setting the	 * <code>POINTER_RELEASE</code> bit in the	 * value returned by the <code>getInteractionModes</code> method.	 * 	 * @param x the x coordinate of the pointer up	 * @param y the x coordinate of the pointer up	 * @see #getInteractionModes()	 */	protected void pointerReleased(int x, int y)	{		//default implementation doesn't do anything	}	/**	 * Called by the system when a pointer drag action (for example, pen	 * motion after a press but before a release) has occurred within the item.	 * The <code>(x,y)</code> coordinates are relative to the origin	 * of the item.	 * Implementations should deliver pointer drag events to an item even if	 * the pointer is being moved outside the item.  In this case	 * the <code>(x,y)</code>	 * coordinates may indicate a location outside the bounds of the item.	 * The implementation indicates support for delivery of pointer release	 * events by setting the <code>POINTER_DRAG</code> bit in the	 * value returned by the	 * <code>getInteractionModes</code> method.	 * 	 * @param x the x coordinate of the pointer drag	 * @param y the x coordinate of the pointer drag	 * @see #getInteractionModes()	 */	protected void pointerDragged(int x, int y)	{		//default implementation doesn't do anything	}	//#ifdef polish.useDynamicStyles		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#createCssSelector()	 */	protected String createCssSelector() {		return "customitem";	}	//#endif			/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#initContent(int, int)	 */	protected void initContent(int firstLineWidth, int lineWidth) {		// intialising the content:		int prefWidth = getPrefContentWidth( -1 );		this.preferredWidth = prefWidth;		boolean resetSize = false;		if (prefWidth > lineWidth) {			prefWidth = lineWidth;			resetSize = true;		}		int prefHeight = getPrefContentHeight(prefWidth);		this.preferredHeight = prefHeight;		if (resetSize) {			sizeChanged( prefWidth, prefHeight );		}		this.contentWidth = prefWidth;		this.contentHeight = prefHeight;	}		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#paintContent(int, int, int, int, javax.microedition.lcdui.Graphics)	 */	protected void paintContent(int x, int y, int leftBorder, int rightBorder,			Graphics g) 	{		int clipX = g.getClipX();		int clipY = g.getClipY();		this.clipWidth = g.getClipWidth();		this.clipHeight = g.getClipHeight();		//#if polish.css.skip-set-clip			if (!this.skipClipping) {		//#endif				// set the clip-area, so that the implementation cannot paint over the content area:				g.clipRect( x, y, this.contentWidth, this.contentHeight );		//#if polish.css.skip-set-clip			}		//#endif		// translate the graphics origin:		g.translate( x, y );				// set default graphics-values:		g.setColor( 0 );		g.setStrokeStyle( Graphics.SOLID );		g.setFont( DEFAULT_FONT  );		// now let the implementation paint the actual content:		this.paint(g, this.contentWidth, this.contentHeight );				// retranslate the graphics-origin:		g.translate( -x, -y );		//#if polish.css.skip-set-clip			if (!this.skipClipping) {		//#endif				// reset the clip:				g.setClip( clipX, clipY, this.clipWidth, this.clipHeight );		//#if polish.css.skip-set-clip			}		//#endif	}		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#defocus(de.enough.polish.ui.Style)	 */	protected void defocus(Style originalStyle) {		super.defocus(originalStyle);		traverseOut();	}		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#focus(de.enough.polish.ui.Style)	 */	protected Style focus(Style focusStyle, int direction ) {		traverse( direction, this.clipWidth, this.clipHeight, this.visRect_inout );		return super.focus(focusStyle, direction );	}		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#handleKeyPressed(int, int)	 */	protected boolean handleKeyPressed(int keyCode, int gameAction) {		if (gameAction == Canvas.UP || gameAction == Canvas.LEFT ||				gameAction == Canvas.DOWN || gameAction == Canvas.RIGHT ) 		{			this.visRect_inout[0] = 0;			this.visRect_inout[1] = 0;			this.visRect_inout[2] = this.contentWidth;			this.visRect_inout[3] = this.contentHeight;			boolean isTraversed = traverse(gameAction, this.clipWidth, this.clipHeight, this.visRect_inout);			if (isTraversed) {				this.internalX = this.visRect_inout[0];				this.internalY = this.visRect_inout[1];				this.internalWidth = this.visRect_inout[2];				this.internalHeight = this.visRect_inout[3];				return true;			}		}		keyPressed( keyCode );		if (this.isInitialised == false) {			return true;		} else {			return super.handleKeyPressed(keyCode, gameAction);		}	}		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#handleKeyRepeated(int, int)	 */	protected boolean handleKeyRepeated(int keyCode, int gameAction) {		keyRepeated( keyCode );		if (this.isInitialised == false) {			return true;		} else {			return super.handleKeyRepeated(keyCode, gameAction);		}	}	/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#handleKeyReleased(int, int)	 */	protected boolean handleKeyReleased(int keyCode, int gameAction) {		keyReleased( keyCode );		if (this.isInitialised == false) {			return true;		} else {			return super.handleKeyReleased(keyCode, gameAction);		}	}		//#ifdef polish.hasPointerEvents	/**	 * Handles the event when a pointer has been pressed at the specified position.	 * The default method translates the pointer-event into an artificial	 * pressing of the FIRE game-action, which is subsequently handled	 * bu the handleKeyPressed(-1, Canvas.FIRE) method.	 * This method needs should be overwritten only when the "polish.hasPointerEvents"	 * preprocessing symbol is defined: "//#ifdef polish.hasPointerEvents".	 *    	 * @param x the x position of the pointer pressing	 * @param y the y position of the pointer pressing	 * @return true when the pressing of the pointer was actually handled by this item.	 */	protected boolean handlePointerPressed( int x, int y ) {		// translate the coordinates to the origin of this custom-item:		x -= this.contentX;		y -= this.contentY;		if (x < 0 || y < 0 || x > this.contentWidth || y > this.contentHeight ) {			// the content area has not been clicked, so return false:			return false;		}		pointerPressed( x, y );		return (this.isInitialised == false);	}	//#endif	protected void setParent( Item item, Item parent ) {		item.parent = parent;	}		protected boolean handleKeyPressed( Item item, int keyCode, int gameAction ) {		return item.handleKeyPressed(keyCode, gameAction);	}	protected void defocus( Item item, Style originalStyle ) {		item.defocus(originalStyle);	}	protected void setInOutRectangle( Item item, int[] visRect_inout ) {		visRect_inout[0] = item.internalX;		visRect_inout[1] = item.internalY;		visRect_inout[2] = item.internalWidth;		visRect_inout[3] = item.internalHeight;	}	//#if polish.css.skip-set-clip		/* (non-Javadoc)	 * @see de.enough.polish.ui.Item#setStyle(de.enough.polish.ui.Style)	 */	public void setStyle(Style style) {		super.setStyle(style);		//#if polish.css.skip-set-clip			Boolean skipClippingBool = style.getBooleanProperty("skip-set-clip");			if (skipClippingBool != null) {				this.skipClipping = skipClippingBool.booleanValue();			}		//#endif	}	//#endif		 }

⌨️ 快捷键说明

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