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

📄 firescreen.java

📁 FIRE (Flexible Interface Rendering Engine)是一个J2ME上的灵活的图形界面引擎
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	protected void pointerPressed(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.pointerPressed(x - cmp.x, y - cmp.y);				break;// only send the pointer event once.			}		}	}	protected void pointerReleased(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;			}		}				Component lsk = componentSlots[LEFT_SOFTKEY_ZINDEX-ZINDEX_MIN];		Component rsk = componentSlots[RIGHT_SOFTKEY_ZINDEX-ZINDEX_MIN];		Component softKeyOwner = selectedComponent;		if((softKeyOwner==null || (softKeyOwner.leftSoftKeyCommand==null && softKeyOwner.rightSoftKeyCommand==null)) && softkeyController>-1)		{			softKeyOwner = componentSlots[softkeyController];		}				if(softKeyOwner!=null)		{			if(lsk!=null && x>=lsk.x && x<(lsk.x+lsk.width) && y>=lsk.y && y<(lsk.y+lsk.height))			{ // left softkey event				handleSoftKeyEvent(softKeyOwner, FireScreen.leftSoftKey);							return;			}			else if(rsk!=null && x>=rsk.x && x<(rsk.x+rsk.width) && y>=rsk.y && y<(rsk.y+rsk.height))			{ // right softkey event				handleSoftKeyEvent(softKeyOwner, FireScreen.rightSoftKey);							return;			}		}		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.pointerReleased(x - cmp.x, y - cmp.y);				break;// only send the pointer event once.			}		}	}	/**	 * The keyState array holds the time that each game key was pressed. The	 * animation thread checks the time to generate repeat events	 * 	 * @param pressed	 * @param keyCode	 */	private void updateRepeatEventData(boolean pressed, int keyCode)	{		if (pressed)		{			pressedKeyCode = keyCode;			pressedKeyTime = System.currentTimeMillis();		} else		{			pressedKeyCode = NO_PRESSED_KEY;		}	}	private void generateRepeatEvent(long now)	{		if (pressedKeyCode != NO_PRESSED_KEY && (now - pressedKeyTime) > keyRepeatPeriod)		{			pressedKeyTime = now;			keyRepeated(pressedKeyCode);		}	}	private int getFireScreenKey(int keyCode)	{		int ga = super.getGameAction(keyCode);		switch (ga)		{		case Canvas.UP:			if (orientation == LANDSCAPELEFT) // up key is right				return getKeyCode(Canvas.RIGHT);			if (orientation == LANDSCAPERIGHT) // up key is left				return getKeyCode(Canvas.LEFT);			return keyCode;		case Canvas.DOWN:			if (orientation == LANDSCAPELEFT) // down key is left				return getKeyCode(Canvas.LEFT);			if (orientation == LANDSCAPERIGHT) // down key is right				return getKeyCode(Canvas.RIGHT);			return keyCode;		case Canvas.LEFT:			if (orientation == LANDSCAPELEFT) // left key is up				return getKeyCode(Canvas.UP);			if (orientation == LANDSCAPERIGHT) // left key is down				return getKeyCode(Canvas.DOWN);			return keyCode;		case Canvas.RIGHT:			if (orientation == LANDSCAPELEFT) // right key is down				return getKeyCode(Canvas.DOWN);			if (orientation == LANDSCAPERIGHT) // left key is up				return getKeyCode(Canvas.UP);			return keyCode;		default:			return keyCode;		}	}	protected void keyPressed(int keyCode)	{		if (orientation != NORMAL)		{			keyCode = getFireScreenKey(keyCode);		}		if (generateRepeatEvents)		{			updateRepeatEventData(true, keyCode);		}		if (selectedComponent != null)		{			selectedComponent.keyPressed(keyCode);		} else		{			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.keyPressed(keyCode);					break;// only send the key event once.				}			}		}	}	public int getGameAction(int keyCode)	{		return super.getGameAction(keyCode);	}	private boolean handleSoftKeyEvent(Component current, int k)	{		if (k == leftSoftKey && current.leftSoftKeyCommand != null)		{			if (animationsEnabled && componentSlots[LEFT_SOFTKEY_ZINDEX - ZINDEX_MIN]!=null) 				registerAnimation((Animation)componentSlots[LEFT_SOFTKEY_ZINDEX - ZINDEX_MIN]);			final Component trigger = current;			Thread th = new Thread()			{				public void run()				{					trigger.commandListener.commandAction(trigger.leftSoftKeyCommand, trigger);				}			};			th.start();			return true;		}		if (k == rightSoftKey && current.rightSoftKeyCommand != null)		{			if (animationsEnabled && componentSlots[RIGHT_SOFTKEY_ZINDEX - ZINDEX_MIN]!=null) 				registerAnimation((Animation)componentSlots[RIGHT_SOFTKEY_ZINDEX - ZINDEX_MIN]);			final Component trigger = current;			Thread th = new Thread()			{				public void run()				{										trigger.commandListener.commandAction(trigger.rightSoftKeyCommand, trigger);				}			};			th.start();			return true;		}		return false;	}	protected void keyReleased(int k)	{		if (orientation != NORMAL)		{			k = getFireScreenKey(k);		}		if (generateRepeatEvents)		{			updateRepeatEventData(false, k);		}		Component current = selectedComponent;		// handle softkey events first		if (k == leftSoftKey || k == rightSoftKey)		{			if (current != null && current.selected && current.commandListener != null && handleSoftKeyEvent(current, k))			{				if (current.keyListener != null)					current.keyListener.keyReleased(k, current); // send the																	// key event																	// if a																	// listener																	// is																	// present				return;			}			// softkey event goes to top level Component. The first top level			// focusable or container component will be used.			// even if it does not have a commandListener or an associated			// softkey event.			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					if (cmp.commandListener != null)						handleSoftKeyEvent(cmp, k);					if (cmp.keyListener != null)						cmp.keyListener.keyReleased(k, cmp); // send the key																// event if a																// listener is																// present					return;// only send the key event once.				}			}		}		if (current != null && current.selected)		{			if ((current instanceof Container) == false)			{ // keyReleased might change the selectedComponent				current.keyReleased(k);				if (current.selected)					return;			}			// else component is not anymore selected due to keyReleased event.			// send the event to the containers			// find a panel that contains this component and send the event to			// it.			Component tmp = current.parent;			while (tmp != null && (tmp instanceof Panel) == false)			{				tmp = tmp.parent;			}			if (tmp != null) // a panel found			{				((Panel) tmp).keyReleased(k);				return;			}		}		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.keyReleased(k);				return;// only send the key event once.			}		}	}	protected void keyRepeated(int k)	{		if (orientation != NORMAL)		{			k = getFireScreenKey(k);		}		Component current = selectedComponent;		if (current != null && current.selected)		{			if ((current instanceof Container) == false)			{ // keyReleased might change the selectedComponent				current.keyReleased(k);				if (current.selected)					return;			}			// else component is not anymore selected due to keyReleased event.			// send the event to the containers			// find a panel that contains this component and send the event to			// it.			Component tmp = current.parent;			while (tmp != null && (tmp instanceof Panel) == false)			{				tmp = tmp.parent;			}			if (tmp != null) // a panel found			{				((Panel) tmp).keyReleased(k);				return;			}		}		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.keyReleased(k);				return;// only send the key event once.			}		}	}	protected void sizeChanged(int w, int h)	{		super.sizeChanged(w, h);		sizeChangedImpl(w, h);	}	private void sizeChangedImpl(int w, int h)	{		offscreen = null;		for (int i = componentSlots.length - 1; i >= 0; --i)		{			Component cmp = componentSlots[i];			if (cmp != null)			{				cmp.valid = false;			}		}				updateSoftKeys();		repaint();	}	/**	 * Returns the width of this FireScreen. If the screen is in landscape mode,	 * it will return the real height of the screen.	 * 	 * @see javax.microedition.lcdui.Displayable#getWidth()	 */	public int getWidth()	{		if (orientation == NORMAL)		{			return super.getWidth();		}		return super.getHeight();	}	/**	 * Returns the height of this FireScreen. If the screen is in landscape	 * mode, it will return the real width of the screen.	 * 	 * @see javax.microedition.lcdui.Displayable#getHeight()	 */	public int getHeight()	{		if (orientation == NORMAL)		{			return super.getHeight();		}		return super.getWidth();	}	/**	 * Returns the orientation of the FireScreen instance.	 * 	 * @see #NORMAL	 * @see #LANDSCAPELEFT	 * @see #LANDSCAPERIGHT	 * 	 * @return	 */	public int getOrientation()	{		return orientation;	}	/**	 * Sets the orientation of the FireScreen to the given value. This method	 * will cause all components to be validated and redrawn on the new	 * orientation.	 * 	 * @throws IllegalArgumentException	 *             if orientation is no FireScreen.NORMAL,	 *             FireScreen.LANDSCAPELEFT or FireScreen.LANDSCAPERIGHT	 * @param orientation	 */	public void setOrientation(int orientation)	{				if (orientation != NORMAL && orientation != LANDSCAPELEFT && orientation != LANDSCAPERIGHT)			throw new IllegalArgumentException("Unknown orientation value " + orientation);				if(this.orientation==orientation) return; // nothing to do.		this.orientation = orientation;		this.sizeChangedImpl(super.getWidth(), super.getHeight());	}	/**	 * Returns the components that currently has keyboard focus (if any)	 * 	 * @return	 */	public Component getSelectedComponent()	{		return selectedComponent;	}	/**	 * Sets the keyboard focus to the given component. If there was already	 * another component in focus this method will cause the old component to be	 * deselected.	 * 	 * @param newSelectedComponent	 */	public void setSelectedComponent(Component newSelectedComponent)	{		boolean updateSoftkeys=false;		if (newSelectedComponent == selectedComponent)			return; // nothing to do here		if (selectedComponent != null)		{			if(selectedComponent.rightSoftKeyCommand!=null || selectedComponent.leftSoftKeyCommand!=null)				updateSoftkeys=true;			if(selectedComponent.selected)				selectedComponent.setSelected(false);		}		this.selectedComponent = newSelectedComponent;				if(newSelectedComponent!=null && (newSelectedComponent.leftSoftKeyCommand!=null || newSelectedComponent.rightSoftKeyCommand!=null))			updateSoftkeys=true;				if(updateSoftkeys) updateSoftKeys();	}	/**	 * Repaints a part of the FireScreen canvas. The coordinates are in	 * reference to the FireScreen coordinates and not to the real screen. That	 * means that in landscape modes the correct part of the screen will be	 * redrawn.	 * 	 * @param cx	 * @param cy	 * @param cwidth	 * @param cheight	 */	public void repaintScreen(int cx, int cy, int cwidth, int cheight)	{		Log.logDebug("Repaint request for " + cx + "," + cy + " / " + cwidth + "," + cheight);		switch (orientation)		{		case NORMAL:			repaint(cx, cy, cwidth, cheight);			break;		case LANDSCAPELEFT:			repaint(cy, super.getHeight() - cx - cwidth, cheight, cwidth);			break;		case LANDSCAPERIGHT:			repaint(super.getWidth() - cy - cheight, cx, cheight, cwidth);			break;		}	}	/**	 * Causes this FireScreen instance to be destroyed. Stopping the animation	 * handler. This method should be called during the middlet clean-up stage.<br/>	 * Note: The method will cause the animation handler to die but may return	 * before the thread is dead.	 */	public void destroy()	{		destroyed = true;		// try		// {		// animationThread.join();		// } catch (InterruptedException e)		// {		// e.printStackTrace();		// }	}	/**	 * @see #setAnimationsEnabled(boolean)	 * @return	 */	public boolean isAnimationsEnabled()	{		return animationsEnabled;	}	/**	 * On lower-end devices with less CPU and memory available it is often good	 * practice not to show animations that may consume resources needed for	 * more usefull operations. When this flag is set the FireScreen and all	 * Fire components that have animations associated with them (i.e. Panel	 * scroll, softkey animations etc) will not display animations.	 * 	 * @param animationsEnabled	 */	public void setAnimationsEnabled(boolean animationsEnabled)	{		this.animationsEnabled = animationsEnabled;	}	protected void hideNotify()	{		pressedKeyCode = NO_PRESSED_KEY;		visible = false;	}	protected void showNotify()	{		pressedKeyCode = NO_PRESSED_KEY; // reset previous keyState,		visible = true;		repaintScreen(0, 0, getWidth(), getHeight());	}}

⌨️ 快捷键说明

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