implementation.java.svn-base

来自「j2me设计的界面包」· SVN-BASE 代码 · 共 905 行 · 第 1/3 页

SVN-BASE
905
字号
        private void setSoftKeyCodes(MIDlet m) {        // initialy set known key codes        setKnownSoftKeyCodes();                try {            // if the back key is assigned to a game action by mistake then            // workaround it implicitly            int game = getGameAction(Form.backSK);            if(game == UP || game == DOWN || game == RIGHT || game == LEFT || game == FIRE) {                Form.backSK = -50000;            }        } catch(Exception ok) {}        try {            // if the clear key is assigned to a game action by mistake then            // workaround it implicitly            int game = getGameAction(Form.clearSK);            if(game == UP || game == DOWN || game == RIGHT || game == LEFT || game == FIRE) {                Form.clearSK = -50000;            }        } catch(Exception ok) {}                // Then Check JAD file for overide specific key mapping        String tmpSoftKey = m.getAppProperty("SoftKey-Right");                if(tmpSoftKey != null && !"".equals(tmpSoftKey)) {            Form.rightSK = Integer.valueOf(tmpSoftKey).intValue();        }        tmpSoftKey = m.getAppProperty("SoftKey-Right2");        if(tmpSoftKey != null && !"".equals(tmpSoftKey)) {            Form.rightSK2 = Integer.valueOf(tmpSoftKey).intValue();        }        tmpSoftKey = m.getAppProperty("SoftKey-Left");        if(tmpSoftKey != null && !"".equals(tmpSoftKey)) {            Form.leftSK = Integer.valueOf(tmpSoftKey).intValue();        }        tmpSoftKey = m.getAppProperty("SoftKey-Back");        if(tmpSoftKey != null && !"".equals(tmpSoftKey)) {            Form.backSK = Integer.valueOf(tmpSoftKey).intValue();        }                tmpSoftKey = m.getAppProperty("SoftKey-Clear");        if(tmpSoftKey != null && !"".equals(tmpSoftKey)) {            Form.clearSK = Integer.valueOf(tmpSoftKey).intValue();        }                // Check Third Soft Button is supported                tmpSoftKey = m.getAppProperty("isThirdSoftButtonSupported");                if(tmpSoftKey != null && "true".equals(tmpSoftKey.toLowerCase().trim())) {                        Display.getInstance().setThirdSoftButton(true);        }    }        public Implementation() {        super(false);        setTitle(null);        setFullScreenMode(true);                // disable the flashGraphics bug on Nokia phones        if(System.getProperty("microedition.platform").toUpperCase().indexOf("NOKIA") >= 0) {            flushGraphicsBug = false;            // Symbian devices should yield a bit to let the paint thread complete its work            // problem is we can't differentiate S40 from S60...            transitionDelay = 1;        } else {            flushGraphicsBug = true;            transitionDelay = -1;        }        wrapper.setGraphics(getGraphics());    }    /**     * Indicate to the implementation whether the flush graphics bug exists on this     * device. By default the flushGraphics bug is set to "true" and only disabled     * on handsets known 100% to be safe     *      * @param flushGraphicsBug true if the bug exists on this device (the safe choice)     * false for slightly higher performance.     */    public void setFlashGraphicsBug(boolean flushGraphicsBug) {        this.flushGraphicsBug = flushGraphicsBug;    }        /**     * Indicates whether a delay should exist between calls to flush graphics during     * transition. In some devices flushGraphics is asynchronious causing it to be     * very slow with our background thread. The solution is to add a short wait allowing     * the implementation time to paint the screen. This value is set automatically by default     * but can be overriden for some devices.     *      * @param transitionDelay -1 for no delay otherwise delay in milliseconds     */    public void setTransitionYield(int transitionDelay) {        this.transitionDelay = transitionDelay;    }    /**     * Encapsulates the editing code which is specific to the platform, some platforms     * would allow "in place editing" MIDP does not.     *      * @param cmp the {@link TextArea} component     */    void editString(Component cmp, int maxSize, int constraint, String text) {        UIManager m = UIManager.getInstance();        CONFIRM_COMMAND = new Command(m.localize("ok", "OK"),Command.OK,1);        CANCEL_COMMAND = new Command(m.localize("cancel", "Cancel"),Command.CANCEL,2);        currentTextBox = new TextBox("", "", maxSize, TextArea.ANY);        currentTextBox.setCommandListener(this);        currentTextBox.addCommand(CONFIRM_COMMAND);        currentTextBox.addCommand(CANCEL_COMMAND);                currentTextComponent = cmp;        currentTextBox.setMaxSize(maxSize);        currentTextBox.setString(text);        currentTextBox.setConstraints(constraint);        display.setCurrent(currentTextBox);        if(waitForEdit == null) {            waitForEdit = new RunnableWrapper(null, 2);        }        waitForEdit.setDone(false);        Display.getInstance().invokeAndBlock(waitForEdit);    }   /**    * Returns the video control for the media player    *     * @param player the media player    * @return the video control for the media player    */    Object getVideoControl(Object player) {        VideoControl vidc = (VideoControl)((Player)player).getControl("VideoControl");        vidc.initDisplayMode(vidc.USE_DIRECT_VIDEO, this);        return vidc;    }        /**     * Return the number of alpha levels supported by the implementation.     *      * @return the number of alpha levels supported by the implementation     */    public int numAlphaLevels(){        return display.numAlphaLevels();    }    /**     * Returns the number of colors applicable on the device, note that the API     * does not support gray scale devices.     *      * @return the number of colors applicable on the device     */    public int numColors() {        return display.numColors();    }        protected void showNotify() {        Form current = Display.getInstance().getCurrentInternal();        if(current != null) {            current.showNotify();        }    }    protected void hideNotify() {        Form current = Display.getInstance().getCurrentInternal();        if(current != null) {            current.hideNotify();        }    }    /**     * Invoked by the EDT to paint the dirty regions     */    void paintDirty() {        int size = 0;        synchronized(Display.lock) {            size = paintQueueFill;            Animation[] array = paintQueue;            paintQueue = paintQueueTemp;            paintQueueTemp = array;            paintQueueFill = 0;        }        if(size > 0) {            wrapper.setGraphics(getGraphics());            int topX = getWidth();            int topY = getHeight();            int bottomX = 0;            int bottomY = 0;            for(int iter = 0 ; iter < size ; iter++) {                Animation ani = paintQueueTemp[iter];                paintQueueTemp[iter] = null;                wrapper.translate(-wrapper.getTranslateX(), -wrapper.getTranslateY());                wrapper.setClip(0, 0, getWidth(), getHeight());                if(ani instanceof Component) {                    Component cmp = (Component)ani;                    Rectangle dirty = cmp.getDirtyRegion();                    if(dirty != null){                        wrapper.setClip(dirty.getX(), dirty.getY(), dirty.getSize().getWidth(), dirty.getSize().getHeight());                        cmp.setDirtyRegion(null);                    }                                        cmp.paintComponent(wrapper);                    int cmpAbsX = cmp.getAbsoluteX() + cmp.getScrollX();                    topX = Math.min(cmpAbsX, topX);                    bottomX  = Math.max(cmpAbsX + cmp.getWidth(), bottomX);                    int cmpAbsY = cmp.getAbsoluteY() + cmp.getScrollY();                    topY = Math.min(cmpAbsY, topY);                    bottomY  = Math.max(cmpAbsY + cmp.getHeight(), bottomY);                } else {                    bottomX = getWidth();                    bottomY = getHeight();                    topX = 0;                    topY = 0;                    ani.paint(wrapper);                }            }            // disable flush graphics bug when media is playing to prevent the double buffer            // from clearing the media and producing flickering            Form current = Display.getInstance().getCurrentInternal();            if(!flushGraphicsBug || (current != null && current.hasMedia())) {                flushGraphics(topX, topY, bottomX - topX, bottomY - topY);            } else {                flushGraphics();            }        }    }    public void repaint(Animation cmp) {        synchronized(Display.lock) {            for(int iter = 0 ; iter < paintQueueFill ; iter++) {                if(paintQueue[iter] == cmp) {                    return;                }            }            // overcrowding the queue don't try to grow the array!            if(paintQueueFill >= paintQueue.length) {                System.out.println("Warning paint queue size exceeded, please watch the amount of repaint calls");                return;            }                        paintQueue[paintQueueFill] = cmp;            paintQueueFill++;            Display.lock.notify();        }    }    private void addInputEvent(int[] ev) {        synchronized(Display.lock) {            inputEvents.addElement(ev);            Display.lock.notify();        }    }    private int[] createSizeChangedEvent(int w, int h) {        return new int[] {SIZE_CHANGED, w, h};    }    /**     * Creates a pointer event with the following properties     */    private int[] createPointerEvent(int x, int y, boolean pressed) {        if(pressed) {            return new int[] {POINTER_PRESSED, x, y};        } else {            return new int[] {POINTER_RELEASED, x, y};        }    }    /**     * Creates a pointer event with the following properties     */    private int[] createPointerDragEvent(int x, int y) {        return new int[] {POINTER_DRAGGED, x, y};    }    private int[] createKeyEvent(int keyCode, boolean pressed) {        if(pressed) {            return new int[] {KEY_PRESSED, keyCode};        } else {            return new int[] {KEY_RELEASED, keyCode};        }    }        private int lastKeyPressed;    protected  void keyPressed(final int keyCode){        Form current = Display.getInstance().getCurrentInternal();        if(current == null){            return;        }        addInputEvent(createKeyEvent(keyCode, true));        keyRepeatCharged = true;        keyRepeatValue = keyCode;        nextKeyRepeatEvent = System.currentTimeMillis() + keyRepeatInitialIntervalTime;        lastKeyPressed = keyCode;    }    protected  void keyReleased(final int keyCode){        keyRepeatCharged = false;        Form current = Display.getInstance().getCurrentInternal();        if(current == null){            return;        }

⌨️ 快捷键说明

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