remotedir.java

来自「java ftp 操作代码,程序可以直接运行」· Java 代码 · 共 1,646 行 · 第 1/4 页

JAVA
1,646
字号
                        jsp.setSize(getSize().width - 20, getSize().height - 72);        add("Center", jsp);        jsp.setVisible(true);                TableUtils.tryToEnableRowSorting(table);                if(Settings.IS_JAVA_1_6) {        	//sorter.setVisible(false);        	buttonPanel.remove(sorter);        }                setVisible(true);    }    public void setViewPort()    {    }    private void setLabel()    {        if(con instanceof FilesystemConnection)        {            label.setText("Filesystem: " + StringUtils.cutPath(path));        }        else if(con instanceof FtpConnection)        {            label.setText("Ftp: " + StringUtils.cutPath(path));        }        else if(con instanceof SftpConnection)        {            label.setText("Sftp: " + StringUtils.cutPath(path));        }        else        {            label.setText(StringUtils.cutPath(path));        }    }    /**    * Part of a gui refresh.    * There's no need to call this by hand.    */    public void gui(boolean fakeInit)    {        if(firstGui)        {            gui_init();            firstGui = false;        }        setLabel();        if(con instanceof FtpConnection)        {            list.show();            cmdButton.show();            transferType.show();        }        else        {            list.hide();            cmdButton.hide();            transferType.hide();        }        if(!fakeInit)        {            setDirList(false);        }        //TODO Log.debug("invalidate()");        invalidate();        validate();        //TODO .debug("validated.");    }    /**    * List directory and create/update the whole file list.    * There's no need to call this by hand.    */    public void setDirList(boolean fakeInit)    {        jlm = new DefaultListModel();        DirEntry dwn = new DirEntry("..", this);        dwn.setDirectory();        jlm.addElement(dwn);        if(!fakeInit)        {            if(pathChanged)            {                pathChanged = false;                //TODO .debug("before DirLister");                DirLister dir = new DirLister(con, sortMode);                while(!dir.finished)                {                    LocalIO.pause(10);                }                if(dir.isOk())                {                    //TODO .debug("dir is ok");                    length = dir.getLength();                    dirEntry = new DirEntry[length];                    files = dir.list();                    String[] fSize = dir.sList();                    int[] perms = dir.getPermissions();                    // --------- sorting aphabetically ------------                    // is now in DirLister                    /*                                        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                                                {                                                    Log.out("permissions  are skipped");                                                    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);                                                if(tmp.indexOf("@@@") > 0)                                                {                                                    fSize[y] = tmp.substring(0,                                                                             tmp.lastIndexOf("@@@"));                                                }                                                else                                                {                                                    fSize[y] = tmp;                                                }                                                if(perms != null)                                                {                                                    perms[y] = Integer.parseInt(tmpx[y].substring(tmpx[y].lastIndexOf("@@@") +                                                                                                  3));                                                }                                            }                                        }                    */                    // ----------- end sorting --------------------                    for(int i = 0; i < length; i++)                    {                        //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 -------                        Object[] d = dir.getDates();                        if(d != null)                        {                            dirEntry[i].setDate((Date) 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");                update();    }    /**    * 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;            }                       int opt = JOptionPane.showOptionDialog(this, "Would you like to type one command or to open a shell?","Question", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,             		new ImageIcon(HImage.getImage(this, Settings.helpImage)), new String[] {"Shell","Command", "Cancel"}, "Command");                        if(opt == 1) {            	RemoteCommand rc = new RemoteCommand();            }            else if(opt == 0) {            	FtpConnection conn = (FtpConnection) con;            	Shell s = new Shell(conn.getCommandInputReader(), conn.getCommandOutputStream());            }            //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            {            	if(!(con instanceof FtpConnection)) {            		 Log.debug("Can only list FtpConnection output!");            	}            	            	PrintStream out = new PrintStream(Settings.ls_out);            	for(int i=0; i<((FtpConnection)con).currentListing.size(); i++) {            		out.println(((FtpConnection)con).currentListing.get(i));            	}            	out.flush();            	out.close();            	                java.net.URL url = new java.io.File(Settings.ls_out).toURL();                Displayer d = new Displayer(url, new Font("monospaced",Font.PLAIN, 11));                JFtp.desktop.add(d, new Integer(Integer.MAX_VALUE - 13));            }            catch(java.net.MalformedURLException ex)            {                ex.printStackTrace();                Log.debug("ERROR: Malformed URL!");            }            catch(FileNotFoundException ex2)            {                ex2.printStackTrace();                Log.debug("ERROR: File not found!");            }        }        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)))

⌨️ 快捷键说明

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