📄 firescreen.java
字号:
/* * 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 gr.fire.ui.TransitionAnimation;import gr.fire.util.AnimationQueue;import gr.fire.util.Log;import java.util.Vector;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.game.Sprite;/** * @author padeler * */public class FireScreen extends Canvas implements Runnable{ public static final int NORMAL=0; public static final int LANDSCAPERIGHT=1; public static final int LANDSCAPELEFT=2; public static final int NONE=0x00000000; public static final int CENTER=0x00000001; public static final int RIGHT=0x00000002; public static final int LEFT=0x00000004; public static final int TOP =0x00000008; public static final int BOTTOM = 0x00000010; public static final int VCENTER=0x00000020; public static final int UP =TOP; public static final int DOWN = BOTTOM; /* 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)} }; private static FireScreen singleton=null; private static Theme theme=new Theme(); // default theme. /* ***************** Support variables ***************************** */ private Display display=null; private Image offscreen; // offscreen image used when rendering in landscape modes. private int realWidth, realHeight; private int orientation=NORMAL; private AnimationQueue animationQueue; private final Object lock = new Object(); /** Vector containing all the stacked components currently open on the scren. */ private Vector containers; private Component selectedComponent=null; // holds the currently selected component. private boolean clearScreen =false; private Thread animationThread; private FireScreen(Display display) { /* **** Hack for Motorola phones ********** Thanks to Maxim Blagov */ /* **** Some (if not all) Motorola phones, return "j2me" to getProperty("microedition.platform") */ String platform = null; String prop = System.getProperty("com.mot.carrier.URL"); if (prop != null) { platform = "motorola"; } else { try{ Class.forName("com.motorola.graphics.j3d.Graphics3D"); platform = "motorola"; }catch (Throwable e) {} } if(platform==null) // ok its propably not a motorola phone. { 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; } } this.display = display; this.realWidth = super.getWidth(); this.realHeight = super.getHeight(); containers = new Vector(); animationQueue = new AnimationQueue(); animationThread = new Thread(this); animationThread.start(); } public void registerAnimation(Animation anim) { Component owner = anim.getOwner(); if(owner.animation!=null) { Log.logWarn("Dropping animation "+anim.getClass().getName()+" because owner has already an animation associated with it."); return; } owner.animation=anim; animationQueue.addAnimation(anim); } public void removeAnimation(Animation anim) { animationQueue.removeAnimation(anim); anim.getOwner().animation=null; } public void paint(Graphics g) { if(containers.size()==0) return; int width = getWidth(); int height = getHeight(); Graphics dest; if(orientation==NORMAL) { dest = g; } else { if(offscreen==null || offscreen.getWidth()!=width || offscreen.getHeight()!=height) { offscreen = Image.createImage(width,height); } dest = offscreen.getGraphics(); switch (orientation) { case LANDSCAPELEFT: // FIXME : To sosto land scape prepei na kanei to katalilo adjustment sto translate/clip dest.translate(g.getTranslateX()-dest.getTranslateX(),g.getTranslateY()-dest.getTranslateY()); dest.setClip(g.getClipX(),g.getClipY(),g.getClipWidth(),g.getClipHeight()); break; case LANDSCAPERIGHT:// FIXME : To sosto land scape prepei na kanei to katalilo adjustment sto translate/clip dest.translate(g.getTranslateX()-dest.getTranslateX(),g.getTranslateY()-dest.getTranslateY()); dest.setClip(g.getClipX(),g.getClipY(),g.getClipWidth(),g.getClipHeight()); break; } } if(clearScreen) { clearScreen=false; dest.setColor(0x00FFFFFF); dest.translate(-dest.getTranslateX(), -dest.getTranslateY()); dest.setClip(0, 0, width, height); dest.fillRect(0,0, width, height); } Component paintable =null; int clipX=dest.getClipX(),clipY=dest.getClipY(),clipW=dest.getClipWidth(),clipH=dest.getClipHeight(); int trX = dest.getTranslateX(); int trY = dest.getTranslateY(); int pos; for(pos=containers.size()-1;pos>0;--pos) { // find the component that receives user input (if there is no such component, pos will be 0) paintable = (Component)containers.elementAt(pos); if(paintable instanceof Container || paintable.isFocusable()) break; } for(int c=pos;c<containers.size();++c) { // now paint the components from bottom up. dest.translate(-dest.getTranslateX()+trX,-dest.getTranslateY()+trY); dest.setClip(clipX,clipY,clipW,clipH); paintable = (Component)containers.elementAt(c); if(paintable.valid==false) { if(!(paintable instanceof Panel) && (paintable instanceof Container)) ((Container)paintable).layoutManager.layoutContainer((Container)paintable); paintable.validate(); } if(paintable.intersects(clipX,clipY,clipW,clipH)) { g.clipRect(paintable.x, paintable.y, paintable.width, paintable.height); g.translate(paintable.x, paintable.y); // ok, now paint or animate the component. if(paintable.animation!=null) { paintable.animation.paint(dest); } else { paintable.paint(dest); if((paintable instanceof Container || paintable.isFocusable()) && (clipY+clipH>height-theme.softKeyFont.getHeight())) { // now repaint the softkeys if needed repaintSoftKeys(paintable.leftSoftKeyCommand,paintable.rightSoftKeyCommand,dest); } } } } switch(orientation) { case NORMAL: break; case LANDSCAPELEFT: g.drawRegion(offscreen,0,0,width,height,Sprite.TRANS_ROT270,0,0,Graphics.TOP|Graphics.LEFT); break; case LANDSCAPERIGHT: g.drawRegion(offscreen,0,0,width,height,Sprite.TRANS_ROT90,0,0,Graphics.TOP|Graphics.LEFT); break; } } private void repaintSoftKeys(Command left,Command right,Graphics dest) { if(left==null && right==null) return; dest.setFont(theme.softKeyFont); int keyH = theme.softKeyFont.getHeight(); int dw = getWidth(); int dh = getHeight(); dest.translate(-dest.getTranslateX(),dh-dest.getTranslateY()-keyH); dest.clipRect(0,0, dw, keyH); if(left!=null) { int keyW = theme.softKeyFont.stringWidth(left.getLabel()); if((theme.softKeyBgColor&0xFF000000)!=0xFF000000) // not transparent bg { dest.setColor(theme.softKeyBgColor); dest.fillRect(0, 0, keyW, keyH); } dest.setColor(theme.softKeyFgColor); dest.drawString(left.getLabel(), 0, 0, Graphics.TOP|Graphics.LEFT); } if(right!=null) { int keyW = theme.softKeyFont.stringWidth(right.getLabel()); if((theme.softKeyBgColor&0xFF000000)!=0xFF000000) // not transparent bg { dest.setColor(theme.softKeyBgColor); dest.fillRect(dw-keyW, 0, keyW, keyH); } dest.setColor(theme.softKeyFgColor); dest.drawString(right.getLabel(), dw-keyW, 0, Graphics.TOP|Graphics.LEFT); } } void inValidateTopLevelContainer() { for(int i=0;i<containers.size();++i) ((Component)containers.elementAt(i)).valid=false; repaint(); } /** * Returns the current panel set on the FireScreen. * @return */ public Component getCurrent() { if(containers.size()>0) return (Component)containers.elementAt(0); return null; } /** * Set a Displayable to the FireScreen. * @param p */ public void setCurrent(Displayable d) { animationQueue.removeAllAnimations(); display.setCurrent(d); } /** * Set a Component to the FireScreen. * @param p */ public void setCurrent(Component c) { setCurrent(c,TransitionAnimation.TRANSITION_NONE); } public void addComponent(Component c) { if(c.parent!=null) { if(c.parent instanceof Container) ((Container)c.parent).remove(c); c.parent=null; } synchronized (lock) { containers.addElement(c); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -