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

📄 funcanvasviewmessage.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        linksCommand=new Command(Localization.getMessages().MVF_LINKS_COMMAND, UIController.COMMAND_TYPE,55);
        //numbersCommand=new Command(Localization.getMessages().MVF_NUMBERS_COMMAND, UIController.COMMAND_TYPE,65);
        fullMessageCommand=new Command(
                Localization.getMessages().MVF_FULL_MSG_CMD,
                UIController.COMMAND_TYPE, 1);
        
        
        //this commands are always present
        this.addCommand(UIController.backCommand);
        this.addCommand(forwardCommand);
        this.addCommand(linksCommand);
        //this.addCommand(numbersCommand);
        
        // This is present if the message is incomplete.
        if(message.getFlags().isSet(MessageFlags.PARTIAL)) {
            this.addCommand(fullMessageCommand);
        }
        
        //this are present if the message is incoming
        if (UiUtils.isIncoming(message)) {
            replyCommand=new Command(Localization.getMessages().MVF_REPLY_COMMAND,UIController.COMMAND_TYPE,9);
            replyAllCommand=new Command(Localization.getMessages().MVF_REPLY_ALL_COMMAND, UIController.COMMAND_TYPE, 15);
            //flagCommand=new Command("Flag",Command.SCREEN,4);
            saveSenderCommand=new Command(Localization.getMessages().MVF_SAVE_SENDER_COMMAND, UIController.COMMAND_TYPE,45);
            recipientsCommand=new Command(Localization.getMessages().MVF_RECIPIENTS_COMMAND,UIController.COMMAND_TYPE,75);
            
            setMarkAsReadCommand();
            setFollowUpCommand();
            
            this.addCommand(deleteCommand);
            this.addCommand(replyCommand);
            this.addCommand(replyAllCommand);
            //this.addCommand(flagCommand);
            this.addCommand(saveSenderCommand);
            this.addCommand(recipientsCommand);
        } else if (UiUtils.isOutgoing(message)) {
            //outbox or draft
            sendCommand=new Command(Localization.getMessages().SEND_COMMAND_LABEL, UIController.COMMAND_TYPE, 0);
            editCommand=new Command(Localization.getMessages().EDIT_COMMAND_LABEL, UIController.COMMAND_TYPE, 1);
            this.addCommand(sendCommand);
            this.addCommand(editCommand);
        } else if (UiUtils.isSent(message)) {
            //sendCommand=new Command(Localization.getMessages("MVF_ResendCommand"),UIController.COMMAND_TYPE, 0);
            editCommand=new Command(Localization.getMessages().EDIT_COMMAND_LABEL, UIController.COMMAND_TYPE, 1);
            //this.addCommand(sendCommand);
            this.addCommand(editCommand);
        }
        this.setCommandListener(this);
        
    }
    
    private void setMarkAsReadCommand() {
        
        removeCommand(markAsReadCommand);
        if(message.getFlags().isSet(MessageFlags.OPENED))
            markAsReadCommand = new Command(Localization.getMessages().UNREAD_COMMAND_LABEL, UIController.COMMAND_TYPE,35);
        else
            markAsReadCommand = new Command(Localization.getMessages().READ_COMMAND_LABEL, UIController.COMMAND_TYPE,35);
        
        this.addCommand(markAsReadCommand);
    }
    
    private void setFollowUpCommand() {
        
        removeCommand(followUpCommand);
        if(message.getFlags().isSet(MessageFlags.FLAGGED))
            followUpCommand = new Command(Localization.getMessages().UNFLAG_COMMAND_LABEL, UIController.COMMAND_TYPE,30);
        else
            followUpCommand = new Command(Localization.getMessages().FLAG_COMMAND_LABEL, UIController.COMMAND_TYPE,30);
        
        this.addCommand(followUpCommand);
    }
    
    /**
     *
     */
    public void commandAction(Command command, Displayable displayable) {
        
        if (command==UIController.backCommand) {
            
            try {
                if (!SyncClient.isBusy()) {
                    UIController.getInboxMessageList().resetTitle();
                }
                UIController.getInboxMessageList().activate(
                        UIController.getInboxMessageList().getActiveElement());
                
                cleanup();    // FIXME
                UIController.showInboxScreen();
                
                //UIController.showBackScreen();
                
            } catch (Exception ex) {
                ex.printStackTrace();
                Log.error("ViewMessage: "+ex);
            }
        } else if (command==replyCommand) {
            UIController.replyMessage(message);
            cleanup();    // FIXME
        } else if (command==forwardCommand) {
            UIController.forwardMessage(message);
            cleanup();    // FIXME
        } else if (command==deleteCommand) {
            UIController.deleteMessage(message);
            cleanup();    // FIXME
            UIController.showInboxScreen();
        } else if (command==saveSenderCommand) {
            if (UIController.checkContactListFull()) {
                UIController.showErrorAlert(
                        Localization.getMessages().AB_LIMIT_ERROR_MSG);
                return;
            }
            Contact contact;
            try {
                if (message.getFrom() != null) {
                    contact = new Contact(
                            message.getFrom().getName(),
                            message.getFrom().getEmail());
                    UIController.showAddContactScreen(
                            UIController.display.getCurrent(),contact);
                } else {
                    UIController.showAlert(Localization.getMessages().FROM_IS_NULL);
                }
                
            } catch (Exception ex) {
                ex.printStackTrace();
                Log.error(this, "Mail Exception while adding Contact" + ex);
                UIController.showAddContactScreen(UIController.display.getCurrent());
                UIController.showErrorAlert(
                        Localization.getMessages().MESSAGE_VIEW_UNABLE_TO_CREATE_CONTACT);
            }
            
        }  else if (command==linksCommand) {
            UIController.showLinkList(UIController.display.getCurrent(), message.getTextContent());
        }
        /*else if (command==numbersCommand ){
            UIController.showPhoneNumberList(UIController.display.getCurrent(), message.getTextContent());
        }*/
        else if (command==recipientsCommand) {
            UIController.showRecipientsList(UIController.display.getCurrent(), message);
        } else if (command==editCommand) {
            message.setMessageId(message.createUniqueMessageIDValue());
            UIController.updateComposeMessageScreen(message,"");
            UIController.showComposeMessageScreen(UIController.display.getCurrent(),UIController.getComposeMessageScreen().body);
            //XXX
        } else if (command==replyAllCommand) {
            UIController.replyAll(message);
            cleanup();    // FIXME
        } else if (command == markAsReadCommand) {
            UIController.changeReadFlag(message);
            setMarkAsReadCommand();
        } else if (command == followUpCommand) {
            UIController.changeFollowUpFlag(message);
            setFollowUpCommand();
        } else if (command==fullMessageCommand) {
            this.removeCommand(fullMessageCommand);
            this.setTitle(Localization.getMessages().MVF_FULL_MESSAGE_LOADING);
            UIController.getThreadPool().startThread(this);
        } else {
            Log.info("MessageViewForm: command not implemented");
        }
    }
    
    private void enterBody(int dir) {
        insideBody = true;
    }
    
    protected void keyRepeated(int keyCode) {
        keyPressed(keyCode);
    }
    
    
    private void drawScrollBar(Graphics g, int h) {
        
        int maxHeight = getHeight() - h;
        
        
        int barheight = (int) ( ( ( bodyItem.getLastLine()*100 -
                bodyItem.getCurrentLine()*100 ) /bodyItem.getNumLines())
                * maxHeight)/100;
        int barposition = (int) (h+((100*  bodyItem.getCurrentLine()* maxHeight
                / bodyItem.getNumLines() ) )/100);
        
        g.setColor(theme.getForegroundColor());
        g.drawRect(getWidth()- SCROLLBAR_WIDTH, h, SCROLLBAR_WIDTH, maxHeight);
        g.fillRect(getWidth() - SCROLLBAR_WIDTH,barposition, SCROLLBAR_WIDTH,
                barheight);
    }
    
    
    /**
     * get the full message
     */
    public void run() {
        this.removeCommand(fullMessageCommand);
        setMessage(UIController.getFullMessage(message));
    }
    
    /**
     * FIXME: this is just a patch. Needs to find why the viewMessage is
     * not collected by the gc.
     */
    private void cleanup() {
        this.message=null;
        this.bodyItem=null;
        this.headerItem=null;
    }
    
    private void setMessage(Message fullmsg) {
        FunCanvasMessageList fcml = UIController.getMessageList(message);
        if(fullmsg == null ) {
            Log.info("The server didn't send the full message.");
            return;
        }
        
        if ( bodyItem == null || headerItem == null ) {
            Log.info("bodyItem == null || headerItem == null ");
            return;
        }
        
        try {
            fullmsg.setParent(message.getParent());
            //Fix for message flags - see 2772 bug
            fullmsg.setFlags(message.getFlags());
            message = fullmsg;
            bodyItem.setMessage(message);
            headerItem.setMessage(message);
            this.setTitle(
                    (message.getFrom()==null)?"":message.getFrom().getVisibleName());
        } catch(MailException e) {
            this.setTitle(Localization.getMessages().MESSAGE_VIEW_FORM_TITLE);
            Log.error("Error getting VisibleName - " + e.getMessage());
            e.printStackTrace();
        } finally {
            this.removeCommand(fullMessageCommand);
            setTitle("Message " + (fcml.getActiveElement()+1)
            + " of " + fcml.getNumMessages());
        }
    }
    
    
    
//------------------------------BODYITEM CLASS ---------------------------//
    
    /**
     * This class handle the visualization of the body of the message.
     */
    class BodyItem {
        private int currentLine;
        private int maxLineIndex;
        private int fontHeight;
        private Vector textStringsVector;
        private String[] textStrings;
        private int bodyLastWidth = -1;
        private int screenHeight;
        
        
        private int lastline;
        
        public BodyItem() {
            fontHeight = bodyFont.getHeight();
            screenHeight = getHeight();
        }
        
        public void traverse(int dir) {
    /*
            for future implementation of internal navigation
     
            if( dir == Canvas.RIGHT) {
                toNextMessage();
                return true;
            } else if (dir == Canvas.LEFT) {
                toPreviousMessage();
                return true;
            }
     */
            if (insideBody) {
                if (dir == Canvas.DOWN) {
                    scroll(Canvas.DOWN);
                    if ( isAtBottom() ) {
                        
                        currentLine =    Math.max( maxLineIndex + 2 -
                                screenHeight / fontHeight, 0);
                        //visRect_inout[1] = calculateY(viewportHeight);
                        exitBody(dir);
                    }
                } else if (dir == Canvas.UP) {
                    scroll(Canvas.UP);
                    if ( isAtTop() ) {
                        currentLine = 0;
                        exitBody(dir);
                    }
                }
            }
        }
        
        public void setMessage(Message fullmsg) {
            //we add a \n to the messagebody for nicer visualization
            textStrings=getStringArray(fullmsg.getTextContent()+" \r\n",bodyLastWidth, bodyFont);
            maxLineIndex = Math.max(textStrings.length -1, 1);
            //       Log.debug (this, "new max line index " + maxLineIndex);
            
        }
        private void scroll(int dir) {
            if ( dir == Canvas.DOWN ) {
                currentLine += SCROLL_AMOUNT ;
            } else if (dir == Canvas.UP) {
                currentLine -= SCROLL_AMOUNT;
            }
            // Log.info ("Currentline: " + currentLine);
        }
        
        /**
         * draw the element with given width starting at given height
         *
         *@return the height to start painting the next item
         */
        public int draw(Graphics g, int w, int h) {
            //  Log.debug(this, "initializing body vectors");
            initializeBodyStringVectors(w-3*MARGIN);
            //   Log.debug(this, " body vectors initialized");
            
            //  drawer.drawBackground(g,w,h,false);
            
            //we draw the lines
            int i;
            for (i= currentLine; i<=currentLine + screenHeight/fontHeight; i++ ) {
                if (i<textStrings.length) {
                    drawer.drawString(textStrings[i], g, MARGIN, h, false);
                    h+=fontHeight;
                    
                } else {
                    break;
                }
            }
            lastline = i;
            
            return h ;
        }
        
        private void initializeBodyStringVectors(int w){
            if (bodyLastWidth!=w) {
                
                //we add a \n to have nicer visualization
                textStrings=getStringArray(message.getTextContent()+" \n",w,
                        drawer.getGraphicalTheme().getDefaultFont());
                bodyLastWidth = w;
                maxLineIndex = Math.max(textStrings.length -1,1);
            }
        }
        private boolean isAtBottom() {
            return (currentLine -2 + screenHeight/fontHeight >=maxLineIndex);
        }
        
        private boolean isAtTop() {
            return ( currentLine <= 0 );
        }
        
        protected int getCurrentLine() {
            return currentLine;
        }
        
        protected int getLastLine() {
            return lastline;
        }
        
        protected int getNumLines() {
            return maxLineIndex;
        }
        
        
        
    }
    
    //------------------------------- HEADERITEM CLASS -----------------------//
    
    /**
     * This class handle the visualization of the body of the message.
     */
    class HeaderItem {
        private int headerLastWidth=-1;
        private boolean expanded;
        

⌨️ 快捷键说明

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