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

📄 firescreen.java

📁 soure code for j2me browser
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Fire (Flexible Interface Rendering Engine) is a set of graphics widgets for creating GUIs for j2me applications.  * Copyright (C) 2006  Bluebird co (www.bluebird.gr) * 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 Aug 25, 2006 */package gr.bluevibe.fire.displayables;import gr.bluevibe.fire.components.FGauge;import gr.bluevibe.fire.components.Panel;import gr.bluevibe.fire.components.Popup;import gr.bluevibe.fire.util.FireIO;import java.util.Vector;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.game.Sprite;import com.sun.cldc.i18n.uclc.DefaultCaseConverter;/** * FireScreen is the core of the Fire engine. * It is the only Displayable in an Fire based, application (not counting SplashScreen). * It is indented to be used as the Display singleton is used when developing a regular j2me midlet. *   * @author padeler * */public final class FireScreen extends Canvas implements Runnable{	/**	 * The step of the inner clock in miliseconds.	 */	public static final long CLOCK_STEP = 100;	/**	 * The name of the theme key, used by FireIO.	 */	public static final String THEME_FILE="firetheme";	/**	 * The name of the backgroung key.	 */	public static final String THEME_BG="firebg";			public static final int CENTRE=0;	public static final int RIGHT=1;	public static final int LEFT=2;	public static final int TOP =3;		public static final int BOTTOM = 4;	public static final int UP =TOP;		public static final int DOWN = BOTTOM;			public static final int NORMAL=0;	public static final int LANDSCAPELEFT=1;	public static final int LANDSCAPERIGHT=2;		public static final int SCROLL_COUNT=3;	public static final int ANIMATION_COUNT=4;		public static final int SCROLLBAR_WIDTH=5;	public static final int SCROLLBAR_HEIGHT=16;		public static final int ALERT_VERTICAL_OFFSET=30;	public static final int ALERT_HORIZONTAL_OFFSET=5;			public static final String defaultLabel = "";	public static final Font defaultLabelFont = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_SMALL);	public static final Font defaultPopupFont = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL);	public static final Font defaultTickerFont = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL);	public static final int defaultTickerColor = 0xFF000000;		public static final int defaultVpos = CENTRE;	public static final int defaultHpos = CENTRE;	public static final boolean defaultVertical = false;	public static final boolean defaultTiled = false;		private static FireScreen singleton=null;			/**	 * 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;	}	/* Key mapping info. */	public static int leftSoftKey = -6;	public static int rightSoftKey = -7;		private static final Object[][] keyMaps = {			{"Nokia",new Integer(-6),new Integer(-7)},{"ricsson",new Integer(-6),new Integer(-7)},			{"iemens",new Integer(-1),new Integer(-4)},{"otorola",new Integer(-21),new Integer(-22)},			{"harp",new Integer(-21),new Integer(-22)},{"j2me",new Integer(-6),new Integer(-7)}	};		/* Default Theme Data */ 	public static int selectedLinkColor;		public static int linkColor;	public static Integer selectedLinkBgColor;	public static int defaultLabelColor;	public static int defaultColor;	public static int defaultFilledRowColor,defaultSecondaryFilledRowColor,defaultBorderColor,defaultPointerColor,defaultSecondaryPointerColor;	public static int defaultTooltipFgColor=0x00000000,defaultTooltipBgColor=0x00FFFFFF;		public static int defaultScrollColor;		public static int defaultRulerColor1;	public static int defaultRulerColor2;	public static int defaultScrollRulerColor1;	public static int defaultScrollRulerColor2;	public static int defaultScrollRulerColor3;	public static Image defaultGradImage;	public static Image defaultBgImageSrc;	public static Image defaultLogo;	public static Image defaultBorder;	public static int SCROLL_HEIGHT=50;	public static int SCROLL_STEP = 10;		private static int logoPossition=RIGHT;	public static int topOffset;	public static int bottomOffset;			private Image bgImage=null;		/** Theme params */	private Font labelFont = defaultLabelFont;	private int vpos = defaultVpos;	private int hpos = defaultHpos;	private boolean vertical = defaultVertical;	private boolean tiled = defaultTiled;			/** Support Vars */	private Display display=null;	private Panel panel=null;	private Vector popups;	private Image offscreen=null;	private boolean forceRepaint=false, panelAnimation=false, userActionRepaint=false;	private FGauge innerGauge=null;		private boolean alive=false;		private Image animationImage=null;	private int animationDirection=UP;	private int animationFrameCount=0;	private int animationX,animationY;		private boolean busyMode=false;	private boolean busyModeRepaint=false;	private Integer orientationKey=null;	private int orientation=NORMAL;		private boolean interactiveBusyMode=false;			private void loadTheme()	{		defaultGradImage=null;		defaultBgImageSrc=null;		defaultLogo=null;		defaultBorder=null;				// first check record store for a custom theme.				Image img = FireIO.getLocalImage(THEME_FILE);						defaultLogo = Image.createImage(50,15);		Graphics g = defaultLogo.getGraphics();		g.drawImage(img,0,0,Graphics.TOP|Graphics.LEFT);		int bgrad[]= new int[15];		img.getRGB(bgrad,0,15,35,16,15,1);		defaultBorder = Image.createRGBImage(bgrad,15,1,false);		int []palete = new int[50];				img.getRGB(palete,0,50,0,16,50,1);		int tmp = palete[12];		System.out.println("12 : "+Integer.toHexString(tmp));				if((tmp&0x00FFFFFF)==0x00FFFFFF) // show grad		{			bgrad= new int[50];			img.getRGB(bgrad,0,50,0,15,50,1);			defaultGradImage = Image.createRGBImage(bgrad,50,1,true);		}		else		{			System.out.println("Grad background is not displayed.");			defaultGradImage=null;		}			defaultColor = palete[0];//		System.out.println("0 : "+Integer.toHexString(palete[0]));				defaultLabelColor = palete[1];//		System.out.println("1 : "+Integer.toHexString(palete[1]));		defaultScrollColor = palete[2];//		System.out.println("2 : "+Integer.toHexString(palete[2]));//		System.out.println("3 : "+Integer.toHexString(palete[3]));		linkColor = palete[3];//		System.out.println("4 : "+Integer.toHexString(palete[4]));		selectedLinkColor = palete[4];		//		System.out.println("5 : "+Integer.toHexString(palete[5]));		tmp = palete[5];		if((tmp&0xFF000000)!=0xFF000000) // dont show bg color		{			selectedLinkBgColor = null;		}		else		{			selectedLinkBgColor = new Integer(tmp);		}				defaultRulerColor1 = palete[6];//		System.out.println("6 : "+Integer.toHexString(palete[6]));		defaultRulerColor2 = palete[7];//		System.out.println("7 : "+Integer.toHexString(palete[7]));		defaultScrollRulerColor1= palete[8];//		System.out.println("8 : "+Integer.toHexString(palete[8]));		defaultScrollRulerColor2 = palete[9];//		System.out.println("9 : "+Integer.toHexString(palete[9]));		defaultScrollRulerColor3 = palete[10];//		System.out.println("10 : "+Integer.toHexString(palete[10]));				defaultFilledRowColor = palete[13];				defaultSecondaryFilledRowColor = palete[14];				defaultBorderColor = palete[15];		defaultPointerColor = palete[16];		defaultSecondaryPointerColor = palete[17];		defaultTooltipFgColor = palete[18];		defaultTooltipBgColor = palete[19];						tmp = palete[11];		if((tmp&0x00FFFFFF)==0x00FFFFFF) // show bg image		{			img = FireIO.getLocalImage(THEME_BG);			defaultBgImageSrc = img;		}		else		{			defaultBgImageSrc=null;		}				String platform = System.getProperty("microedition.platform");		for(int i =0 ;i< keyMaps.length;++i)		{			String manufacturer = (String)keyMaps[i][0];						if(platform.indexOf(manufacturer)!=-1)			{				if(i==1) // ta sony ericsson exoun enalaktika keys sta p800/p900/p908/p802				{					if(platform.indexOf("P900")!=-1 || platform.indexOf("P908")!=-1)					{						leftSoftKey = ((Integer)keyMaps[i][2]).intValue();						rightSoftKey = ((Integer)keyMaps[i][1]).intValue();					}					else					{						leftSoftKey = ((Integer)keyMaps[i][1]).intValue();						rightSoftKey = ((Integer)keyMaps[i][2]).intValue();					}				}				else				{					leftSoftKey = ((Integer)keyMaps[i][1]).intValue();					rightSoftKey = ((Integer)keyMaps[i][2]).intValue();				}				break;			}		}	}		/**	 * Creates all the decoration of a canvas based on the default theme values and its parameters.	 * @param width	 * @param height	 * @param color	 * @param gradImage	 * @param bg	 * @param hpos	 * @param vpos	 * @param vertical	 * @param tiled	 * @return An Image with the decorations (theme) of the FireScreen	 */	private Image prepareBgImage(int width,int height)	{		int color= defaultColor;		Image gradImage = defaultGradImage;		Image bg = defaultBgImageSrc;		int hpos = defaultHpos;		int vpos = defaultVpos;		boolean vertical = defaultVertical;		boolean tiled =defaultTiled;				bottomOffset = defaultLabelFont.getHeight()+2;						if(defaultLogo.getHeight()+2> bottomOffset)		{			topOffset= defaultLogo.getHeight()+2;		}		else		{			topOffset = bottomOffset;		}				System.out.println("BottomOffset: "+bottomOffset );		System.out.println("TopOffset: "+topOffset);				Image img = Image.createImage(width,height);		Graphics g = img.getGraphics();		if(gradImage==null)		{			g.setColor(color);			g.fillRect(0,0,width,height);		}		else		{			int srcLen = gradImage.getWidth() * gradImage.getHeight();			int srcColorMap[] = new int[srcLen];			gradImage.getRGB(srcColorMap,0,gradImage.getWidth(),0,0,gradImage.getWidth(),gradImage.getHeight());						int len;			if(vertical) len = width;			else len = height;						int []colorMap = new int[len];			for(int i=0;i<len;++i)			{				colorMap[i] = srcColorMap[(i*srcLen)/len];			}			srcColorMap=null;						if(vertical)			{				int i;				for(i=0;i<width;++i)				{					g.setColor(colorMap[i]);					g.drawLine(i,0,i,height);				}			}			else			{				int i;				for(i=topOffset;i<len-bottomOffset;++i)				{					g.setColor(colorMap[i-topOffset]);					g.drawLine(0,i,width,i);				}			}		}				if(defaultBorder!=null)		{			// draw top border.			int len = defaultBorder.getWidth() * defaultBorder.getHeight();			int colorMap[] = new int[len];			defaultBorder.getRGB(colorMap,0,defaultBorder.getWidth(),0,0,defaultBorder.getWidth(),defaultBorder.getHeight());//			System.out.println("Rendering Border GRADIENT: "+len);			int i;			for(i=0;i<(topOffset-1) && i<len ;++i)			{				g.setColor(colorMap[i]&0x00FFFFFF);				g.drawLine(0,i,width,i);			}			for(i=len;i<(topOffset-1);++i)			{				g.drawLine(0,i,width,i);							}			g.setColor(defaultRulerColor2);			g.drawLine(0,topOffset-2,width,topOffset-2);			g.setColor(defaultRulerColor1);			g.drawLine(0,topOffset-1,width,topOffset-1);						// draw bottom border.			int p = height-bottomOffset+2;			for(i=0;i<bottomOffset && i<len;++i)			{				g.setColor(colorMap[i]);				g.drawLine(0,p+i,width,p+i);			}			for(i=len;i<bottomOffset;++i)			{				g.drawLine(0,p+i,width,p+i);			}									g.setColor(defaultRulerColor2);			g.drawLine(0,height-bottomOffset+2,width,height-bottomOffset+2);			g.setColor(defaultRulerColor1);			g.drawLine(0,height-bottomOffset+1,width,height-bottomOffset+1);		}		if(defaultLogo!=null)		{			switch (logoPossition)			{				case LEFT:					g.drawImage(defaultLogo,0,0,Graphics.TOP|Graphics.LEFT);										break;				case CENTRE:					g.drawImage(defaultLogo,(width/2)-(defaultLogo.getWidth()/2),0,Graphics.TOP|Graphics.LEFT);										break;				default: // default is RIGHT.					g.drawImage(defaultLogo,width-defaultLogo.getWidth(),0,Graphics.TOP|Graphics.LEFT);					break;			}		}				// draw bgImage		if(bg!=null)		{			int w = width;			int h = height-topOffset-bottomOffset;						int offx = bg.getWidth()/2,offy=bg.getHeight()/2;			int x=0,y=0;			if(hpos==CENTRE) x = w/2 - offx;			else if(hpos==LEFT) x=0;			else if(hpos==RIGHT) x=w-offx-offx;						if(vpos==CENTRE) y = h/2-offy; 			else if(vpos==TOP) y= 0;			else if(vpos==BOTTOM) y=h-offy-offy;						g.drawImage(bg,x,y+topOffset,Graphics.TOP|Graphics.LEFT);		}

⌨️ 快捷键说明

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