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

📄 jftp.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package net.sf.jftp;import net.sf.jftp.config.Settings;import net.sf.jftp.gui.*;import net.sf.jftp.gui.framework.*;import net.sf.jftp.net.*;import net.sf.jftp.tools.*;import net.sf.jftp.util.*;import java.awt.*;import java.awt.datatransfer.*;import java.awt.dnd.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;public class JFtp extends JPanel implements WindowListener, ComponentListener,                                            Logger, ChangeListener,                                            InternalFrameListener{    public static boolean mainUsed = false;    public static StatusPanel statusP;    public static JLabel statusL = new JLabel("Welcome to JFtp...                                                            ");    public static JFrame mainFrame;    public static Dir localDir;    public static Dir remoteDir;    public static DownloadList dList = new DownloadList();    public static DownloadQueue dQueue = new DownloadQueue();    public static boolean uiBlocked = false;    public static HostInfo hostinfo = new HostInfo();    //public static BasicConnection controlConnection = null;    private static ConnectionHandler defaultConnectionHandler = new ConnectionHandler();    public static JDesktopPane desktop = new JDesktopPane();    private static JScrollPane logSp;    public static JTextArea log;    //***appMenuBar: this must now be a public object that JFtp refers to    public static AppMenuBar menuBar = null;    public static final int CAPACITY = 9; //number of connections remembered    public static final int CONNECTION_DATA_LENGTH = 10;    public static DropTarget dropTarget;    public static DropTargetListener dtListener;    public static int acceptableActions = DnDConstants.ACTION_COPY;    private LogFlusher flusher;    private boolean initSize = true;    public JTabbedPane remoteConnectionPanel = new JTabbedPane();    public JTabbedPane localConnectionPanel = new JTabbedPane();    private String oldText = "";    private HDesktopBackground background;    /** JSplitPane that holds the directory panes and the log/dl JSplitPane */    private JSplitPane workP = null;    /** JSplitPane that holds the log download parts */    private JSplitPane logP = null;    /** JInternatFrames that hold the main components */    private JInternalFrame j1;    /** JInternatFrames that hold the main components */    private JInternalFrame j2;    /** JInternatFrames that hold the main components */    private JInternalFrame j3;    /** JInternatFrames that hold the main components */    private JInternalFrame j4;    /** JInternatFrames that hold the main components */    private JInternalFrame j5;    /** JInternatFrames that hold the main components */    private JInternalFrame j6;    private Hashtable internalFrames = new Hashtable();    public HostChooser hc;    private String buffer = "";    private long oldtime = 0;    private UpdateDaemon daemon;    //***        public JFtp()    {        Log.setLogger(this);        // we have jesktop-environment        if(statusP != null)        {            statusP.remove(statusP.close);        }        init();    }    public JFtp(boolean mainUsed)    {        Log.setLogger(this);        this.mainUsed = mainUsed;        init();    }    public void init()    {        dtListener = new DTListener();        dropTarget = new DropTarget(this, this.acceptableActions, dtListener,                                    true);        setLayout(new BorderLayout());        setBackground(GUIDefaults.mainBack);        setForeground(GUIDefaults.front);        statusP = new StatusPanel(this);        add("North", statusP);        localDir = (Dir) new LocalDir(Settings.defaultWorkDir);        localDir.setDownloadList(dList);        remoteDir = (Dir) new RemoteDir();        remoteDir.setDownloadList(dList);        desktop.setDropTarget(this.dropTarget);        Dimension d = Settings.getWindowSize();        setPreferredSize(d);        setSize(d);        int width = (int) d.getWidth();        int height = (int) d.getHeight();        dList.setMinimumSize(new Dimension((int) (width / 2.5),                                           (int) (height * 0.20)));        dList.setPreferredSize(new Dimension((int) (width / 2.5),                                             (int) (height * 0.25)));        dList.setSize(new Dimension((int) (width / 2.5), (int) (height * 0.25)));        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);        addBackgroundImage();        j1 = new JInternalFrame("Local filesystem", true, false, true, true);        j1.setMinimumSize(new Dimension(300, 300));        j1.setLocation(5, 5);        localConnectionPanel.addTab("file://", null, (Component) localDir,                                    "Filesystem");        localConnectionPanel.setSelectedIndex(0);        localConnectionPanel.addChangeListener(this);        j1.getContentPane().add(localConnectionPanel);        localDir.fresh();        desktop.add(j1);        j1.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);        j1.addInternalFrameListener(this);        j1.pack();        j1.setSize(new Dimension(400, j1.getSize().height));        j1.show();        j2 = new JInternalFrame("Remote connections", true, false, true, true);        j2.setLocation(430, 5);        remoteConnectionPanel.addTab("file://", null, (Component) remoteDir,                                     "Filesystem");        remoteConnectionPanel.setSelectedIndex(0);        remoteConnectionPanel.addChangeListener(this);        j2.getContentPane().add(remoteConnectionPanel);        desktop.add(j2);        j2.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);        j2.addInternalFrameListener(this);        j2.pack();        j2.setSize(new Dimension(415, j1.getSize().height));        j2.show();        log = new JTextArea();        log.setBackground(GUIDefaults.light);        log.setForeground(GUIDefaults.front);        log.setEditable(false);        logSp = new JScrollPane(log);        logSp.setSize(new Dimension(438, 148));        j5 = new JInternalFrame("Queue System", true, false, true, true);        j5.setLocation(5, 400);        j5.getContentPane().add(dQueue, BorderLayout.CENTER);        desktop.add(j5);        j5.pack();        j5.setSize(new Dimension(440, 150));        j5.show();        j3 = new JInternalFrame("Log", true, false, true, true);        int x = (int) (desktop.getSize().width / 2);        j3.setLocation(5, 425);        j3.getContentPane().add(logSp, BorderLayout.CENTER);        desktop.add(j3);        j3.pack();        j3.setSize(new Dimension(440, 150));        j3.show();        j4 = new JInternalFrame("Download Manager", true, false, true, true);        j4.setLocation(450, 425);        j4.getContentPane().add(dList, BorderLayout.CENTER);        desktop.add(j4);        j4.pack();        j4.setSize(new Dimension(380, 150));        j4.show();        j6 = new JInternalFrame("Insomniac Client", true, true, true, true);        j6.setMinimumSize(new Dimension(750, 350));        j6.setLocation(5, 25);        j6.getContentPane().add(new InsomniacClient());        desktop.add(j6);        j6.pack();        j6.setSize(new Dimension(790, j1.getSize().height - 25));        j6.hide();        j1.toFront();        j2.toFront();        if(Settings.isInsomniacClient)        {            switchToInsomniacUI();        }        add("Center", desktop);        JToolBar j = new JToolBar();        j.setFloatable(false);        j.add(statusP.status, FlowLayout.LEFT);		if(Settings.getEnableRSS()) 	{		j.add(new RSSFeeder());	}        add("South", j);        addComponentListener(this);        componentResized(new ComponentEvent(log, 0));        validate();        setVisible(true);        if(!mainUsed)        {            SwingUtilities.invokeLater(new Runnable()                {                    public void run()                    {                        chooseHost();                    }                });        }        else        {            chooseHost();        }        flusher = new LogFlusher();        daemon = new UpdateDaemon(this);    }    protected void chooseHost()    {        hc = new HostChooser(this);        if(!mainUsed)        {            hc.update();        }    }    public static String getHost()    {        return statusP.getHost();    }    public static void setHost(String which)    {        statusP.setHost(which);    }    public static void localUpdate()    {        localDir.fresh();    }    public static void remoteUpdate()    {        remoteDir.fresh();    }    public void windowClosing(WindowEvent e)    {        Settings.setProperty("jftp.window.width", this.getWidth());        Settings.setProperty("jftp.window.height", this.getHeight());        if(!mainUsed)        {            Settings.setProperty("jftp.window.x",                                 (int) this.getLocationOnScreen().getX());            Settings.setProperty("jftp.window.y",                                 (int) this.getLocationOnScreen().getY());        }        else        {            Settings.setProperty("jftp.window.x",                                 (int) mainFrame.getLocationOnScreen().getX());            Settings.setProperty("jftp.window.y",                                 (int) mainFrame.getLocationOnScreen().getY());        }        Settings.save();        safeDisconnect();        if(Settings.isStandalone)        {            System.exit(0);        }        else        {            mainFrame.dispose();        }    }    public static void safeDisconnect()    {        BasicConnection con = remoteDir.getCon();        if((con != null) && con.isConnected())        {            try            {                con.disconnect();            }            catch(Exception ex)            {            }        }        FilesystemConnection c = new FilesystemConnection();        c.addConnectionListener((ConnectionListener) remoteDir);        remoteDir.setCon(c);        if(!c.chdir("/"))        {            c.chdir("C:\\");        }    }    public void windowClosed(WindowEvent e)    {    }    public void windowActivated(WindowEvent e)    {    }    public void windowDeactivated(WindowEvent e)    {    }    public void windowIconified(WindowEvent e)    {    }    public void windowDeiconified(WindowEvent e)    {    }    public void windowOpened(WindowEvent e)    {    }    public void componentHidden(ComponentEvent e)    {    }    public void componentMoved(ComponentEvent e)    {    }    public void componentShown(ComponentEvent e)    {    }    public void componentResized(ComponentEvent e)    {        localDir.actionPerformed(this, "local");        remoteDir.actionPerformed(this, "remote");        desktop.remove(background);        addBackgroundImage();        validate();    }    public void addBackgroundImage()    {        try        {            background = new HDesktopBackground(Settings.background, null);            background.setBounds(0, 0, getSize().width, getSize().height);            desktop.add(background, new Integer(Integer.MIN_VALUE));        }        catch(Exception ex)        {            Log.out(Settings.background + " missing, no background image used");        }    }    private static void compile()    {        /*        try        {               Compiler.enable();           System.out.println(Compiler.compileClass(Class.forName("java.util.Hashtable")));           System.out.println(Compiler.compileClasses("net.sf.jftp"));           System.out.println(Compiler.compileClasses("net.sf.jftp.JFtp"));           System.out.println(Compiler.compileClasses("JFtp"));         }         catch(ClassNotFoundException ex)         {                 ex.printStackTrace();         }         */    }    private static void setSocksProxyOptions(String proxy, String port)    {        if(proxy.equals("") || port.equals(""))        {            return;        }        java.util.Properties sysprops = System.getProperties();        // Remove previous values        sysprops.remove("socksProxyHost");        sysprops.remove("socksProxyPort");        // Set your values        sysprops.put("socksProxyHost", proxy);        sysprops.put("socksProxyPort", port);        Log.out("socks proxy: " + sysprops.get("socksProxyHost") + ":" +                sysprops.get("socksProxyPort"));    }    public static void main(String[] argv)    {        long start = System.currentTimeMillis();

⌨️ 快捷键说明

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