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

📄 alert.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * is as if a new snapshot of img's contents is taken.  Thus, after
	 * painting into a mutable image contained by an <code>Alert</code>, the
	 * application can call
	 * 
	 * <TABLE BORDER="2">
	 * <TR>
	 * <TD ROWSPAN="1" COLSPAN="1">
	 * <pre><code>
	 * alert.setImage(alert.getImage());    </code></pre>
	 * </TD>
	 * </TR>
	 * </TABLE>
	 * <p>to refresh the <code>Alert's</code> snapshot of its
	 * <code>Image</code>.</p>
	 * 
	 * <p>If the <code>Alert</code> is visible on the display when its
	 * contents are updated
	 * through a call to <code>setImage</code>, the display will be
	 * updated with the new
	 * snapshot as soon as it is feasible for the implementation to do so.
	 * </p>
	 * 
	 * @param img the Alert's image, or null if there is no image
	 * @see #getImage()
	 */
	public void setImage( Image img)
	{
		setImage(img, null);
	}
	
	/**
	 * Sets the <code>Image</code> used in the <code>Alert</code>.
	 * The <code>Image</code> may be mutable or
	 * immutable.  If <code>img</code> is <code>null</code>, specifies
	 * that this <code>Alert</code> has no image.
	 * If <code>img</code> is mutable, the effect is as if a snapshot is taken
	 * of <code>img's</code> contents immediately prior to the call to
	 * <code>setImage</code>.  This
	 * snapshot is used whenever the contents of the
	 * <code>Alert</code> are to be
	 * displayed.  If <code>img</code> is already the
	 * <code>Image</code> of this <code>Alert</code>, the effect
	 * is as if a new snapshot of img's contents is taken.  Thus, after
	 * painting into a mutable image contained by an <code>Alert</code>, the
	 * application can call
	 * 
	 * <TABLE BORDER="2">
	 * <TR>
	 * <TD ROWSPAN="1" COLSPAN="1">
	 * <pre><code>
	 * alert.setImage(alert.getImage());    </code></pre>
	 * </TD>
	 * </TR>
	 * </TABLE>
	 * <p>to refresh the <code>Alert's</code> snapshot of its
	 * <code>Image</code>.</p>
	 * 
	 * <p>If the <code>Alert</code> is visible on the display when its
	 * contents are updated
	 * through a call to <code>setImage</code>, the display will be
	 * updated with the new
	 * snapshot as soon as it is feasible for the implementation to do so.
	 * </p>
	 * 
	 * @param img the Alert's image, or null if there is no image
	 * @param style the new style
	 * @see #getImage()
	 */
	public void setImage( Image img, Style style )
	{
		if (this.iconItem == null) {
			createItem(null, img, style);
		} else if (style != null) {
			this.iconItem.setStyle(style);
		}
		this.iconItem.setImage(img);
	}


	/**
	 * Sets an activity indicator on this <code>Alert</code>.  The
	 * activity indicator is a
	 * <A HREF="../../../javax/microedition/lcdui/Gauge.html"><CODE>Gauge</CODE></A> object.  It must be in a restricted state in order for it
	 * to be used as the activity indicator for an <code>Alert</code>.
	 * The restrictions
	 * are listed <a href="#indicator">above</a>.  If the
	 * <code>Gauge</code> object
	 * violates any of these restrictions,
	 * <code>IllegalArgumentException</code> is thrown.
	 * 
	 * <p>If <code>indicator</code> is <code>null</code>, this removes any
	 * activity indicator present on this <code>Alert</code>.</p>
	 * 
	 * @param indicator - the activity indicator for this Alert, or null if there is to be none
	 * @throws IllegalArgumentException - if indicator does not meet the restrictions for its use in an Alert
	 * @see #getIndicator()
	 * @since  MIDP 2.0
	 */
	public void setIndicator( Gauge indicator)
	{
		setIndicator( indicator, null );
	}

	/**
	 * Sets an activity indicator on this <code>Alert</code>.  The
	 * activity indicator is a
	 * <A HREF="../../../javax/microedition/lcdui/Gauge.html"><CODE>Gauge</CODE></A> object.  It must be in a restricted state in order for it
	 * to be used as the activity indicator for an <code>Alert</code>.
	 * The restrictions
	 * are listed <a href="#indicator">above</a>.  If the
	 * <code>Gauge</code> object
	 * violates any of these restrictions,
	 * <code>IllegalArgumentException</code> is thrown.
	 * 
	 * <p>If <code>indicator</code> is <code>null</code>, this removes any
	 * activity indicator present on this <code>Alert</code>.</p>
	 * 
	 * @param indicator - the activity indicator for this Alert, or null if there is to be none
	 * @param style the style
	 * @throws IllegalArgumentException - if indicator does not meet the restrictions for its use in an Alert
	 * @see #getIndicator()
	 * @since  MIDP 2.0
	 */
	public void setIndicator( Gauge indicator, Style style )
	{
		if (this.indicator != null) {
			this.container.remove( this.indicator );
		}
		if (style != null && indicator != null) {
			indicator.setStyle( style );
		}
		this.indicator = indicator;
		this.container.add( this.indicator );
	}

	/**
	 * Gets the activity indicator for this <code>Alert</code>.
	 * 
	 * @return a reference to this Alert's activity indicator, or null if there is none
	 * @see #setIndicator( Gauge )
	 * @since  MIDP 2.0
	 */
	public Gauge getIndicator()
	{
		return this.indicator;
	}


	//#ifdef polish.useDynamicStyles	
	//# protected String createCssSelector() {
		//# return "alert";
	//# }
	//#endif
	
	

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#paintScreen(javax.microedition.lcdui.Graphics)
	 */
//	protected void paintScreen(Graphics g) {
//		int x = this.contentX;
//		int y = this.contentY;
//		int height = this.contentHeight;
//		int width = this.contentWidth;
//		if (this.indicator != null) {
//			if ( (this.indicator.layout & Item.LAYOUT_TOP) == Item.LAYOUT_TOP ) {
//				this.indicator.paint( x, y, x, x + width, g );
//				y += this.indicator.itemHeight;
//			} else {
//				int indicatorHeight = this.indicator.getItemHeight(width, width);
//				this.indicator.paint( x, y + height - indicatorHeight, x, x + width, g );
//			}
//			height -= this.indicator.itemHeight;
//		}
//		if (this.iconItem != null) {
//			if ( (this.iconItem.layout & Item.LAYOUT_TOP) == Item.LAYOUT_TOP ) {
//				this.iconItem.paint( x, y, x, x + width, g );
//				//y += this.iconItem.itemHeight;
//			} else {
//				int iconItemHeight = this.iconItem.getItemHeight(width, width);
//				this.iconItem.paint( x, y + height - iconItemHeight, x, x + width, g );
//			}
//		}
//	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#animate()
	 */
	public boolean animate() {
		boolean animated = super.animate();
		//System.out.println("Alert: super.animate()=" + animated );
		if (this.iconItem != null) {
			animated |= this.iconItem.animate();
		}
		if (this.indicator != null) {
			animated |= this.indicator.animate();
		}
		if (this.timeout != FOREVER ) {
			if (System.currentTimeMillis() - this.showTime > this.timeout) {
				commandAction(DISMISS_COMMAND, this);
				return false;
			}
		}
		return animated; 
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#getRootItems()
	 */
//	protected Item[] getRootItems() {
//		if (this.iconItem != null ) {
//			if (this.indicator != null) {
//				return new Item[]{ this.iconItem, this.indicator };
//			} else {
//				return new Item[]{ this.iconItem };
//			}
//		} else if (this.indicator != null) {
//			return new Item[]{ this.indicator };
//		} else {
//			return new Item[0];
//		}
//	}
		
	/* (non-Javadoc)
	 * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
	 */
	public void commandAction(Command cmd, Displayable thisScreen) {
		if (this.nextDisplayable == null) {
			//#debug error
			//# System.out.println("unablet to handle command " + cmd.getLabel() + ": nextDisplayable == null.");
			//throw new IllegalStateException();
			return;
		}
		Displayable next = this.nextDisplayable;
		this.nextDisplayable = null;
		//#debug
		//# System.out.println("Alert: setting nextDisplayable=" + next );
		StyleSheet.display.setCurrent( next );
	}
	
	
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#showNotify()
	 */
	public void showNotify() {
		this.showTime = System.currentTimeMillis();
		if (this.nextDisplayable == null) {
			Displayable last = StyleSheet.display.getCurrent();
			if (last != this && last != null) {
				this.nextDisplayable = last;
			}
		}
		super.showNotify();
	}

	public static void setCurrent( Display display, Alert alert, Displayable nextDisplayable ) {
		//#debug
		//# System.out.println("Alert.setCurrent() of " + alert + " with nextDisplayable=" + nextDisplayable);
		if (nextDisplayable == null) {
			//System.out.println("Alert: storing current displayable from display");
			nextDisplayable = display.getCurrent();
		}
		alert.nextDisplayable = nextDisplayable;
		display.setCurrent( alert );
	}
	
	
	//#if polish.css.show-dismiss-command
	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#setStyle(de.enough.polish.ui.Style)
	 */
	public void setStyle(Style style) {
		super.setStyle(style);
		//#if polish.css.show-dismiss-command
			Boolean showDismissCommandBool = style.getBooleanProperty(112);
			if (showDismissCommandBool != null) {
				this.showDismissCommand = showDismissCommandBool.booleanValue();
				if (!this.showDismissCommand && this.timeout != FOREVER) {
					super.removeCommand(DISMISS_COMMAND);
				}
			}
		//#endif
	}
	//#endif

}

⌨️ 快捷键说明

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