📄 localdir.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.net.*;import java.util.*;import java.util.zip.*;import javax.swing.*;import javax.swing.event.*;public class LocalDir extends DirPanel implements ListSelectionListener, ActionListener, ConnectionListener, KeyListener{ 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 zipString = "zip"; static final String cpString = "cp"; static final String rnString = "rn"; static final String cdUpString = "cdUp"; HImageButton deleteButton; HImageButton mkdirButton; HImageButton cmdButton; HImageButton refreshButton; HImageButton cdButton; HImageButton uploadButton; HImageButton zipButton; HImageButton cpButton; HImageButton rnButton; 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 Hashtable dummy = new Hashtable(); private JPopupMenu popupMenu = new JPopupMenu(); private JMenuItem viewFile = new JMenuItem("View file"); 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); HImageButton cdUpButton; /** * LocalDir constructor. */ public LocalDir() { type = "local"; con = new FilesystemConnection(); con.addConnectionListener(this); } /** * LocalDir constructor. */ public LocalDir(String path) { type = "local"; path = path; con = new FilesystemConnection(); con.addConnectionListener(this); con.chdir(path); //gui(false); } /** * 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.RIGHT)); viewFile.addActionListener(this); props.addActionListener(this); popupMenu.add(viewFile); 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"); uploadButton = new HImageButton(Settings.uploadImage, uploadString, "Upload selected", this); uploadButton.setToolTipText("Upload selected"); zipButton = new HImageButton(Settings.zipFileImage, zipString, "Add selected to new zip file", this); zipButton.setToolTipText("Create zip"); cpButton = new HImageButton(Settings.copyImage, cpString, "Copy selected files to another local dir", this); cpButton.setToolTipText("Local copy selected"); rnButton = new HImageButton(Settings.textFileImage, rnString, "Rename selected file or directory", this); rnButton.setToolTipText("Rename selected"); cdUpButton = new HImageButton(Settings.cdUpImage, cdUpString, "Go to Parent Directory", this); cdUpButton.setToolTipText("Go to Parent Directory"); label.setText("Filesystem: " + StringUtils.cutPath(path)); 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(sorter); buttonPanel.add(new JLabel(" ")); buttonPanel.add(refreshButton); buttonPanel.add(new JLabel(" ")); buttonPanel.add(cpButton); buttonPanel.add(rnButton); buttonPanel.add(mkdirButton); buttonPanel.add(cdButton); buttonPanel.add(deleteButton); buttonPanel.add(cdUpButton); buttonPanel.add(new JLabel(" ")); buttonPanel.add(zipButton); buttonPanel.add(new JLabel(" ")); buttonPanel.add(uploadButton); buttonPanel.setVisible(true); buttonPanel.setSize(getSize().width - 10, 32); //JPanel sortPanel = new JPanel(); p.add("East", buttonPanel); //p.add("West", sortPanel); sorter.addActionListener(this); add("North", p); setDirList(true); jlm = new DefaultListModel(); jl = new JList(jlm); jl.setCellRenderer(new DirCellRenderer()); jl.setVisibleRowCount(Settings.visibleFileRows); jl.addListSelectionListener(this); jl.addKeyListener(this); jl.requestFocus(); // 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, ui refresh bugfix if(index < -1) { return; } String tgt = (String) jl.getSelectedValue().toString(); //System.out.println("List selection: "+index); if(index < 0) { chdir(path + tgt); } else if((dirEntry == null) || (dirEntry.length < index) || (dirEntry[index] == null)) { return; } else if(dirEntry[index].isDirectory()) { if(JFtp.mainFrame != null) { JFtp.mainFrame.setCursor(Cursor.WAIT_CURSOR); } chdir(path + tgt); if(JFtp.mainFrame != null) { JFtp.mainFrame.setCursor(Cursor.DEFAULT_CURSOR); } } 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() { } /** * 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); 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!");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -