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

📄 hostchooser.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.gui;import net.sf.jftp.*;import net.sf.jftp.config.*;import net.sf.jftp.gui.framework.*;import net.sf.jftp.net.*;import net.sf.jftp.util.*;import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;public class HostChooser extends HFrame implements ActionListener,                                                   WindowListener{    public HTextField host = new HTextField("Hostname:", "localhost");    public HTextField user = new HTextField("Username:", "anonymous");    //public static HTextField pass = new HTextField("Password:","none@nowhere.no");    public HPasswordField pass = new HPasswordField("Password:",                                                    "none@nowhere.no");    public HTextField port = new HTextField("Port:    ", "21");    public HTextField cwd = new HTextField("Remote:  ", Settings.defaultDir);    public HTextField lcwd = new HTextField("Local:   ", Settings.defaultWorkDir);    public HTextField dl = new HTextField("Max. connections:    ", "3");    private JCheckBox anonBox = new JCheckBox("Use anonymous login", false);    private JCheckBox listBox = new JCheckBox("LIST compatibility mode", false);    private JCheckBox dirBox = new JCheckBox("Use default directories",                                             Settings.getUseDefaultDir());    private JCheckBox modeBox = new JCheckBox("Use active Ftp (no need to)",                                              false);    private JCheckBox threadBox = new JCheckBox("Multiple connections", false);    private HPanel okP = new HPanel();    private HButton ok = new HButton("Connect");    private HButton backMode = new HButton("Yes");    private HButton frontMode = new HButton("No");    private HFrame h = new HFrame();    private HPanel listP = new HPanel();    private HButton list = new HButton("Choose from or edit list...");    private ComponentListener listener = null;    private int mode = 0;    private boolean useLocal = false;    public HostChooser(ComponentListener l, boolean local)    {        listener = l;        useLocal = local;        init();    }    public HostChooser(ComponentListener l)    {        listener = l;        init();    }    public HostChooser()    {        init();    }    public void init()    {        setSize(600, 340);        setLocation(50, 150);        setTitle("Ftp Connection...");        setBackground(okP.getBackground());        getContentPane().setLayout(new GridLayout(7, 2));        anonBox.setSelected(false);        user.setEnabled(true);        pass.text.setEnabled(true);        LoadSet l = new LoadSet();        String[] login = l.loadSet(Settings.login_def);        if((login != null) && (login[0] != null))        {            host.setText(login[0]);            user.setText(login[1]);            if(login[3] != null)            {                port.setText(login[3]);            }            if(login[4] != null)            {                cwd.setText(login[4]);            }            if(login[5] != null)            {                lcwd.setText(login[5]);            }        }        if(Settings.getStorePasswords())        {            if(login != null)            {                pass.setText(login[2]);            }        }        else        {            pass.setText("");        }        getContentPane().add(host);        getContentPane().add(port);        getContentPane().add(anonBox);        getContentPane().add(listBox);        getContentPane().add(user);        getContentPane().add(pass);        getContentPane().add(dirBox);        getContentPane().add(modeBox);        getContentPane().add(lcwd);        getContentPane().add(cwd);        getContentPane().add(threadBox);        getContentPane().add(dl);        modeBox.setSelected(!Settings.getFtpPasvMode());        threadBox.setSelected(Settings.getEnableMultiThreading());        dirBox.setSelected(Settings.getUseDefaultDir());        anonBox.addActionListener(this);        threadBox.addActionListener(this);        getContentPane().add(okP);        okP.add(ok);        ok.addActionListener(this);        getContentPane().add(listP);        listP.add(list);        list.addActionListener(this);        dirBox.addActionListener(this);        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);        lcwd.setEnabled(!dirBox.isSelected());        cwd.setEnabled(!dirBox.isSelected());        pass.text.addActionListener(this);        setModal(false);        setVisible(false);        invalidate();        validate();        addWindowListener(this);        prepareBackgroundMessage();    }    public void update()    {        setVisible(true);        toFront();        host.requestFocus();    }    public void update(String url)    {        try        {            FtpURLConnection uc = new FtpURLConnection(new java.net.URL(url));            FtpConnection con = uc.getFtpConnection();            JFtp.statusP.jftp.addConnection(url, con);            //con.addConnectionListener((ConnectionListener) JFtp.localDir);            //con.addConnectionListener((ConnectionListener) JFtp.remoteDir);            //JFtp.remoteDir.setCon(con);            uc.connect();            int response = uc.getLoginResponse();            if(response != FtpConnection.LOGIN_OK)            {                setTitle("Wrong password!");                host.setText(uc.getHost());                port.setText(Integer.toString(uc.getPort()));                user.setText(uc.getUser());                pass.setText(uc.getPass());                setVisible(true);                toFront();                host.requestFocus();            }            else            {                this.dispose();                if(listener != null)                {                    listener.componentResized(new ComponentEvent(this, 0));                }                JFtp.mainFrame.setVisible(true);                JFtp.mainFrame.toFront();            }        }        //catch(MalformedURLException ex)        //{        //	Log.debug("Malformed URL!");        //	ex.printStackTrace();        //}        catch(IOException ex)        {            Log.debug("Error!");            ex.printStackTrace();        }    }    public void actionPerformed(ActionEvent e)    {        if((e.getSource() == ok) || (e.getSource() == pass.text))        {            // Switch windows            //this.setVisible(false);            setCursor(new Cursor(Cursor.WAIT_CURSOR));            //JFtp.mainFrame.setVisible(true);            //JFtp.mainFrame.toFront();            FtpConnection con = null;            JFtp.setHost(host.getText());            String htmp = StringUtils.cut(host.getText(), " ");            String utmp = StringUtils.cut(user.getText(), " ");            String ptmp = StringUtils.cut(pass.getText(), " ");            String potmp = StringUtils.cut(port.getText(), " ");            Settings.setProperty("jftp.ftpPasvMode", !modeBox.isSelected());            Settings.setProperty("jftp.enableMultiThreading",                                 threadBox.isSelected());            Settings.setProperty("jftp.useDefaultDir", dirBox.isSelected());            if(listBox.isSelected())            {                FtpConnection.LIST = "LIST";            }            else            {                FtpConnection.LIST = "LIST -laL";            }            /* All the information of the current server are stored in JFtp.HostInfo */            JFtp.hostinfo.hostname = htmp;            JFtp.hostinfo.username = utmp;            JFtp.hostinfo.password = ptmp;            JFtp.hostinfo.port = potmp;            JFtp.hostinfo.type = "ftp";            boolean pasv = Settings.getFtpPasvMode();            boolean threads = Settings.getEnableMultiThreading();            if(!pasv && threads) // only passive ftp threading works            {                Settings.setProperty("jftp.enableMultiThreading", false);                JDialog j = new JDialog();                j.setTitle("Warning");                j.setLocation(150, 150);                j.setSize(450, 100);                j.getContentPane().add(new JLabel(" Multithreading does not work with active ftp yet, disabled it..."));                j.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);                j.setModal(true);                j.show();            }            int x = Integer.parseInt(dl.getText().trim());            Settings.maxConnections = x;            Settings.save();            //*** My modifications are below here            String dtmp;            String ltmp;            if(dirBox.isSelected())            {                dtmp = Settings.defaultDir;                ltmp = Settings.defaultWorkDir;            }            else            {                dtmp = cwd.getText();                ltmp = lcwd.getText();            }            //*** More of my stuff            SaveSet s = new SaveSet(Settings.login_def, htmp, utmp, ptmp,                                    potmp, dtmp, ltmp);

⌨️ 快捷键说明

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