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

📄 thebox.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
MujMail - Simple mail client for J2ME
Copyright (C) 2003 Petr Spatka <petr.spatka@centrum.cz>
Copyright (C) 2005 Pavel Machek <pavel@ucw.cz>
Copyright (C) 2006 Nguyen Son Tung <n.sontung@gmail.com>
Copyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the 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 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 General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


package mujmail;

import mujmail.util.Functions;
import java.util.Enumeration;
import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import mujmail.account.MailAccount;
import mujmail.ordering.ComparatorStrategy;
import mujmail.ordering.Criterion;
import mujmail.ordering.Ordering;
import mujmail.protocols.InProtocol;
import mujmail.threading.ThreadedEmails;
//#ifdef MUJMAIL_DEBUG_CONSOLE
import mujmail.debug.DebugConsole;
//#endif
//#ifdef MUJMAIL_TOUCH_SCR
import mujmail.pointer.MujMailPointerEventListener;
import mujmail.pointer.MujMailPointerEventProducer;
//#endif

/**
 * Represents boxes: see Inbox, Outbox, ...
 * 
 * Each message is stored in the container and RMS database of one persistent box.
 * Moreover, it can be stored in the container of more Nonpersistent boxes.
 * See documentation of PersistentBox and UnpersistentBox for more details.
 * 
 * It displays the box. That is, it displays headers of mails in the box (paint()) and
 * it displays the progress bar (paintProgress(), report())
 */
public abstract class TheBox extends Canvas implements CommandListener {
    
    /** Set to true if debug information should be displayed while reporting
     messages using methods report() */
    private static final boolean DEBUG = false;
    
    /** The name of this source file */
    private static final String SOURCE_FILE = "TheBox";
    
    private boolean tickerEnabled = true;

    /** The name of the box that is shown to user */
    private String name;
    
    protected final MujMail mujMail;
    /** Mails in the box. */
    protected IStorage storage;

    int deleted; //counter of mails that are going to be deleted
    /**
     * Index of currently selected message.
     * Even if threading is enabled this number is index to the storage vector
     * (the empty messages are skipped in this index).  
     */
    int cur; //the currently selected mail
    /**
     * This number indicates the number of empty message before {@link #cur}
     * index. It's used when showing index of the message in box.
     */
    int empties;
    byte pageJump; //offset of the next page from the current page of email list
    Image imNormal, imDeleted, imRead, imAnswered, imSent, imFailedSent, imAttch, imFlagged, imRoot;
    public Command stop, exit, delete, deleteNow, viewMessage, empty, sort, seen,
            flagged, showHeader;
    boolean btnsHidden = false; //are some buttons hidden?	
    String activity = "";

    //represents sort mode of the box. 
    //the most right bit represents sort order, the other 3bits represents sort criteria
    //the meaning of criterion bits are defined in Functions.SRT_HDR_*
    //private byte sortMode;

    private Ordering ordering;
    private Criterion criterion;

    /** Item used for text rotating (shifting if too long) */
    Timer tickerTimer;
    short tIndex; //aindex is substring index of the tText, from where the ticker should begin			
    boolean tStarted; //indicates whether the ticker has been initiated
    String tText;//a text of the ticker
    int tY; //y-position of the ticker

    private final EventListener eventListener = new EventListener();
    //#ifdef MUJMAIL_TOUCH_SCR
    private final MujMailPointerEventProducer pointerEventTransformer;
    //#endif

    /** Used to paint something below header details. */
    protected MessagePartPainter belowHeaderDetailsPainter;
    /** Used to paint header details. */
    protected MessagePartPainter headerDetailsPainter;

    protected MujMail getMujMail() {
        if (mujMail == null) {
            System.out.println("mujmail is null");
        }
        return MujMail.mujmail;
    }

    /**
     * Increments the number of deleted messages in this box.
     */
    public void incDeleted() {
        deleted++;
    }

    /**
     * @return the ordering
     */
    public Ordering getOrdering() {
        return ordering;
    }

    public void setOrdering(Ordering ordering) {
        this.ordering = ordering;
    }

    /**
     * @return the criterion
     */
    public Criterion getCriterion() {
        return criterion;
    }

    public void setCriterion(Criterion criterion) {
        this.criterion = criterion;
    }

    public IStorage getStorage() {
        return storage;
    }

    public void setStorage(ThreadedEmails storage) {
        //#ifdef MUJMAIL_DEBUG_CONSOLE
        DebugConsole.println("Setting storage " + storage);
        if (storage == null) {
            DebugConsole.println("Setting storage is null");
            return;
        }
        //#endif
        if ( DEBUG && storage != null ) {
              System.out.println("DEBUG InBox.setStorage(ThreadedEmails) - new storage size: " + (storage == null?"":Integer.toString( storage.getSize()) ) );
              System.out.println("DEBUG InBox.setStorage(ThreadedEmails) - new storage: " );
              //#ifdef MUJMAIL_DEVELOPMENT
//#               ((ThreadedEmails)storage).printToConsole();
              //#endif
          }
          
        this.storage = storage;
    }

    private class Ticker extends TimerTask {

        public void run() {
            tStarted = true;
            if (isBusy()) {
                return;
            }
            repaint(); //we just repaint the needed part not whole screen			
        }
    }

    /**
     * Creates the box.
     * 
     * @param mMail 		the main object in the application
     * @param name 			the name of the box
     * @param searchable 	true if the box should be searchable
     */
    public TheBox(MujMail mMail, String name) {
        
        setBelowHeaderDetailsPainter();
        setHeaderDetailsPainter();
        
        this.name = name;
        mujMail = mMail;
        //storage = new Vector();
        storage = new ThreadedEmails();
        imNormal = Functions.getIcon("m_normal.png");
        imDeleted = Functions.getIcon("m_deleted.png");
        imRead = Functions.getIcon("m_opened.png");
        imAnswered = Functions.getIcon("m_answered.png");
        imSent = Functions.getIcon("m_sent.png");
        imFailedSent = Functions.getIcon("m_failed_send.png");
        imAttch = Functions.getIcon("m_attachment.png");
        imFlagged = Functions.getIcon("m_flagged.png");
        imRoot = Functions.getIcon( "m_root.png" );

        exit = new Command(Lang.get(Lang.BTN_BACK), Command.BACK, 0);
        viewMessage = new Command(Lang.get(Lang.BTN_TB_VIEW_MESS), Command.OK, 1);
        stop = new Command(Lang.get(Lang.BTN_TB_STOP), Command.STOP, 2);
        delete = new Command(Lang.get(Lang.BTN_DEL_UNDEL), Command.ITEM, 4);
        deleteNow = new Command(Lang.get(Lang.BTN_TB_DEL_NOW), Command.ITEM, 5);
        empty = new Command(Lang.get(Lang.BTN_CLEAR), Command.ITEM, 7);
        sort = new Command(Lang.get(Lang.BTN_TB_SORT), Command.ITEM, 9);
        seen = new Command(Lang.get(Lang.BTN_TB_MARK_SEEN), Command.ITEM, 6);
        flagged = new Command(Lang.get(Lang.BTN_TB_MARK_FLAGGED), Command.ITEM, 10);
        showHeader = new Command(Lang.get(Lang.BTN_MF_HEADERS_DETAILS), Command.ITEM, 11);
        addCommand(sort);
        addCommand(deleteNow);
        addCommand(viewMessage);
        addCommand(exit);
        addCommand(delete);
        addCommand(empty);
        addCommand(seen);
        addCommand(flagged);
        addCommand(showHeader);
        setCommandListener(this);
        
        //#ifdef MUJMAIL_TOUCH_SCR
        pointerEventTransformer = new MujMailPointerEventProducer(eventListener, getWidth(), getHeight());
        //#endif

          // TODO (Betlista): this shouldn't be here (my opinion, I think it should be loaded or something)
        this.ordering = Ordering.NATURAL;
        this.criterion = Criterion.TIME;
    }

    public void commandAction(Command c, Displayable d) {
          if (DEBUG) System.out.println( "DEBUG TheBox.commandAction(Command, Displayable)  - displayable: " + d.getClass().toString() );
        standardButtons(c);
    }

    /// Manages standard command actions of the boxes
    private void standardButtons(Command c) {
        if (c == viewMessage) {
            MujMail.mujmail.mailForm.viewMessage(getSelectedHeader(), this);
        } else if (c == exit) {
            exit();
        } else if (c == delete) {
            markAsDeleted(getSelectedHeader());
        } else if (c == deleteNow) {
            deleteMarkedFromBoxAndDB();
        } else if (c == seen) {
        	markSeen(getSelectedHeader());
        } else if (c == flagged) {
        	markFlagged(getSelectedHeader());
        } else if (c == empty) {
            deleteAllMailsFromBoxAndDB(false);
        } else if (c == sort) {
            MujMail.mujmail.getSettings().showSortFrm(this);
        } else if (c == showHeader) {
              if (DEBUG) System.out.println( "DEBUG TheBox.standardButtons() - c == showHeader" );
            MujMail.mujmail.mailForm.showHeader(getSelectedHeader(), this);
        }

    }

    

    public String toString() {
        return name;
    }
    
    /**
     * Gets the enumeration of all messages in this box.
     * @return the enumeration of all messages in this box
     */
    public Enumeration getMessages() {
        return storage.getEnumeration();
    }
    
    /**
     * @return gets box name
     */
    public final String getName() {
        return name;
    }
    
    /** 
     * Changes name of the box.
     * @param newName Name to set.
     */
    public void setName(String newName) {
        if (newName != null) {
            name = newName;
        }
    }
    
    /**
     * Gets number of messages in this box.
     * If threading is enabled it returns number of messages without empty root
     * messages.
     * 
     * @return the number of messages.
     */
    public int getMessageCount() {
    	final int storageSize = storage.getSize();
    	int emptyRootsNumber = 0;
    	if ( storage instanceof ThreadedEmails ) {
    		emptyRootsNumber = ((ThreadedEmails)storage).getEmptyRootsNumber();
    	}
        return storageSize - emptyRootsNumber;
    }

    // TODO (Betlista): why there are 2 methods for retrieving messages? (storageAt(int), getMessage(int) ) 
    /*
     * Return i-th message in storage.
     * 
     * @param index of the message to be retrieved
     * @return message for requested index or null if there is not message with such index
     */
//    public MessageHeader storageAt(int index) {
//        if (index >= storage.size() || index < 0) {
//            return null;
//        }
//        return (MessageHeader) storage.elementAt(index);
//    }

    /**
     * Return i-th message in storage.
     * 

⌨️ 快捷键说明

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