composemessageform.java

来自「moblie syncml mail javame」· Java 代码 · 共 437 行 · 第 1/2 页

JAVA
437
字号
                }
                this.originalMessage = null;
            }
        } else if (command==sendLaterCommand) {
            //Log.debug(this, "Send later command pressed");
            if (prepareMessage()) {
                addToFlagQueue();
                UIController.sendLaterMessage(message);
                this.originalMessage = null;
            }
        } else if (command== recipientStringItem.addRecipientsCommand ){
            commandAction(command, recipientStringItem);
        } else if (command==saveCommand) {
            if (prepareMessage()) {
                UIController.saveMessage(message);
                this.setToAppend("");
            }
        }else if(command == UIController.blackberryExitCommand) {
            UIController.midlet.destroyApp( false );
        }else {
            Log.error(this, "Error: unrecognized command");
        }

    }

    /**
     * open the recipent list
     */
    private void openContactList() {

        message.setSubject(subject.getString());
        try {
            //message.setContent(body.getString());
            message.setTextBody(body.getString());
        } catch (MailException ex) {
            ex.printStackTrace();
            Log.error(this, "Message body invalid!");
        }

        //    UIController.showAddressList(UIController.display.getCurrent(), message);
        UIController.getContactList().setMessage(message);
        UIController.getContactList().SortByState();
        UIController.getContactList().handleKey(Canvas.KEY_NUM0);

        UIController.showContactList(this);
    }

    public void update() {
        String content = message.getTextContent();
      
        if ((content!=null) && (content.length() > body.getMaxSize())) {
                String sub = content.substring(0, body.getMaxSize()-5);
            body.setString(sub + " ...");
        } else {
            body.setString(content);
        }
        if ((message.getSubject()!=null) && (message.getSubject().length() > MAX_SUBJECT_SIZE)) {
            subject.setString(message.getSubject().substring(0, MAX_SUBJECT_SIZE-5) + " ...");
        } else {
            subject.setString(message.getSubject());
        }
        recipientStringItem.setMessage(message);

    }

    private boolean prepareMessage() {
        try {
            if ((recipientStringItem.getText().equals(Localization.getMessages().SELECT_RECIPIENTS))) {
                UIController.showAlert(
                        Localization.getMessages().COMPOSE_MESSAGE_FORM_ERROR_MESSAGE,
                        UIController.display.getCurrent());
                return false;
            } else {
                message.setFrom(UIController.getMyFrom());
                message.setSubject(subject.getString());
                //message.setContent(body.getString() + getToAppend());
                message.setTextBody(body.getString() + getToAppend());
                return true;
            }
        } catch (MailException ex) {
            ex.printStackTrace();
            Log.error(this, "Message body invalid!");
            return false;
        }
    }

    public void setMessage(Message message) {
        this.message=message;
        update();
    }
    

    public TextField getBody() {
        return body;
    }

    public TextField getSubject() {
        return subject;
    }

    public String getToAppend() {
        return toAppend;
    }

    public void setToAppend(String toAppend) {

        this.toAppend = toAppend;

    //Log.debug(this, "toAppend = " + getToAppend());
    }
    

    /**
     * enable or disable the send command
     * @param enable if true enable the command, if false disable the command
     */
    public void enableSendCommand(boolean enable) {
        Log.debug(this, "Enable sync commands: " + enable);
        if(enable) {
            addCommand(sendCommand);
        } else {
            removeCommand(sendCommand);
        }
    }
    
    
    

    /**
     * set the flags that will be added to the flagqueue for the original message
     * when this message will be sent
     * original message must be set using setOriginalMessage before addToFlagQueue
     * method is called (usually at the send or sendlater command action)
     */
    public void setMessageFlag(int flag) {
        flagToBeSet = flag;
    }
    /*
    public void setFlagsToSet(MessageFlags flag) {
    
    // Log.info(this,  "setting new flag to " +flag.getFlags());
    flagsToSet = flag;
    }*/

    /**
     * if this method is called, with a non-null message,
     * when the send or send later command is pressed,
     * the message passed will have the flags given by
     * the value set by setFlagsToSet added to the flagqueue
     */
    public void setOriginalMessage(Message message) {

        //   Log.info(this, "setting original message to " +
        //           message.getSubject() + "(" + message.getMessageId() +")");
        this.originalMessage = message;

    }

    /**
     * this method adds the messagequeue
     */
    private void addToFlagQueue() {
        if (originalMessage != null) {
            //    Log.info(this, "original message is not null, updateing message flags");
            UIController.messageManager.updateMessageFlag(originalMessage, flagToBeSet, true);
            originalMessage = null;
        }
    }

    private class PopupCancelCompose implements PopupAction {

        public PopupCancelCompose() {
            
        }

        public void cancel() {
            UIController.showBackScreen();
        }

        public void confirm() {
            // UIController.destroyAddressList();
            originalMessage = null;

            if((message.getParent() != null) && message.getParent().getFullName().equals("/Outbox")){
                //Editing a message in OUTBOX folder and clicking cancelCommand
                //return in OUTBOX folder
                UIController.updateOutboxMessageList("");
                UIController.showOutboxScreen(null);
            }else if ((message.getParent() != null) && (message.getParent().getFullName().equals("/Drafts"))){
                //Editing a message in DRAFT folder and clicking cancelCommand
                //return in DRAFT folder
                UIController.updateDraftMessageList("");
                UIController.showDraftScreen(null);
            } else{
                UIController.showInboxScreen();
            }

            if (!UIController.getContactsLoader().isLocked()) {
                UIController.getContactList().SortAlphabetically();
            }
        }
    }
    
    private Image getLineImage() {
        int w = getWidth();
        if (w == 0) {
            w = UIController.getInboxMessageList().screenWidth;
        }
            
        Image i = Image.createImage(w , LINE_H);
        i.getGraphics().setColor(UIController.getDrawer().getGraphicalTheme().getForegroundColor());
        i.getGraphics().fillRect(0, 0, w, LINE_H);
        return i;
        
    }
    
}

⌨️ 快捷键说明

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