📄 firescreen.java
字号:
repaint(); } public boolean removeComponent(Component c) { boolean done=false; if(c.animation!=null) { removeAnimation(c.animation); } synchronized (lock) { done = containers.removeElement(c); } if(done) { repaint(); } return done; } /** * Shows the container p on the screen with the supplied animation direction. * @param p * @param animDirection */ public void setCurrent(Component p,int animDirection) { Log.logInfo("Setting Current the component "+p); if(p.parent!=null) { if(p.parent instanceof Container) ((Container)p.parent).remove(p); p.parent=null; } animationQueue.removeAllAnimations(); synchronized(lock) { Component last = null; if(containers.size()>0) last = (Component)containers.elementAt(0); containers.removeAllElements(); Displayable dsp = display.getCurrent(); if(dsp!=this) // no animation of previous screen was not a FireScreen component. { display.setCurrent(this); last=null; } if(last!=null && animDirection!=TransitionAnimation.TRANSITION_NONE) { TransitionAnimation anim = new TransitionAnimation(); anim.setup(p,last,new Integer(animDirection)); registerAnimation(anim); } containers.addElement(p); } repaint(); } public void run() { long minLoopTime = 30; // dont loop faster than this period, in order to avoid busy waits long start,period; try{ while(true) { start = System.currentTimeMillis(); Animation anim = animationQueue.getNextAnimation(); Component owner = anim.getOwner(); if(anim.isRunning()==false)// animation completed. remove it from the queue. { removeAnimation(anim); // ask for a repaint of its owner component. owner.repaint(); continue; } if(anim.step()) { owner.repaint(); } period = System.currentTimeMillis() - start; if(period<minLoopTime) { try{ Thread.sleep(minLoopTime-period); }catch(InterruptedException e) { Log.logError("Interrupted inside animation thread.",e); } } } }catch(Throwable e) { Log.logError("Animation thread exception",e); } } /** * 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; } /** * Used to create and retrieve the FireScreen singleton. * @return the FireScreen singleton. */ public static FireScreen getScreen() { if(singleton==null) throw new NullPointerException("FireScreen is not initialized."); return singleton; } public static Theme getTheme() { return theme; } public static void setTheme(Theme theme) { if(theme!=null) FireScreen.theme = theme; else FireScreen.theme = new Theme(); } protected void pointerDragged(int x, int y) { for(int i=containers.size()-1;i>=0;--i) { Component cmp = (Component)containers.elementAt(i); if(cmp instanceof Container || cmp.isFocusable()) { // only send events to containers or focusable components cmp.pointerDragged(x-cmp.x,y-cmp.y); break;// only send the pointer event once. } } } protected void pointerPressed(int x, int y) { for(int i=containers.size()-1;i>=0;--i) { Component cmp = (Component)containers.elementAt(i); if(cmp instanceof Container || cmp.isFocusable()) { // only send events to containers or focusable components cmp.pointerPressed(x-cmp.x,y-cmp.y); break;// only send the pointer event once. } } } protected void pointerReleased(int x, int y) { for(int i=containers.size()-1;i>=0;--i) { Component cmp = (Component)containers.elementAt(i); if(cmp instanceof Container || cmp.isFocusable()) { // only send events to containers or focusable components cmp.pointerReleased(x-cmp.x,y-cmp.y); break;// only send the pointer event once. } } } protected void keyPressed(int keyCode) { if(selectedComponent!=null) { selectedComponent.keyPressed(keyCode); } else { for(int i=containers.size()-1;i>=0;--i) { Component cmp = (Component)containers.elementAt(i); if(cmp instanceof Container || cmp.isFocusable()) { // only send events to containers or focusable components cmp.keyPressed(keyCode); break;// only send the key event once. } } } } public int getGameAction(int keyCode) { return super.getGameAction(keyCode); } protected void keyReleased(int k) { Component current = selectedComponent; if(current!=null && current.selected && !((k==leftSoftKey && current.leftSoftKeyCommand==null) ||// must send the event to the container or panel (k==rightSoftKey && current.rightSoftKeyCommand==null)) ) { current.keyReleased(k); // keyReleased might change the selectedComponent if(current.selected) return; // else component is not anymore selected due to keyReleased event. send the event to the containers } for(int i=containers.size()-1;i>=0;--i) { Component cmp = (Component)containers.elementAt(i); if(cmp instanceof Container || cmp.isFocusable()) { // only send events to containers or focusable components cmp.keyReleased(k); break;// only send the key event once. } } } protected void keyRepeated(int keyCode) { if(selectedComponent!=null) { selectedComponent.keyRepeated(keyCode); } else { for(int i=containers.size()-1;i>=0;--i) { Component cmp = (Component)containers.elementAt(i); if(cmp instanceof Container || cmp.isFocusable()) { // only send events to containers or focusable components cmp.keyRepeated(keyCode); break;// only send the key event once. } } } } protected void sizeChanged(int w, int h) { super.sizeChanged(w, h); sizeChangedImpl(w, h); } private void sizeChangedImpl(int w,int h) { realWidth=w; realHeight=h; offscreen=null; clearScreen=true; for(int i=0;i<containers.size();++i) { ((Component)containers.elementAt(i)).valid=false; } repaint(); } /** * Returns the width of this FireScreen. If the screen is in landscape mode, it will return the real height of the screen. * @see javax.microedition.lcdui.Displayable#getWidth() */ public int getWidth() { if(orientation==NORMAL) { return realWidth; } return realHeight; } /** * Returns the height of this FireScreen. If the screen is in landscape mode, it will return the real width of the screen. * @see javax.microedition.lcdui.Displayable#getHeight() */ public int getHeight() { if(orientation==NORMAL) { return realHeight; } return realWidth; } public int getOrientation() { return orientation; } public void setOrientation(int orientation) { if(orientation!=NORMAL && orientation!=LANDSCAPELEFT && orientation!=LANDSCAPERIGHT) throw new IllegalArgumentException("Unknown orientation value "+orientation); this.orientation = orientation; this.sizeChangedImpl(super.getWidth(),super.getHeight()); } /** * Return left softkey shortcut, depending on the screen orientation (left/right landscare or normal) * @return */ public String getLeftSoftKeyShortcut() { switch (orientation) { case LANDSCAPELEFT: return "[9]"; case LANDSCAPERIGHT: return "[1]"; default: return "[1]"; } } /** * Returns right softkey shortcut, depending on the screen orientation (left/right landscare or normal) * @return */ public String getRightSoftKeyShortcut() { switch (orientation) { case LANDSCAPELEFT: return "[3]"; case LANDSCAPERIGHT: return "[7]"; default: return "[3]"; } } Component getSelectedComponent() { return selectedComponent; } void setSelectedComponent(Component newSelectedComponent) { if(newSelectedComponent==selectedComponent) return; // nothing to do here if(selectedComponent!=null && selectedComponent.selected) { selectedComponent.setSelected(false); } this.selectedComponent = newSelectedComponent; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -