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

📄 storetreenode.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
字号:
/*** $Id: StoreTreeNode.java,v 1.4 2001/05/07 12:37:22 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 javax.mail.AuthenticationFailedException;import javax.mail.Folder;import javax.mail.MessagingException;import javax.mail.Store;import javax.mail.URLName;import javax.swing.JOptionPane;import javax.swing.tree.DefaultMutableTreeNode;import org.icemail.Package;/** * The class represents a store and all related folders as nodes on a tree. * <p> * Store nodes are constructed from the configured stores, and added to * the root node of the folder tree panel. * * @see RootTreeNode * @see FolderTreePanel */public class StoreTreeNode  extends DefaultMutableTreeNode{  private static final int Debug_ = Package.DEBUG ? Package.getLevel( "StoreTreeNode" ) : 0;  private String       name_ = null;  private Store        store_ = null;  private Folder       folder_ = null;  private String       nameSpace_ = null;  /**   * Construct a tree node that points to the given Store.   *   * @param what  the store for this node   */  public  StoreTreeNode( String name, Store store, String nameSpace ) {    super( store );    if ( Package.DEBUG && Package.isTraceable( "StoreTreeNode" ) ) {      System.out.println( "StoreTreeNode(s,s,s): n-" + name +                          ", s-" + store + "(" + store.getClass().getName() + ")" );    }    name_ = name;    store_ = store;    nameSpace_ = nameSpace;  }  /**   * Returns a shallow copy of this node; the new node has no parent   * or children and has a reference to the same user object, if any.   * <p>   * Implementation of java.swing.tree.DefaultMutableTreeNode.clone()   *   * @return a copy of this node   */  public Object  clone() {    if ( Package.DEBUG && Package.isTraceable( "StoreTreeNode" ) ) {      System.out.println( "StoreTreeNode.clone(): " + name_ );    }    StoreTreeNode newNode = (StoreTreeNode)super.clone();    newNode.name_ = name_;    newNode.store_ = store_;    newNode.folder_ = null;    newNode.nameSpace_ = nameSpace_;    return newNode;  }  public String  getName() {    return name_;  }  public Store  getStore() {    return store_;  }  public Folder  getDefaultFolder() {    return folder_;  }  public String  getNameSpace() {    return nameSpace_;  }  /**   * Returns true if this node has no children.   * <p>   * Implementation of java.swing.tree.DefaultMutableTreeNode.isLeaf()   *   * @return always false as a Store is never a leaf node   */  public boolean  isLeaf() {    if ( Package.DEBUG && Package.isTraceable( "StoreTreeNode" ) ) {      System.out.println( "StoreTreeNode.isLeaf(): " + this );    }    return false;    //return ( folder_ == null ? false : getChildCount() > 0 );  }  /**   * Returns the number of children of this node.   * <p>   * The first time this method is called, all folders are added   * for the defaultFolder for the store.   * <p>   * Implementation of java.swing.tree.DefaultMutableTreeNode.getChildCount()   *   * @return the number of children of this node   */  public int  getChildCount() {    if ( Package.DEBUG && Package.isTraceable( "StoreTreeNode" ) ) {      System.out.println( "StoreTreeNode.getChildCount(): " + this );    }    if ( folder_ == null ) {      this.loadChildren();    }    return super.getChildCount();  }  private void  loadChildren() {    if ( Package.DEBUG && Package.isTraceable( "StoreTreeNode" ) ) {      System.out.println( "StoreTreeNode.loadChildren()" );    }    try {    // connect to the Store if we need to      MailUtilities.setStoreConnected( store_ );    // get the default folder, and list the    // subscribed folders on it      folder_ = store_.getDefaultFolder();      Folder[] sub = ( nameSpace_ == null ? folder_.list() :                                            folder_.list( nameSpace_ ) );      if ( sub == null ) {        return;      }      if ( sub.length > 1 ) {        RootTreeNode.sortFolderList( sub );      }    // add a FolderTreeNode for each Folder      int num = sub.length;      for( int i = 0 ; i < num ; i++ ) {        FolderTreeNode node = new FolderTreeNode( sub[i] );      // we used insert here, since add() would make      // another recursive call to getChildCount();        this.insert( node, i );      }          } catch ( AuthenticationFailedException ex ) {    // UNDONE    // I think what I need to do here is to somehow remove and    // reinstall this node. This should cause the tree to decide    // to call loadChildren() again when we are opened again.    //      Object[] xargs = new Object[1];      xargs[0] = ex.getMessage();System.err.println( "StoreTreeNode Exception: " + ex );//      ComponentFactory.showDialog( ICEMail.bundle, "StoreTreeNode.AuthenticationError",//                                   0, JOptionPane.ERROR_MESSAGE, xargs );    } catch ( MessagingException ex ) {//      Object[] xargs = new Object[1];//      xargs[0] = ex.getMessage();//      ComponentFactory.showDialog( ICEMail.bundle, "StoreTreeNode.MessageError",//                                   0, JOptionPane.ERROR_MESSAGE, xargs );System.err.println( "StoreTreeNode Exception: " + ex );    }  }  /**   * Return the store URLName without the password.   *   * @return the store URLName without the password.   */  public String  toString() {    String xresult = null;    URLName url = store_.getURLName();    if ( url == null ) {      xresult = store_.toString();    } else {      xresult = name_;      if ( xresult == null ) {        xresult = url.getUsername();      }    }    return xresult;  }}

⌨️ 快捷键说明

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