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

📄 menu.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                leftPressedAction();
                break;

            case FIRE:
                firePressedAction();
                break;
        }
    }
    
    /**
     * The action when left button was pressed.
     */
    private void leftPressedAction() {
        setSelectedTab((byte) (currTab - 1));
    }
    
    /**
     * The action when left button was pressed.
     */
    private void rightPressedAction() {
        setSelectedTab((byte) (currTab + 1));
    }
    
    /**
     * The action when up button was pressed.
     */
    private void upPressedAction() {
        setSelectedItem((short) (currItem - 1));
    }
    
    /**
     * The action when down button was pressed.
     */
    private void downPressedAction() {
        setSelectedItem((short) (currItem + 1));
    }
    
    /**
     * The action when fire button was pressed.
     */
    private void firePressedAction() {
        commandAction(null, this);
    }

    /**
     * Reacts on keys being held. It occurs only while pressing arrows in the menu.
     * @param keyCode - a code of key that is held.
     */
    protected void keyRepeated(int keyCode) {
        if (hasRepeatEvents()) {
            int gameAction = getGameAction(keyCode);
            if (gameAction == UP || gameAction == DOWN || gameAction == RIGHT || gameAction == LEFT) {
                starPressed = false;
                poundPressed = false;
                // stop TickerTask
                cancelTickerTask();
            }

            switch (gameAction) {
                case UP:
                    upPressedAction();
                    break;

                case DOWN:
                    downPressedAction();
                    break;

                case RIGHT:
                    rightPressedAction();
                    break;

                case LEFT:
                    leftPressedAction();
                    break;
            }
        }
    }

    private short getMaxItems() {
        short j = 0;
        short itemCount = (short) tabs[currTab].item.size();
        int y = 0;
        while (y + fontHeight < clientHeight && j < itemCount) {
            MenuItem mi = (MenuItem) (tabs[currTab].item.elementAt((firstItem + j) % itemCount));
            // if there is only one line
            if (mi.value == null) {
                y += fontHeight;
            } else if (y + 2 * fontHeight <= clientHeight) {
                y += 2 * fontHeight;
            } else {
                // to set maxItems correctly afterwards
                //++j;
                break;
            }
            ++j;
        }

        return j;
    }

    /**
     * Recounts three variables that describe current position of the item cursor.
     * These variables are:
     * <ul>
     *    <li><B>firstItem</B> - it is in range of <0 .. itemCount - maxDsplItems -1> and determines a
     * <CODE>Vector</CODE> ID of the first item on the current display.</li>
     *    <li><B>currItem</B> - it is in range of <0 .. itemCount - 1> and holds an ID of the <CODE>MenuItem Vector</CODE> of
     *    the item that is selected.</li>
     *    <li><B>selectedItem</B> - it is in range of <0 .. maxDsplItem - 1> and describes just relative
     *    position of the cursor from the firstItem.</li>
     * <ul>
     * @param newItem - ID of the new position.
     */
    public void setSelectedItem(short newItem) {
        cancelTickerTask();
        // count new positions		
        short itemCount = (short) tabs[currTab].item.size();
        if (itemCount == 0) {
            return;
        }

        short offset = (short) (newItem - currItem);
        short newCurrItem = (short) (currItem + offset);
        currItem = (short) ((newCurrItem + itemCount) % itemCount);
        short maxItems = getMaxItems();

        // cursor is at the begining
        if (newCurrItem < 0) {
            firstItem = (short) ((currItem - maxItems + itemCount + 1) % itemCount);
            selectedItem = (short) (maxItems - 1);
        } // cursor is at the end
        else if (newCurrItem >= itemCount) {
            firstItem = currItem;
            selectedItem = 0;
        } // cursor is in the middle
        else if (selectedItem + offset >= 0 && selectedItem + offset < maxItems) {
            selectedItem += offset;
        } // cursor is at the beginning of the display
        else if (selectedItem + offset < 0) {
            firstItem = currItem;
            selectedItem = 0;
        } // cursor is at the end of the display
        else if (selectedItem + offset >= maxItems) {
            firstItem = (short) ((currItem - maxItems + itemCount + 1) % itemCount);
            selectedItem = (short) (maxItems - 1);
        }
        
        //#ifdef MUJMAIL_USR_FOLDERS
        // Customize user folder actions
        if ( getSelectedTab() == FOLDERS) {
            addCommand(select);
            if (currItem == MENU_FOLDERS_SEPARATOR) removeCommand(select);
            
            if (currItem >= MENU_FOLDERS_USERBOX_FIRST) {
                addCommand(fldEdit);
                addCommand(fldDel);
            } else {
                removeCommand(fldEdit);
                removeCommand(fldDel);
            }
        }
        //#endif
        repaint();

    }

    /**
     *
     * @return current position of the cursor.
     */
    public short getSelectedIndex() {
        return currItem;
    }

    void cancelTickerTask() {
        if (timer != null) {
            timer.cancel();
            timer = null;
            sindex = 0;
            aindex = 0;
            sStarted = false;
            aStarted = false;
        }
    }

    void cancelRefreshTask() {
        if (refreshTimer != null) {
            refreshTimer.cancel();
            refreshTimer = null;
        }
    }

    /**
     * Recounts three variables that describe current position of the tab cursor.
     * These variables are:
     * <ul>
     *    <li><B>firstTab</B> - it is in range of <0 .. MAX_TABS - maxTabs -1> where maxTabs is a count
     * of tabs that fits to the display's width. It determines a
     * <CODE>Menu Array</CODE> ID of the first tab on the display.</li>
     *    <li><B>currTab</B> - it is in range of <0 .. MAX_TABS - 1> and holds an ID of the <CODE>Menu Array</CODE>
     * of the tab that is selected.</li>
     *    <li><B>selectedTab</B> - it is in range of <0 .. maxTabs - 1> and describes just relative
     *    position of the cursor from the firstTab which is displayed on selectTab = 0 position.</li>
     * <ul>
     * @param newTab - a new position of the tab cursor.
     */
    public void setSelectedTab(byte newTab) {
        if (DEBUG) { System.out.println("setSelectedTab(byte) - start"); }
        cancelRefreshTask();
        cancelTickerTask();
        // move a cursor of the list item at the begining
        firstItem = 0;
        currItem = 0;
        selectedItem = 0;

        // count new positions
        byte offset = (byte) (newTab - currTab);

        byte newCurrTab = (byte) (currTab + offset);
        currTab = (byte) ((newCurrTab + MAX_TABS) % MAX_TABS);

        // if paint method has not been called yet
        if (maxTabs == 0) {
            firstTab = currTab;
            selectedTab = 0;
        } // cursor is at the beginning
        else if (newCurrTab < 0) {
            firstTab = (byte) ((currTab - maxTabs + MAX_TABS + 1) % MAX_TABS);
            selectedTab = (byte) (maxTabs - 1);
        } // cursor is at the end
        else if (newCurrTab >= MAX_TABS) {
            firstTab = currTab;
            selectedTab = 0;
        } // cursor is in the middle
        else if (selectedTab + offset >= 0 && selectedTab + offset < maxTabs) {
            selectedTab += offset;
        } // cursor is at the beginning of the display
        else if (selectedTab + offset < 0) {
            firstTab = currTab;
            selectedTab = 0;
        } // cursor is at the end of the display
        else if (selectedTab + offset >= maxTabs) {
            firstTab = (byte) ((currTab - maxTabs + MAX_TABS + 1) % MAX_TABS);
            selectedTab = (byte) (maxTabs - 1);
        }

        setTabContext(currTab);

        // TODO: not necessary?
        repaint();

        mujMail.getDisplay().setCurrent(this);

        if (DEBUG) System.out.println("setSelectedTab(byte) - end");
    }

    /**
     * @return current position of the cursor.
     */
    public byte getSelectedTab() {
        return currTab;
    }

    public String getSelectedAccount() {
        if (tabs[getSelectedTab()].item.isEmpty()) {
            return null;
        }
        short index = getSelectedIndex();
        MenuItem itm = (MenuItem) tabs[getSelectedTab()].item.elementAt(index);
        return itm.name;
    }

    private void setTabContext(byte currTab) {
        removeCommand(cmdNew);
        removeCommand(change);
        removeCommand(delete);
        removeCommand(setPrimary);
        removeCommand(retrieve);
        removeCommand(clear);
        //#ifdef MUJMAIL_USR_FOLDERS
        removeCommand(fldAdd);
        removeCommand(fldEdit);
        removeCommand(fldDel);
        //#endif
        addCommand(select);
        switch (currTab) {
            case ACTION:
                break;
            //#ifdef MUJMAIL_USR_FOLDERS
            case FOLDERS:
                addCommand(fldAdd);
                if (getSelectedIndex() >= MENU_FOLDERS_USERBOX_FIRST) {
   

⌨️ 快捷键说明

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