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

📄 clientgui.java

📁 NAS文件器的模拟
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package clientGui;

import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.table.DefaultTableModel;

import java.text.SimpleDateFormat;
import java.util.*;

import client.*;

public class ClientGui extends JFrame {
	
	private JPanel mainPanel = null;
	private JToolBar fileTool = null;
	private JToolBar dirTool = null;
	private JToolBar loginTool = null;
	private JPanel tool = null;
	private JMenuBar menu = null;
	private JMenu fileMenu = null;
	private JMenu dirMenu = null;
	private JMenu loginMenu = null;
	private Action fileCreatAction = null;
	private Action fileOpenAction = null;
	private Action fileCloseAction = null;
	private Action fileReadAction = null;
	private Action fileWriteAction = null;
	private Action fileRenameAction = null;
	private Action fileDeleteAction = null;
	private Action dirCreatAction = null;
	private Action dirDeleteAction = null;
	private Action dirOpenAction = null;
	private Action loginAction = null;
	private Action exitAction = null;
	private JScrollPane fileDirScrollPane = null;
	private JTable dirTable = null;
	private JTable fileTable = null;
	private DefaultTableModel dirDtm = new DefaultTableModel();
	private DefaultTableModel fileDtm = new DefaultTableModel();	
	
	private file.Path currentPath = new file.Path("root");;
	private file.ClientID currentID = new file.ClientID(0,0);
	private PWDText pwd;
	private ClientConnect clientConnect = new ClientConnect(this);
	private file.FileAttr currentFile = null;
	
	private JToolBar getDirToolBar() {
		if (dirTool == null) {
			dirTool = new JToolBar();
			dirTool.add(getDirCreatAction());
			dirTool.add(getDirOpenAction());
			dirTool.add(getDirDeleteAction());
		}
		return dirTool;
	}
	
	private JToolBar getFileToolBar() {
		if (fileTool == null) {
			fileTool = new JToolBar();
			fileTool.add(getFileCreatAction());
			fileTool.add(getFileOpenAction());
			fileTool.add(getFileCloseAction());
			fileTool.add(getFileReadAction());
			fileTool.add(getFileWriteAction());
			fileTool.add(getFileRenameAction());
			fileTool.add(getFileDeleteAction());
		}
		return fileTool;
	}
	
	private JToolBar getLoginToolBar() {
		if (loginTool == null) {
			loginTool = new JToolBar();
			loginTool.add(getLoginAction());
			loginTool.add(getExitAction());
		}
		return loginTool;
	}
	
	private JMenuBar getmenuBar() {
		if (menu == null) {
			menu = new JMenuBar();
			dirMenu = new JMenu("Direction");
			dirMenu.setMnemonic('D');
			dirMenu.add(getDirCreatAction());
			dirMenu.add(getDirOpenAction());
			dirMenu.add(getDirDeleteAction());
			menu.add(dirMenu);
			fileMenu = new JMenu("File");
			fileMenu.setMnemonic('F');
			fileMenu.add(getFileCreatAction());
			fileMenu.add(getFileOpenAction());
			fileMenu.add(getFileCloseAction());
			fileMenu.add(getFileReadAction());
			fileMenu.add(getFileWriteAction());
			fileMenu.add(getFileRenameAction());
			fileMenu.add(getFileDeleteAction());
			menu.add(fileMenu);
			loginMenu = new JMenu("login");
			loginMenu.setMnemonic('L');
			loginMenu.add(getLoginAction());
			loginMenu.add(getExitAction());
			menu.add(loginMenu);
		}
		return menu;
	}
	
	private Action getDirCreatAction() {
		if (dirCreatAction == null) {
			dirCreatAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					dirCreat();
				}
			};
			dirCreatAction.putValue(Action.NAME, "Creat a directory");
			dirCreatAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/dircreat.png")));
			dirCreatAction.putValue(Action.SHORT_DESCRIPTION, "Creat a directory");
			dirCreatAction.putValue(Action.MNEMONIC_KEY, new Integer('A'));
		}
		return dirCreatAction;
	}
	
	private Action getDirDeleteAction() {
		if (dirDeleteAction == null) {
			dirDeleteAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					dirDelete();
				}
			};
			dirDeleteAction.putValue(Action.NAME, "Delete an empty directory");
			dirDeleteAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/dirdelete.png")));
			dirDeleteAction.putValue(Action.SHORT_DESCRIPTION, "Delete an empty directory");
			dirDeleteAction.putValue(Action.MNEMONIC_KEY, new Integer('B'));
		}
		return dirDeleteAction;
	}
	
	private Action getDirOpenAction() {
		if (dirOpenAction == null) {
			dirOpenAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					dirOpen();
				}
			};
			dirOpenAction.putValue(Action.NAME, "Open a directory");
			dirOpenAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/diropen.png")));
			dirOpenAction.putValue(Action.SHORT_DESCRIPTION, "Open a directory");
			dirOpenAction.putValue(Action.MNEMONIC_KEY, new Integer('C'));
		}
		return dirOpenAction;
	}
	
	private Action getFileCloseAction() {
		if (fileCloseAction == null) {
			fileCloseAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileClose();
				}
			};
			fileCloseAction.putValue(Action.NAME, "Close a file");
			fileCloseAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/fileclose.png")));
			fileCloseAction.putValue(Action.SHORT_DESCRIPTION, "Close a file");
			fileCloseAction.putValue(Action.MNEMONIC_KEY, new Integer('D'));
		}
		return fileCloseAction;
	}
	
	private Action getFileCreatAction() {
		if (fileCreatAction == null) {
			fileCreatAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileCreat();
				}
			};
			fileCreatAction.putValue(Action.NAME, "Creat a file");
			fileCreatAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/filecreat.png")));
			fileCreatAction.putValue(Action.SHORT_DESCRIPTION, "Creat a file");
			fileCreatAction.putValue(Action.MNEMONIC_KEY, new Integer('E'));
		}
		return fileCreatAction;
	}
	
	private Action getFileDeleteAction() {
		if (fileDeleteAction == null) {
			fileDeleteAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileDelete();
				}
			};
			fileDeleteAction.putValue(Action.NAME, "Delete a file");
			fileDeleteAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/filedelete.png")));
			fileDeleteAction.putValue(Action.SHORT_DESCRIPTION, "Delete a file");
			fileDeleteAction.putValue(Action.MNEMONIC_KEY, new Integer('F'));
		}
		return fileDeleteAction;
	}
	
	private Action getFileOpenAction() {
		if (fileOpenAction == null) {
			fileOpenAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileOpen();
				}
			};
			fileOpenAction.putValue(Action.NAME, "Open a file");
			fileOpenAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/fileopen.png")));
			fileOpenAction.putValue(Action.SHORT_DESCRIPTION, "Open a file");
			fileOpenAction.putValue(Action.MNEMONIC_KEY, new Integer('G'));
		}
		return fileOpenAction;
	}
	
	private Action getFileReadAction() {
		if (fileReadAction == null) {
			fileReadAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileRead();
				}
			};
			fileReadAction.putValue(Action.NAME, "Read a file");
			fileReadAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/fileread.png")));
			fileReadAction.putValue(Action.SHORT_DESCRIPTION, "Read a file");
			fileReadAction.putValue(Action.MNEMONIC_KEY, new Integer('H'));
		}
		return fileReadAction;
	}
	
	private Action getFileRenameAction() {
		if (fileRenameAction == null) {
			fileRenameAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileRename();
				}
			};
			fileRenameAction.putValue(Action.NAME, "Rename a file");
			fileRenameAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/filerename.png")));
			fileRenameAction.putValue(Action.SHORT_DESCRIPTION, "Rename a file");
			fileRenameAction.putValue(Action.MNEMONIC_KEY, new Integer('I'));
		}
		return fileRenameAction;
	}

	private Action getFileWriteAction() {
		if (fileWriteAction == null) {
			fileWriteAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					fileWrite();
				}
			};
			fileWriteAction.putValue(Action.NAME, "Write a file");
			fileWriteAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/filewrite.png")));
			fileWriteAction.putValue(Action.SHORT_DESCRIPTION, "Write a file");
			fileWriteAction.putValue(Action.MNEMONIC_KEY, new Integer('J'));
		}
		return fileWriteAction;
	}
	
	private Action getLoginAction() {
		if (loginAction == null) {
			loginAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {					
					login();					
				}
			};
			loginAction.putValue(Action.NAME, "Login");
			loginAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/login.png")));
			loginAction.putValue(Action.SHORT_DESCRIPTION, "Login");
			loginAction.putValue(Action.MNEMONIC_KEY, new Integer('K'));
		}
		return loginAction;
	}
	
	private Action getExitAction() {
		if (exitAction == null) {
			exitAction = new AbstractAction() {
				public void actionPerformed(ActionEvent e) {
					exit();
				}
			};
			exitAction.putValue(Action.NAME, "Exit");
			exitAction.putValue(Action.SMALL_ICON, new ImageIcon(
					ClientGui.class.getResource("/img/exit.png")));
			exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");
			exitAction.putValue(Action.MNEMONIC_KEY, new Integer('L'));
		}
		return exitAction;
	}
	
	private void setDirCir(){
		dirOpenAction.setEnabled(true);
		dirCreatAction.setEnabled(true);
		dirDeleteAction.setEnabled(true);
		fileCloseAction.setEnabled(false);
		fileCreatAction.setEnabled(true);
		fileDeleteAction.setEnabled(true);
		fileOpenAction.setEnabled(true);
		fileReadAction.setEnabled(false);
		fileRenameAction.setEnabled(true);
		fileWriteAction.setEnabled(false);
	}
	
	private void setFileCir(){
		dirOpenAction.setEnabled(false);
		dirCreatAction.setEnabled(false);
		dirDeleteAction.setEnabled(false);
		fileCloseAction.setEnabled(true);
		fileCreatAction.setEnabled(false);
		fileDeleteAction.setEnabled(false);
		fileOpenAction.setEnabled(false);
		fileReadAction.setEnabled(true);
		fileRenameAction.setEnabled(false);
		fileWriteAction.setEnabled(true);
	}
	
	private JScrollPane getFileDirScrollPane() {
		if (fileDirScrollPane == null) {
			fileDirScrollPane = new JScrollPane();
			fileDirScrollPane.setViewportView(dirTable);
		}
		return fileDirScrollPane;
	}
	
	private JPanel getToolPanel() {
		if (tool == null) {
			tool = new JPanel();
			tool.setLayout(new BorderLayout());
			tool.add(getDirToolBar(), java.awt.BorderLayout.WEST);
			tool.add(getFileToolBar(), java.awt.BorderLayout.CENTER);
			tool.add(getLoginToolBar(),java.awt.BorderLayout.EAST);
		}
		return tool;
	}
	
	private void initialize() {		
		Vector vt = new Vector();
		vt.add("name");
		vt.add("creat time");
		vt.add("last access time");
		vt.add("type");
		dirTable = new JTable();
		dirTable.setModel(dirDtm);
		for(int i=0;i<vt.size();i++) 
			dirDtm.addColumn((String)vt.elementAt(i));
		do_dirOpen();
		
		Vector vt2 = new Vector();
		vt2.add("name");
		vt2.add("size");
		vt2.add("creat time");
		vt2.add("last access time");
		vt2.add("last amend time");
		fileTable = new JTable();
		fileTable.setModel(fileDtm);
		for(int i=0;i<vt2.size();i++) 
			fileDtm.addColumn((String)vt2.elementAt(i));
		
		this.setContentPane(getMainPanel());
		this.setTitle(currentPath.toString());
		this.setJMenuBar(getmenuBar());
		this.setBounds(225, 120, 565, 500);

⌨️ 快捷键说明

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