implementation.java.svn-base

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

SVN-BASE
905
字号
/* * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.  Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code 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 General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */package com.sun.lwuit;import com.sun.lwuit.animations.Animation;import com.sun.lwuit.animations.Transition;import com.sun.lwuit.geom.Rectangle;import com.sun.lwuit.plaf.UIManager;import java.util.Vector;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.TextBox;import javax.microedition.lcdui.game.GameCanvas;import javax.microedition.media.Player;import javax.microedition.media.control.VideoControl;import javax.microedition.midlet.MIDlet;/** * This class implements many of the implementation details related to Display * that shouldn't be exposed by the API normally. It acts as the canvas, the * thread for the events and a command listener which are 3 unrelated tasks. * The purpose of using a single class for these 3 tasks is reduced class count * and thus reduced overhead. *  * @author Shai Almog */class Implementation extends GameCanvas implements Runnable, CommandListener {    private static final int POINTER_PRESSED = 1;    private static final int POINTER_RELEASED = 2;    private static final int POINTER_DRAGGED = 3;    private static final int KEY_PRESSED = 4;    private static final int KEY_RELEASED = 5;    private static final int SIZE_CHANGED = 7;        private static final AlertType[] TYPES = new AlertType[] {        AlertType.ALARM, AlertType.CONFIRMATION, AlertType.ERROR,         AlertType.INFO, AlertType.WARNING    };        /**     * The command used for accepting a text field change     */    private static Command CONFIRM_COMMAND;    /**     * Indicates the maximum drawing speed of no more than 10 frames per second     * by defult (this can be increased or decreased) the advantage of limiting     * framerate is to allow the CPU to perform other tasks besides drawing.     * Notice that when no change is occuring on the screen no frame is drawn and     * so a high/low FPS will have no effect then.     */    private int framerateLock = 30;    /**     * The command used for canceling a text field change     */    private static Command CANCEL_COMMAND;    /**     * The currently edited text box used to input into text field, this is a MIDP implementation     * detail.     */    private TextBox currentTextBox;        /**     * The currently edited text component that will be updated after the dismissal     * of the text box     */    private Component currentTextComponent;        private boolean flushGraphicsBug;    private int transitionDelay;    private Graphics wrapper = new Graphics();    /**     * Elements waiting for a paint     */    //private Vector paintQueue = new Vector();    private Animation[] paintQueue = new Animation[50];    private Animation[] paintQueueTemp = new Animation[50];    private int paintQueueFill = 0;    /**     * Events to broadcast on the EDT     */    private Vector inputEvents = new Vector();    private static javax.microedition.lcdui.Display display;        private boolean keyRepeatCharged;    private long nextKeyRepeatEvent;    private int keyRepeatValue;    private int keyRepeatInitialIntervalTime = 800;    private int keyRepeatNextIntervalTime = 10;    private RunnableWrapper waitForEdit;    private boolean block = false;    private int dragActivationCounter = 0;            void init(Object m) {        display = javax.microedition.lcdui.Display.getDisplay((MIDlet)m);        //display.setCurrent(this);        setSoftKeyCodes((MIDlet)m);    }        /**     * Plays sound for the dialog     */    void playDialogSound(final int type) {        TYPES[type - 1].playSound(display);    }            void confirmControlsView() {        if(display == null){            throw new IllegalStateException("First call Display.setDisplay(javax.microedition.lcdui.Display d) method");        }        if(display.getCurrent() != this){            setCurrent(this);        }    }    private void setCurrent(Displayable d){        if(display == null){            throw new IllegalStateException("First call Display.setDisplay(javax.microedition.lcdui.Display d) method");        }        if(d instanceof Canvas) {            ((Canvas)d).setFullScreenMode(true);        }         display.setCurrent(d);                // wait for call serially to complete to make sure the full screen mode actually worked..,        if(Display.getInstance().isEdt()) {            // using Thread as a runnable implementation that doesn't do anything...            RunnableWrapper c = new RunnableWrapper(new Thread(), 0);            display.callSerially(c);            synchronized(Display.lock) {                while(!c.isDone()) {                    try {                        Display.lock.wait(5);                    } catch(InterruptedException err) {}                }            }        }    }        /**     * Vibrates the device for the given length of time     *      * @param duration length of time to vibrate     */    public void vibrate(int duration) {        display.vibrate(duration);    }        /**     * Flash the backlight of the device for the given length of time     *      * @param duration length of time to flash the backlight     */    public void flashBacklight(int duration) {        display.flashBacklight(duration);    }    /**     * Indicates the maximum frames the API will try to draw every second     * by defult this is set to 10. The advantage of limiting     * framerate is to allow the CPU to perform other tasks besides drawing.     * Notice that when no change is occuring on the screen no frame is drawn and     * so a high/low FPS will have no effect then.     * 10FPS would be very reasonable for a business application.     *      * @param rate the frame rate     */    public void setFramerate(int rate) {        framerateLock = 1000 / rate;    }        /**     * Indicates the maximum frames the API will try to draw every second     *      * @return the frame rate     */    public int getFrameRate() {        return 1000 / framerateLock;    }        private void setKnownSoftKeyCodes() {        try {            Class.forName("com.siemens.mp.game.Light");            Form.leftSK = -1;            Form.rightSK = -4;            Form.clearSK = -12;            return;        } catch(ClassNotFoundException _ex) { }        try {            Class.forName("com.motorola.phonebook.PhoneBookRecord");            Form.leftSK = -21;            Form.rightSK = -22;            return;            //maybe Motorola A1000 has different keyCodes            //Left soft key: Key code -10,            //Right soft key: Key code -11,        } catch(ClassNotFoundException _ex) { }        try {            Class.forName("com.nokia.mid.ui.FullCanvas");            Form.leftSK = -6;            Form.rightSK =-7;            return;        } catch(ClassNotFoundException _ex) { }        try {            Class.forName("net.rim.device.api.system.Application");            //there are no soft keys on the Blackberry            //instead use the Q and P keys            Form.leftSK = 113;            Form.rightSK = 112;            //some BB devices use O as the most right key            Form.rightSK2 = 111;            Form.clearSK = 8;            return;        } catch (ClassNotFoundException ex) { }        // detecting LG          try {              // iden device            Class.forName("com.mot.iden.util.Base64");              Form.clearSK = -5000;            Form.leftSK = -20;            Form.rightSK = -21;            return;        } catch (Throwable ex) { }        try {            Class.forName("mmpp.media.MediaPlayer");              Form.clearSK = -204;        } catch(ClassNotFoundException ex) {}        try {            if(getKeyName(-6).toUpperCase().indexOf("SOFT") >= 0) {                Form.leftSK = -6;                Form.rightSK = -7;                return;            }            if(getKeyName(21).toUpperCase().indexOf("SOFT") >= 0) {                Form.leftSK = 21;                Form.rightSK = 22;                return;            }        } catch(Exception ex) { }        boolean leftInit = false;        boolean rightInit = false;        for(int i = -127; i < 127; i++) {            if(leftInit && rightInit){  //I have added this if to avoid unnecessary loops                return; //but the main reason is that sometimes after the correct negative values were initialized also positive            }          // keycodes had "soft" in the name.            try {                if(getKeyName(i).toUpperCase().indexOf("SOFT") < 0)                    continue;                if(getKeyName(i).indexOf("1") >= 0) {                    Form.leftSK = i;                    leftInit = true;                }                if(getKeyName(i).indexOf("2") >= 0) {                    Form.rightSK = i;                    rightInit = true;                }                continue;            } catch(Exception ex) {                            }        }    }        int getDisplayWidth() {        return getWidth();    }    int getDisplayHeight() {        return getHeight();    }

⌨️ 快捷键说明

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