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

📄 localdir.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        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]))            {                Log.out("mismatch");            }        }        for(int i = 0; i < cacheEntry.length; i++)        {            if(bFileSelected[i])            {                startTransfer(cacheEntry[i]);            }        }    }    /**    * Start a file transfer.    * Depending on the local and remote connection types some things like    * local working directory have to be set, resuming may have to be checked etc.    * As with ftp to ftp transfers the action used to download a file might actually be    * an upload.    *    * WARNING: If you do anything here, please check RemoteDir.startTransfer(), too!    */    public void startTransfer(DirEntry entry)    {        if(con instanceof FilesystemConnection &&               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(con instanceof FtpConnection &&                    JFtp.remoteDir.getCon() instanceof FtpConnection)        {            // local: ftp, remote: ftp            if(entry.isDirectory())            {                Log.debug("Directory transfer between remote connections is not supported yet!");                return;            }            Log.out("direct ftp transfer started (upload)");            ((FtpConnection) JFtp.remoteDir.getCon()).upload(entry.file,                                                             ((FtpConnection) JFtp.localDir.getCon()).getDownloadInputStream(path +                                                                                                                             entry.file));        }        else if(con instanceof FtpConnection &&                    JFtp.remoteDir.getCon() instanceof FilesystemConnection)        {            con.setLocalPath(JFtp.remoteDir.getPath());            con.handleDownload(path + entry.file);        }        else if(con instanceof FilesystemConnection &&                    JFtp.remoteDir.getCon() instanceof FilesystemConnection)        {            con.upload(entry.file);            JFtp.remoteDir.actionPerformed(con, "FRESH");        }        else if(con instanceof FilesystemConnection)        {            // local: file, remote: smb,sftp,nfs            JFtp.remoteDir.getCon().handleUpload(entry.file);            JFtp.remoteDir.actionPerformed(con, "FRESH");        }        else        {            if(entry.isDirectory())            {                Log.debug("Directory transfer between remote connections is not supported yet!");                return;            }            Log.out("direct transfer started (upload)");            JFtp.remoteDir.getCon().upload(entry.file,                                           JFtp.localDir.getCon()                                                        .getDownloadInputStream(path +                                                                                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]);        }    }    /**    * Safely refresh the UI.    */    public void safeUpdate()    {        UpdateDaemon.updateLocalDir();        /*        long time = System.currentTimeMillis();        if((time - oldtime) < 5000)        {            return;        }        oldtime = time;        fresh();        */    }        /**    * Called by FtpConnection    */    public void actionPerformed(Object target, String msg)    {        //System.out.print(msg);        //fresh();        safeUpdate();    }    /**    * Called by FtpConnection, DownloadList is updated from here    */    public void updateProgress(String file, String type, long bytes) // only for url-downloads, for other see RemoteDir    {        if((dList == null) || (dirEntry == null))        {            return;        }        boolean flag = false;        if(file.endsWith("/") && (file.length() > 1))        {            flag = true;            file = file.substring(0, file.lastIndexOf("/"));        }        file = file.substring(file.lastIndexOf("/") + 1);        if(flag)        {            file = file + "/";        }        long s = 0;        if(JFtp.dList.sizeCache.containsKey(file))        {            s = ((Long) JFtp.dList.sizeCache.get(file)).longValue();        }        else        {            s = new File(getPath() + file).length();            JFtp.dList.sizeCache.put(file, new Long(s));        }        dList.updateList(file, type, bytes, s);    }    /**    * Called by FtpConnection    */    public void connectionInitialized(BasicConnection con)    {    }    /**    * Called by FtpConnection    */    public void actionFinished(BasicConnection con)    {        //fresh();        safeUpdate();    }    /**    * Called by FtpConnection    */    public void connectionFailed(BasicConnection con, String reason)    {    }    /**    * Called by FtpConnection    */    public void updateRemoteDirectory(BasicConnection c)    {        if(con instanceof FtpConnection)        {            path = ((FtpConnection) con).getCachedPWD();        }        else if(con instanceof SmbConnection && !path.startsWith("smb://"))        {            path = con.getPWD();        }        else        {            path = con.getPWD();        }        //fresh();        safeUpdate();    }    /**    * Extract a zip file and change to the directory    */    private void setZipFilePath(DirEntry entry)    {        if(JFtp.mainFrame != null)        {            JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR);        }        String n = entry.toString();        String tmp = path + n + "-dir/";        Log.debug("\nExtracting: " + path + n);        File tmpDir = new File(tmp);        if(tmpDir.exists() || tmpDir.mkdir())        {	 try	 {	    ZipFile z = new ZipFile(path + n);            Enumeration e = z.entries();            while(e.hasMoreElements())            {                ZipEntry z1 = (ZipEntry) e.nextElement();                Log.debug("-> " + z1.getName());                BufferedInputStream in = new BufferedInputStream(z.getInputStream(z1));		BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmp+z1.getName()));		byte buf[] = new byte[8192];				while(in.read(buf,0,8192) != StreamTokenizer.TT_EOF)		{			out.write(buf);		}				out.flush();		out.close();		in.close();            }	    	    chdir(tmp);	  }	  catch(IOException ex)	  {	  	ex.printStackTrace();		Log.debug("ERROR: " + ex);	  }        }        else        {            Log.debug("Cannot create directory, skipping extraction...");        }        //chdir(path + tgt);        if(JFtp.mainFrame != null)        {            JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR);        }    }    /**    * Mime type handler for doubleclicks on files    */    public void showContentWindow(String url, DirEntry d)    {        if(d.toString().endsWith(".zip"))        {            setZipFilePath(d);        }        else        {            try            {                if(d.getRawSize() > 200000)                {                    Log.debug("File is too big - 200kb is the maximum, sorry.");                    return;                }                url = "file://" + url;                HPanel f = new HPanel();                JEditorPane pane = new JEditorPane(url);                pane.setEditable(false);                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.setLayout(new BorderLayout());                f.add("Center", jsp);                JFtp.statusP.jftp.addToDesktop(url, f, 600, 400);            }            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 + -