📄 firescreen.java
字号:
// draw scroll bar area. g.setColor(defaultScrollRulerColor1); g.drawLine(width-SCROLLBAR_WIDTH,topOffset,width-SCROLLBAR_WIDTH,height-bottomOffset); g.drawLine(width-SCROLLBAR_WIDTH,topOffset,width,topOffset); g.drawLine(width-SCROLLBAR_WIDTH,height-bottomOffset,width,height-bottomOffset); g.setColor(defaultScrollRulerColor2); g.drawLine(width-SCROLLBAR_WIDTH+1,topOffset+1,width-SCROLLBAR_WIDTH+1,height-bottomOffset-1); g.setColor(defaultScrollRulerColor3); g.fillRect(width-SCROLLBAR_WIDTH+2,topOffset+1,SCROLLBAR_WIDTH-2,height-topOffset-bottomOffset-1); return img; } private FireScreen(Display display) { this.display = display; popups = new Vector(); bgImage = null; alive = true; loadTheme(); bgImage=prepareBgImage(getWidth(),getHeight()); innerGauge = new FGauge(); innerGauge.setWidth(bottomOffset-1); innerGauge.setHeight(bottomOffset-1); display.callSerially(this); } protected void paint(Graphics sg) { int width = getWidth(); int height = getHeight(); if(offscreen==null || offscreen.getWidth()!=width || offscreen.getHeight()!=height) {// some implementations dont call correctly the sizeChanged() method so we cannot rely on it. offscreen = Image.createImage(width,height); } /* **************** Code to Handle animations and fancy stuff ********************** */ if(animationImage!=null) { Graphics g = offscreen.getGraphics(); int h,w,diff,py,px; switch (animationDirection) { case UP: h = animationImage.getHeight(); w = animationImage.getWidth(); diff = h/ANIMATION_COUNT; py = animationY+h-(diff*animationFrameCount); g.setClip(animationX,py,w,(diff*animationFrameCount)); g.drawImage(animationImage,animationX,py,Graphics.LEFT|Graphics.TOP); break; case DOWN: h = animationImage.getHeight(); w = animationImage.getWidth(); diff = h/ANIMATION_COUNT; py = animationY-h+(diff*animationFrameCount); g.setClip(animationX,animationY,w,(diff*animationFrameCount)); g.drawImage(animationImage,animationX,py,Graphics.LEFT|Graphics.TOP); break; case LEFT: h = animationImage.getHeight(); w = animationImage.getWidth(); diff = w/ANIMATION_COUNT; px = animationX-(diff*animationFrameCount); py= animationY; //sg.setClip(px,py,(diff*animationFrameCount),h); //sg.drawImage(animationImage,px,py,Graphics.LEFT|Graphics.TOP); g.drawRegion(animationImage,0,0,diff*animationFrameCount,h,Sprite.TRANS_NONE,px,py,Graphics.LEFT|Graphics.TOP); break; case RIGHT: h = animationImage.getHeight(); w = animationImage.getWidth(); diff = w/ANIMATION_COUNT; px = animationX; py= animationY; int sw = (diff*animationFrameCount); g.drawRegion(animationImage,w-sw,0,sw,h,Sprite.TRANS_NONE,px,py,Graphics.LEFT|Graphics.TOP); break; default: break; } finalPaint(offscreen,sg,width,height); return; } if(!forceRepaint && !userActionRepaint) { if(busyModeRepaint) { busyModeRepaint=false; width = super.getWidth(); height = super.getHeight(); int gw = innerGauge.getWidth(); int gh = innerGauge.getHeight(); switch (orientation) { case LANDSCAPELEFT: sg.translate(width-gw,height/2-gh/2); sg.setClip(0,0,gh,gw); break; case LANDSCAPERIGHT: sg.translate(0,height/2-gw/2); sg.setClip(0,0,gh,gw); break; default: sg.translate(width/2-gw/2,height-gh); sg.setClip(0,0,gw,gh); break; } innerGauge.paint(sg); return; } if(panelAnimation) { Graphics g = offscreen.getGraphics(); panelAnimation=false; if(popups.size()>0) { Popup popup = (Popup)popups.lastElement(); g.translate(popup.getPosX(),popup.getPosY()); g.setClip(0,0,popup.getWidth(),popup.getHeight()); popup.paint(g); } else if(panel!=null)// draw panel if any. { g.setClip(0,0,width,height); panel.paint(g); } finalPaint(offscreen,sg,width,height); return; } } /* ************************* Code to Handle usefull painting operations ************************ */ if(bgImage==null) { bgImage=prepareBgImage(getWidth(),getHeight()); if(panel!=null) { panel.validate(); } } Graphics g = offscreen.getGraphics(); g.translate(-g.getTranslateX(),-g.getTranslateY()); // reset. if(!forceRepaint) // in normal operation, only the top level panel is redrawn. { userActionRepaint=false; if(popups.size()>0) { Popup popup = (Popup)popups.lastElement(); g.translate(popup.getPosX(),popup.getPosY()); g.setClip(0,0,popup.getWidth(),popup.getHeight()); popup.paint(g); } else if(panel!=null)// draw panel if any. { g.setClip(0,0,width,height); panel.paint(g); } } else // if a repaint is forced, everything is redrawn. { forceRepaint = false; if(panel!=null)// draw panel if any. { g.setClip(0,0,width,height); panel.paint(g); } for(int i =0;i<popups.size();++i) // redraw all popups. { Popup popup = (Popup)popups.elementAt(i); g.translate(-g.getTranslateX(),-g.getTranslateY()); // reset. g.translate(popup.getPosX(),popup.getPosY()); g.setClip(0,0,popup.getWidth(),popup.getHeight()); popup.paint(g); } } finalPaint(offscreen,sg,width,height); } private void finalPaint(Image src, Graphics dest,int width,int height) { if(orientation==NORMAL) { dest.drawImage(src,0,0,Graphics.TOP|Graphics.LEFT); } else if(orientation==LANDSCAPELEFT) { dest.drawRegion(src,0,0,width,height,Sprite.TRANS_ROT270,0,0,Graphics.TOP|Graphics.LEFT); } else if(orientation==LANDSCAPERIGHT) { dest.drawRegion(src,0,0,width,height,Sprite.TRANS_ROT90,0,0,Graphics.TOP|Graphics.LEFT); } } /** * Sets Displayable c as the Current display. * @param c a displayable */ public void setCurrent(Displayable c) { display.setCurrent(c); } /** * Returns the current panel set on the FireScreen. * @return */ public Panel getCurrentPanel() { return panel; } /** * Set a panel to the FireScreen. * @param p */ public void setCurrent(Panel p) { setCurrent(p,LEFT); } /** * Shows the panel p on the screen with the supplied animation direction. * @param p * @param animDirection */ public void setCurrent(Panel p,int animDirection) { popups.removeAllElements(); p.setWidth(getWidth()); p.setHeight(getHeight()); p.validate(); p.resetPointer(); Displayable dsp = display.getCurrent(); if(dsp!=this) { display.setCurrent(this); panel=null; } if(panel==null) // den exei animation. { panel = p; repaint(); } else { // kanoume ena animation gia tin pozeria. int w = getWidth(); int h = getHeight(); Image img = Image.createImage(w,h); Graphics g = img.getGraphics(); p.paint(g); g.setColor(0x00000000); g.translate(-g.getTranslateX(),-g.getTranslateY()); g.setClip(0,0,w,h); g.drawRect(0,0,w,h); animationDirection=animDirection; animationFrameCount=0; if(animDirection==LEFT) { animationX = getWidth(); } else if(animDirection==RIGHT) { animationX=0; } animationY = 0; animationImage= img; panel=p; } } /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ public void run() { if(alive) { try{ try{Thread.sleep(CLOCK_STEP);} catch (InterruptedException e) { } Displayable disp; disp = display.getCurrent(); if(disp!=null && disp instanceof FireScreen) { // stin othonh exoume ena panel (kai oxi textbox ) // check for animation if(animationImage!=null) { animationFrameCount++; if(animationFrameCount>ANIMATION_COUNT) { animationImage=null; forceRepaint=true; } } if(popups.size()>0) { Panel p= (Panel)popups.lastElement(); if(p.isAnimated() && p.clock()) { panelAnimation=true; } } else if(panel!=null && panel.isAnimated()) { boolean repaint = panel.clock(); if(repaint) { panelAnimation=true; } } if(busyMode) { busyModeRepaint=true; innerGauge.clock(); } if(forceRepaint || animationImage!=null|| busyModeRepaint || panelAnimation) { repaint(); } } else if(disp!=null && disp instanceof SplashScreen) //nice hack for the SplashScreen animation. { ((SplashScreen)disp).clock(); ((SplashScreen)disp).repaint(); } }catch(Throwable e) { System.out.println("Error: "+e.getClass().getName()+". Msg: "+e.getMessage()); } display.callSerially(this); } } public static int getTopOffset() { return topOffset; } public static int getBottomOffset() { return bottomOffset; } public Font getLabelFont() { return labelFont; } public void setLabelFont(Font labelFont) { this.labelFont = labelFont; } public boolean isTiled() { return tiled; } public void setTiled(boolean tiled) { if(this.tiled!=tiled) { bgImage=null; this.tiled = tiled; } } public boolean isVertical() { return vertical; } public void setVertical(boolean vertical) { bgImage=null; this.vertical = vertical; } public int getVpos() { return vpos; } public void setVpos(int vpos) { if(this.vpos!=vpos) { bgImage=null; this.vpos = vpos; } } /** * This method is called by the vm every time the with and the height of the screen change. The parameters are the real width and height of the screen. * @see javax.microedition.lcdui.Displayable#sizeChanged(int, int) */ protected void sizeChanged(int ww, int hh) { // force recalculation of backgrounds. int w,h; if(orientation==NORMAL) // keep in mind the screen orientation. { w=ww; h=hh; } else { w = hh; h =ww; } SCROLL_HEIGHT = h/2; SCROLL_STEP = SCROLL_HEIGHT/SCROLL_COUNT; bgImage=prepareBgImage(w,h); offscreen = null; if(panel!=null) { panel.setWidth(w); panel.setHeight(h); panel.validate(); } for(int i =0 ;i< popups.size();++i) { Panel popup = (Panel)popups.elementAt(i); popup.setWidth(w-SCROLLBAR_WIDTH); // den tha fenete oraio, alla toulaxiston tha mini to functionallity tou popup. popup.validate(); } try{ System.gc(); // now its a very good time for garbage collection }catch(Throwable e){ System.out.println("Failed to call garbage collector."+e.getMessage()); e.printStackTrace(); } } public static int getLeftSoftKey() { return leftSoftKey; } public static void setLeftSoftKey(int leftSoftKey) { FireScreen.leftSoftKey = leftSoftKey; } public static int getRightSoftKey()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -