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

📄 ftptree.java

📁 Ftp服务1.0
💻 JAVA
字号:
package ranab.server.ftp.gui;


import java.util.Vector;
import javax.swing.JTree;
import javax.swing.JPanel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeModel;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.event.TreeModelListener;

import ranab.server.ftp.FtpServer; 
import ranab.server.ftp.FtpConfig;

/**
 * This is FTP user interface tree structure. Currently it is very simple.
 * It looks like:
 * <pre>
 *   FTP
 *    |
 *    +-- User (User management)
 *    |
 *    +-- Ip (IP restrictions)
 *    |
 *    +-- Connection (Connection monitor)
 *    |
 *    +-- Spy (Spy user activities)
 *    |
 *    +-- Statistics (Global statistics)
 *    |
 *    +-- Upload (File upload statistics)
 *    |
 *    +-- Download (File download statistics)
 *    |
 *    +-- Delete (File deletion statistics)
 *    |
 *    +-- About (Ftp server summary)
 * </pre>
 */

public
class FtpTree extends JTree implements TreeModel {
    
    public final static String[] CHILDREN = {
        "User",
        "IP",
        "Connection",
        "Spy",
        "Statistics",
        "Upload",
        "Download",
        "Delete",
        "About"    
    }; 
    
    private Vector mListenrList;
    
    private FtpRootPanel mRootPanel;
    private PluginPanel[] mPluginPanels;
    
    
    /**
     * create this tree model
     */
    public FtpTree() {
        mListenrList = new Vector();
        setModel(this);
        
        setSelectionPath(new TreePath(FtpServer.NAME));
        putClientProperty("JTree.lineStyle", "Angled");
        
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setLeafIcon(null);
        renderer.setOpenIcon(null);
        renderer.setClosedIcon(null);
        setCellRenderer(renderer);
        
        mRootPanel = new FtpRootPanel(this);
        initPlugins();
    }
    
    /**
     * Initialize all plugin panels
     */
    private void initPlugins() {
        mPluginPanels = new PluginPanel[CHILDREN.length];
        
        mPluginPanels[0] = new FtpUserPanel(this);
        mPluginPanels[1] = new FtpIpPanel(this);
        mPluginPanels[2] = new FtpConnectionPanel(this);
        mPluginPanels[3] = new FtpSpyContainerPanel(this);
        mPluginPanels[4] = new FtpStatisticsPanel(this);
        mPluginPanels[5] = new FtpFilePanel(this, ((FtpStatisticsPanel)mPluginPanels[4]).getUploadModel(),   "Uploaded Files");
        mPluginPanels[6] = new FtpFilePanel(this, ((FtpStatisticsPanel)mPluginPanels[4]).getDownloadModel(), "Downloaded Files");
        mPluginPanels[7] = new FtpFilePanel(this, ((FtpStatisticsPanel)mPluginPanels[4]).getDeleteModel(),   "Deleted Files");
        mPluginPanels[8] = new FtpAboutPanel(this);
    }
    

    /**
     * get root object
     */
    public Object getRoot() {
        return FtpServer.NAME;
    }

    /** 
     * get child object
     */
    public Object getChild(Object parent, int index) {
        return CHILDREN[index];
    } 

    /**
     * get child count
     */
    public int getChildCount(Object parent) {
        if(parent.equals(FtpServer.NAME)) {
            return CHILDREN.length;
        }
        return 0;
    }

    /**
     * is a leaf or node
     */
    public boolean isLeaf(Object node) {
       return !node.equals(FtpServer.NAME);
    }

    /**
     * get child index
     */
    public int getIndexOfChild(Object parent, Object child) {
       int childIdx = -1;
       for(int i=0; i<CHILDREN.length; i++) {
           if(CHILDREN[i].equals(child)) {
               childIdx = i;
               break;
           }
       }
       return childIdx;
    }

    /**
     * Object changed. In our case it is not possible - so igmore it.
     */
    public void valueForPathChanged(TreePath path, Object newValue) {
    }

    /**
     * add a listener
     */
    public void addTreeModelListener(TreeModelListener l) {
        mListenrList.add(l);
    }

    /**
     * remove a listener
     */
    public void removeTreeModelListener(TreeModelListener l) {
        mListenrList.remove(l);
    }
    
    /**
     * Refresh all panels
     */
    public void refresh(FtpConfig config) {
        for(int i=0; i<mPluginPanels.length; i++) {
            mPluginPanels[i].refresh(config);
        }
    }
    
    /**
     * Get root panel.
     */
    public FtpRootPanel getRootPanel() {
        return mRootPanel;
    }
    
    /**
     * Get plugin panel.
     */
    public PluginPanel getPluginPanel(String panelName) {
        PluginPanel panel = null;
        for(int i=0; i<CHILDREN.length; i++) {
            if (CHILDREN[i].equals(panelName)) {
                panel = mPluginPanels[i];
                break;
            }
        }
        return panel;
    }
     
     
    /**
     * Get the selected panel.
     */ 
    public JPanel getSelectedPanel() {
        Object node = getSelectionPath().getLastPathComponent();
        
        JPanel dispPane = null;
        if(getRoot().equals(node)) {
            dispPane = mRootPanel;
        }
        else {
            dispPane = getPluginPanel(node.toString());
            if ( (dispPane == null) || (!dispPane.isDisplayable()) ) {
                dispPane = mRootPanel;
            }
        }
        
        return dispPane;
    } 
     
}

⌨️ 快捷键说明

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