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

📄 localdir.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.gui.framework.*;import net.sf.jftp.config.*;import net.sf.jftp.net.*;import net.sf.jftp.util.*;import net.sf.jftp.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;import java.net.*;import java.util.*;public class LocalDir extends DirPanel implements ListSelectionListener, ActionListener, ConnectionListener, KeyListener{    HImageButton deleteButton;    HImageButton mkdirButton;    HImageButton cmdButton;    HImageButton refreshButton;    HImageButton cdButton;    HImageButton uploadButton;    HImageButton zipButton;    HImageButton cpButton;    HImageButton rnButton;    static final String deleteString = "rm";    static final String mkdirString = "mkdir";    static final String refreshString = "fresh";    static final String cdString = "cd";    static final String cmdString = "cmd";    static final String downloadString = "<-";    static final String uploadString = "->";    static final String zipString = "zip";    static final String cpString = "cp";    static final String rnString = "rn";    private DirCanvas label = new DirCanvas(this);    private boolean pathChanged = true;    private boolean firstGui = true;    private int pos=0;    private JPanel p = new JPanel();    private BorderPanel buttonPanel = new BorderPanel();    private JPanel currDirPanel = new JPanel();    private DefaultListModel jlm;    private JScrollPane jsp = new JScrollPane(jl);    private int tmpindex = -1;    private Hashtable dummy = new Hashtable();public LocalDir(){	type = "local";	con = new FilesystemConnection();	con.addConnectionListener(this);}public LocalDir(String path){	type = "local";	path = path;	con = new FilesystemConnection();	con.addConnectionListener(this);	con.chdir(path);	//gui(false);}   public void gui_init()    {	setLayout(new BorderLayout());	buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));        deleteButton = new HImageButton(Settings.deleteImage,deleteString,"Delete selected",this);        deleteButton.setToolTipText("Delete selected");        mkdirButton = new HImageButton(Settings.mkdirImage,mkdirString,"Create a new directory",this);        mkdirButton.setToolTipText("Create directory");        refreshButton = new HImageButton(Settings.refreshImage,refreshString,"Refresh current directory",this);        refreshButton.setToolTipText("Refresh directory");        cdButton = new HImageButton(Settings.cdImage,cdString,"Change directory",this);        cdButton.setToolTipText("Change directory");        uploadButton = new HImageButton(Settings.uploadImage,uploadString,"Upload selected",this);        uploadButton.setToolTipText("Upload selected");        zipButton = new HImageButton(Settings.zipFileImage,zipString,"Add selected to new zip file",this);        zipButton.setToolTipText("Create zip");        cpButton = new HImageButton(Settings.copyImage,cpString,"Copy selected files to another local dir",this);        cpButton.setToolTipText("Local copy selected");        rnButton = new HImageButton(Settings.textFileImage,rnString,"Rename selected file or directory",this);        rnButton.setToolTipText("Rename selected");	label.setText("Filesystem: "+cutPath(path));        label.setSize(getSize().width-10, 24);        currDirPanel.add(label);        currDirPanel.setSize(getSize().width-10, 32);        label.setSize(getSize().width-20, 24);	p.setLayout(new BorderLayout());	p.add("North", currDirPanel);	buttonPanel.add(new JLabel(" "));        buttonPanel.add(refreshButton);	buttonPanel.add(new JLabel(" "));		buttonPanel.add(cpButton);	buttonPanel.add(rnButton);	buttonPanel.add(mkdirButton);        buttonPanel.add(cdButton);	buttonPanel.add(deleteButton);	buttonPanel.add(new JLabel(" "));	buttonPanel.add(zipButton);	buttonPanel.add(new JLabel("                "));        buttonPanel.add(uploadButton);        buttonPanel.setVisible(true);        buttonPanel.setSize(getSize().width-10, 32);	p.add("East", buttonPanel);	add("North", p);        setDirList(true);        jlm=new DefaultListModel();        jl=new JList(jlm);        jl.setCellRenderer(new DirCellRenderer());        jl.setVisibleRowCount(Settings.visibleFileRows);        jl.addListSelectionListener(this);	jl.addKeyListener(this);	jl.requestFocus();        // add this becaus we need to fetch only doubleclicks        MouseListener mouseListener = new MouseAdapter()                                      {                                          public void mouseClicked(MouseEvent e)                                          {					   if(JFtp.uiBlocked) return;						//System.out.println("DirEntryListener::");                                              if (e.getClickCount() == 2)                                              {                                                      //System.out.println("2xList selection: "+jl.getSelectedValue().toString());                                                      int index = jl.getSelectedIndex()-1;						      // mousewheel bugfix, ui refresh bugfix						      if(index < -1) return;                                                      String tgt=(String)jl.getSelectedValue().toString();                                                      //System.out.println("List selection: "+index);                                                      if (index < 0)                                                      {                                                          chdir(path+tgt);                                                      }						      else if(dirEntry == null || dirEntry.length < index || dirEntry[index] == null) return;                                                      else if (dirEntry[index].isDirectory())                                                      {						      	   if(JFtp.mainFrame != null) JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR);                                                          chdir(path+tgt);							   if(JFtp.mainFrame != null) JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR);                                                      }                                                      else                                                      {						      	  showContentWindow(path + dirEntry[index].toString(), dirEntry[index]);                                                          //blockedTransfer(index);                                                      }                                              }                                          }                                      };        jl.addMouseListener(mouseListener);        jsp = new JScrollPane(jl);        jsp.setSize(getSize().width-20, getSize().height-72);        add("Center", jsp);        jsp.setVisible(true);        setVisible(true);    }    public void setViewPort() {}    public void gui(boolean fakeInit)    {        if (firstGui)        {            gui_init();            firstGui=false;        }	label.setText("Filesystem: "+cutPath(path));        if (!fakeInit)        {            setDirList(false);        } 	invalidate();	validate();    }    public void setDirList(boolean fakeInit)    {        jlm = new DefaultListModel();        DirEntry dwn = new DirEntry("..",this);        dwn.setDirectory();        jlm.addElement(dwn);        if(!fakeInit)        {            if(pathChanged)            {                pathChanged = false;                DirLister dir = new DirLister(con);                while(!dir.finished) LocalIO.pause(10);                if(dir.isOk())                {                    length = dir.getLength();                    dirEntry = new DirEntry[length];                    files = dir.list();                    String fSize[] = dir.sList();		    int perms[] = dir.getPermissions();		    // --------- sorting aphabetically ------------		    if(Settings.sortDir)	            {		      String[] tmpx = new String[length];		      //if(fSize != null) System.out.println(":"+length+":"+fSize.length+":"+files.length);		      int pLength = length;		      if(perms != null) pLength = perms.length;		      //System.out.println(files.length + ":" + fSize.length+":"+ pLength + ":"+ length);		      if(fSize.length != files.length || pLength != files.length || length != files.length) System.out.println("Sort mismatch - hopefully ignoring it...");                      for(int x=0; x<length; x++)                      {			if(perms != null) tmpx[x] = files[x] + "@@@" + fSize[x] + "@@@" + perms[x];			else  tmpx[x] = files[x] + "@@@" + fSize[x];		      }		      LocalIO.sortStrings(tmpx);                      for(int y=0; y<length; y++)                      {			files[y] = tmpx[y].substring(0,tmpx[y].indexOf("@@@"));			String tmp = tmpx[y].substring(tmpx[y].indexOf("@@@")+3);			fSize[y] =  tmp.substring(0,tmp.lastIndexOf("@@@"));			if(perms != null) perms[y] = Integer.parseInt(tmpx[y].substring(tmpx[y].lastIndexOf("@@@")+3));		      }		    }		    // ----------- end sorting --------------------                    for(int i=0; i<length; i++)                    {			if(files == null || files[i] == null)			{				//System.out.println("Critical error, files or files[i] is null!\nPlease report when and how this happened...");				System.out.println("skipping setDirList, files or files[i] is null!");				return;				//System.exit(0);			}			dirEntry[i] = new DirEntry(files[i],this);			if(dirEntry[i] == null) { System.out.println("\nskipping setDirList, dirEntry[i] is null!"); return; }			if(dirEntry[i].file == null) { System.out.println("\nskipping setDirList, dirEntry[i].file is null!"); return; }			if(perms != null) dirEntry[i].setPermission(perms[i]);                            dirEntry[i].setFileSize(Long.parseLong(fSize[i]));                            if(dirEntry[i].file.endsWith("/"))                            {                                dirEntry[i].setDirectory();                            }                            else                            {                                dirEntry[i].setFile();                            }			    jlm.addElement(dirEntry[i]);                    }                }                else                {                    Log.debug("Not a directory: " + path);                }            }            //System.out.println("length: "+dirEntry.length);        }        jl.setModel(jlm);    }    // 20011213:rb - Added logic for MSDOS style root dir    public boolean chdir(String p)    {    		if(JFtp.remoteDir == null) return false;	       BasicConnection c = JFtp.remoteDir.getCon();		if(c != null && (c instanceof FtpConnection))		{		 FtpConnection con = (FtpConnection) c;		 //con.setLocalPath(path);                 SaveSet s = new SaveSet(Settings.login_def,                                        con.getHost(),                                        con.getUsername(),                                        con.getPassword(),                                        Integer.toString(con.getPort()),                                        con.getCachedPWD(),                                        con.getLocalPath()                                       );		}	    if(con.chdirNoRefresh(p))	    {	      path = con.getPWD();	      JFtp.remoteDir.getCon().setLocalPath(path);              pathChanged = true;              gui(false);	      return true;	    }	//Log.debug("CWD (local) : " + p);        return false;    }    public void actionPerformed(ActionEvent e)    {     if(JFtp.uiBlocked) return;        if(e.getActionCommand().equals("rm"))        {	   lock(false);	   if(Settings.getAskToDelete())	   {	  	if(!UITool.askToDelete(this)) return;	   }            for(int i=0; i<length;i++)            {                if(dirEntry[i].selected)                {			con.removeFileOrDir(dirEntry[i].file);		}	    }	   unlock(false);	    fresh();        }        else if(e.getActionCommand().equals("mkdir"))        {            Creator c = new Creator("Create:",con);	    fresh();        }        else if(e.getActionCommand().equals("cmd"))        {            RemoteCommand rc = new RemoteCommand();	    fresh();        }        else if(e.getActionCommand().equals("cd"))        { 		 String tmp = UITool.getPathFromDialog(path);		 chdir(tmp);        }        else if(e.getActionCommand().equals("fresh"))        {            fresh();        }

⌨️ 快捷键说明

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