📄 ftpwizard1.java
字号:
//Title: Curriculum Development Tool
//Copyright: Copyright (c) 2001
//Author: David Bradford - dbrad@medstat.med.utah.edu
//Company: Knowledge Weavers - http://medstat.med.utah.edu/kw/
//File: FtpWizard2.java
//Description: 2rd page of Ftp Wizard
package cdt.projects.export.ftp;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import cdt.wizard.*;
import cdt.gui.*;
import com.ibm.network.ftp.protocol.*;
import com.ibm.network.ftp.*;
/**
* Welcome to page 2 of the incredible, amazing ftp wizard. This is the page that lets
* the user choose where to place the exported project. All the functionality is here.
* But, it could use some tweaks in the user interface that I have not had a chance to
* add.
*
* @version 1.0
* @author David Bradford<BR>
* Brad Schaefer (<A HREF="mailto:schaefer@medstat.med.utah.edu">schaefer@medstat.med.utah.edu</A>)
*/
public class FtpWizard1 extends WizardFrame implements ActionListener,
ListSelectionListener {
/** This is the ftp connection we use to get info from the server. */
private FTPProtocol ftp;
/** the directory we are in. */
private JTextField pwd = new JTextField(30);
/** button to create a new directory. */
private FlatButton newDir;
/** This button puts us up a directory. ie cd .. */
private FlatButton upDir;
/** A button to specify a full directory */
private FlatButton goDir;
/** this is a list of all the folder in the current one. */
private JList folders = new JList();
/**
* This creates our second page in the ftp wizard.
*
* @param parent frame that is the owning this one.
*/
public FtpWizard1(JFrame parent) {
super(parent);
ftp = (FTPProtocol)getData().get("ftp");
init();
}
/**
* Set up the layout.
*/
public void customize() {
setTitle("FTP Wizard");
setFrameLabel1("Choose output directory");
showFinishButton(false);
centerPanel.setLayout(new BorderLayout());
JPanel dirInfo = new JPanel();
String s = ftp.getCurrentDir(true);
pwd.setEditable(false);
pwd.setText(s);
dirInfo.add(pwd);
newDir = new FlatButton("N");
newDir.setToolTipText("Create a new directory");
newDir.addActionListener(this);
dirInfo.add(newDir);
upDir = new FlatButton("^");
upDir.setToolTipText("Go up a directory");
upDir.addActionListener(this);
dirInfo.add(upDir);
goDir = new FlatButton("go");
goDir.setToolTipText("Go to a specified directory");
goDir.addActionListener(this);
dirInfo.add(goDir);
centerPanel.add(dirInfo, BorderLayout.NORTH);
createList();
folders.addListSelectionListener(this);
centerPanel.add(new JScrollPane(folders), BorderLayout.CENTER);
}
/**
* The user has pressed the next button lets save the directory they want to put the data in
* and bring up the next page in the wizard.
*/
public void nextAction() {
String uploadDir = pwd.getText();
putData("dir", uploadDir);
setVisible(false);
pushFrame(this);
new FtpWizard2((JFrame)getData().get("parentFrame"));
}
/**
* This fills our list with the directories in the current directory.
*/
private void createList() {
Vector v = ftp.getRemoteFileList();
Vector dirs = new Vector();
for(int i=0;i<v.size();i++) {
FileInfo f = (FileInfo)v.elementAt(i);
if(!f.isFile()) {
dirs.add(f.getName());
}
}
folders.setListData(dirs);
}
/**
* This is for when the user presses buttons. It handles new directories and going up a
* directory.
*
* @param event Info about the button press.
*/
public void actionPerformed(ActionEvent event) {
if(event.getSource() == newDir) {
String name = JOptionPane.showInputDialog(this, "Please enter name of new directory:");
if(name==null||name.equals("")) {
return;
}
ftp.makeDir(name, true);
ftp.changeDir(".", true);
createList();
} else if(event.getSource() == upDir) {
changeDir("..");
} else if(event.getSource() == goDir) {
String newPath = JOptionPane.showInputDialog(this, "Enter a pathname:", ftp.getCurrentDir(true));
changeDir(newPath);
}
}
/**
* Used for changing directories on the FTP server.
*
* @param newPath The relative or explicit path to change directories to.
*/
private void changeDir(String newPath) {
if(null == newPath || newPath.equals("")) { return; }
this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
// 550 means the path was not found
if(550 == ftp.changeDir(newPath, true)) {
cdt.ErrorD.ErrorDlg.ErrorMsg("Unable to find path: " +newPath);
ftp.changeDir(".", true);
}
createList();
pwd.setText(ftp.getCurrentDir(true));
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
/**
* This is for when they select something is the list. We make the directory they selected
* the new current directory.
*
* @param event info about what was selected.
*/
public void valueChanged(ListSelectionEvent event) {
this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
String dirName = (String)folders.getSelectedValue();
ftp.changeDir(pwd.getText()+"/"+dirName, true);
createList();
pwd.setText(ftp.getCurrentDir(true));
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -