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

📄 datefield.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        int numEls = (mode == DATE_TIME) ? 2 : 1;        if (!traversedIn) {            traversedIn = true;            if (highlight == -1) {                switch (dir) {                    case Canvas.UP:                        highlight = numEls - 1;                        break;                    case Canvas.DOWN:                        highlight = 0;                        break;                    case CustomItem.NONE:                }            }        } else {            if (dir == Canvas.UP) {                if (highlight > 0) {                    highlight--;                } else {                    return false;                }            } else if (dir == Canvas.DOWN) {                if (highlight < (numEls - 1)) {                    highlight++;                } else {                    return false;                }            }        }        visRect[Y] = getLabelHeight(visRect[WIDTH]) + LABEL_PAD;        if (highlight > 0) {            visRect[Y] += Screen.CONTENT_HEIGHT;        }        visRect[HEIGHT] = Screen.CONTENT_HEIGHT;        repaint();        return true;    }    /**     * Called by the system to indicate traversal has left this Item     */    void callTraverseOut() {        super.callTraverseOut();        traversedIn = false;    }    /**     * Called by the system to signal a key press     *     * @param keyCode the key code of the key that has been pressed     */    void callKeyPressed(int keyCode) {        if (keyCode != Display.KEYCODE_SELECT) {            return;        }        Screen returnScreen = getOwner();        if (editor == null) {            editor = new EditScreen(returnScreen, this);        }        switch (mode) {        case DATE:            if (!initialized) {                currentDate.set(Calendar.HOUR, 0);                currentDate.set(Calendar.MINUTE, 0);                currentDate.set(Calendar.SECOND, 0);                currentDate.set(Calendar.MILLISECOND, 0);            }            editor.setDateTime(currentDate.getTime(), DATE);            break;        case TIME:            editor.setDateTime(initialized ? currentDate.getTime() : EPOCH,                               TIME);            break;        case DATE_TIME:            editor.setDateTime(currentDate.getTime(),                               (highlight < 1) ? TIME : DATE);        }        returnScreen.resetToTop = false;        returnScreen.currentDisplay.setCurrent(editor);    }    /**     * Get the am/pm text given a Calandar     *     * @param calendar The Calendar object to retrieve the time from     * @return String The am/pm text based on the time in the calendar     */    static String ampmString(Calendar calendar) {        int hour   = calendar.get(Calendar.HOUR_OF_DAY);        int minute = calendar.get(Calendar.MINUTE);        if (hour >= 12) {            return ((minute == 0) && (hour == 12)) ? "noon" : "PM";        } else {            return ((minute == 0) && (hour == 00)) ? "mid." : "AM";        }    }    /**     * Get the day of the week text given a Calendar     *     * @param calendar The Calendar object to retrieve the date from     * @return String The day of the week text based on the date in the     *                  calendar     */    static String dayOfWeekString(Calendar calendar) {        String str;        switch (calendar.get(Calendar.DAY_OF_WEEK)) {        case Calendar.SUNDAY:    str = "Sun"; break;        case Calendar.MONDAY:    str = "Mon"; break;        case Calendar.TUESDAY:   str = "Tue"; break;        case Calendar.WEDNESDAY: str = "Wed"; break;        case Calendar.THURSDAY:  str = "Thu"; break;        case Calendar.FRIDAY:    str = "Fri"; break;        case Calendar.SATURDAY:  str = "Sat"; break;        default:             str = Integer.toString(calendar.get(Calendar.DAY_OF_WEEK));        }        return str;    }    /**     * Translate the mode of a DateField into a readable string     *     * @param mode The mode to translate     * @return String A human readable string representing the mode of the     *              DateField     */    String toString(int mode) {        if (mode == DATE) {            if (!initialized) {                    return Resource.getString("<date>");            }            return Resource.getDateString(                dayOfWeekString(currentDate),                twoDigits(currentDate.get(Calendar.DATE)),                MONTH_NAMES[currentDate.get(Calendar.MONTH)].substring(0, 3),                Integer.toString(currentDate.get(Calendar.YEAR)));        } else if (mode == TIME) {            if (!initialized) {                    return Resource.getString("<time>");            }            if (CLOCK_USES_AM_PM) {                return Resource.getTimeString(                    twoDigits(currentDate.get(Calendar.HOUR)),                    twoDigits(currentDate.get(Calendar.MINUTE)),                    twoDigits(currentDate.get(Calendar.SECOND)),                    ampmString(currentDate));            } else {                return Resource.getTimeString(                    twoDigits(currentDate.get(Calendar.HOUR_OF_DAY)),                    twoDigits(currentDate.get(Calendar.MINUTE)),                    twoDigits(currentDate.get(Calendar.SECOND)),                    null);            }        } else {            if (!initialized) {                    return Resource.getString("<date/time>");            }            return Resource.getDateTimeString(                dayOfWeekString(currentDate),                twoDigits(currentDate.get(Calendar.DATE)),                MONTH_NAMES[currentDate.get(Calendar.MONTH)].substring(0, 3),                Integer.toString(currentDate.get(Calendar.YEAR)),                twoDigits(currentDate.get(Calendar.HOUR_OF_DAY)),                twoDigits(currentDate.get(Calendar.MINUTE)),                twoDigits(currentDate.get(Calendar.SECOND)),                ampmString(currentDate));        }    }    /**     * Static zero epoch Date - used as a default value for     * uninitialized DateFields with TIME mode.     */    static final java.util.Date EPOCH = new java.util.Date(0);    // REMIND: Needs to be localized?    /**     * Static array holding the names of the 12 months     */    static final String MONTH_NAMES[] = {        "January", "February", "March",     "April",   "May",      "June",        "July",    "August",   "September", "October", "November", "December"    };    /**     * table of trigonometric functions, in 16.16 fixed point     */    static final int TRIG_TABLE[] = {        65535, // cos 0        65525, // cos 1        65495, // cos 2        65445, // cos 3        65375, // cos 4        65285, // cos 5        65175, // cos 6        65046, // cos 7        64897, // cos 8        64728, // cos 9        64539, // cos 10        64330, // cos 11        64102, // cos 12        63855, // cos 13        63588, // cos 14        63301, // cos 15        62996, // cos 16        62671, // cos 17        62327, // cos 18        61964, // cos 19        61582, // cos 20        61182, // cos 21        60762, // cos 22        60325, // cos 23        59869, // cos 24        59394, // cos 25        58902, // cos 26        58392, // cos 27        57863, // cos 28        57318, // cos 29        56754, // cos 30        56174, // cos 31        55576, // cos 32        54962, // cos 33        54330, // cos 34        53683, // cos 35        53018, // cos 36        52338, // cos 37        51642, // cos 38        50930, // cos 39        50202, // cos 40        49459, // cos 41        48701, // cos 42        47929, // cos 43        47141, // cos 44        46340, // cos 45        45524, // cos 46        44694, // cos 47        43851, // cos 48        42994, // cos 49        42125, // cos 50        41242, // cos 51        40347, // cos 52        39439, // cos 53        38520, // cos 54        37589, // cos 55        36646, // cos 56        35692, // cos 57        34728, // cos 58        33753, // cos 59        32767, // cos 60        31771, // cos 61        30766, // cos 62        29752, // cos 63        28728, // cos 64        27696, // cos 65        26655, // cos 66        25606, // cos 67        24549, // cos 68        23485, // cos 69        22414, // cos 70        21336, // cos 71        20251, // cos 72        19160, // cos 73        18063, // cos 74        16961, // cos 75        15854, // cos 76        14742, // cos 77        13625, // cos 78        12504, // cos 79        11380, // cos 80        10251, // cos 81        9120,  // cos 82        7986,  // cos 83        6850,  // cos 84        5711,  // cos 85        4571,  // cos 86        3429,  // cos 87        2287,  // cos 88        1143,  // cos 89        0      // cos 90    };    /**     * Utility method to return the cosine of an angle     *     * @param angle The angle to compute the cosine of     * @return int The cosine of the angle     */    static int cos(int angle) {        angle += 360000;        angle %= 360;        if (angle >= 270) {            return TRIG_TABLE[360 - angle];        } else if (angle >= 180) {            return -TRIG_TABLE[angle - 180];        } else if (angle >= 90) {            return -TRIG_TABLE[180 - angle];        } else {            return TRIG_TABLE[angle];        }    }    /**     * Utility method to return the sin of an angle     *     * @param angle The angle to compute the sin of     * @return int The sin of the angle     */    static int sin(int angle) {        return cos(angle - 90);    }    // private    /**     * A utility method to return a numerical digit as two digits     * if it is less than 10     *     * @param n The number to convert     * @return String The String representing the number in two digits     */    private static String twoDigits(int n) {        if (n == 0) {            return "00";        } else if (n < 10) {            return "0" + n;        } else {            return "" + n;        }    }    /**     * The highlight of this DateField     */    private int highlight = -1;    /**     * A flag indicating a prior call to callTraverse()     */    private boolean traversedIn;    /**     * A flag indicating the initialization state of this DateField     */    private boolean initialized; // = false;    /**     * The mode of this DateField     */    private int mode;    /**     * The editor for this DateField     */    private EditScreen editor = null;    /**     * The last saved date.     * This is used for making the last saved date bold.     */    private Calendar currentDate;    /**     * Flag to signal the clock representation uses AM and PM notation     */    private static final boolean CLOCK_USES_AM_PM = true;    /**     * The image representing an up arrow     */    private static final Image ARROW_UP;    /**     * The image representing an down arrow     */    private static final Image ARROW_DOWN;    /**     * The image representing an left arrow     */    private static final Image ARROW_LEFT;    /**     * The image representing an right arrow     */    private static final Image ARROW_RIGHT;    static {        /*         * Initialize the icons necessary for the date editor.         */        ARROW_UP    = ImmutableImage.createIcon("date_up.png");        ARROW_DOWN  = ImmutableImage.createIcon("date_down.png");        ARROW_LEFT  = ImmutableImage.createIcon("date_left.png");        ARROW_RIGHT = ImmutableImage.createIcon("date_right.png");    }    /**     * The EditScreen class is a special editor for a DateField.     * It can edit both date and time.     */    class EditScreen extends Screen implements CommandListener {        /**         * The calendar holding the date/time for this editor         */        Calendar calendar;        /**         * The mode of this editor (Date, Time, Date & Time)         */        int mode;        /**         * The DateField being edited by this editor         */        DateField field;        /**         * The encapsulating Screen holding the DateField being         * edited by this editor (allows us to return to this screen         * when we are done editing).         */

⌨️ 快捷键说明

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