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

📄 firescreen.java

📁 FIRE (Flexible Interface Rendering Engine)是一个J2ME上的灵活的图形界面引擎
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				if (!popup.valid)		{			popup.validate();		}				int sw = getWidth();		int sh = getHeight();		int pw = popup.getWidth();		int ph = popup.getHeight();				// first try to place the popup above the trigger cmp.		// if it doesn't fit check bottom of the trigger cmp		// else check right		// else check left 		// else try to fit it over the trigger cmp.				if(cmpY-ph>0) // popup height fits above the trigger component.		{			popupY = cmpY-ph;			if(pw>=sw) popupX = 0;			else if(cmpX+pw<sw)				popupX = cmpX;			else if(cmpX+cmpW-pw>0) popupX = cmpX+cmpW-pw;			else {				popupX = cmpX + (sw - (cmpX+pw));			}		}		else if(cmpY+cmpH+ph<sh) // popup fits below the trigger component		{			popupY = cmpY+cmpH;			if(pw>=sw) popupX = 0;			else if(cmpX+pw<sw)				popupX = cmpX;			else if(cmpX+cmpW-pw>0) popupX = cmpX+cmpW-pw;			else {				popupX = cmpX + (sw - (cmpX+pw));			}		}		else if(cmpX+cmpW+pw<sw) // popup fits on the right of the trigger component.		{			popupX = cmpX+cmpW;			if(ph>=sh) popupY =0;			else if(cmpY+ph<sh) popupY = cmpY;			else {				popupX = cmpY + (sh - (cmpY+ph));			}		}		else if(cmpX-pw>=0) // popup fits on the left of the trigger component		{			popupX = cmpX-pw;			if(ph>=sh) popupY =0;			else if(cmpY+ph<sh) popupY = cmpY;			else {				popupX = cmpY + (sh - (cmpY+ph));			}					}		else // try to show the popup over the trigger component		{			popupX = cmpX;			popupY = cmpY;			if(popupX+pw>sw) popupX += (sw - (popupX+pw));			if(popupY+ph>sh) popupY += (sh - (popupY+ph));			if(popupX<0) popupX=0;			if(popupY<0) popupY=0;		}				popup.setX(popupX);		popup.setY(popupY);		addComponent(popup,zindex);	}		/**	 * Utility method to open a popup on the left softkey.	 * It is equivalent to: 	 * FireScreen.getScreen().showPopupOnComponent(popup,FireScreen.getScreen().getComponent(FireScreen.LEFT_SOFTKEY_ZINDEX),zindex)	 * 	 * @see #showPopupOnComponent(Component, Component, int)	 * @param popup 	 * @param zindex	 */	public void showPopupOnLeftSoftkey(Component popup,int zindex)	{		showPopupOnComponent(popup,componentSlots[LEFT_SOFTKEY_ZINDEX-ZINDEX_MIN],zindex);	}		/**	 * Utility method to open a popup on the right softkey.	 * It is equivalent to: 	 * FireScreen.getScreen().showPopupOnComponent(popup,FireScreen.getScreen().getComponent(FireScreen.RIGHT_SOFTKEY_ZINDEX),zindex)	 * 	 * @see #showPopupOnComponent(Component, Component, int)	 * @param popup 	 * @param zindex	 */	public void showPopupOnRightSoftkey(Component popup,int zindex)	{		showPopupOnComponent(popup,componentSlots[RIGHT_SOFTKEY_ZINDEX-ZINDEX_MIN],zindex);	}	/**	 * Adds the given component as a top level component on index zidx	 * 	 * @see #ZINDEX_MAX	 * @param c	 * @param zidx	 */	public void addComponent(Component c, int zidx)	{		if (zidx < ZINDEX_MIN || zidx > ZINDEX_MAX)			throw new IllegalArgumentException("zindex must be between [" + ZINDEX_MIN + "," + ZINDEX_MAX + "].");		int zindex = zidx - ZINDEX_MIN;		if (c.parent != null)		{			if (c.parent instanceof Container)				((Container) c.parent).remove(c);			c.parent = null;		}		if (!c.valid)		{			c.validate();		}		Component last = componentSlots[zindex];		if (last != null)		{			removeComponent(zidx);		}		componentSlots[zindex] = c;		if (c instanceof Animation)		{			registerAnimation((Animation) c);		} else		{			setSelectedComponent(null); // this will allow for returning to the										// selected input field after editing										// it.			if (c.animation != null)			{				registerAnimation(c.animation);			}			if (c instanceof Container || c.isFocusable())			{				if (softkeyController < zindex)				{					// new softkey controller.					softkeyController = zindex;					// softkeys should be updated.					updateSoftKeys();				}			}		}		c.repaint();		if (display.getCurrent() != this)		{			display.setCurrent(this);			repaintScreen(0, 0, getWidth(), getHeight());		}	}	/**	 * Utility method for fast and easy user notification. Creates an alert with	 * the given parameters and displayes it on the screen using zindex (see	 * {@link #ZINDEX_MAX} 4	 * 	 * @see Alert	 * 	 * @param message	 *            The message to be shown in the alert	 * @param type	 *            The type of the alert	 * @param defaultSelection	 *            The default button selected.	 * @param command	 *            The command to be send to the listener when the user presses a	 *            button on the alert.	 * @param listener	 *            The listener to receive the command when the user presses a	 *            button on the alert.	 */	public void showAlert(String message, byte type, byte defaultSelection, Command command, CommandListener listener)	{		Image icon = null;		String iconPath;		switch (type)		{		case Alert.TYPE_WARNING:			iconPath = theme.getStringProperty("alert.warning.icon");			break;		case Alert.TYPE_ERROR:			iconPath = theme.getStringProperty("alert.error.icon");			break;		case Alert.TYPE_YESNO:			iconPath = theme.getStringProperty("alert.yesno.icon");			break;		case Alert.TYPE_YESNOCANCEL:			iconPath = theme.getStringProperty("alert.yesnocancel.icon");			break;		default: // default is Information alert.			iconPath = theme.getStringProperty("alert.info.icon");			break;		}		try		{			if (iconPath != null)				icon = Image.createImage(new FireConnector().openInputStream(iconPath));		} catch (Exception e)		{			Log.logWarn("Failed to load Alert icon form: " + iconPath, e);		}		Alert alert = new Alert(message, icon, type, defaultSelection);		alert.setCommand(command);		alert.setCommandListener(listener);		int[] ps = alert.getPrefSize();		alert.setX(getWidth() / 2 - ps[0] / 2);		alert.setY(getHeight() / 2 - ps[1] / 2);		if (animationsEnabled)		{			FlyAnimation anim = new FlyAnimation(alert.getX(), getHeight(), alert.getX(), alert.getY(), ps[0], ps[1]);			alert.setAnimation(anim);		}		addComponent(alert, 4);		setSelectedComponent(alert.getSelectedButton());	}	/**	 * Utility method to easilly remove the top most component that is NOT an	 * animation. It is used to close popups etc.	 * 	 * @see #removeComponent(int)	 * @return	 */	public boolean removeTopComponent()	{		for (int i = componentSlots.length - 1; i >= 0; --i)		{			Component c = componentSlots[i];			if (c != null && (c instanceof Animation) == false)			{				return removeComponent(i) != null;			}		}		return false;	}	/**	 * Removes the top level component, returns true if the component was found	 * among the top level components and was removed.	 * 	 * @param c	 * @return	 */	public boolean removeComponent(Component c)	{		if (c == null)			throw new NullPointerException("Cannot remove null component.");		for (int i = componentSlots.length - 1; i >= 0; --i)		{			if (componentSlots[i] == c)				return (removeComponent(i + ZINDEX_MIN) != null);		}		return false;	}	/**	 * Returns the component on given zindex (see {@link #ZINDEX_MAX})	 * 	 * @param zindex	 * @return	 */	public Component getComponent(int zindex)	{		if (zindex < ZINDEX_MIN || zindex > ZINDEX_MAX)			throw new IllegalArgumentException("zindex must be between [" + ZINDEX_MIN + "," + ZINDEX_MAX + "].");		return componentSlots[zindex - ZINDEX_MIN];	}	/**	 * Removes and returns the component on given zindex	 * 	 * @param zindex	 * @return	 */	public Component removeComponent(int zindex)	{		if (zindex < ZINDEX_MIN || zindex > ZINDEX_MAX)			throw new IllegalArgumentException("zindex must be between [" + ZINDEX_MIN + "," + ZINDEX_MAX + "].");		Component c = componentSlots[zindex - ZINDEX_MIN];		if (c == null)			return null;		if (c instanceof Animation)		{ // remove the animation from the queue			animationQueue.remove((Animation) c);		}		animationQueue.removeAllWithParent(c);		if (selectedComponent != null)		{			Component tmp = selectedComponent;			while (tmp.parent != null)				tmp = tmp.parent;			if (tmp == c) // selected component is inside the component that							// is going to be removed.			{ // so we must deselect it				setSelectedComponent(null);			}		}		componentSlots[zindex - ZINDEX_MIN] = null;		repaintScreen(c.x, c.y, c.width, c.height);		if(softkeyController==(zindex-ZINDEX_MIN)) // find a new softkeyController		{			softkeyController=-1;			for(int i=componentSlots.length-1;i>=0;--i)			{				if(componentSlots[i]!=null && (componentSlots[i] instanceof Container || componentSlots[i].isFocusable()))				{					softkeyController=i;					break;				}			}			updateSoftKeys();		}else if(zindex==LEFT_SOFTKEY_ZINDEX || zindex==RIGHT_SOFTKEY_ZINDEX)		{ // the component beeing removed is a softkey. need to update softkeys now.			updateSoftKeys();		}				return c;	}	/**	 * Sets the given component on zindex 0.	 * 	 * @param p	 * @param animDirection	 */	public void setCurrent(Component p)	{		addComponent(p, 0);	}	private boolean destroyed = false;	public void run()	{		long minLoopTime = 30; // dont loop faster than this period, in order								// to avoid busy waits		long start, period;		try		{			while (!destroyed)			{				start = System.currentTimeMillis();				if (visible)				{					if (generateRepeatEvents)					{						generateRepeatEvent(start);					}					Animation anim = (Animation) animationQueue.getNext();					if (!anim.isRunning())// animation completed. remove it											// from the queue.					{						if (anim.parent == null) // top level animations must													// be removed using the													// removeComponent						{							removeComponent(anim);						} else						// all other animations just need to be removed from the						// animation Queue, using the removeAnimation.						{							// ask for a repaint of its owner component.							animationQueue.remove(anim);							anim.parent.animation = null;							anim.parent.repaint();						}						continue;					}					int x = anim.x, y = anim.y, w = anim.width, h = anim.height;// get																				// coords																				// and																				// dimensions																				// before																				// step					boolean repaintNeeded = anim.step();					// animations can move around on the screen or change size.					// we must make sure all					// artifacts are cleared from the screen before redrawing					// the animation					if (anim.x != x || anim.y != y || anim.width != w || anim.height != h)					{// i need to clear the old frame of the animation						if (anim.parent != null && anim.parent.parent != null) // NOT																				// a																				// top																				// level																				// animation,																				// or																				// animation																				// of																				// top																				// level																				// component						{// find the real x,y coords of the animation							anim.parent.repaint(x, y, w, h);						}						repaintScreen(x, y, w, h);					}					if (repaintNeeded && anim.visible)					{						anim.repaint(); // repaint the animation's new frame					}				}				period = System.currentTimeMillis() - start;				if (period < minLoopTime)				{					try					{						Thread.sleep(minLoopTime - period);					} catch (InterruptedException e)					{						Log.logError("Interrupted inside animation thread.", e);					}				}			}		} catch (OutOfMemoryError e)		{			animationsEnabled = false; // not much to do at this point but										// disable animations anyway.			animationQueue.removeAll();			Runtime.getRuntime().gc();			Log.logError("Animation thread OutOfMemory.", e);		} catch (Throwable e)		{			Log.logError("Animation thread died.", e);		}	}	/**	 * Used to create and retrieve the FireScreen singleton.	 * 	 * @param display,	 *            if not null and its the first call of the method, a FireScreen	 *            instance for this display is created.	 * @return the FireScreen singleton.	 */	public static FireScreen getScreen(Display display)	{		if (display != null && singleton == null)		{			singleton = new FireScreen(display);		}		return singleton;	}	/**	 * Used to create and retrieve the FireScreen singleton.	 * 	 * @return the FireScreen singleton.	 */	public static FireScreen getScreen()	{		if (singleton == null)			throw new NullPointerException("FireScreen is not initialized.");		return singleton;	}	/**	 * Returns the current Theme set to Fire	 * 	 * @return	 */	public static Theme getTheme()	{		return theme;	}	/**	 * Sets the given theme as the default theme of fire<br/> Note: Some	 * components might need redrawing after a theme change. This method does	 * not cause anything to be redrawn or recreated with the new theme settings	 * 	 * @param theme	 */	public static void setTheme(Theme theme)	{		if (theme != null)			FireScreen.theme = theme;		else			FireScreen.theme = new Theme();		navbarFont = theme.getFontProperty("navbar.font");	}	protected void pointerDragged(int x, int y)	{		if (orientation != NORMAL)		{ // screen is on landscape mode, width is height and vise versa			int t = x;			if (orientation == LANDSCAPELEFT)			{				x = super.getHeight() - y;				y = t;			} else			{				x = y;				y = super.getWidth() - t;			}		}		for (int i = componentSlots.length - 1; i >= 0; --i)		{			Component cmp = componentSlots[i];			if (cmp != null && (cmp instanceof Container || cmp.isFocusable()))			{ // only send events to containers or focusable components				cmp.pointerDragged(x - cmp.x, y - cmp.y);				break;// only send the pointer event once.			}		}	}

⌨️ 快捷键说明

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