⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platformcanvas.se

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 SE
字号:
package com.jmobilecore.ui.core;

import javax.microedition.lcdui.*;

/**
 * Provides platform dependent settings for SonyEricsson platform
 *
 * @author Greg Gridin
 */
abstract public class PlatformCanvas extends Canvas {

    static public final byte PLATFORM_BARTEO = 1;
    static public final byte PLATFORM_LG = 2;
    static public final byte PLATFORM_MOTOROLA = 3;
    static public final byte PLATFORM_MOTOROLA_V = 4;
    static public final byte PLATFORM_NOKIA = 5;
    static public final byte PLATFORM_NOKIA_30 = 6;
    static public final byte PLATFORM_SIEMENS = 7;
    static public final byte PLATFORM_SAMSUNG = 8;
    static public final byte PLATFORM_SONYERICSSON = 9;
    static public final byte PLATFORM_SUN_WTK = 10;

    static public final byte PLATFORM = PLATFORM_SONYERICSSON;

    /**
     * This class is created specifically for SE phones, which does not provide
     * key press codes for right soft buttons in Canvas
     * This class imitates pressing of soft button key when corresponding command is received
     */
    class SoftKeyListener implements CommandListener {

        private Command leftCommand;
        private Command rightCommand;

        /**
         * Constructs new <code>SoftKeyListener</code> instance.
         *
         * @param rightCommand - Command for the right soft key
         */
        public SoftKeyListener(Command leftCommand, Command rightCommand) {

            this.leftCommand = leftCommand;
            this.rightCommand = rightCommand;
        }

        /**
         * Imitates key press when correspondent command is received
         *
         * @param command - command event
         * @param display - displayable object
         */
        public void commandAction(Command command, Displayable display) {

            if (display == null || command == null) return;

            if (leftCommand != null && leftCommand.equals(command) && display instanceof ScreenCanvas) {
                ((ScreenCanvas) display).keyPressed(PlatformCanvas.KEY_SOFT_LEFT);
                return;
            }
            if (rightCommand != null && rightCommand.equals(command) && display instanceof ScreenCanvas) {
                ((ScreenCanvas) display).keyPressed(PlatformCanvas.KEY_SOFT_RIGHT);
                return;
            }
        }
    }  // class SoftKeyListener

    public PlatformCanvas() {

        Command leftCommand = new Command("", Command.OK, 1);
        Command rightCommand = new Command("", Command.CANCEL, 1);
        addCommand(leftCommand);
        addCommand(rightCommand);
        setCommandListener(new SoftKeyListener(leftCommand, rightCommand));
    }

    /**
     * The width in pixels of a screen
     */
    public static final int WIDTH;

    /**
     * The height in pixels of a screen
     */
    public static final int HEIGHT;

    /**
     * Indicated whether the phone has hardware support for double buffering for screen painting
     * Siemens phones supports double buffering badly. It is preferable to perform double buffering manually
     */
    public static final boolean DOUBLE_BUFFER = false;

    static {
        Canvas dummy = new Canvas() {
            public void paint(Graphics g) {
            }
        };
        WIDTH = dummy.getWidth();
        HEIGHT = dummy.getHeight();
        dummy = null;
    }

    /**
     * "No-key" key code
     */
    public static final int KEY_UNDEFINED = 0;

    /**
     * Key code for the UP game action.
     */
    public static final int KEY_UP = -1;

    /**
     * Key code for the LEFT game action.
     */
    public static final int KEY_LEFT = -3;

    /**
     * Key code for the RIGHT game action.
     */
    public static final int KEY_RIGHT = -4;

    /**
     * Key code for the DOWN game action.
     */
    public static final int KEY_DOWN = -2;

    /**
     * Key code for the FIRE game action.
     */
    public static final int KEY_FIRE = -5;

    /**
     * Key code for left soft key
     */
    public static final int KEY_SOFT_LEFT = -6;

    /**
     * Key code for right soft key
     */
    public static final int KEY_SOFT_RIGHT = -7;

    /**
     * Key code for PHONE_ON key (green button)
     */
    public static final int KEY_PHONE_ON = KEY_UNDEFINED;

    /**
     * Key code for PHONE_OFF key (red button)
     */
    public static final int KEY_PHONE_OFF = KEY_UNDEFINED;

    /**
     * Key code for CLEAR key
     */
    public static final int KEY_CLEAR = -8;

    /**
     * Key code for VOLUME UP key
     */
    public static final int KEY_VOLUME_UP = UP;

    /**
     * Key code for VOLUME DOWN key
     */
    public static final int KEY_VOLUME_DOWN = DOWN;

    /**
     * Key code for BACK key (SonyEricsson phones)
     */
    public static final int KEY_BACK = -11;

    /**
     * Key code for "fictitious" ENTER key
     * Some phones does not have FIRE button, we have to find out the replacement
     */
    public static final int KEY_ENTER = KEY_FIRE;

} // class PlatformCanvas

⌨️ 快捷键说明

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