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

📄 component.java

📁 最强手机阅读器Anyview3.0版的界面代码
💻 JAVA
字号:
package com.ismyway.fairyui;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;import com.ismyway.anyview.others.Settings;import com.ismyway.util.ArrayList;/** * Component是对控件的抽象描述,每个控件有自己的高与宽,同时,也有坐标 * 其中,left/top是描述相对于物理屏幕的绝对坐标 * 而innerLeft/innerTop是描述相对于包含于该控件的相对坐标 * 当改变Componet的坐标时,推荐使用setInnerTop()/setInnerLeft()方法 * 在绘制的时候,推荐使用getTop()/getLeft()来取得绝对坐标,以便于判断是否需要重绘 * @author lEFTmOON * */public abstract class Component {	public final static int ANCHOR = 20;	private int _componentID = -1;	private int left = 0; //相对于物理屏幕的绝对X坐标	private int top = 0; //相对于物理屏幕的绝对Y坐标	protected int innerLeft = 0; //相对于parent(如果不为null)的X坐标	protected int innerTop = 0; //相对于parent(如果不为null)的Y坐标	private int height = 1; //高	private int width = 1; //宽	private Command command = null; //该控件关联的命令	private boolean selected = false; //是否被选中	private CommandListener listener = null; //监听器	private int shortCut = -123456; //快捷键	protected boolean border = false; //是否有边框	protected int borderStyle = Graphics.SOLID; //边框的样式	public static Font defaultFont = Font.getDefaultFont(); //默认字体	private Font font = null;	protected Component parent = null; //该控件的父控件	protected ArrayList components = new ArrayList(); //该控件包含的子控件	//////  以下变量只供全局使用	protected final static Command EMPTY_CMD = new Command("", Command.OK, 1);	public static final byte VECPADDING = 3; //边距	public static final byte HORPADDING = 1; //边距	public final static Font LARGE_FONT = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);	public final static Font MEDIUM_FONT = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);	public final static Font SMALL_FONT = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);		public final static int[] shortcutList = {		Settings.VKEY_NUM1,		Settings.VKEY_NUM2,		Settings.VKEY_NUM3,		Settings.VKEY_NUM4,		Settings.VKEY_NUM5,		Settings.VKEY_NUM6,		Settings.VKEY_NUM7,		Settings.VKEY_NUM8,		Settings.VKEY_NUM9,		Settings.VKEY_NUM0,		Settings.VKEY_STAR,		Settings.VKEY_POUND	};	public int getShortCut() {		return shortCut;	}	public void setShortCut(int shortCut) {		this.shortCut = shortCut;	}	public Component() {	}	/**	 * 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) {	//		paint(g, 0, 0);	//	}	//	//	/**	//	 * 	//	 * @param g	//	 * @param adjustx 当前视窗顶点的坐标	//	 * @param adjusty	//	 */	//	abstract public void paint(Graphics g, int adjustx, int adjusty);	/**	 * 如果该控制触发事件,则该控制可以停留	 * @return	 */	public boolean isTraversable() {		return command != null;	}	/**	 * If a componets states that it is animated, it will receive periodically clock events in order to update its animation.	 * @return	 */	public boolean isAnimated() {		return false;	}	/**	 * Animated components receive clock events in order to update their animation.	 * @return true if repainting is needed after the clock event.	 */	public boolean clock() {		return false;	}	/**	 * Sets this component on/off selected mode. 	 * @param v	 */	public void setSelected(boolean v) {		selected = v;	}	public boolean isSelected() {		return selected;	}	/**	 * 键盘的事件将会从Canvas一直传递到控件	 * @param key	 * @return 	 */	abstract public boolean keyReleased(int key);	/**	 * 键盘的事件将会从Canvas一直传递到控件	 * @param key	 * @return 	 */	abstract public boolean keyRepeated(int key);	/**	 * 判断某个坐标是否在当前控件内	 * @param x	 * @param y	 * @return	 */	abstract public boolean isPointerIn(int x, int y);	/**	 * A validate event requests from the component to recalculate its internal properties suck as width/height etc.	 *	 */	abstract public void validate();	public int getHeight() {		return height;	}	public void setHeight(int height) {		this.height = height;	}	public int getWidth() {		return width;	}	public Panel getContentPanel() {		if (null == parent) {			return null;		}		Component component = this;		while (true) {			component = component.parent;			if (null == component.parent) {				return (Panel) component;			}		}	}	public void setWidth(int width) {		this.width = width;	}	/**	 * Add a command to the components. If a components has a command assosiated with it, then it is considered traversable.	 * @param c	 */	public void addCommand(Command c) {		command = c;	}	public Command getCommand() {		return command;	}	public void setCommandListener(CommandListener listener) {		this.listener = listener;	}	public CommandListener getCommandListener() {		return listener;	}	public boolean generateEvent() {		if (listener != null && command != null) {			listener.commandAction(command, this);			return true;		}		return false;	}	public int get_componentID() {		return _componentID;	}	public void set_componentID(int _componentid) {		_componentID = _componentid;	}	public boolean equals(Object o) {		if (o instanceof Component) {			Component c = (Component) o;			if (c.get_componentID() == get_componentID())				return true;		}		return false;	}	public int getLeft() {		return left;		//return 0;	}	public void setLeft(int left) {		this.left = left;	}	public int getTop() {		return top;		//return 0;	}	public void setTop(int top) {		this.top = top;	}	public void setFont(Font font) {		this.font = font;	}	public Font getFont() {		if (null == font) {			return defaultFont;		}		return font;	}	public boolean isBorder() {		return border;	}	public void setBorder(boolean border) {		this.border = border;	}	public final void setLocation(int x, int y) {		if (this.parent == null) {			left = x;			top = y;		} else {			innerLeft = x;			innerTop = y;			left = parent.left + innerLeft;			top = parent.top + innerTop;		}		// 通知包含在当前控件中的子控件改变坐标		for (int i = 0; i < components.size(); i++) {			Component component = (Component) components.get(i);			if (component.parent == this) {				component.setLocation(component.innerLeft, component.innerTop);			}		}	}	/////////////////////// 为了方便,以下是全局方法	/**	 * 恢复裁剪区域	 */	public static void restoreClip(Graphics g) {		MainCanvas canvas = MainCanvas.getInstance();		g.setClip(0, 0, canvas.getWidth(), canvas.getHeight());	}	public static void restoreClip(Graphics g, Component c) {		g.setClip(c.getLeft(), c.getTop(), c.getWidth(), c.getHeight());	}	/**	 * 设置裁剪区域,取与前裁剪区域的交集	 * @param g	 * @param x	 * @param y	 * @param width	 * @param height	 */	public static void setClip(Graphics g, int x, int y, int width, int height) {		int ox = g.getClipX();		int oy = g.getClipY();		int ex = ox + g.getClipWidth();		int ey = oy + g.getClipHeight();		if (ox > x) {			x = ox;		}		if (oy > y) {			y = oy;		}		int xx = x + width;		int yy = y + height;		if (xx > ex) {			xx = ex;		}		if (yy > ey) {			yy = ey;		}		width = xx - x;		height = yy - y;		g.setClip(x, y, width, height);	}	public final int LEFTTOP = Graphics.LEFT | Graphics.TOP;	public Component getParent() {		return parent;	}	public void setParent(Component parent) {		this.parent = parent;	}	public int getBorderStyle() {		return borderStyle;	}	public void setBorderStyle(int borderStyle) {		this.borderStyle = borderStyle;	}	public int getInnerLeft() {		return innerLeft;	}	public void setInnerLeft(int innerLeft) {		this.innerLeft = innerLeft;		if (null != parent) {			this.left = parent.getLeft() + innerLeft;		}	}	public int getInnerTop() {		return innerTop;	}	public void setInnerTop(int innerTop) {		this.innerTop = innerTop;		if (null != parent) {			this.top = parent.getTop() + innerTop;		}	}}

⌨️ 快捷键说明

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