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

📄 foldertablemodel.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*** $Id: FolderTableModel.java,v 1.7 2001/05/07 12:37:21 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail;import java.awt.Image;import javax.mail.Address;import javax.mail.FetchProfile;import javax.mail.Flags;import javax.mail.Folder;import javax.mail.FolderClosedException;import javax.mail.MessagingException;import javax.mail.Message;import javax.mail.event.MessageCountAdapter;import javax.mail.event.MessageCountEvent;import javax.mail.internet.ContentType;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import java.util.Date;import java.util.Vector;import java.util.Hashtable;import java.text.SimpleDateFormat;import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JProgressBar; import javax.swing.SwingConstants; import javax.swing.event.TableModelEvent; import javax.swing.table.AbstractTableModel; import org.icemail.Package; import org.icemail.util.AWTUtilities; import org.icemail.util.UserProperties; /** * This class manages a table model for all the messages in a folder. * <p> * A folder is interogated for all it's messages, which are then accessed * to create as series of rows and columns for the message parts, such as * To address, flags, etc. The rows and columns are used to represent the * data underlying the table and viewer, i.e. MessagePanel. * <p> * The initial ordering of the columns is read from the user's properties, * and can be changed by the viewer. These are then saved whenever the * application quits. * <p> * The rows can be sorted by a single column. * * @see MessagePanel */public class FolderTableModel  extends AbstractTableModel{  private static final int Debug_ = Package.DEBUG ? Package.getLevel( "FolderTableModel" ) : 0;  static private ImageIcon  delMarkOnIcon;  static private ImageIcon  delMarkOffIcon;  static private ImageIcon  highMarkIcon;  static private ImageIcon  lowMarkIcon;  static private ImageIcon  signedMarkIcon;  static private ImageIcon  encryptMarkIcon;  static private ImageIcon  attachMarkIcon;  private String[]          columnFields_; // provided  private Class[]           columnTypes_;  // derived from columnFields  private String[]          columnNames_;  // derived from columnFields  private Folder            folder_;  private FTMCounterAdapter adapter_;  private Message[]         messages_;  private Object[][]        convData_;  private int               nextFetchRow_;  private boolean           useFetchProfile_;  private int               fetchQuantum_;  static {    try {      Image iconImg;      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/delmkon.gif" );      FolderTableModel.delMarkOnIcon = new ImageIcon( iconImg );      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/delmkoff.gif" );      FolderTableModel.delMarkOffIcon = new ImageIcon( iconImg );      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/highmk.gif" );      FolderTableModel.highMarkIcon = new ImageIcon( iconImg );      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/lowmk.gif" );      FolderTableModel.lowMarkIcon = new ImageIcon( iconImg );      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/signedmk.gif" );      FolderTableModel.signedMarkIcon = new ImageIcon( iconImg );      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/encryptmk.gif" );      FolderTableModel.encryptMarkIcon = new ImageIcon( iconImg );      iconImg = AWTUtilities.getImageResource( "/org/icemail/mail/images/attachmk.gif" );      FolderTableModel.attachMarkIcon = new ImageIcon( iconImg );    } catch ( Exception ex ) {      System.err.println( "FolderTableModel.static: Couldn't load images: " + ex.getMessage() );    }  }  /**   * Create a table model with the given ordering of fields (columns).   * The contents of the model are empty.   *   * @param fields the names of the fields (columns)   */  public  FolderTableModel( String[] fields ) {    super();    adapter_ = null;    columnFields_ = fields;    columnTypes_ = new Class[ fields.length ];    columnNames_ = new String[ fields.length ];    for ( int t = 0 ; t < fields.length ; ++t ) {      if ( fields[t].equalsIgnoreCase( "FLAG" ) ) {        columnTypes_[t] = ImageIcon.class;        columnNames_[t] = ICEMail.getBundle().getString( "FolderTableModel.Flag" );      } else if ( fields[t].equalsIgnoreCase( "TO" ) ) {        columnTypes_[t] = String.class;        columnNames_[t] = ICEMail.getBundle().getString( "FolderTableModel.To" );      } else if ( fields[t].equalsIgnoreCase( "FROM" ) ) {        columnTypes_[t] = JLabel.class;        columnNames_[t] = ICEMail.getBundle().getString( "FolderTableModel.From" );      } else if ( fields[t].equalsIgnoreCase( "SENTDATE" ) ) {        columnTypes_[t] = Date.class;        columnNames_[t] = ICEMail.getBundle().getString( "FolderTableModel.SentDate" );      } else if ( fields[t].equalsIgnoreCase( "RECVDATE" ) ) {        columnTypes_[t] = Date.class;        columnNames_[t] = ICEMail.getBundle().getString( "FolderTableModel.RecvDate" );      } else if ( fields[t].equalsIgnoreCase( "SUBJECT" ) ) {        columnTypes_[t] = String.class;        columnNames_[t] = ICEMail.getBundle().getString( "FolderTableModel.Subject" );      } else {      // unknown field type        columnTypes_[t] = String.class;        columnNames_[t] = "unknown";      }    }    folder_ = null;    messages_ = null;    convData_ = null;    nextFetchRow_ = 0;    useFetchProfile_ = UserProperties.getProperty( "useFetchProfiles", true );    fetchQuantum_ = UserProperties.getProperty( "fetchQuantum", 25 );  }  /**   * Set the underlying folder of the table model, preparing the table   * model for accessing the associated message contents.   *   * @param folder the underlying folder to use   */  public void  setFolder( Folder folder ) throws MessagingException {    if ( Package.DEBUG && Package.isTraceable( "FolderTableModel" ) ) {      System.out.println( "FolderTableModel.setFolder(f): " + folder );    }    if ( folder_ != null && adapter_ != null ) {      folder_.removeMessageCountListener( adapter_ );    }    folder_ = folder;    messages_ = null;    convData_ = null;    if ( folder_ == null ) {      fireTableChanged( new TableModelEvent( this ) );      return;    }  // opened if needed    MailUtilities.setFolderOpenAndReady( folder_, Folder.READ_WRITE );    nextFetchRow_ = 0;  // get the messages    Message[] tempMsgs = folder_.getMessages();    messages_ = new Message[ tempMsgs.length ];    int m = 0;    int t = tempMsgs.length - 1;    for ( ; m < messages_.length ; ) {      messages_[ m++ ] = tempMsgs[ t-- ];    }    if ( Package.DEBUG && Debug_ > 0 ) {      System.err.println( "FolderTableModel.setFolder(): " + messages_.length + " messages." );    }    convData_ = new Object[ messages_.length ][];    adapter_ = new FTMCounterAdapter();    folder_.addMessageCountListener( adapter_ );        MailEventThread.getInstance().setMonitorFolder( folder_ );    fireTableChanged( new TableModelEvent( this ) );  }  /**   * Get the underlying message at the given row.   *   * @param row the index of the row in the table   */  public Message  getMessage( int row ) {    if ( messages_ == null )      return null;    return messages_[ row ];  }  /**   * Get the underlying message's flags at the given row.   *   * @param row the index of the row in the table   */  public Flags  getMessageFlags( int row ) {    Flags result = null;    try {      result = messages_[ row ].getFlags();    } catch ( Exception ex ) {      result = new Flags();    }    return result;  }  /**   * Set the underlying message's SEEN flag at the given row.   *   * @param row the index of the row in the table   */  public void  setMessageSeen( int row ) {    try {      MailUtilities.setFolderOpenAndReady( folder_, Folder.READ_WRITE );      Message xmessage = messages_[ row ];      xmessage.setFlag( Flags.Flag.SEEN, true );      fireTableRowsUpdated( row, row );    } catch ( MessagingException ex ) {      ex.printStackTrace();    }  }  /**   * Suck all the messages into the table model indicating the progress in   * the given progess bar.   *   * @param progress the progess bar to use   */  public void  cacheAllMessages( JProgressBar progress ) {    int pVal = (progress == null) ? 0 : progress.getValue();    for ( int i = 0 ; i < messages_.length ; ++i ) {      if ( convData_[ i ] == null ) {        getConvertedData( i );      }      if ( progress != null ) {        progress.setValue( ++pVal );      }    }  }  /**   * Flush the table model of all data.   */  public void  flushCache( int[] rows ) {    for ( int i = 0 ; i < rows.length ; ++i ) {      convData_[ rows[i] ] = null;    }  }  /**   * Fire update events on the given rows.   *   * @param rows the rows to fire updates upon   */  public void  fireRowsUpdated( int[] rows ) {    for ( int i = 0 ; i < rows.length ; ++i ) {      fireTableRowsUpdated( rows[i], rows[i] );    }  }  /**   * Sort the table model based on the given column and direction,   * indicating the progress in the given progess bar.   *   * @param progress the progess bar to use   * @param col the index of the column to sort by   * @param asc ascending sort indicator   */  public void  sortOnColumn( JProgressBar progress, int col, boolean asc ) {    if ( Package.DEBUG && Package.isTraceable( "FolderTableModel" ) ) {      System.out.println( "FolderTableModel.sortOnColumn(pb,i,b): col-" + col + ", asc-" + asc );    }    int pVal = (progress == null) ? 0 : progress.getValue();    Vector dV = new Vector();    Vector mV = new Vector();    Class colClass = columnTypes_[ col ];    if ( Package.DEBUG && Debug_ > 0 ) {      System.out.println( "FolderTableModel.sortOnColumn(): colClass=" + colClass );    }    for ( int row = 0 ; row < messages_.length ; ++row ) {      if ( convData_[ row ] == null ) {        getConvertedData( row );      }

⌨️ 快捷键说明

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