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

📄 inputcomponent.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 *  *//** *  */package gr.fire.ui;import gr.fire.core.Component;import gr.fire.core.FireScreen;import gr.fire.core.Theme;import gr.fire.util.StringUtil;import java.util.Vector;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.TextField;/** * @author padeler * */public class InputComponent extends Component{	public static final int LINE_DISTANCE=0;		public static final byte TEXT=0x01;	public static final byte RADIO=0x02;	public static final byte CHECKBOX=0x03;	public static final byte SWITCH=0x04;	public static final byte BUTTON=0x05;	public static final byte SUBMIT=0x06;	public static final byte RESET=0x07;	public static final byte MENU=0x08;	public static final byte HIDDEN=0x09;		public static final int RADIO_WIDTH=16;	public static final int RADIO_HEIGHT=16;		public static final int TEXT_BORDER=4;	public static final int SWITCH_BORDER=3;	protected String name,value,initialValue,text;	protected boolean enabled=true;	protected int maxWidth=1000;	private byte type=TEXT;		private int size=200,maxLen=100,rows=1;		private boolean checked=false;	private int textConstraints = TextField.ANY;	private Vector formatedText=null;			public InputComponent()	{}		public InputComponent(byte type)	{		this.type=type;		if(font==null)			font = FireScreen.getTheme().getFontProperty("font");	}		public void validate()	{				int []ps= getPrefSize();		if(ps==null)		{			ps = getMinSize();		}				if(type==TEXT)		{			formatedText = StringUtil.format(value,font,ps[0],ps[1]);		}				if(width==0 && height==0) // width, height are not set		{			width = ps[0];height=ps[1];		}				valid=true;	}		public boolean isFocusable()	{		return enabled;	}		public void paint(Graphics g)	{		switch (type)		{		case TEXT:			paintText(g);			break;		case RADIO:			paintRadioOrCheckbox(g);			break;		case CHECKBOX:			paintRadioOrCheckbox(g);			break;		case BUTTON:			paintButton(g);			break;		case RESET:			paintButton(g);			break;		case SUBMIT:			paintButton(g);			break;		case SWITCH:			paintSwitch(g);			break;		case MENU:			paintMenu(g);			break;		}	}		private void paintSwitch(Graphics g)	{		// create a bordered area with the text inside.		int valign = getValign();		int halign = getHalign();				Theme theme = FireScreen.getTheme();		int width = getWidth();		int height = getHeight();		g.setFont(font);				if(isSelected())		{			g.setColor(theme.getIntProperty("link.active.bg.color"));			g.fillRect(0,0,width,height);		}		else if(checked)		{			g.setColor(theme.getIntProperty("bg.alt2.color"));			g.fillRect(0,0,width,height);		}		else if(backgroundColor!=Theme.TRANSPARENT)		{			g.setColor(backgroundColor);			g.fillRect(0,0,width,height);		}							int rowHeight = font.getHeight();		String str = text;				int x=0,y=0;		switch(valign)		{		case FireScreen.TOP:			y = SWITCH_BORDER;			break;		case FireScreen.VCENTER:			y = (height -(rowHeight+LINE_DISTANCE))/2;			break;		case FireScreen.BOTTOM:			y = height - ((rowHeight+LINE_DISTANCE) )-SWITCH_BORDER;			break;			}				switch(halign)		{		case FireScreen.LEFT:			x =SWITCH_BORDER;			break;		case FireScreen.CENTER:			x = width/2 - font.stringWidth(str)/2;			break;		case FireScreen.RIGHT:			x = width- font.stringWidth(str)-SWITCH_BORDER;			break;		}		if(isSelected())			g.setColor(theme.getIntProperty("link.active.fg.color"));		else			g.setColor(foregroundColor);				g.drawString(str,x, y, Graphics.TOP | Graphics.LEFT);	}		private void paintMenu(Graphics g)	{		// create a bordered area with the text inside.		int valign = getValign();		int halign = getHalign();				Theme theme = FireScreen.getTheme();		int width = getWidth();		int height = getHeight();		g.setFont(font);				g.setColor(theme.getIntProperty("bg.alt2.color"));		g.fillRect(2,2,width-3,height-3);				int rowHeight = font.getHeight();		String str = text;				int x=0,y=0;		switch(valign)		{		case FireScreen.TOP:			y = SWITCH_BORDER;			break;		case FireScreen.VCENTER:			y = (height -(rowHeight+LINE_DISTANCE))/2;			break;		case FireScreen.BOTTOM:			y = height - ((rowHeight+LINE_DISTANCE) )-SWITCH_BORDER;			break;			}				switch(halign)		{		case FireScreen.LEFT:			x =SWITCH_BORDER;			break;		case FireScreen.CENTER:			x = width/2 - font.stringWidth(str)/2;			break;		case FireScreen.RIGHT:			x = width- font.stringWidth(str)-SWITCH_BORDER;			break;		}		if(!isSelected())			g.setColor(foregroundColor);		else			g.setColor(theme.getIntProperty("link.active.fg.color"));		g.drawString(str,x, y, Graphics.TOP | Graphics.LEFT);			g.setColor(theme.getIntProperty("border.color"));		g.drawRect(2,2,width-4,height-4);				if(isSelected())		{			g.setColor(theme.getIntProperty("link.active.bg.color"));			g.drawRect(1,1,width-2,height-2);					}	}	private void paintButton(Graphics g)	{		if(formatedText==null)		{			int[] ps = getPrefSize();			if(ps==null) ps = getMinSize();			formatedText = StringUtil.format(value,font,ps[0],ps[1]);		}		// create a bordered area with the text inside.		int valign = getValign();		int halign = getHalign();				Theme theme = FireScreen.getTheme();		int width = getWidth();		int height = getHeight();		g.setFont(font);		Vector lines = formatedText;		//g.setColor(theme.getIntProperty("bg.alt2.color"));		if(backgroundColor!=Theme.TRANSPARENT)			g.setColor(backgroundColor);		else			g.setColor(theme.getIntProperty("bg.alt2.color"));		g.fillRoundRect(2,2,width-4,height-4,6,6);				int rowHeight = font.getHeight();		int lineCount = lines.size();		int txtHeight = (rowHeight + LINE_DISTANCE)*lines.size();		for (int i = 0; i < lineCount && i<rows; ++i)		{			String str = (String) lines.elementAt(i);						if((textConstraints & TextField.PASSWORD) == TextField.PASSWORD)			{ // just draw a string of starts				int len = str.length();				str="";				for (int j = 0; j < len; ++j)					str += "*";			}						int x=0,y=0;			switch(valign)			{			case FireScreen.TOP:				y = (rowHeight+LINE_DISTANCE) * i +TEXT_BORDER;				break;			case FireScreen.VCENTER:				y = (height/2 - txtHeight/2) +  (rowHeight+LINE_DISTANCE) * i;				break;			case FireScreen.BOTTOM:				y = height - txtHeight +((rowHeight+LINE_DISTANCE) * i)-TEXT_BORDER;				break;				}						switch(halign)			{			case FireScreen.LEFT:				x =TEXT_BORDER;				break;			case FireScreen.CENTER:				x = width/2 - font.stringWidth(str)/2;				break;			case FireScreen.RIGHT:				x = width- font.stringWidth(str)-TEXT_BORDER;				break;			}			if(!isSelected())				g.setColor(foregroundColor);			else				g.setColor(theme.getIntProperty("link.active.fg.color"));			g.drawString(str,x, y, Graphics.TOP | Graphics.LEFT);		}				if(isSelected())		{			g.setColor(theme.getIntProperty("link.active.bg.color"));			g.drawRoundRect(1,1,width-2,height-2,8,8);		}		else		{			g.setColor(theme.getIntProperty("border.color"));		}		g.drawRoundRect(2,2,width-4,height-4,6,6);	}		private void paintText(Graphics g)	{		if(formatedText==null)		{			int[] ps = getPrefSize();			if(ps==null) ps = getMinSize();			formatedText = StringUtil.format(value,font,ps[0],ps[1]);		}		// create a bordered area with the text inside.		int valign = getValign();		int halign = getHalign();				Theme theme = FireScreen.getTheme();		int width = getWidth();		int height = getHeight();		g.setFont(font);

⌨️ 快捷键说明

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