recipientsstringitem.java

来自「moblie syncml mail javame」· Java 代码 · 共 161 行

JAVA
161
字号
/*
 * 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 com.funambol.mail.Address;
import com.funambol.mail.MailException;
import com.funambol.mail.Message;

import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.loc.Localization;
import com.funambol.util.Log;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Item;

import javax.microedition.lcdui.StringItem;
//import com.funambol.mailclient.ui.mvc.view.AddressList;


public class RecipientsStringItem extends StringItem {
    
    public Command addRecipientsCommand;
    
    // private AddressList addressList;
    private Vector addressVector;
    
    private final String ADD_RECIPIENTS=Localization.getMessages().ADD_RECIPIENTS_COMMAND;
    private final String TO=Localization.getMessages().TO_LABEL;
    private final String CC=Localization.getMessages().CC_LABEL;
    private final String BCC=Localization.getMessages().BCC_LABEL;
    private Message message;
    
    /**
     * Creates a new instance of RecipientsStringItem
     */
    public RecipientsStringItem(Message message) {
        // TODO: use preprocessing here to avoid Motorola Gray Skin issue
        // For Motorola phones use Item.Button apperance mode
        super(null,Localization.getMessages().SELECT_RECIPIENTS, Item.HYPERLINK);
        addRecipientsCommand=new Command(ADD_RECIPIENTS,UIController.COMMAND_TYPE,0);
        this.setDefaultCommand(addRecipientsCommand);
        //this.setItemCommandListener(this);
        
        //TODO: add addresses from the message
        this.setMessage(message);
    }
    
    /**
     * commandlistener implementation
     */
    
    public void update(){
        //TODO: should we use just addressvector  to
        //fill the content of the recipient StringItem?
        //it's slower but more clean...
        //String s=Localization.getMessages("RSIPleaseAddRecipientsMsg");
        String s="";
        try {
            Address list[] = message.getTo();
            if (list != null && list.length > 0) {
                s=TO;
                for(int i=0;i<list.length;i++) {
                    s+= i > 0 ? ", ":"";
                    s+=list[i].getVisibleName();
                    // Log.debug(this, "addedd " + list[i].getVisibleName());
                }
                s+="\n";
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            Log.error(this, "exception parsing to message addresses");
        }
        //Log.debug(this, "to list created, "+list.length+" elements");
        try {
            Address list[] = message.getCc();
            if (list != null && list.length > 0) {
                //  Log.debug("cc list length > 0");
                s+=CC;
                for(int i=0;i<list.length;i++) {
                    s+= i > 0 ? ", ":"";
                    s+=list[i].getVisibleName();
                }
                s+="\n";
            }
        } catch (Exception ex) {
            Log.error(this, "exception parsing cc message addresses");
            ex.printStackTrace();
        }
        //Log.debug(this, "cc list created, "+list.length+" elements");
        
        try {
            Address list[] = message.getBcc();
            if (list != null && list.length > 0) {
                s+=BCC;
                for(int i=0;i<list.length;i++) {
                    s+= i > 0 ? ", ":"";
                    s+=list[i].getVisibleName();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            Log.error(this, "exception parsing Bcc message addresses");
        }
        //Log.debug(this, "bcc list created, "+list.length+" elements");
        
        if (s.equals(""))
            s=Localization.getMessages().SELECT_RECIPIENTS;
        this.setText(s);
    }
    
    void setMessage(Message message) {
        this.message=message;
        update();
    }
    
    public boolean isEmpty() {
        return getText().equals(Localization.getMessages().SELECT_RECIPIENTS);
    }
}

⌨️ 快捷键说明

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