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

📄 smbhostchooser.java

📁 JAVA FTP客户端经典
💻 JAVA
字号:
/* * 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.gui.framework.*;import net.sf.jftp.net.*;import net.sf.jftp.config.*;import net.sf.jftp.util.*;import net.sf.jftp.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.net.*;public class SmbHostChooser extends HFrame implements ActionListener, WindowListener{    public static HTextField host = new HTextField("URL:","smb://localhost/");    JCheckBox lan = new JCheckBox("Browse LAN", true);    public static HTextField user = new HTextField("Username:","guest");    //public static HTextField pass = new HTextField("Password:","none@nowhere.no");    public static HPasswordField pass = new HPasswordField("Password:","nopasswd");    public HTextField domain = new HTextField("Domain:    ","WORKGROUP");    public HTextField ip = new HTextField("Local IP:    ","<default>");    private HPanel okP = new HPanel();    private HButton ok = new HButton("Connect");    private ComponentListener listener = null;    public SmbHostChooser(ComponentListener l)    {    	listener = l;	init();    }    public SmbHostChooser()    {    	init();    }    public void init()    {        setSize(500,220);        setLocation(100,150);        setTitle("Smb Connection...");        setBackground(okP.getBackground());        getContentPane().setLayout(new GridLayout(4,2));        getContentPane().add(host);        getContentPane().add(lan);        getContentPane().add(user);        getContentPane().add(pass);	getContentPane().add(ip);	getContentPane().add(domain);	getContentPane().add(new JLabel(""));	getContentPane().add(okP);        okP.add(ok);        ok.addActionListener(this);	host.setEnabled(!lan.isSelected());	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);	lan.addActionListener(this);	pass.text.addActionListener(this);        setModal(false);        setVisible(false);	addWindowListener(this);	try	{		Log.debugRaw("Trying to guess correct network adapter... ");		JConnection jcon = new JConnection("j-ftp.sourceforge.net", 80, Settings.testTimeout);		if(!jcon.isThere())		{			Log.debug("failed.\n");		}		else		{			Log.debugRaw("ok.\n");			ip.setText(jcon.getLocalAddress().getHostAddress());		}	}	catch(Exception ex)	{		Log.debug("Error determining default network interface: " + ex);	}    }    public void update() {        setVisible(true);        toFront();	host.requestFocus();    }    public void actionPerformed(ActionEvent e)    {        if(e.getSource() == lan)        {		host.setEnabled(!lan.isSelected());        }        else if(e.getSource() == ok || e.getSource() == pass.text)        {	    // Switch windows	    this.setVisible(false);	    JFtp.mainFrame.setVisible(true);            JFtp.mainFrame.toFront();	    SmbConnection con = null;	    //System.out.println(jcifs.Config.getProperty("jcifs.smb.client.laddr"));	    String tmp = ip.getText().trim();	    if(!tmp.equals("") && !tmp.equals("<default>"))	    {	    	Log.debug("Setting LAN interface to: " + tmp);	    	jcifs.Config.setProperty("jcifs.netbios.laddr", tmp);	    }	    //System.out.println(jcifs.Config.getProperty("jcifs.smb.client.laddr"));            //JFtp.setHost(host.getText());            String htmp = host.getText().trim();            String utmp = user.getText().trim();            String ptmp = pass.getText().trim();	    String dtmp = domain.getText().trim();	    if(dtmp.equals("")) dtmp = null;	    if(lan.isSelected()) htmp = null;	    try	    {	     con = new SmbConnection(htmp,dtmp,utmp,ptmp, ((ConnectionListener)JFtp.remoteDir));	    JFtp.remoteDir.setCon(con);	    con.setLocalPath(JFtp.localDir.getCon().getPWD());	    con.addConnectionListener((ConnectionListener) JFtp.localDir);	    //con.addConnectionListener((ConnectionListener) JFtp.remoteDir);	    JFtp.remoteDir.fresh();	    }	    catch(Exception ex)	    {	    	Log.debug("Could not create SMBConnection, does this distribution come with jcifs?");            }            this.dispose();	    if(listener != null) listener.componentResized(new ComponentEvent(this, 0));	}    }    public void windowClosing(WindowEvent e)    {        //System.exit(0);	this.dispose();    }    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 Insets getInsets()    {        Insets std = super.getInsets();        return new Insets(std.top + 15, std.left + 15, std.bottom + 15, std. right + 15);    }    public void pause(int time)    {    	try { Thread.sleep(time); }	catch(Exception ex) {}    }}

⌨️ 快捷键说明

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