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

📄 component.java

📁 FIRE (Flexible Interface Rendering Engine)是一个J2ME上的灵活的图形界面引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Fire (Flexible Interface Rendering Engine) is a set of graphics widgets for creating GUIs for j2me applications.  * Copyright (C) 2006-2008 Bluevibe (www.bluevibe.net) * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA *  *//* * Created on Feb 22, 2008 */package gr.fire.core;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;/** * @author padeler * */public class Component{		protected Component parent;	private String id;			/** Constrains for this object, used by the layoutManager */	Object constrains=null; 		/**	 * Location of the component inside its parent container. 	 * These coordinates are refer to the top left corner of this component, relative to the 	 * top left corder (0,0) of the parent container. 	 */	int x,y;				/** 	 * The actual dimensions of this component 	 */	protected int width,height;		/**	 * The font used by this component when displaying text.	 */	protected Font font;		/**	 * The layout of this Component's contents i.e (FireScreen.TOP|FireScreen.LEFT)	 */	protected int layout;	protected int foregroundColor;	protected int backgroundColor;	/*	 * Padding is the distance of this component's border from its content	 * The Component is responsible for rendering correctly the padding.	protected int paddingLeft;	protected int paddingTop;	protected int paddingRight;	protected int paddingBottom;	/*	 * The internal padding between the component's elements 	protected int paddingVertical;	protected int paddingHorizontal;		/*	 * The margin is the distance of the component from its neighbors. 	 * The parent container is responsible for rendering the margins correctly.	protected int marginLeft;	protected int marginTop;	protected int marginRight;	protected int marginBottom;	 */		protected boolean border=false;				/** If the Component is not valid, its characteristics (with,height,etc) need validation */	protected boolean valid;	/** If it can be focused (traversed) by the user */	private boolean focusable;		boolean visible=true;		/** 	 * If this component is in animation mode then the animation is held in this field.	 */	Animation animation=null;		/** If the component is currently selected, i.e. the curson is on it */	boolean selected; 		/**	 * Dimensions of the component that control its layout inside a Container. 	 */	private int prefWidth=-1,prefHeight=-1;		protected CommandListener commandListener;	protected KeyListener keyListener;	protected PointerListener pointerListener;	protected Command command;		protected Command leftSoftKeyCommand;	protected Command rightSoftKeyCommand;		/**	 * Component's default constructor.	 */	public Component() 	{		Theme t = FireScreen.getTheme();		backgroundColor = t.getIntProperty("bg.color");		foregroundColor = t.getIntProperty("fg.color");	}		/**	 * Paint is called by the container of the component to allow it to draw itself on Graphics g	 * The drawable area on g is (0,0,width,height).	 * 	 * @param g the area on witch the component will draw it self.	 */	public void paint(Graphics g)	{	}		/**	 * Sets this component on/off selected mode. 	 * 	 * When a component is selected it should render itself 	 * approprietly in order to be easily identified by the user	 *  	 * @param v	 */	public void setSelected(boolean v){selected = v;}		/**	 * @see #setSelected(boolean)	 * @return	 */	public boolean isSelected(){return selected;}		/**	 * A validate event requests from the component to recalculate its internal properties such as width/height etc.	 */	public void validate(){valid=true;}	/**	 * @see #validate()	 * @return	 */	public boolean isValid(){		return valid;	}		/**	 * Returns the height of this component	 * @return	 */	public int getHeight()	{		return height;	}	/**	 * Sets the height of this component	 * @param height	 */	public void setHeight(int height)	{		if(height<0) throw new IllegalArgumentException("Height cannot be negative.");		this.height = height;	}	/**	 * Returns the width of this component 	 * @return	 */	public int getWidth()	{		return width;	}	/**	 * Sets the width of this component	 * @param width	 */	public void setWidth(int width)	{		if(width<0) throw new IllegalArgumentException("Width cannot be negative.");		this.width = width;	}		/**	 * set a command to this component. 	 * @param c	 */	public void setCommand(Command c)	{		command=c;		focusable= (focusable||commandListener!=null||keyListener!=null||pointerListener!=null||command!=null);	}		/**	 * Events that have a command assosiated with them 	 * {@link #setCommand(Command)}, {@link #setLeftSoftKeyCommand(Command)}, {@link #setRightSoftKeyCommand(Command)}	 * will cause this component send the event to the given CommandListener.	 * 	 * @see CommandListener	 * @param listener	 */	public void setCommandListener(CommandListener listener)	{		this.commandListener=listener;		focusable= (focusable||commandListener!=null||keyListener!=null||pointerListener!=null||command!=null);	}		/**	 * Key events received by this components will cause this component to send	 * the appropriate key event to the given listener.	 * 	 * @see KeyListener 	 * @param listener	 */	public void setKeyListener(KeyListener listener)	{		this.keyListener=listener;		focusable= (focusable||commandListener!=null||keyListener!=null||pointerListener!=null||command!=null);	}		/**	 * Pointer events received by this components will cause this component to send	 * the appropriate pointer event to the given listener.	 * 	 * @see PointerListener	 * @param listener	 */	public void setPointerListener(PointerListener listener)	{		this.pointerListener=listener;		focusable= (focusable||commandListener!=null||keyListener!=null||pointerListener!=null||command!=null);	}		/**	 * If this component can receive and handle Key events or pointer events then it is Focusable and should return true	 * @see KeyListener	 * @see PointerListener  	 * @see CommandListener	 * @return	 */	public boolean isFocusable()	{		return focusable;	}			/**	 * Checks if the point (x,y) is inside this Component. The point must be on the coordinate system of this Component.	 * That means that the top left corner of the component is (0,0).	 * @param x	 * @param y	 * @return	 */	public boolean contains(int x,int y)	{		return (x>=0 && y>=0 && x<width && y<height);	}	    /**	 * Determines whether or not this <code>Component</code> and the specified	 * rectangular area intersect. Two rectangles intersect if their	 * intersection is nonempty.	 * 	 * @return <code>true</code> if the specified area and this	 *         <code>Component</code> intersect; <code>false</code>	 *         otherwise.	 */	public boolean intersects(int rx, int ry, int rw, int rh)	{		int tw = width;		int th = height;		if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0)		{			return false;		}		int tx = x;		int ty = y;		rw += rx;		rh += ry;		tw += tx;		th += ty;		// overflow || intersect		return ((rw < rx || rw > tx) && (rh < ry || rh > ty)				&& (tw < tx || tw > rx) && (th < ty || th > ry));	}		/**	 * Causes this component only to be repainted on the screen.	 */	public void repaint()	{		repaint(0,0, width, height);	}	/**	 * Get the X position of this component inside its parent. 	 * @return	 */	public int getX()	{		return x;	}	/**	 * Set the X position of this component inside its parent.	 * @param x	 */	public void setX(int x)	{		this.x = x;	}	/**	 * Get the Y position of this component inside its parent.	 * @return	 */	public int getY()	{		return y;	}	/**	 * Set the Y position of this component inside its parent.	 * @param y	 */	public void setY(int y)	{		this.y = y;	}		void repaint(int cx,int cy,int cwidth,int cheight)	{				if(parent!=null)		{//			System.out.println("Repaint for "+cx+","+cy);

⌨️ 快捷键说明

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