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

📄 remotedir.java

📁 一个JAVA做的FTP软件,带源码的,可以很好的进行二次开发,,并带有详细说明文件的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        //System.out.println(files[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);                        }                        //Log.debug("adding: " + files[i]);                        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]);                        }                        if(fSize[i].startsWith("@"))                        {                            fSize[i] = fSize[i].substring(1);                        }                        dirEntry[i].setFileSize(Long.parseLong(fSize[i]));                        if(dirEntry[i].file.endsWith("/"))                        {                            dirEntry[i].setDirectory();                        }                        else                        {                            dirEntry[i].setFile();                        }                        if(dirEntry[i].file.endsWith("###"))                        {                            dirEntry[i].setLink();                        }						//------ date parser -------			Date[] d = dir.getDates();			if(d != null)			{				dirEntry[i].setDate(d[i]);			}			//--------------------------                        jlm.addElement(dirEntry[i]);                    }                }                else                {                    Log.debug("Not a directory: " + path);                }            }            //System.out.println("length: "+dirEntry.length);        }        jl.setModel(jlm);        jl.grabFocus();        jl.setSelectedIndex(0);        //Log.debug("ListModel set.");        //System.out.print("x");        //new Exception().printStackTrace();        //System.out.println("\n\n\n");    }    /**    * Handles the user events if the ui is unlocked    */    public void actionPerformed(ActionEvent e)    {        if(JFtp.uiBlocked)        {            return;        }        if(e.getActionCommand().equals("rm"))        {            lock(false);            if(Settings.getAskToDelete())            {                if(!UITool.askToDelete(this))                {                    unlock(false);                    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);	    //TODO: do we need this on events? UpdateDaemon.updateRemoteDirGUI();            //fresh();        }        else if(e.getActionCommand().equals("cmd"))        {            if(!(con instanceof FtpConnection))            {                Log.debug("This feature is for ftp only.");                return;            }            RemoteCommand rc = new RemoteCommand();            //fresh();        }        else if(e.getActionCommand().equals("cd"))        {            PathChanger pthc = new PathChanger("remote");            //fresh();            //String tmp = UITool.getPathFromDialog();            //setPath(tmp);        }        else if(e.getActionCommand().equals("fresh"))        {            fresh();        }        else if(e.getActionCommand().equals("->"))        {            blockedTransfer(-2);        }        else if(e.getActionCommand().equals("<-"))        {            blockedTransfer(-2);        }        else if(e.getActionCommand().equals("list"))        {            try            {                java.net.URL url = new java.io.File(Settings.ls_out).toURL();                Displayer d = new Displayer(url);                JFtp.desktop.add(d, new Integer(Integer.MAX_VALUE - 13));            }            catch(java.net.MalformedURLException ex)            {                ex.printStackTrace();            }        }        else if(e.getActionCommand().equals("type") && (!JFtp.uiBlocked))        {            if(!(con instanceof FtpConnection))            {                Log.debug("You can only set the transfer type for ftp connections.");                return;            }            FtpConnection c = (FtpConnection) con;            String t = c.getTypeNow();            boolean ret = false;            if(t.equals(FtpConnection.ASCII))            {                ret = c.type(FtpConnection.BINARY);            }            else if(t.equals(FtpConnection.BINARY))            {                ret = c.type(FtpConnection.EBCDIC);            }            if(t.equals(FtpConnection.EBCDIC) ||                   (!ret && !t.equals(FtpConnection.L8)))            {                ret = c.type(FtpConnection.L8);            }            if(!ret)            {                c.type(FtpConnection.ASCII);                Log.debug("Warning: type should be \"I\" if you want to transfer binary files!");            }            Log.debug("Type is now " + c.getTypeNow());        }        else if(e.getActionCommand().equals("que")) /*&& (!JFtp.uiBlocked))*/        {            if(!(con instanceof FtpConnection))            {                Log.debug("Queue supported only for FTP");                return;            }            Object[] o = jl.getSelectedValues();            DirEntry[] tmp = new DirEntry[Array.getLength(o)];            for(int i = 0; i < Array.getLength(o); i++)            {                tmp[i] = (DirEntry) o[i];                JFtp.dQueue.addFtp(tmp[i].toString());            }        }        else if(e.getSource() == props)        {            JFtp.statusP.jftp.clearLog();            int x = currentPopup.getPermission();            String tmp;            if(x == FtpConnection.R)            {                tmp = "read only";            }            else if(x == FtpConnection.W)            {                tmp = "read/write";            }            else if(x == FtpConnection.DENIED)            {                tmp = "denied";            }            else            {                tmp = "undefined";            }            String msg = "File: " + currentPopup.toString() + "\n" + " Size: " +                         currentPopup.getFileSize() + " raw size: " +                         currentPopup.getRawSize() + "\n" + " Symlink: " +                         currentPopup.isLink() + "\n" + " Directory: " +                         currentPopup.isDirectory() + "\n" + " Permission: " +                         tmp + "\n";            Log.debug(msg);        }        else if(e.getSource() == sorter)        {            sortMode = (String) sorter.getSelectedItem();	    	    if(sortMode.equals("Date")) Settings.showDateNoSize = true;	    else Settings.showDateNoSize = false;	                fresh();        }        else if(e.getActionCommand().equals("cdUp"))        {            JFtp.remoteDir.getCon().chdir("..");        }    }    /**    * Initiate a tranfer with ui locking enabled    */    public synchronized void blockedTransfer(int index)    {        tmpindex = index;        Runnable r = new Runnable()        {            public void run()            {                boolean block = !Settings.getEnableMultiThreading();                if(!(con instanceof FtpConnection))                {                    block = true;                }                if(block)                {                    lock(false);                }                transfer(tmpindex);                if(block)                {                    JFtp.localDir.fresh();                    unlock(false);                }            }        };        Thread t = new Thread(r);        t.start();    }    /**    * Lock the gui.    */    public void lock(boolean first)    {        JFtp.uiBlocked = true;        jl.setEnabled(false);        if(!first)        {            JFtp.localDir.lock(true);        }        Log.out("ui locked.");    }    /**    * Unlock the gui.    */    public void unlock(boolean first)    {        JFtp.uiBlocked = false;        jl.setEnabled(true);        if(!first)        {            JFtp.localDir.unlock(true);        }        Log.out("ui unlocked.");    }    /**    * Do a hard UI refresh - do no longe call this directly, use    * safeUpdate() instead if possible.    */    public void fresh()    {        Log.out("fresh() called.");        Cursor x = null;               if(JFtp.mainFrame != null)        {           x = JFtp.mainFrame.getCursor();           JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR);        }         //TODO .debug("fresh()");        String i = "";        int idx = jl.getSelectedIndex();        if(idx >= 0)        {            Object o = jl.getSelectedValue();            if(o != null)            {                i = o.toString();            }        }        con.chdir(path);        if((idx >= 0) && (idx < jl.getModel().getSize()))        {            if(jl.getModel().getElementAt(idx).toString().equals(i))            {                jl.setSelectedIndex(idx);            }            else            {                jl.setSelectedIndex(0);            }        }        if((JFtp.mainFrame != null) && (x.getType() != Cursor.WAIT_CURSOR))        {            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            {                String tgt = (String) jl.getSelectedValue().toString();                //if (index < 0)                //{                //con.chdir(path+tgt);                //}                for(int i = 0; i < dirEntry.length; i++)                {                    dirEntry[i].setSelected(jl.isSelectedIndex(i + 1));                }            }        }    }    /**    * Called by FtpConnection, DownloadList is updated from here    */    public void updateProgress(String file, String type, long bytes)    {        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        {            for(int i = 0; i < dirEntry.length; i++)            {                if(dirEntry[i] == null)                {                    continue;                }                if(dirEntry[i].toString().equals(file))                {                    s = dirEntry[i].getRawSize();                    JFtp.dList.sizeCache.put(file, new Long(s));                    break;                }            }            if(s <= 0)            {                File f = new File(JFtp.localDir.getPath() + file);                if(f.exists())                {                    s = f.length();                }            }        }        dList.updateList(file, type, bytes, s);    }    /**    * Called by FtpConnection    */    public void connectionInitialized(BasicConnection con)    {        if(con == null)        {            return;

⌨️ 快捷键说明

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