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

📄 localdir.java

📁 JAVA FTP客户端经典
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        else if(e.getActionCommand().equals("cp"))        {	    Object o[] = jl.getSelectedValues();	    if(o == null) return;	    String tmp = UITool.getPathFromDialog(path);	    if(tmp == null) return;	    if(!tmp.endsWith("/")) tmp = tmp + "/";	    try	    {	    	copy(o, path, "", tmp);		fresh();		Log.debug("Copy finished...");	    }	    catch(Exception ex)	    {	    	ex.printStackTrace();		Log.debug("Copy failed!");	    }        }        else if(e.getActionCommand().equals("zip"))        {	 try	 {	    Object entry[] = jl.getSelectedValues();	    if(entry == null) return;	    String tmp[] = new String[entry.length];	    for(int i=0; i<tmp.length; i++)	    {	    	tmp[i] = entry[i].toString();	    }	    NameChooser n = new NameChooser();	    String name = n.text.getText();            ZipFileCreator z = new ZipFileCreator(tmp, path, name);	    fresh();	 }	 catch(Exception ex)	 {	 	ex.printStackTrace();	 }        }        else if(e.getActionCommand().equals("->"))        {	 blockedTransfer(-2);        }        else if(e.getActionCommand().equals("<-"))        {	 blockedTransfer(-2);        }	else  if(e.getActionCommand().equals("rn"))        {		String target = jl.getSelectedValue().toString();		if(target == null) return;		Renamer r = new Renamer(target, path);		fresh();        }    }    private void copy(Object fRaw[], String path, String offset, String target) throws Exception    {	String files[] = new String[fRaw.length];	for(int j=0; j<fRaw.length; j++)	{		files[j] = fRaw[j].toString();	}    	for(int i=0; i<files.length; i++)	{		File f = new File(path+offset +files[i]);		BufferedInputStream in = null;		BufferedOutputStream out = null;		byte buf[] = new byte[4096];		if(f.exists() && !f.isDirectory())		{			 in = new BufferedInputStream(new FileInputStream(path+offset + files[i]));			 out = new BufferedOutputStream(new FileOutputStream(target + offset + files[i]));			int len = 0;		 	while(in != null)			 {			 	len = in.read(buf);				if(len== StreamTokenizer.TT_EOF) break;				out.write(buf,0,len);			 }			out.flush();		 	out.close();		}		else if(f.exists())		{			if(!files[i].endsWith("/")) files[i] = files[i] +"/";			File f2 = new File(target + offset + files[i]);			if(!f.exists()) f.mkdir();			copy(f.list(), path, offset + files[i], target);		}	}     }    public synchronized void blockedTransfer(int index)    {	 tmpindex = index;	 Runnable r = new Runnable()	 {	  public void run()	  {     // --------------- local -------------------	        boolean block = !Settings.getEnableMultiThreading();		if(!(con instanceof FtpConnection)) block = true;	    	if(block || Settings.getNoUploadMultiThreading()) lock(false);            	transfer(tmpindex);	    	if(block || Settings.getNoUploadMultiThreading()) unlock(false);		//{		 //JFtp.remoteDir.fresh();		 //unlock(false);		 //}	  }	 };	 Thread t = new Thread(r);	 t.start();    }    public void lock(boolean first)    {    	JFtp.uiBlocked = true;	jl.setEnabled(false);	if(!first) JFtp.remoteDir.lock(true);    }    public void unlock(boolean first)    {    	JFtp.uiBlocked = false;	jl.setEnabled(true);	if(!first) JFtp.remoteDir.unlock(true);    }    public void fresh()    {	    if(JFtp.mainFrame != null) JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR);	    String i = "";	    int idx = jl.getSelectedIndex();	    if(idx >= 0)	    {	    	Object o = jl.getSelectedValue();	   	 if(o != null) i = o.toString();	    }            chdir(path);	    if(idx >= 0 && (idx < jl.getModel().getSize()))	    	    if(jl.getModel().getElementAt(idx).toString().equals(i)) jl.setSelectedIndex(idx);	    else jl.setSelectedIndex(0); 	    //JFtp jftp = JFtp.statusP.jftp;	    //jftp.paintImmediately(0,0,jftp.getSize().width,jftp.getSize().height);	     if(JFtp.mainFrame != null) JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR);    }    /** this manages the selections */    public void valueChanged(ListSelectionEvent e)    {        if (e.getValueIsAdjusting() == false)        {	    							  //  ui refresh bugfix	    int index = jl.getSelectedIndex()-1;            if (index < 0 || dirEntry == null || dirEntry.length < index || dirEntry[index] == null)            {	    	return;            }            else            {        // -------------------- local --------------------------                    String tgt=(String)jl.getSelectedValue().toString();                    for (int i=0; i<dirEntry.length; i++)                    {                        dirEntry[i].setSelected(jl.isSelectedIndex(i+1));                    }            }        }    }    /** Transfers all selected files */    public synchronized void transfer()    {      boolean bFileSelected[] = new boolean[dirEntry.length + 1];      DirEntry cacheEntry[] = new DirEntry[dirEntry.length];      System.arraycopy(dirEntry,0,cacheEntry,0,cacheEntry.length);      for (int i = 0; i < dirEntry.length; i++)      {        bFileSelected[i] = cacheEntry[i].selected;	if(!cacheEntry[i].equals(dirEntry[i])) System.out.println("mismatch");      }      for (int i = 0; i < cacheEntry.length; i++)      {        if (bFileSelected[i])	{		startTransfer(cacheEntry[i]);        }      }    } public void startTransfer(DirEntry entry) {  if(JFtp.remoteDir.getCon() instanceof FtpConnection)  {	if(entry.getRawSize() < Settings.smallSizeUp && !entry.isDirectory()) JFtp.remoteDir.getCon().upload(path+entry.file);	else JFtp.remoteDir.getCon().handleUpload(path+entry.file);  }  else if(JFtp.remoteDir.getCon() instanceof FilesystemConnection)  {	//if(entry.getRawSize() < Settings.smallSize && !entry.isDirectory()) con.upload(entry.file);	//else con.handleUpload(path+entry.file);	con.upload(entry.file);	JFtp.remoteDir.actionPerformed(con, "FRESH");  }  else  {  	JFtp.remoteDir.getCon().handleUpload(entry.file);	JFtp.remoteDir.actionPerformed(con, "FRESH");  }}    /** Transfers single file, or all selected files if index is -1 */    public void transfer(int i)    {    	if(i == -2)	{		transfer();		return;	}	else if(dirEntry[i].selected)        {		startTransfer(dirEntry[i]);        }    }public void safeUpdate(){        long time = System.currentTimeMillis();	if((time-oldtime) < 5000)	{		return;	}	oldtime = time;	fresh();}public void actionPerformed(Object target, String msg){	//System.out.print(msg);	//fresh();	safeUpdate();}public void updateProgress(String file, String type, long bytes) {}public void connectionInitialized(BasicConnection con){	//fresh();}public void actionFinished(BasicConnection con){	fresh();	//safeUpdate();}public void connectionFailed(BasicConnection con, String reason) {}public void updateRemoteDirectory(BasicConnection con){	fresh();	//safeUpdate();}   String cutPath(String s)    {        int maxlabel = 64;        if(s.length() > maxlabel)        {            while(true)            {                s = StringUtils.cutAfter(s,'/');                if(s.length() < 16)                {                    StringBuffer sb = new StringBuffer(s);                    sb.insert(0,".../");                    return sb.toString();                }            }        }        return s;    }    public void showContentWindow(String url, DirEntry d)    {     try     {	 if(d.getRawSize() > 200000)	 {		Log.debug("File is too big - 200kb is the maximum, sorry.");		return;	}        url = "file://"+url;	HFrame f = new HFrame();	f.setTitle(url);	JEditorPane pane = new JEditorPane(url);	if(!pane.getEditorKit().getContentType().equals("text/html") && !pane.getEditorKit().getContentType().equals("text/rtf"))	{		if(!pane.getEditorKit().getContentType().equals("text/plain"))		{			Log.debug("Nothing to do with this filetype - use the buttons if you want to transfer files.");			return;		}		pane.setEditable(false);	}	JScrollPane jsp = new JScrollPane(pane);	f.getContentPane().setLayout(new BorderLayout());	f.getContentPane().add("Center", jsp);	f.setModal(false);	f.setLocation(100,100);	f.setSize(600, 400);	f.show();	/*	 DataHandler dh = new DataHandler(new URL(url));	CommandInfo bi = dh.getCommand("view");	if (bi == null) {	    Log.debug("No default application found.");	}	f.getContentPane().add((Component)dh.getBean(bi));	f.setSize(new Dimension(600,400));	f.show();	*/     }     catch(Exception ex)     {     	Log.debug("File error: " + ex);     }    } public void keyPressed(KeyEvent e) { 	if(e.getKeyCode() == KeyEvent.VK_ENTER)	{		Object o = jl.getSelectedValue();		if(o == null) return;		String tmp = ((DirEntry) o).toString();		if(tmp.endsWith("/") || tmp.equals("..")) chdir(tmp);		else showContentWindow(path + tmp, (DirEntry) o);	}	else if(e.getKeyCode() == KeyEvent.VK_SPACE)	{		int x = ((DirPanel)JFtp.remoteDir).jl.getSelectedIndex();		if(x == -1) x = 0;		((DirPanel)JFtp.remoteDir).jl.grabFocus();		((DirPanel)JFtp.remoteDir).jl.setSelectedIndex(x);	} } public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) {}}

⌨️ 快捷键说明

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