?? ftpdisk.java
字號:
/** * File and FTP Explorer * Copyright 2002 * BOESCH Vincent * * 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 javaexplorer.gui.disk;import java.awt.*;import java.awt.event.*;import javaexplorer.Launcher;import javaexplorer.gui.dnd.XTree;import javaexplorer.gui.renderer.*;import javaexplorer.gui.treenode.ftp.*;import javaexplorer.model.XFile;import javaexplorer.util.ftp.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.tree.*;/** *@author BOESCH Vincent *@created 21 janvier 2002 *@version 3.3 */public class FtpDisk extends JPanel implements Disk, ActionListener, TreeSelectionListener { private Launcher _launcher = null; private Ftp _scCut = null; private FtpTreeNode _stnRoot = null; private FtpTreeNode _stnSelected = null; BorderLayout borderLayout1 = new BorderLayout(); BorderLayout borderLayout2 = new BorderLayout(); GridLayout gridLayout2 = new GridLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); private JLabel jLabel3 = new JLabel(); private JLabel jLabel4 = new JLabel(); private JLabel jLabel5 = new JLabel(); private JLabel jLabel6 = new JLabel(); private JLabel jLabel7 = new JLabel(); private JLabel jlblGroup = new JLabel(); JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); JPanel jPanel3 = new JPanel(); JScrollPane jScrollPane1 = new JScrollPane(); XTree jTree1 = new XTree(); JButton jbtCreate = new JButton(); JButton jbtCut = new JButton(); JButton jbtDelete = new JButton(); JButton jbtModify = new JButton(); JButton jbtPaste = new JButton(); private JCheckBox jcbPasvMode = new JCheckBox(); private JCheckBox jcbShowInList = new JCheckBox(); private JTextField jtfHost = new JTextField(); JTextField jtfPassword = new JTextField(); private JTextField jtfPort = new JTextField(); JTextField jtfTitle = new JTextField(); private JTextField jtfUser = new JTextField(); private JTextField jtfGroup = new JTextField(); TitledBorder titledBorder1; /** * Constructeur objet FtpDisk * *@param launcher Description of the * Parameter */ public FtpDisk(Launcher launcher) { try { _launcher = launcher; jbInit(); } catch (Exception e) { javaexplorer.util.Log.addError(e); } } /** *@param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (obj == jbtDelete) { deleteFtp(); return; } if (obj == jbtModify) { modifyFtp(); return; } if (obj == jbtCreate) { create(); return; } if (obj == jbtCut) { cutFtp(); return; } if (obj == jbtPaste) { pasteFtp(); return; } } /** */ public void create() { if (_stnSelected == null) { return; } String title = jtfTitle.getText(); String host = jtfHost.getText(); if ((host == null) || (host.length() == 0)) { host = null; } String user = jtfUser.getText(); if ((user == null) || (user.length() == 0)) { user = "anonymous"; } String group = jtfGroup.getText(); if ((group == null) || (group.length() == 0)) { group = ""; } String password = jtfPassword.getText(); if ((password == null) || (password.length() == 0)) { password = "guest"; } int port = 21; try { port = Integer.parseInt(jtfPort.getText()); } catch (NumberFormatException nfe) { port = 21; } if ((title == null) || (title.length() == 0)) { return; } Ftp sc = _stnSelected.getFtp(); FtpContainer parent = null; if (sc instanceof FtpContainer) { parent = (FtpContainer) sc; } else { FtpTreeNode tnParent = (FtpTreeNode) _stnSelected.getParent(); if (tnParent == null) { tnParent = _stnRoot; } parent = (FtpContainer) tnParent.getFtp(); } Ftp ftpRef = null; if (host != null) { Ftp ftp = new Ftp(); ftp.setTitle(title); ftp.setHost(host); ftp.setUser(user); ftp.setGroup(group); ftp.setPassword(password); ftp.setPort(port); ftp.setUsePassiveMode(jcbPasvMode.isSelected()); ftp.setShowInDiskList(jcbShowInList.isSelected()); ftpRef = ftp; } else { FtpContainer ftpc = new FtpContainer(); ftpc.setTitle(title); ftpRef = ftpc; } parent.addFtp(ftpRef); jTree1.setModel(new DefaultTreeModel(_stnRoot)); jTree1.setSelectionRow(0); } /** */ public void cutFtp() { if (_stnSelected == null) { return; } _scCut = _stnSelected.getFtp(); deleteFtp(); } /** */ public void deleteFtp() { if ((_stnSelected == null) || (_stnSelected == _stnRoot)) { return; } FtpTreeNode parent = (FtpTreeNode) _stnSelected.getParent(); FtpContainer scc = null; if (parent == null) { parent = _stnRoot; } scc = (FtpContainer) (parent.getFtp()); scc.removeFtp(_stnSelected.getFtp().getTitle()); jTree1.setModel(new DefaultTreeModel(_stnRoot)); jTree1.setSelectionRow(0); } /** * Gets the container attribute of the * FtpDisk object * *@return The container value */ public FtpContainer getContainer() { return (FtpContainer) _stnRoot.getFtp(); } /** * Gets the root attribute of the FtpDisk * object * *@return The root value */ public Object getRoot() { return _stnRoot; } /** *@param e Description of the Parameter */ void jTree1_keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (e.isControlDown()) { switch (code) { case KeyEvent.VK_X: cutFtp(); break; case KeyEvent.VK_V: pasteFtp(); break; case KeyEvent.VK_N: create(); break; case KeyEvent.VK_M: modifyFtp(); break; } } else { if (code == KeyEvent.VK_DELETE) { deleteFtp(); } } } /** *@throws Exception Description of the * Exception */ private void jbInit() throws Exception { titledBorder1 = new TitledBorder(""); this.setLayout(borderLayout1); jPanel1.setLayout(borderLayout2); jScrollPane1.setBorder(BorderFactory.createLineBorder(Color.black)); this.setBorder(titledBorder1); jPanel2.setLayout(gridLayout2); gridLayout2.setRows(8); gridLayout2.setColumns(2); jLabel2.setText("host"); jLabel1.setText("label"); jbtDelete.setText("Delete"); jbtModify.setText("Modify"); jbtCreate.setText("Create"); jbtCreate.setToolTipText("Create dir or link if host is not null"); jtfPassword.setToolTipText(""); jTree1.setCellRenderer(new FtpTreeCellRenderer()); jTree1.addTreeSelectionListener(this); jbtCut.setText("Cut"); jbtPaste.setText("Paste"); jTree1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) { jTree1_keyPressed(e); } }); jtfUser.setToolTipText(""); jLabel3.setText("user"); jtfGroup.setToolTipText("Groupname for the user (optionnal)"); jlblGroup.setText("group"); jtfHost.setToolTipText(""); jLabel4.setText("password"); jtfPort.setToolTipText(""); jLabel5.setText("port"); jLabel6.setText("add To Disk List"); jcbShowInList.setSelected(true); jLabel7.setText("use passive mode"); this.add(jScrollPane1, BorderLayout.CENTER); this.add(jPanel1, BorderLayout.SOUTH); jPanel1.add(jPanel2, BorderLayout.CENTER); jPanel2.add(jLabel1, null); jPanel2.add(jtfTitle, null); jPanel2.add(jLabel2, null); jPanel2.add(jtfHost, null); jPanel2.add(jLabel3, null); jPanel2.add(jtfUser, null); jPanel2.add(jlblGroup, null); jPanel2.add(jtfGroup, null); jPanel2.add(jLabel4, null); jPanel2.add(jtfPassword, null); jPanel2.add(jLabel5, null); jPanel2.add(jtfPort, null); jPanel2.add(jLabel7, null); jPanel2.add(jcbPasvMode, null); jPanel2.add(jLabel6, null); jPanel2.add(jcbShowInList, null); jPanel1.add(jPanel3, BorderLayout.SOUTH); jPanel3.add(jbtDelete, null); jPanel3.add(jbtModify, null); jPanel3.add(jbtCut, null); jPanel3.add(jbtPaste, null); jPanel3.add(jbtCreate, null); jScrollPane1.getViewport().add(jTree1, null); jTree1.setRootVisible(true); jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jbtDelete.addActionListener(this); jbtModify.addActionListener(this); jbtCreate.addActionListener(this); jbtCut.addActionListener(this); jbtPaste.addActionListener(this); } /** */ public void modifyFtp() { if (_stnSelected == null) { return; } Ftp sc = _stnSelected.getFtp(); String title = jtfTitle.getText(); if ((title == null) || (title.length() == 0)) { return; } if (sc instanceof FtpContainer) { sc.setTitle(title); } else { String host = jtfHost.getText(); if ((host == null) || (host.length() == 0)) { host = null; } String user = jtfUser.getText(); if ((user == null) || (user.length() == 0)) { user = "anonymous"; } String group = jtfGroup.getText(); if ((group == null) || (group.length() == 0)) { group = ""; } String password = jtfPassword.getText(); if ((password == null) || (password.length() == 0)) { password = "guest"; } int port = 21; try { port = Integer.parseInt(jtfPort.getText()); } catch (NumberFormatException nfe) { port = 21; } if (host == null) { return; } sc.setTitle(title); sc.setHost(host); sc.setUser(user); sc.setGroup(group); sc.setPassword(password); sc.setPort(port); sc.setUsePassiveMode(jcbPasvMode.isSelected()); sc.setShowInDiskList(jcbShowInList.isSelected()); } jTree1.setModel(new DefaultTreeModel(_stnRoot)); jTree1.setSelectionRow(0); } /** */ public void pasteFtp() { if (_scCut == null) { return; } if (_stnSelected == null) { return; } FtpContainer parent = null; Ftp sc = _stnSelected.getFtp(); if (sc instanceof FtpContainer) { parent = (FtpContainer) sc; } else { FtpTreeNode tnParent = (FtpTreeNode) _stnSelected.getParent(); if (tnParent == null) { tnParent = _stnRoot; } parent = (FtpContainer) tnParent.getFtp(); } parent.addFtp(_scCut); _scCut = null; jTree1.setModel(new DefaultTreeModel(_stnRoot)); jTree1.setSelectionRow(0); } /** *@param f Description of the Parameter */ public void refreshView(XFile f) { //Sans objet } /** * Sets the container attribute of the * FtpDisk object * *@param sc The new container value */ public void setContainer(FtpContainer sc) { _stnRoot = new FtpTreeNode(sc); jTree1.setModel(new DefaultTreeModel(_stnRoot)); jTree1.setSelectionRow(0); } /** * Sets the launcher attribute of the * FtpDisk object * *@param launcher The new launcher value */ public void setLauncher(Launcher launcher) { _launcher = launcher; } /** */ public void updateVisual() { Ftp sc = _stnSelected.getFtp(); jtfTitle.setText(sc.getTitle()); jtfHost.setText(sc.getHost()); jtfUser.setText(sc.getUser()); jtfGroup.setText((sc.getGroup() == null ? "": sc.getGroup())); jtfPassword.setText(sc.getPassword()); jtfPort.setText("" + sc.getPort()); jcbPasvMode.setSelected(sc.getUsePassiveMode()); jcbShowInList.setSelected(sc.getShowInDiskList()); if (sc instanceof FtpContainer) { jtfHost.setText(""); jtfUser.setText(""); jtfGroup.setText(""); jtfPassword.setText(""); jtfPort.setText(""); jcbPasvMode.setSelected(false); jcbShowInList.setSelected(false); } } /** *@param e Description of the Parameter */ public void valueChanged(TreeSelectionEvent e) { TreePath tp = jTree1.getSelectionPath(); if (tp != null) { Object obj = tp.getLastPathComponent(); if (obj != null) { _stnSelected = (FtpTreeNode) obj; updateVisual(); } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -