📄 remotedir.java
字号:
/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package net.sf.jftp.gui;import net.sf.jftp.*;import net.sf.jftp.config.*;import net.sf.jftp.gui.framework.*;import net.sf.jftp.net.*;import net.sf.jftp.util.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.lang.reflect.Array;import java.util.*;import javax.swing.*;import javax.swing.event.*;public class RemoteDir extends DirPanel implements ListSelectionListener, ActionListener, ConnectionListener, KeyListener{ //HImageButton openButton; static final String deleteString = "rm"; static final String mkdirString = "mkdir"; static final String refreshString = "fresh"; static final String cdString = "cd"; static final String cmdString = "cmd"; static final String downloadString = "<-"; static final String uploadString = "->"; static final String queueString = "que"; static final String cdUpString = "cdUp"; HImageButton deleteButton; HImageButton mkdirButton; HImageButton cmdButton; HImageButton refreshButton; HImageButton cdButton; HImageButton uploadButton; HImageButton downloadButton; HImageButton queueButton; HImageButton cdUpButton; //static final String openString = "open"; private DirCanvas label = new DirCanvas(this); private boolean pathChanged = true; private boolean firstGui = true; private int pos = 0; private JPanel p = new JPanel(); private JToolBar buttonPanel = new JToolBar(); private JToolBar currDirPanel = new JToolBar(); private DefaultListModel jlm; private JScrollPane jsp = new JScrollPane(jl); private int tmpindex = -1; private HImageButton list = new HImageButton(Settings.listImage, "list", "Show remote listing...", this); private HImageButton transferType = new HImageButton(Settings.typeImage, "type", "Toggle transfer type...", this); private JPopupMenu popupMenu = new JPopupMenu(); private JMenuItem props = new JMenuItem("Properties"); private DirEntry currentPopup = null; private String sortMode = null; String[] sortTypes = new String[] { "Normal", "Reverse", "Size", "Size/Re" }; private JComboBox sorter = new JComboBox(sortTypes); private boolean dateEnabled = false; /** * RemoteDir constructor. */ public RemoteDir() { type = "remote"; con = new FilesystemConnection(); con.addConnectionListener(this); if(!con.chdir("/")) { con.chdir("C:\\"); } } /** * RemoteDir constructor. */ public RemoteDir(String path) { type = "remote"; path = path; con = new FilesystemConnection(); con.addConnectionListener(this); con.chdir(path); } /** * Creates the gui and adds the MouseListener etc. */ public void gui_init() { setLayout(new BorderLayout()); currDirPanel.setFloatable(false); buttonPanel.setFloatable(false); buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); props.addActionListener(this); popupMenu.add(props); deleteButton = new HImageButton(Settings.deleteImage, deleteString, "Delete selected", this); deleteButton.setToolTipText("Delete selected"); mkdirButton = new HImageButton(Settings.mkdirImage, mkdirString, "Create a new directory", this); mkdirButton.setToolTipText("Create directory"); refreshButton = new HImageButton(Settings.refreshImage, refreshString, "Refresh current directory", this); refreshButton.setToolTipText("Refresh directory"); cdButton = new HImageButton(Settings.cdImage, cdString, "Change directory", this); cdButton.setToolTipText("Change directory"); cmdButton = new HImageButton(Settings.cmdImage, cmdString, "Execute remote command", this); cmdButton.setToolTipText("Execute remote command"); downloadButton = new HImageButton(Settings.downloadImage, downloadString, "Download selected", this); downloadButton.setToolTipText("Download selected"); queueButton = new HImageButton(Settings.downloadImage, queueString, "Queue selected", this); queueButton.setToolTipText("Queue selected"); cdUpButton = new HImageButton(Settings.cdUpImage, cdUpString, "Go to Parent Directory", this); cdUpButton.setToolTipText("Go to Parent Directory"); //openButton = new HImageButton(Settings.openImage,openString,"Connect to server",this); //openButton.setToolTipText("Connect"); setLabel(); label.setSize(getSize().width - 10, 24); currDirPanel.add(label); currDirPanel.setSize(getSize().width - 10, 32); label.setSize(getSize().width - 20, 24); p.setLayout(new BorderLayout()); p.add("North", currDirPanel); buttonPanel.add(downloadButton); //buttonPanel.add(new JLabel(" ")); buttonPanel.add(queueButton); buttonPanel.add(new JLabel(" ")); //buttonPanel.add(openButton); //buttonPanel.add(new JLabel(" ")); buttonPanel.add(refreshButton); buttonPanel.add(new JLabel(" ")); buttonPanel.add(mkdirButton); buttonPanel.add(cdButton); buttonPanel.add(deleteButton); buttonPanel.add(cdUpButton); buttonPanel.add(new JLabel(" ")); buttonPanel.add(cmdButton); buttonPanel.add(list); buttonPanel.add(transferType); //buttonPanel.add(new JLabel(" ")); buttonPanel.add(sorter); buttonPanel.setVisible(true); buttonPanel.setSize(getSize().width - 10, 32); p.add("West", buttonPanel); add("North", p); sorter.addActionListener(this); //setDirList(true); jlm = new DefaultListModel(); jl = new JList(jlm); jl.setCellRenderer(new DirCellRenderer()); jl.setVisibleRowCount(Settings.visibleFileRows); jl.addListSelectionListener(this); jl.addKeyListener(this); jl.setDropTarget(JFtp.statusP.jftp.dropTarget); // add this becaus we need to fetch only doubleclicks MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { if(JFtp.uiBlocked) { return; } if(e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e)) { int index = jl.getSelectedIndex() - 1; if(index < -1) { return; } String tgt = (String) jl.getSelectedValue().toString(); if(index < 0) { } else if((dirEntry == null) || (dirEntry.length < index) || (dirEntry[index] == null)) { return; } else { currentPopup = dirEntry[index]; popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } public void mouseClicked(MouseEvent e) { if(JFtp.uiBlocked) { return; } //System.out.println("DirEntryListener::"); if(e.getClickCount() == 2) { //System.out.println("2xList selection: "+jl.getSelectedValue().toString()); int index = jl.getSelectedIndex() - 1; // mousewheel bugfix if(index < -1) { return; } String tgt = (String) jl.getSelectedValue().toString(); if(index < 0) { if(JFtp.mainFrame != null) { JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR); } con.chdir(path + tgt); if(JFtp.mainFrame != null) { JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR); } } else if((dirEntry == null) || (dirEntry.length < index) || (dirEntry[index] == null)) { return; } else if(dirEntry[index].isDirectory()) { con.chdir(path + tgt); } else if(dirEntry[index].isLink()) { if(!con.chdir(path + tgt)) { showContentWindow(path + dirEntry[index].toString(), dirEntry[index]); //blockedTransfer(index); } } else { showContentWindow(path + dirEntry[index].toString(), dirEntry[index]); //blockedTransfer(index); } } } }; jl.addMouseListener(mouseListener); jsp = new JScrollPane(jl); jsp.setSize(getSize().width - 20, getSize().height - 72); add("Center", jsp); jsp.setVisible(true); 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++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -