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

📄 clientgui.java

📁 NAS文件器的模拟
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
		this.setResizable(false);
		setDirCir();
	}	

	private JPanel getMainPanel() {
		if (mainPanel == null) {
			mainPanel = new JPanel();
			mainPanel.setLayout(new BorderLayout());
			mainPanel.add(getToolPanel(), java.awt.BorderLayout.NORTH);
			mainPanel.add(getFileDirScrollPane(), java.awt.BorderLayout.CENTER);
		}
		return mainPanel;
	}
	
	public ClientGui() {
		super();
		initialize();
	}
	
	private JPanel getFileDirContent() {
		return null;
	}
	
	private void login() {
		if (!PWDText.visible){
			pwd = new PWDText(this);
		}
	}
	
	public boolean do_login(String name,String pwd) {
		boolean ok = clientConnect.ClientLogin(name, pwd);
		if (ok) {
			setCurrentID(Integer.valueOf(clientConnect.getAMessage()),
					Integer.valueOf(clientConnect.getAMessage()));
			return true;
		}
		else {
			return false;
		}
	}
	
	private void setCurrentID(int u, int g) {
		currentID.setClientID(u, g);
	}
	
	private void exit() {
		currentID.setClientID(0, 0);
	}
	
	public int returnUID(){
		return currentID.returnUID();
	}
	public int returnGID(){
		return currentID.returnGID();
	}
	
	private void dirCreat(){
		setDirCir();
		String dirName = JOptionPane.showInputDialog("Please input directory'name");
		if (dirName == null) return;
		int get = clientConnect.ClientCreatDir(dirName, currentPath);
		if (get == 0) {
			JOptionPane.showMessageDialog(null, "No INode", 
					"ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else if (get == 1) {
			JOptionPane.showMessageDialog(null, "No Disk space", 
					"ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else if (get == 2) {
			JOptionPane.showMessageDialog(null, "Same name", 
					"ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else if (get == 3) {
			Vector row = new Vector();
			row.add(dirName);
			row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()));
			row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()));
			row.add("directory");
			dirDtm.addRow(row);
		}
		else {
			JOptionPane.showMessageDialog(null, "Creat failed", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	private void dirDelete(){
		setDirCir();
		int selectedRowCount = dirTable.getSelectedRowCount();
		int selectedRow = dirTable.getSelectedRow();
		if (selectedRowCount > 1 || selectedRowCount == 0 || 
				!((String)dirDtm.getValueAt(selectedRow, 3)).equals("directory")) {
			JOptionPane.showMessageDialog(null, "Choose a directory", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else {
			String dirName = (String)dirDtm.getValueAt(selectedRow, 0);
			if (dirName.equals("..")) {
				JOptionPane.showMessageDialog(null, "The directory is not empty", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
			else if (dirName.equals(".") &&
					dirDtm.getRowCount() != 2) {
				JOptionPane.showMessageDialog(null, "The directory is not empty", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
			else if (currentPath.getName().equals("root") && currentPath.getTail() == null
					&& dirName.equals(".")) {
				JOptionPane.showMessageDialog(null, "Root directory can not be deleted", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
			else {
				boolean ok = false;
				if (dirName.equals(".")){
					ok = clientConnect.ClientDeleteDir(currentPath);
					currentPath = currentPath.upperPath();
				}
				else {
					ok = clientConnect.ClientDeleteDir(currentPath.addPath(dirName));
					currentPath = currentPath.upperPath();
				}
				if (ok == false){
					JOptionPane.showMessageDialog(null, "The directory is not empty", "ERROR", JOptionPane.ERROR_MESSAGE);
				}
				else {
					int rowCount = dirDtm.getRowCount();
					for (int i = 0; i < rowCount ; i++){
						dirDtm.removeRow(0);
					}
					do_dirOpen();
				}
			}
		}
	}
	
	private void dirOpen(){
		setDirCir();
		int selectedRowCount = dirTable.getSelectedRowCount();
		int selectedRow = dirTable.getSelectedRow();
		if (selectedRowCount > 1 || selectedRowCount == 0 || 
				!((String)dirDtm.getValueAt(selectedRow, 3)).equals("directory")) {
			JOptionPane.showMessageDialog(null, "Choose a directory", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else {
			String pathName = (String)dirDtm.getValueAt(selectedRow, 0);
			if (pathName.equals("..")) {
				if (currentPath.getTail() != null){
					currentPath = currentPath.upperPath();
				}
			}
			else if (pathName.equals(".")) {
			}
			else {
				currentPath = currentPath.addPath(pathName);
			}
			int rowCount = dirDtm.getRowCount();
			for (int i = 0; i < rowCount ; i++){
				dirDtm.removeRow(0);
			}
			do_dirOpen();
		}
	}
	
	private void do_dirOpen() {
		boolean ok = clientConnect.ClientOpenDir(currentPath);
		if (ok){
			String m = clientConnect.getAMessage();
			while(!m.equals("end_end")){
				Vector row = new Vector();
				row.add(m);
				row.add(clientConnect.getAMessage());
				row.add(clientConnect.getAMessage());
				row.add(clientConnect.getAMessage());
				dirDtm.addRow(row);
				m = clientConnect.getAMessage();
			}
			this.setTitle(currentPath.toString());
		}
		else {
			JOptionPane.showMessageDialog(null, "Open failed", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}

	private void fileClose(){
		setDirCir();
		fileDirScrollPane.setViewportView(dirTable);
		int rowCount = fileDtm.getRowCount();
		for (int i = 0; i < rowCount ; i++){
			fileDtm.removeRow(0);
		}
		currentFile = null;
		currentPath = currentPath.upperPath();
		this.setTitle(currentPath.toString());
	}
	
	private void fileCreat(){
		setDirCir();
		String fileName = JOptionPane.showInputDialog("Please input file'name");
		if (fileName == null) return;
		int get = clientConnect.ClientCreatFile(fileName, currentPath);
		if (get == 0) {
			JOptionPane.showMessageDialog(null, "No INode", 
					"ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else if (get == 1) {
			JOptionPane.showMessageDialog(null, "No Disk space", 
					"ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else if (get == 2) {
			JOptionPane.showMessageDialog(null, "Same name", 
					"ERROR", JOptionPane.ERROR_MESSAGE);
		}
		else if (get == 3) {
			Vector row = new Vector();
			row.add(fileName);
			row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()));
			row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()));
			row.add("file");
			dirDtm.addRow(row);
		}
		else {
			JOptionPane.showMessageDialog(null, "Creat failed", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	private void fileDelete(){
		setDirCir();
		int selectedRowCount = dirTable.getSelectedRowCount();
		int selectedRow = dirTable.getSelectedRow();
		if (selectedRowCount > 1 || selectedRowCount == 0 || 
				!((String)dirDtm.getValueAt(selectedRow, 3)).equals("file")) {
			JOptionPane.showMessageDialog(null, "Choose a file", "ERROR", JOptionPane.ERROR_MESSAGE);
			return;
		}
		if (!clientConnect.checkID(currentPath.addPath((String)dirDtm.getValueAt(selectedRow, 0)))){
			JOptionPane.showMessageDialog(null, "You have not authority", "ERROR", JOptionPane.ERROR_MESSAGE);
			currentPath.upperPath();
			return;
		}
		else {
			currentPath = currentPath.upperPath();
			String fileName = (String)dirDtm.getValueAt(selectedRow, 0);
			boolean ok = false;
			ok = clientConnect.ClientDeleteFile(currentPath.addPath(fileName));
			currentPath = currentPath.upperPath();
			if (ok == false){
				JOptionPane.showMessageDialog(null, "ERROR", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
			else {
				int rowCount = dirDtm.getRowCount();
				for (int i = 0; i < rowCount ; i++){
					dirDtm.removeRow(0);
				}
				do_dirOpen();
			}
		}
	}
	
	private void fileOpen(){
		int selectedRowCount = dirTable.getSelectedRowCount();
		int selectedRow = dirTable.getSelectedRow();
		if (selectedRowCount > 1 || selectedRowCount == 0 || 
				!((String)dirDtm.getValueAt(selectedRow, 3)).equals("file")) {
			JOptionPane.showMessageDialog(null, "Choose a file", "ERROR", JOptionPane.ERROR_MESSAGE);
			return;
		}
		if (!clientConnect.checkGID(currentPath.addPath((String)dirDtm.getValueAt(selectedRow, 0)))){
			JOptionPane.showMessageDialog(null, "You have not authority", "ERROR", JOptionPane.ERROR_MESSAGE);
			currentPath.upperPath();
			return;
		}
		else {
			currentPath = currentPath.upperPath();
			boolean ok = clientConnect.ClientOpenFile(
					currentPath.addPath(((String)dirDtm.getValueAt(selectedRow, 0))));
			if (ok) {
				setFileCir();
				fileDirScrollPane.setViewportView(fileTable);
				currentFile = new file.FileAttr (clientConnect.getAMessage(),
						Integer.valueOf(clientConnect.getAMessage()),clientConnect.getAMessage(),
						clientConnect.getAMessage(),clientConnect.getAMessage());
				this.setTitle(currentPath.toString());
			}
			else {
				JOptionPane.showMessageDialog(null, "ERROR", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
		}
	}
	
	private void fileRead(){
		Vector row = new Vector();
		row.add(currentFile.getName());
		row.add(String.valueOf(currentFile.getSize()));
		row.add(currentFile.getCreatTime());
		row.add(currentFile.getAccessTime());
		row.add(currentFile.getAmendTime());
		fileDtm.addRow(row);
		fileReadAction.setEnabled(false);
	}
	
	private void fileRename(){
		int selectedRowCount = dirTable.getSelectedRowCount();
		int selectedRow = dirTable.getSelectedRow();
		if (selectedRowCount > 1 || selectedRowCount == 0 || 
				!((String)dirDtm.getValueAt(selectedRow, 3)).equals("file")) {
			JOptionPane.showMessageDialog(null, "Choose a file", "ERROR", JOptionPane.ERROR_MESSAGE);
			return;
		}
		if (!clientConnect.checkID(currentPath.addPath((String)dirDtm.getValueAt(selectedRow, 0)))){
			JOptionPane.showMessageDialog(null, "You have not authority", "ERROR", JOptionPane.ERROR_MESSAGE);
			currentPath.upperPath();
			return;
		}
		else {
			currentPath = currentPath.upperPath();
			String newName = JOptionPane.showInputDialog("new name:");
			if (newName == null) return;
			String oldName = (String)dirDtm.getValueAt(selectedRow, 0);
			int get = clientConnect.ClientRenameFile(oldName, newName, currentPath);
			if (get == 2) {
				dirDtm.setValueAt(newName, selectedRow, 0);
				setDirCir();
			}
			else if (get == 0){
				JOptionPane.showMessageDialog(null, "Same name", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
			else if (get == 1) {
				JOptionPane.showMessageDialog(null, "You haven't authority", "ERROR", JOptionPane.ERROR_MESSAGE);
			}
		}
	}
	
	private void fileWrite(){
		if (!clientConnect.checkID(currentPath)){
			JOptionPane.showMessageDialog(null, "You have not authority", "ERROR", JOptionPane.ERROR_MESSAGE);
			return;
		}
		String s = JOptionPane.showInputDialog("added size:");
		if (s == null) return;
		int size = 0;
		try {
			size = Integer.valueOf(s);
		}catch (java.lang.NumberFormatException e) {
			JOptionPane.showMessageDialog(null, "Input a number", "ERROR", JOptionPane.ERROR_MESSAGE);
			return;
		}
		boolean ok = clientConnect.ClientWriteFile(size, currentPath);
		if (ok) {
			if(fileDtm.getRowCount()!=0){
				fileDtm.setValueAt(String.valueOf(Integer.valueOf((String)fileDtm.getValueAt(0, 1))+size), 0, 1);
				fileDtm.setValueAt(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()),
						0, 4);
			}
			else {
				currentFile.setSize(currentFile.getSize() + size);
				currentFile.setAmendTime();
				fileRead();				
			}
			fileReadAction.setEnabled(false);
			currentFile.setSize(currentFile.getSize() + size);
		}
		else {
			JOptionPane.showMessageDialog(null, "Creat failed", "ERROR", JOptionPane.ERROR_MESSAGE);
		}
	}
	
	public void changedUpdate(DocumentEvent e) {
	}

	public void insertUpdate(DocumentEvent e) {
	}

	public void removeUpdate(DocumentEvent e) {
	}
}

⌨️ 快捷键说明

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