alertlfimpl.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 846 行 · 第 1/2 页

JAVA
846
字号
        if (alert.text != null) {            g.translate(AlertSkin.MARGIN_H, 0);            Text.paint(g, alert.text, AlertSkin.FONT_TEXT,                       AlertSkin.COLOR_FG, 0,                       viewable[WIDTH], viewable[HEIGHT],                       0, Text.NORMAL, null);            g.translate(-AlertSkin.MARGIN_H, 0);        }    }       /**     * Handle a key press     *     * @param keyCode the key which was pressed     */    void uCallKeyPressed(int keyCode) {        int gameAction = KeyConverter.getGameAction(keyCode);        synchronized (Display.LCDUILock) {            switch (gameAction) {            case Canvas.UP:                if (viewable[Y] > 0) {                    viewable[Y] -= AlertSkin.SCROLL_AMOUNT;                    if (viewable[Y] < 0) {                        viewable[Y] = 0;                    }                    lRequestPaint();                }                break;            case Canvas.DOWN:                if (viewable[Y] < maxScroll) {                    viewable[Y] += AlertSkin.SCROLL_AMOUNT;                    if (viewable[Y] > maxScroll) {                        viewable[Y] = maxScroll;                    }                    lRequestPaint();                }                break;            }        }        setVerticalScroll();    }        /**     * Handle a key repeat     *     * @param keyCode the key which was repeated     */    void uCallKeyRepeated(int keyCode) {        uCallKeyPressed(keyCode);    }        /**     * Notify this Alert that is being displayed on the     * given Display and whether it needs to initialize its     * highlight     */    void lCallShow() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION,                            LogChannels.LC_HIGHUI_FORM_LAYOUT,                           "# in AlertLFImpl: lCallShow");                }        super.lCallShow();        if (alert.type != null) {            currentDisplay.playAlertSound(alert.type);        }        if (alert.indicator != null) {            ((GaugeLFImpl)alert.indicator.gaugeLF).lCallShowNotify();        }                if (!isLayoutValid) {            layout();        }        lSetTimeout(alert.getTimeout());                // We reset any scrolling done in a previous showing        viewable[Y] = 0;                setVerticalScroll();    }    /**     * Notify this Alert that it will no longer be displayed     * on the given Display     */    void lCallHide() {                super.lCallHide();                if (alert.indicator != null) {            ((GaugeLFImpl)alert.indicator.gaugeLF).lCallHideNotify();        }        if (timerTask != null) {            timerTask.cancel();            timerTask = null;        }    }    /**     * Cancel the timer whenever the alert is frozen. Alert is frozen     * when the display does not have foreground     */    void lCallFreeze() {                super.lCallFreeze();        if (timerTask != null) {            timerTask.cancel();            timerTask = null;        }    }    /**      * Called upon content change to schedule a request for relayout and      * repaint.      */    void lRequestInvalidate() {        super.lRequestInvalidate();        isLayoutValid = false;    }        /**     * Set the vertical scroll indicators for this Screen.     * We override this from our superclass because the viewport[] is     * set to the entire Alert dialog, but scrolling is confined to the     * "inner" viewport we've constructed beneath the title to scroll     * the text content. This scrolling behavior is maintained by     * 'maxScroll' - which represents the maximum number of pixels     * needed to scroll in order to reach the bottom of the scrollable     * content. If maxScroll is 0, no scrolling is necessary.     */    void setVerticalScroll() {                if (maxScroll == 0) {            setVerticalScroll(0, 100);        } else {            setVerticalScroll((viewable[Y] * 100 / (maxScroll)),                              ((AlertSkin.HEIGHT - AlertSkin.TITLE_HEIGHT)                                     * 100 / viewable[HEIGHT]));        }    }    /**     * Layout the content of this Alert given the width and     * height parameters     */    void layout() {        super.layout();        // layout() is called from DisplayableLFImpl constructor        // and at that time alert is not initialized        if (alert == null) {            maxScroll = 0;            return;        }        // The width of the viewable area is equal to the width of        // the alert minus a left and right margin        viewable[WIDTH] = getDisplayableWidth() - (2 * AlertSkin.MARGIN_H);        // height of activity indicator, if any        int indHeight = 0;                        if (alert.indicator != null) {            GaugeLFImpl indicatorLF = (GaugeLFImpl)alert.indicator.gaugeLF;            if (indicatorLF.bounds == null) {                indicatorLF.bounds = new int[4];            }                        int pW = indicatorLF.lGetPreferredWidth(-1);            if (pW > viewable[WIDTH] - (2 * AlertSkin.PAD_HORIZ)) {                pW = viewable[WIDTH] - (2 * AlertSkin.PAD_HORIZ);            }            indHeight = indicatorLF.lGetPreferredHeight(pW);            // We assign the item a bounds which is its pixel location,            // width, and height in coordinates which represent offsets            // of the viewport origin (that is, are in the viewport            // coordinate space)            indicatorLF.bounds[X] = 0;            indicatorLF.bounds[Y] = 0;            indicatorLF.bounds[WIDTH]  = pW;            indicatorLF.bounds[HEIGHT] = indHeight;        }                // height of the alert's image, if any        int imageHeight = (alert.image == null) ? 0 : alert.image.getHeight();                // height of the alert's text content, if any        int textHeight = (alert.text == null) ? 0 :             Text.getHeightForWidth(alert.text, AlertSkin.FONT_TEXT,                                   viewable[WIDTH], 0);                // This gives us the height of the scrollable area        viewable[HEIGHT] = AlertSkin.PAD_VERT;        if (indHeight > 0) {                        viewable[HEIGHT] += (indHeight + AlertSkin.PAD_VERT);        }        if (imageHeight > 0) {            viewable[HEIGHT] += (imageHeight + AlertSkin.PAD_VERT);        }        if (textHeight > 0) {            viewable[HEIGHT] += (textHeight + AlertSkin.PAD_VERT);        }                maxScroll = viewable[HEIGHT] -             (AlertSkin.HEIGHT - AlertSkin.TITLE_HEIGHT);        if (maxScroll < 0) {            maxScroll = 0;        }                isLayoutValid = true;    }       /**     * Returns the system image to draw in title area.     * If AlertType is not set, no image is drawn.     * @param alertType The type of the Alert     * @return the image to draw in title area     */    static Image getIcon(AlertType alertType) {        if (alertType == null) {            return null;        }        if (alertType.equals(AlertType.INFO)) {            return AlertSkin.IMAGE_ICON_INFO;        } else if (alertType.equals(AlertType.WARNING)) {            return AlertSkin.IMAGE_ICON_WARN;        } else if (alertType.equals(AlertType.ERROR)) {            return AlertSkin.IMAGE_ICON_ERRR;        } else if (alertType.equals(AlertType.ALARM)) {            return AlertSkin.IMAGE_ICON_ALRM;        } else {             return AlertSkin.IMAGE_ICON_CNFM;        }    }        /**     * Returns the system image to draw in title area.     * If AlertType is not set, no image is drawn.     * @param alertType The type of the Alert     * @return the image to draw in title area     */    String getTitle(AlertType alertType) {        if (alert.title != null) {            return alert.title;        }        if (alertType.equals(AlertType.INFO)) {            return AlertSkin.TEXT_TITLE_INFO;        } else if (alertType.equals(AlertType.WARNING)) {            return AlertSkin.TEXT_TITLE_WARN;        } else if (alertType.equals(AlertType.ERROR)) {            return AlertSkin.TEXT_TITLE_ERRR;        } else if (alertType.equals(AlertType.ALARM)) {            return AlertSkin.TEXT_TITLE_ALRM;        } else {            return AlertSkin.TEXT_TITLE_CNFM;        }    }        /**     * Calculate the height a displayable would occupy if it was to     * be displayed.     *     * @return the height a displayable would occupy      */    public int getDisplayableHeight() {        return currentDisplay != null ?            currentDisplay.getDisplayableHeight() :            AlertSkin.HEIGHT;    }    /**     * Calculate the width a displayable would occupy if it was to     * be displayed     *     * @return the width a displayable would occupy      */    public int getDisplayableWidth() {        return currentDisplay != null ?            currentDisplay.getDisplayableWidth() :            AlertSkin.WIDTH;    }    /**     * The maximum amount of scroll needed to see all the contents     * @return get the maximum scroll amount     */    protected int getMaxScroll() {        return maxScroll;    }        /**     * This is the number of pixels left from the previous "page"     * when a page up or down occurs. The same value is used for line by     * line scrolling      * @return the number of pixels.      */    protected int getScrollAmount() {        return AlertSkin.SCROLL_AMOUNT;    }        /**     * Static default Command for "OK"     */    static final Command OK =        new Command(Resource.getString(ResourceConstants.DONE),                     Command.OK, 0);        /**     * A Timer which serves all Alert objects to schedule     * their timeout tasks     */    static Timer timeoutTimer;        /**     * Variables to hold the clip coordinates     */    int clipx, clipy, clipw, cliph;    /**     * The maximum amount of scroll needed to see all the contents     * of the Alert     */    int maxScroll;        /**     * The total maximum height of this Alert.      * This will be <= AlertSkin.MAX_HEIGHT.     */    int totalHeight;        /**     * Alert associated with this view     */    Alert alert;        /**     * The icon for the Alert     */    Image icon;    /**     * A TimerTask which will be set to expire this Alert after     * its timeout period has elapsed.     */    TimerTask timerTask;    /**     * A flag indicates that whether the layout of the alert     * is known.     */    boolean isLayoutValid; // Default is false        /** local variable for the paint method (title x location) */    int titlex;    /** local variable for the paint method (title y location) */    int titley;    /** local variable for the paint method (title width) */    int titlew;    /** local variable for the paint method (title height) */    int titleh;    /** local variable for the paint method (icon y location) */    int icony;    /** local variable for the paint method (icon width) */    int iconw;    /** local variable for the paint method (icon height) */    int iconh;    /** Alert's title */    String title;    // *****************************************************//  Internal Class// *****************************************************    /**     * A TimerTask subclass which will notify the Display to     * make the 'returnScreen' of this Alert the new current screen.     */    private class TimeoutTask extends TimerTask {                /**         * Create a new timeout task         */        TimeoutTask() { }                /**         * Simply set the Display's current screen to be this         * Alert's return screen         */        public void run() {            // It could be this timeout task got scheduled and in            // the meantime the alert's contents were updated. There is            // a timing condition whereby an old timeout task could dismiss            // an alert which is now updated, so we stop and check to make            // sure the alert is not modal before we go ahead and dismiss it            synchronized (Display.LCDUILock) {                if (lIsModal() || alert.getTimeout() == Alert.FOREVER) {                    return;                }            }            alert.uNotifyTimeout();        }    } // TimeoutTask}

⌨️ 快捷键说明

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