composemessageform.java

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

JAVA
437
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission 
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License 
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably 
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

package com.funambol.mailclient.ui.view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.TextField;

import com.funambol.mail.MailException;
import com.funambol.mail.Message;
import com.funambol.mail.MessageFlags;
import com.funambol.mailclient.loc.Localization;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.util.Log;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Image;

public class ComposeMessageForm extends Form implements ItemCommandListener, CommandListener {

    public RecipientsStringItem recipientStringItem;
    public TextField body;
    public TextField subject;
    private final int MAX_BODY_SIZE=1000;
    private final int MAX_SUBJECT_SIZE=256;
    private Message message;
    private Command sendCommand;
    private Command addRecipientCommand;
    private Command sendLaterCommand;
    private Command saveCommand;
    private String toAppend;
    private int LINE_H = 1;
    //indicate how flags should be changed when forwarding or replying to a message
    private int flagToBeSet;
    
    // the original message
    private Message originalMessage;
    

    /** Creates a new instance of ComposeMessageForm */
    public ComposeMessageForm(Message message, String toAppend) {
        super(Localization.getMessages().COMPOSE_MESSAGE_FORM_TITLE);

        recipientStringItem=new RecipientsStringItem(message);
        recipientStringItem.setItemCommandListener(this);
        this.append(recipientStringItem);
        this.setToAppend(toAppend);
        
        String title = Localization.getMessages().CMF_BODY_TF_LABEL;
        if (UIController.appProperties.isNoCaptionInBodyField()) {
            title = null;
        } 
        body =
                new TextField(title,"",MAX_BODY_SIZE,TextField.ANY);
                
        subject =
                new TextField(Localization.getMessages().CMF_SUBJECT_TF_LABEL ,
                "", MAX_SUBJECT_SIZE,TextField.ANY);
        this.append(subject);
        
        //TODO: Add something to set body size to a nicer dimension!
        if (UIController.appProperties.isNoCaptionInBodyField()) {
            this.append(getLineImage());
        } 
        this.append(body);
        
        addCommands();
        this.setCommandListener(this);
        this.setMessage(message);

    //start loading the contact list
    //  UIController.getThreadPool().startThread(new ContactListLoader());

    }

    private String getDefaultTitle() {
        return Localization.getMessages().COMPOSE_MESSAGE_FORM_TITLE;
    }

    public void setDefaultTitle() {
        this.setTitle(Localization.getMessages().COMPOSE_MESSAGE_FORM_TITLE);
    }

    public ComposeMessageForm(Message message) {
        this(message, "");
    }

    /**
     * calling other constructor with empy message
     */
    public ComposeMessageForm() {
        this(new Message());
    }

    /**
     * returns the message
     */
    public Message getMessage(){
        return message;
    }

    public Item getRecipientStringItem() {
        return recipientStringItem;
    }

    public void commandAction(Command command, Item item) {
        if (command == recipientStringItem.addRecipientsCommand) {
            if (!UIController.getContactsLoader().isLocked()) {
                setTitle(Localization.getMessages().LOADING_CONTACTS);
                //Log.debug(this,"title set, opening contact list");
                openContactList();
                setDefaultTitle();
            } else {
                UIController.showErrorAlert(
                        Localization.getMessages().CONTACTSLOADER_LOCKED_ERROR, 
                        this);
            }
        }
    }

    public void addCommands( ) {
        /**
         * Adding commands
         */
        sendCommand =
                new Command(Localization.getMessages().SEND_COMMAND_LABEL,
                UIController.COMMAND_TYPE, 1);
        sendLaterCommand =
                new Command(Localization.getMessages().CMF_SEND_LATER_COMMAND,
                UIController.COMMAND_TYPE,2);

        saveCommand =
                new Command(Localization.getMessages().SAVE_COMMAND,
                UIController.COMMAND_TYPE,3);
        if (UIController.isSyncPermitted()) {
            addCommand(sendCommand);
        }

        addCommand(sendLaterCommand);
        // TODO: this already present in RecipientStringItem should we use also here?
        //addCommand(addRecipientCommand);
        
        addCommand(saveCommand);
        this.addCommand(UIController.cancelCommand);

    //#ifdef isBlackberry
    //To override blackberry's Close command placed on menus automatically. 
//#        addCommand( UIController.blackberryExitCommand );
    //#endif

    }

    /**
     * Commandlistener implementation
     */
    public void commandAction(Command command, Displayable displayable) {

        Log.debug("command pressed in compose message form");


        if (command==UIController.cancelCommand) {
            /** if ((message.getParent() != null) && (message.getParent().getFullName().equals("/Drafts"))){
             * //Editing a message in DRAFT folder and clicking cancelCommand
             * //return in DRAFT folder without show any alert
             * UIController.updateDraftMessageList("");
             * UIController.showBackScreen();
             * }else { **/
            ModalPopup popup =
                    new ModalPopup("Cancel",
                    Localization.getMessages().CMF_CANCEL_COMMAND,
                    new PopupCancelCompose());
            UIController.showModalPopup(popup, this);
        // }

        } else if (command==sendCommand) {
            //Log.debug(this,"ComposeMessage: sendCommand");
            if (prepareMessage()) {

                addToFlagQueue();
                UIController.setSyncCaller(UIController.USER);
                UIController.sendMessage(message);
                if (!UIController.getContactsLoader().isLocked()) {
                    UIController.getContactList().SortAlphabetically();

⌨️ 快捷键说明

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