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

📄 mailform.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*MujMail - Simple mail client for J2MECopyright (C) 2006 Nguyen Son Tung <n.sontung@gmail.com>Copyright (C) 2006 Martin Stefan <martin.stefan@centrum.cz>Copyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com> This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package mujmail;import java.util.Vector;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Choice;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.List;import javax.microedition.lcdui.StringItem;import mujmail.MailForm.BPViewingModes.ViewingModesWithActions;import mujmail.util.Functions;//#ifdef MUJMAIL_TOUCH_SCRimport mujmail.pointer.MujMailPointerEventListener;import mujmail.pointer.MujMailPointerEventProducer;//#endif//#ifdef MUJMAIL_HTMLimport mujmail.html.Browser;import mujmail.html.Parser;//#endif/** * Displays the mail header as well as whole mail. */public class MailForm extends Canvas implements Runnable {    private static final boolean DEBUG = false;    static final int COLOR[] = {        0x00000000,        0x00CC0000,        0x00008800,        0x00000088,        0x00CC8800,        0x0000CCCC,        0x00CC00CC,        0x00330000,        0x00003300,        0x00000033,    };    private Displayable prevScreen = this;    static final int MAX_COLORS = 10;    static final int BACKGROUND_COLOR = 0x00FFFFFF;    // graphical modes    public static final byte MODE_LIST = 0; //when we only list the bodyparts of the mail    public static final byte MODE_BASIC = 1; //when we display the first viewable bodypart	    public static final byte MODE_BROWSE = 2; //when we display other bodyparts than the first viewable    static final byte LOAD_BODY = 0;    static final byte REDOWNLOAD_BODY = 1;    private final EventListener pointerEventListener = new EventListener();    //#ifdef MUJMAIL_TOUCH_SCR    private final MujMailPointerEventProducer pointerEventTransformer;    //#endif        byte runMode = LOAD_BODY;    MujMail mujMail; // TODO (Betlista): this doesn't need to here while Mujmail have public static field mujmail     private boolean previewMode = false;    TheBox callBox; //the box that called this MailForm    Command back, listAttachments, showAttachment, deleteAttachment, redownAttchment,            showAddresses, showHeader, addMailToBook, viewConverted;    //#ifdef MUJMAIL_FS    Command exportToFS;    //#endif    // display the attachement as plain text    Command displayAsText;    // exports bodypart to filesystem    Command exportBPToFS;    Command forward, reply, replyAll, quotedReply, delete, edit;    List attchList, mailAdrList;    Form headerForm;    MessageHeader msgHeader; //header of the message that is being displayed    byte bodyPartToRedown; //the particular bodypart that should be redownloaded				    //stuffs for displaying a text bodypart		    int currDisplay = 0; //current text page    byte contextID = MODE_BASIC;    byte currAttachmentID = 0;    byte firstViewable = -1;    /** defines if the bodypart have to be downloaded before reading */    boolean newTextSelected = false;    boolean newConvertedTextSelected = false;    // a Vector of displays that stores the text bodyparts	    Vector textBodyDisplays;    // contains a text of a text bodypart, 	    String textBodyString;        /** The viewing mode of the body part */    private BPViewingModes bpViewingMode;    /**     * Shows previous screen, which reference is stored in {@link #prevScreen}     * variable. Important thing is to set the {@link #contextID} variable, see     * the comment in {@link #setContext(byte)} method.     *      * @see #prevScreen     * @see #contextID     * @see #setContext(byte)     */    public void showPreviousScreen() {        MujMail.mujmail.getDisplay().setCurrent(prevScreen);    }    /**     * Enumeration class of all possible viewing modes of body parts.     * It is possible to obtain instance of ViewingModesWithActions form each     * viewing using method <code>getViewingModeWithActions</code>.     */    public static class BPViewingModes {        /** Used for method <code>toString</code> */        private final String viewingModeString;        private BPViewingModes(String viewingModeString) {            this.viewingModeString = viewingModeString;        }                /** View body part as plain text. */        public static final ViewingModesWithActions PLAIN_TEXT = new PlainTextMode("PLAIN TEXT");        /** View body part as HTML. */        public static final ViewingModesWithActions HTML = new HTMLMode("HTML");        /** View converted body part */        public static final ViewingModesWithActions CONVERTED = new ConvertedMode("CONVERTED");        /** View multimedia body part. */        public static final ViewingModesWithActions MULTIMEDIA = new MultimediaMode("MULTIMEDIA");        /** Do not view this body part. */        public static final ViewingModesWithActions NO_VIEW = new NoViewMode("NO VIEW");        /** View body part as text. That means without any converting.         This viewing mode is converted by method BodyPart.getSpecifiedViewingMode         to PLAIN_TEXT viewing mode. */        public static final ViewingModesWithActions AS_TEXT = new AsTextMode("AS TEXT");                /** View body part according of the information contained in body part.          * Virtual viewing mode. Method getViewingModeWithActions returns         * some other viewing mode. */        public static final BPViewingModes NOT_SPECIFIED = new BPViewingModes("NOT SPECIFIED");        /**         * Gets viewing mode with actions.         * @param bp body part that is actually viewed.         * @return viewing mode with actions.         */        public ViewingModesWithActions getViewingModeWithActions(BodyPart bp) {            if (this instanceof ViewingModesWithActions) {                return (ViewingModesWithActions) this;            }            return bp.getAutoViewingMode();        }        public String toString() {            return viewingModeString;        }        /**         * Viewing modes with methods representing actions that can be done with         * viewing modes.         * There is a subclass of this class for each viewing mode. That is,         * subclassing is used instead of if-else conditions of type:         * <code>if (viewingMode == BPViewingModes.PLAIN_TEXT) {...}</code>         */        public static class ViewingModesWithActions extends BPViewingModes {            private ViewingModesWithActions(String viewingModeString) {                super(viewingModeString);            }            protected String getBodyPartContent(MessageHeader msgHeader, byte currAttachmentID) {                return msgHeader.getBodyPartContent(currAttachmentID);            }            protected boolean prepareForViewingBP(BodyPart actBodyPart, byte ID, MailForm mailForm) {                return true;            }            protected void prepareBeforeDisplayingBP(MailForm mailForm) {            }            protected boolean displayBodyPart(Graphics g, MailForm mailForm) {                return false;            }            protected String preprocessBodyPartBeforeDisplaying(MailForm mailFrom) {                return mailFrom.textBodyString;            }            protected void setCorrectStateOfMailFormAfterPreparingText(MailForm mailFrom) {                mailFrom.newTextSelected = false;            }            protected void up(MailForm mailForm) {            }            protected void down(MailForm mailForm) {            }            protected void initDisplayingVariables(MailForm mailForm) {            }            protected boolean isViewable(BodyPart actBodyPart, Displayable attchList) {                return true;            }                    }        /**         * Class with actions of viewing mode PLAIN_TEXT.         */        private static class PlainTextMode extends ViewingModesWithActions {            private PlainTextMode(String viewingModeString) {                super(viewingModeString);                if (DEBUG) System.out.println("DEBUG PlainTextMode.PlainTextMode()");            }            protected void initDisplayingVariables(MailForm mailForm) {            	if (DEBUG) System.out.println("DEBUG PlainTextMode.initDisplayingVariables(MailForm)");                // init displaying variables                mailForm.newTextSelected = true;                mailForm.currDisplay = 0;            }            protected void down(MailForm mailForm) {            	if (DEBUG) System.out.println("DEBUG PlainTextMode.down(MailForm)");                // skip to the next line                mailForm.currDisplay = (mailForm.currDisplay + (1) + mailForm.textBodyDisplays.size()) % mailForm.textBodyDisplays.size();                mailForm.repaint();                mailForm.serviceRepaints();            }            protected void up(MailForm mailForm) {            	if (DEBUG) System.out.println("DEBUG PlainTextMode.up(MailForm)");                // skip to the previous line                mailForm.currDisplay = (mailForm.currDisplay + (-1) + mailForm.textBodyDisplays.size()) % mailForm.textBodyDisplays.size();                mailForm.repaint();                mailForm.serviceRepaints();            }            protected boolean displayBodyPart(Graphics g, MailForm mailForm) {            	if (DEBUG) System.out.println("DEBUG MailForm - PlainTextMode.displayBodyPart(Graphics, MailForm)");                //BodyPart actBodyPart = mailForm.msgHeader.getBodyPart(mailForm.currAttachmentID);                try {//                    if ( mailForm.msgHeader.getBpType(mailForm.currAttachmentID) == BodyPart.TYPE_TEXT //                    	 || mailForm.msgHeader.get(mailForm.currAttachmentID) ) {                        mailForm.displayPlainTextBodyPart( g );//                    } else if ( mailForm.msgHeader.getBpType(mailForm.currAttachmentID) == BodyPart.TYPE_HTML ) {//                        mailForm.displayHTMLBodyPart( g );//                    } else {//                        //                    }                } catch (MyException ex) {                    ex.printStackTrace();                    return false;                }                return true;            }            protected void prepareBeforeDisplayingBP(MailForm mailForm) {            	if (DEBUG) System.out.println("DEBUG PlainTextMode.prepareBeforeDisplayingBP(MailForm)");                //if a different text body part than the first viewable was chosen                if (mailForm.currAttachmentID != mailForm.firstViewable ) {                    mailForm.newTextSelected = true;                } //then we have to reparse the text            }            protected boolean prepareForViewingBP(BodyPart actBodyPart, byte ID, MailForm mailForm) {            	if (DEBUG) System.out.println("DEBUG PlainTextMode.prepareForViewingBP(...)");                // if a different text bodypart was chosen                if (ID != mailForm.currAttachmentID || !mailForm.newConvertedTextSelected) {                    mailForm.newTextSelected = true;                } //set the flag to null in order to parse a new text                mailForm.currDisplay = 0;                return true;            }        }        /**         * Class with actions of viewing mode AS_TEXT.         */        private static class AsTextMode extends PlainTextMode {            private AsTextMode(String viewingModeString) {                super(viewingModeString);            }            protected String preprocessBodyPartBeforeDisplaying(MailForm mailFrom) {                return mailFrom.textBodyString;            }//            protected String getBodyPartContent(MessageHeader msgHeader, byte currAttachmentID) {//                if (msgHeader.getBodyPart(currAttachmentID).getStorage().isContentRaw()) {//                    return msgHeader.getBodyPart(currAttachmentID).getStorage().getContentRawAsString();//                } else {//                    return super.getBodyPartContent(msgHeader, currAttachmentID);//                }//            }        }        /**         * Class with actions of viewing mode CONVERTED.         */        private static class ConvertedMode extends PlainTextMode {            private ConvertedMode(String viewingModeString) {                super(viewingModeString);            }            protected void setCorrectStateOfMailFormAfterPreparingText(MailForm mailFrom) {                mailFrom.newConvertedTextSelected = false;            }            protected boolean displayBodyPart(Graphics g, MailForm mailForm) {                if (DEBUG) System.out.println("DEBUG - MailForm.CONVERTED_MODE.displayBodyPart");                // if CONVERTED view mode was selected set it back to PLAIN_TEXT                // in order to avoid conversion of previously displayed bodypart                // when Back command is selected                boolean retVal = super.displayBodyPart(g, mailForm);                                mailForm.bpViewingMode = BPViewingModes.PLAIN_TEXT;                return retVal;            }            protected void prepareBeforeDisplayingBP(MailForm mailForm) {                if (mailForm.currAttachmentID != mailForm.firstViewable) {                    mailForm.newConvertedTextSelected = true;                } //then we have to reparse the text            }            protected boolean prepareForViewingBP(BodyPart actBodyPart, byte ID, MailForm mailForm) {                //if a different bodypart was chosen                if (ID != mailForm.currAttachmentID || !mailForm.newTextSelected) {                    mailForm.newConvertedTextSelected = true;                } //set the flag to null in order to parse a new text                mailForm.currDisplay = 0;                return true;            }            protected String getBodyPartContent(MessageHeader msgHeader, byte currAttachmentID) {                return Functions.removeTags( msgHeader.getConvertedBodyPartContent(currAttachmentID) );            }        }        /**         * Class with actions of viewing mode MULTIMEDIA.         */

⌨️ 快捷键说明

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