localdir.java
来自「java ftp 操作代码,程序可以直接运行」· Java 代码 · 共 1,552 行 · 第 1/4 页
JAVA
1,552 行
jl.addKeyListener(this); jl.addMouseListener(mouseListener); jl.requestFocus(); } 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() { } /** * 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; } if(con instanceof FilesystemConnection) { label.setText("Filesystem: " + StringUtils.cutPath(path)); } else { label.setText("Remote: " + StringUtils.cutPath(path)); } if(!fakeInit) { setDirList(false); } invalidate(); validate(); } /** * 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; DirLister dir = new DirLister(con, sortMode, Settings.getHideLocalDotNames()); 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 ------------ // 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 { 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]); } 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(); } //------ 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); update(); } // 20011213:rb - Added logic for MSDOS style root dir /** * Change the directory of this connection and update the gui */ public boolean chdir(String p) { if((JFtp.remoteDir == null) || (p == null) || p.trim().equals("")) { 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(); if(con instanceof FilesystemConnection) { JFtp.remoteDir.getCon().setLocalPath(path); //con.fireDirectoryUpdate(con); //OR setDate(); } pathChanged = true; gui(false); return true; } //Log.debug("CWD (local) : " + p); return false; } /** * 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); //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(); } 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("->"))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?