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

📄 mainframe.java

📁 ftp 客服端和服务器端
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * NewJFrame.java
 *
 * Created on 2008年12月1日, 上午10:26
 */

package com.topking.ftp.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JWindow;

import sun.net.TelnetInputStream;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;

import com.topking.ftp.bean.FileBean;
import com.topking.ftp.bean.UpLoadBean;
import com.topking.ftp.util.FileDownLoadUtil;
import com.topking.ftp.util.PathUtil;
import com.topking.swingui.MyJTable;
import com.topking.swingui.install.InstallData;
import com.topking.swingui.renderer.MyListCellRenderer;

/**
 *
 * @author  lzkj
 */
public class MainFrame extends javax.swing.JFrame implements ActionListener,Observer{

    /** Creates new form NewJFrame */

    // Variables declaration - do not modify
    private javax.swing.JTextField T_local;
    private javax.swing.JTextField T_remote;
    private javax.swing.JButton bt_browser;
    private javax.swing.JButton bt_localreturn;
    private javax.swing.JButton bt_remotereturn;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList list_local;
    private javax.swing.JList list_remote;
    private MyJTable tb_progress;
    private String[] title;
    private Vector installs;
    private FtpClient ftp;
    private String currentDir;
    private String host;
    private String localPath;
    private String remotePath;    
    private DateFormat df;
    
    private JPopupMenu Lpop;
    private JMenuItem Lrename;
    private JMenuItem Ldelete;
    private JMenuItem Lproperty;
    private JMenuItem Lupload;
    
    private JPopupMenu Rpop;
    private JMenuItem Rrename;
    private JMenuItem Rdelete;
    private JMenuItem Rproperty;
    private JMenuItem Rdownload;
    private JMenuItem Rload;
    
    private int Rx = 0;
    private int Ry = 0;
    
    private int Lx = 0;
    private int Ly = 0;
    
    private int RowCount = 0;
    private String userName;
    private String passWord;
    
    private List<UpLoadBean> upList;
    
    public MainFrame(FtpClient ftp,String host,String userName,String passWord) {    
        this.ftp = ftp;
        this.host = host;
        this.userName = userName;
        this.passWord = passWord;
        this.setTitle("FTP工具(JAVA版) @Author: jacky   @HomePage: http://jacky68147527.javaeye.com");    	
    	this.setIconImage(this.getToolkit().createImage(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/ftplogo.gif")));
//        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        currentDir = "";
        localPath = "C:/";
    	remotePath = "/";
    	df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	upList = new ArrayList<UpLoadBean>();
    	initComponents();    	
    	loadLocalFile();    	
    	loadRemoteFile();
    	refreshLocalPath();
    	refreshRemotePath();
    	new Thread(new removeTB()).start();
    	
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    	title = new String []{"文件名", "大小", "进度", "速度", "状态"};
    	installs = new Vector();  
		InstallData data_name = new InstallData("文件名",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/name.gif")));
        
        InstallData data_sex = new InstallData("大小",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/size.gif")));
       
        InstallData data_brith = new InstallData("进度",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/progress.gif")));
       
        InstallData data_phone = new InstallData("速度",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/speed.gif")));
       
        InstallData data_address = new InstallData("状态",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/state.gif")));
        
        installs.add(data_name);
        installs.add(data_sex);
        installs.add(data_brith);
        installs.add(data_phone);
        installs.add(data_address);
        
        bt_browser = new javax.swing.JButton();
        T_local = new javax.swing.JTextField();
        bt_localreturn = new javax.swing.JButton();
        bt_remotereturn = new javax.swing.JButton();
        T_remote = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        list_local = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        list_remote = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        tb_progress = new MyJTable(title,installs);
        
        Lpop = new JPopupMenu();
        Lrename = new JMenuItem("重命名");
        Ldelete = new JMenuItem("删除");
        Lproperty = new JMenuItem("属性");
        Lupload = new JMenuItem("上传");
        
        bt_browser.addActionListener(this);
        
        Lproperty.addActionListener(this);
        Lrename.addActionListener(this);
        Ldelete.addActionListener(this);
        Lupload.addActionListener(this);
        Lpop.add(Lproperty);
        Lpop.add(Lupload);
        Lpop.add(Lrename);
        Lpop.add(Ldelete);
        
        list_local.add(Lpop);
        
        Rpop = new JPopupMenu();
        Rrename = new JMenuItem("重命名");
        Rload = new JMenuItem("刷新");
        Rdelete = new JMenuItem("删除");
        Rproperty = new JMenuItem("属性");
        Rdownload = new JMenuItem("下载");
        
        Rproperty.addActionListener(this);
        Rdownload.addActionListener(this);
        Rrename.addActionListener(this);
        Rdelete.addActionListener(this);        
        Rpop.add(Rproperty);
        Rpop.add(Rload);
        Rpop.add(Rdownload);
        Rpop.add(Rrename);
        Rpop.add(Rdelete);
        
        list_remote.add(Rpop);
        
        list_local.addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				InstallData d = (InstallData)list_local.getSelectedValue();
				FileBean fb = (FileBean)d.getValue();
				//System.err.println(fb.getType()+";"+fb.getSize()+";"+fb.getTime());
				if(e.getClickCount()==2){
					InstallData data = (InstallData)list_local.getSelectedValue();
					//System.out.println(data.getText());
					if(!isFile(localPath+"/"+data.getText())){
						localPath = localPath+"/"+data.getText();
						refreshLocalPath();
						loadLocalFile();
						JWindow jw = new JWindow(MainFrame.this);
						jw.add(new JLabel("hello"));
						jw.setVisible(true);
					}else{						
						openFile(localPath+"/"+data.getText());
					}
				}//end if
				if(e.getButton()==3){
					Lpop.show(list_local, e.getX(), e.getY());
					Lx = 0;
					Ly = 0;
					Lx = e.getX()+10;
					Ly = e.getY()+10;
				}
			}        	
        });
        
        list_remote.addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				InstallData d = (InstallData)list_remote.getSelectedValue();
				FileBean fb = (FileBean)d.getValue();
				//System.err.println(fb.getType()+";"+fb.getSize()+";"+fb.getTime());
				if(e.getClickCount()==2){
					InstallData data = (InstallData)list_remote.getSelectedValue();
					//System.out.println(data.getText());
					if(!data.getText().contains(".")){//文件夹
						if(ftp.serverIsOpen()){
							try {
								ftp.cd(remotePath+data.getText()+"/");
								remotePath = remotePath+data.getText()+"/";
								refreshRemotePath();
								loadRemoteFile();
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}else{
							JOptionPane.showMessageDialog(MainFrame.this, "服务器已经关闭,操作失败","错误",JOptionPane.ERROR_MESSAGE);
						}
					}	//end if				
				}//end if
				if(e.getButton()==3){
					Rpop.show(list_remote, e.getX(), e.getY());
					Rx = 0;
					Ry = 0;
					Rx = e.getX()+400;
					Ry = e.getY()+10;
				}
			}        	
        });
        
        T_local.addActionListener(this);
        T_remote.addActionListener(this);
        bt_localreturn.addActionListener(this);
        bt_remotereturn.addActionListener(this);
        
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        bt_browser.setText("浏览");

        bt_localreturn.setText("返回");

        bt_remotereturn.setText("返回");

        /*list_local.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });*/
        jScrollPane1.setViewportView(list_local);

       /* list_remote.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });*/
        jScrollPane2.setViewportView(list_remote);

      /*  tb_progress.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "文件名", "大小", "进度", "速度", "状态"
            }
        ));*/
        jScrollPane3.setViewportView(tb_progress);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_browser)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

⌨️ 快捷键说明

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