⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpwizard2.java

📁 eclipse平台的CDT项目3.0版本的源代码
💻 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:  3rd page of Ftp Wizard

package cdt.projects.export.ftp;

import cdt.projects.Project;
import cdt.projects.export.Export;
import cdt.wizard.WizardFrame;
import com.ibm.network.ftp.protocol.FTPProtocol;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;

/**
 * Page 3 of the incredibly amazing ftp wizard.  This is where the files are uploaded and it tells
 * the user "all done."
 *
 * @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 FtpWizard2 extends WizardFrame {
	/** this would be the project to upload. */
	private Project proj;

	/** Text describing the current FTP action. */
	private JLabel ftpText;
	/** Timer to get updates from the thread that's uploading. */
	private javax.swing.Timer barRefresh;
	/** The progress bar showing how far along the upload is. */
	private JProgressBar progressBar;
	/** The thread that's currently uploading. */
	private FtpUploadThread ftpThread;


	/**
	 * Create this page in the wizard.
	 *
	 * @param parent owner of the wizard.
	 */
	public FtpWizard2(JFrame parent) {
        super(parent);
        proj = (Project)getData().get("Project");
		init();
	}

	/**
	 * Sets up the layout of this page.
	 */
	public void customize() {

        FTPProtocol ftp = (FTPProtocol)getData().get("ftp");
        proj.exportProject(true);
        File projDir;
        try {
            projDir = Export.getTemporaryDirectory();
        } catch(IOException e) {
            projDir = null;
            e.printStackTrace();
        }

        ftp.changeDir(projDir.getAbsolutePath(), false);

		ftpThread = new FtpUploadThread(projDir, ftp, this);
		
        new Thread(ftpThread).start();

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				if(null != ftpThread) {
					ftpThread.notifyFail();
				}
				resetData();
				resetPurgeableKeys(); // Must come after resetData() -B
				dispose();
			}
		} );

		setTitle("FTP Wizard");
		setFrameLabel1("Project uploading...");

		showNextButton(false);
		showPreviousButton(false);
		showCancelButton(false);
		showFinishButton(false);
		
		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new GridLayout(2, 0));
		
		  // Progress Bar stuff
		progressBar = new JProgressBar();
		progressBar.setStringPainted(true);
		progressBar.setMaximum(ftpThread.getTotalFiles());
		
		ftpText = new JLabel("");
		
		JPanel progPanel = new JPanel();
		progPanel.setLayout(new GridLayout(2, 0));
		
		JPanel ftpTextPanel = new JPanel();
		ftpTextPanel.add(ftpText, "Center");
		JPanel barPanel = new JPanel();
		barPanel.add(progressBar, "South");
		progPanel.add(ftpTextPanel);
		progPanel.add(barPanel);
		
		JPanel textPanel = new JPanel();
		textPanel.add(new JLabel("Your project is being uploaded...\n"));
		mainPanel.add(textPanel);
		mainPanel.add(progPanel);
		centerPanel.add(mainPanel);
//		centerPanel.add(new JLabel("Your project is being uploaded...\n"));
		
		// Sets up the timer to update our progress bar
		barRefresh = new javax.swing.Timer(200,
		   new ActionListener() {
			   public void actionPerformed(ActionEvent event) {
				   if(null == ftpThread) { return; }
				   int current = ftpThread.getCurrentFileNumber();
				   
				   // Changes the Progress Bar
				   progressBar.setValue(current);
				   if(current == progressBar.getMaximum()) {
					   barRefresh.stop(); // Stops the timer
					   ftpText.setText("FTP Completed");
				   } else {
					   ftpText.setText(ftpThread.getCurrentFileName());
				   }
			   }
		   } );
		barRefresh.setInitialDelay(200);
		barRefresh.start();
		

//		centerPanel.add(new JLabel("Your project is being uploaded.  Please wait."));

	}

	/**
	 * This does absolutly nothing because this is the last page in the wizard.
	 */
	public void nextAction() {
	}

	/**
	 * This will change the layout of the project because when it is called the ftping will
	 * been done and the wizard needs to tell the user we're done.
	 */
    public void FtpDone() {
        centerPanel.removeAll();
        centerPanel = new JPanel();
        centerPanel.add(new JLabel("Your project has been uploaded."));
        setFrameLabel1("Project Upload Successful");
        showFinishButton(true);
        proj.removeProject();
//      this.invalidate();
        this.validate();
        this.repaint();
    }
    
    /**
     * This will change the layout of the project to indicate that the FTPing has been
     * cancelled.
     */
    public void FtpCancelled() {
		centerPanel.removeAll();
		centerPanel.add(new JLabel("Project upload was unsuccessful.  To complete the export of"
		  + " this project to an FTP server, you will need to re-run the export utility."));
		setFrameLabel1("Project Upload Unsuccessful");
		showFinishButton(true);
		proj.removeProject();
		this.invalidate();
        this.validate();
        this.repaint();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -