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

📄 maingui.java

📁 CD Manager光盘资料管家婆源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		treeDragSource = new DragSource(albumTree, DND.DROP_MOVE);
		treeDragSource.setTransfer(new Transfer[]{TextTransfer.getInstance()});
		
		treeDropTarget = new DropTarget(albumTree, DND.DROP_NONE);
		treeDropTarget.setTransfer(new Transfer[]{TextTransfer.getInstance()});
		
		TreeItem root = new TreeItem(albumTree, SWT.SINGLE);
		root.setImage(SWTResourceManager
				.getImage(MainGUI.class, ImageFactory.ALBUM));
		root.setText("CD Manager");
		albumMap.put(root, CDManager.action.getRootAlbum());
		albumTree.setSelection(root);
		initialAlbumTree(root, CDManager.action.getRootAlbum());

		albumTreeMenu = new Menu(albumTree);
		albumTree.setMenu(albumTreeMenu);

		newAlbumPopItem = new MenuItem(albumTreeMenu, SWT.NONE);
		newAlbumPopItem.setText("新建专辑");


		deleteAlbumPopItem = new MenuItem(albumTreeMenu, SWT.NONE);
		deleteAlbumPopItem.setText("删除专辑");

		new MenuItem(albumTreeMenu, SWT.SEPARATOR);

		newCDPopItem = new MenuItem(albumTreeMenu, SWT.NONE);
		newCDPopItem.setText("新建光盘");

		modifyCDPopItem = new MenuItem(albumTreeMenu, SWT.NONE);
		modifyCDPopItem.setText("添加注释");

		deleteCDPopItem = new MenuItem(albumTreeMenu, SWT.NONE);
		deleteCDPopItem.setText("删除光盘");

		new MenuItem(albumTreeMenu, SWT.SEPARATOR);

		renameCDPopItem = new MenuItem(albumTreeMenu, SWT.NONE);
		renameCDPopItem.setText("重 命 名");

		final Composite buttomTreeCoposite = new Composite(leftSashForm,
				SWT.BORDER);
		buttomTreeCoposite.setLayout(new FillLayout());
		buttomTreeCoposite.setBackground(Display.getCurrent().getSystemColor(
				SWT.COLOR_WHITE));

		documentTree = new Tree(buttomTreeCoposite, SWT.NONE);

		final SashForm rightSashForm = new SashForm(rootSashForm, SWT.VERTICAL
				| SWT.SMOOTH);
		final Composite topTableCoposite = new Composite(rightSashForm,
				SWT.BORDER);
		topTableCoposite.setLayout(new FillLayout());
		topTableCoposite.setBackground(Display.getCurrent().getSystemColor(
				SWT.COLOR_WHITE));

		table = new Table(topTableCoposite, SWT.FULL_SELECTION);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		final TableColumn nameColumn = new TableColumn(table, SWT.NONE);
		nameColumn.setWidth(132);
		nameColumn.setText("文件名");
		final TableColumn sizeColumn = new TableColumn(table, SWT.NONE);
		sizeColumn.setAlignment(SWT.RIGHT);
		sizeColumn.setWidth(84);
		sizeColumn.setText("大小");
		final TableColumn descriptionColumn = new TableColumn(table, SWT.NONE);
		descriptionColumn.setWidth(128);
		descriptionColumn.setText("修改时间");
		final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
		newColumnTableColumn.setWidth(64);
		newColumnTableColumn.setText("所属光盘");
		final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
		newColumnTableColumn_1.setWidth(207);
		newColumnTableColumn_1.setText("路径");

		final Composite buttomTableCoposite = new Composite(rightSashForm,
				SWT.BORDER);
		buttomTableCoposite.setLayout(new FillLayout());
		buttomTableCoposite.setBackground(Display.getCurrent().getSystemColor(
				SWT.COLOR_WHITE));
		
		final Group group_2 = new Group(buttomTableCoposite, SWT.NONE);
		group_2.setLayout(new FormLayout());

		final Group group_3 = new Group(group_2, SWT.NONE);
		group_3.setLayout(new FillLayout());
		final FormData fd_group_3 = new FormData();
		fd_group_3.top = new FormAttachment(0, 0);
		fd_group_3.bottom = new FormAttachment(100, -5);
		fd_group_3.right = new FormAttachment(0, 105);
		fd_group_3.left = new FormAttachment(0, 5);
		group_3.setLayoutData(fd_group_3);

		final Label label_6 = new Label(group_3, SWT.NONE);
		label_6.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/cdinfo90.png"));

		final Group group_4 = new Group(group_2, SWT.NONE);
		group_4.setLayout(new FormLayout());
		final FormData fd_group_4 = new FormData();
		fd_group_4.top = new FormAttachment(0, 0);
		fd_group_4.right = new FormAttachment(100, -5);
		fd_group_4.bottom = new FormAttachment(group_3, 0, SWT.BOTTOM);
		fd_group_4.left = new FormAttachment(0, 115);
		group_4.setLayoutData(fd_group_4);

		final Label label = new Label(group_4, SWT.NONE);
		final FormData fd_label = new FormData();
		fd_label.bottom = new FormAttachment(0, 25);
		fd_label.left = new FormAttachment(0, 5);
		fd_label.top = new FormAttachment(0, 8);
		label.setLayoutData(fd_label);
		label.setText("光盘名称:");

		cdNameText = new Text(group_4, SWT.BORDER);
		fd_label.right = new FormAttachment(cdNameText, 0, SWT.LEFT);
		cdNameText.setEditable(false);
		final FormData fd_cdNameText = new FormData();
		cdNameText.setLayoutData(fd_cdNameText);

		Label label_1 = new Label(group_4, SWT.NONE);
		final FormData fd_label_1 = new FormData();
		fd_label_1.top = new FormAttachment(label, 0, SWT.TOP);
		fd_label_1.right = new FormAttachment(0, 220);
		fd_label_1.left = new FormAttachment(0, 165);
		label_1.setLayoutData(fd_label_1);
		label_1.setText("所属专辑:");

		belongAlbumText = new Text(group_4, SWT.BORDER);
		belongAlbumText.setEditable(false);
		final FormData fd_belongAlbumText = new FormData();
		fd_belongAlbumText.left = new FormAttachment(0, 220);
		fd_belongAlbumText.right = new FormAttachment(0, 305);
		fd_belongAlbumText.bottom = new FormAttachment(cdNameText, 18, SWT.TOP);
		fd_belongAlbumText.top = new FormAttachment(cdNameText, 0, SWT.TOP);
		belongAlbumText.setLayoutData(fd_belongAlbumText);

		final Label label_2 = new Label(group_4, SWT.NONE);
		final FormData fd_label_2 = new FormData();
		fd_label_2.bottom = new FormAttachment(belongAlbumText, 0, SWT.BOTTOM);
		fd_label_2.top = new FormAttachment(0, 8);
		fd_label_2.left = new FormAttachment(0, 320);
		label_2.setLayoutData(fd_label_2);
		label_2.setText("创建日期:");

		createDateText = new Text(group_4, SWT.BORDER);
		fd_cdNameText.bottom = new FormAttachment(createDateText, 18, SWT.TOP);
		fd_cdNameText.top = new FormAttachment(createDateText, 0, SWT.TOP);
		createDateText.setEditable(false);
		final FormData fd_createDateText = new FormData();
		fd_createDateText.bottom = new FormAttachment(0, 23);
		fd_createDateText.top = new FormAttachment(0, 5);
		fd_createDateText.right = new FormAttachment(label_2, 99, SWT.RIGHT);
		fd_createDateText.left = new FormAttachment(label_2, 0, SWT.RIGHT);
		createDateText.setLayoutData(fd_createDateText);

		final Label label_3 = new Label(group_4, SWT.NONE);
		final FormData fd_label_3 = new FormData();
		fd_label_3.top = new FormAttachment(0, 42);
		fd_label_3.right = new FormAttachment(label, 55, SWT.LEFT);
		fd_label_3.left = new FormAttachment(label, 0, SWT.LEFT);
		label_3.setLayoutData(fd_label_3);
		label_3.setText("文件数目:");

		fileNumText = new Text(group_4, SWT.BORDER);
		fd_cdNameText.left = new FormAttachment(fileNumText, -85, SWT.RIGHT);
		fd_cdNameText.right = new FormAttachment(fileNumText, 0, SWT.RIGHT);
		fileNumText.setEditable(false);
		final FormData fd_fileNumText = new FormData();
		fd_fileNumText.bottom = new FormAttachment(0, 56);
		fd_fileNumText.top = new FormAttachment(0, 38);
		fd_fileNumText.right = new FormAttachment(label_3, 85, SWT.RIGHT);
		fd_fileNumText.left = new FormAttachment(label_3, 0, SWT.RIGHT);
		fileNumText.setLayoutData(fd_fileNumText);

		Label label_4;
		label_4 = new Label(group_4, SWT.NONE);
		final FormData fd_label_4 = new FormData();
		fd_label_4.top = new FormAttachment(0, 74);
		label_4.setLayoutData(fd_label_4);
		label_4.setText("文件夹数:");

		folderNumText = new Text(group_4, SWT.BORDER);
		fd_label_3.bottom = new FormAttachment(folderNumText, -5, SWT.TOP);
		fd_label_4.bottom = new FormAttachment(folderNumText, 0, SWT.BOTTOM);
		fd_label_4.left = new FormAttachment(folderNumText, -55, SWT.LEFT);
		fd_label_4.right = new FormAttachment(folderNumText, 0, SWT.LEFT);
		folderNumText.setEditable(false);
		final FormData fd_folderNumText = new FormData();
		fd_folderNumText.top = new FormAttachment(0, 72);
		fd_folderNumText.bottom = new FormAttachment(0, 90);
		fd_folderNumText.left = new FormAttachment(fileNumText, -85, SWT.RIGHT);
		fd_folderNumText.right = new FormAttachment(fileNumText, 0, SWT.RIGHT);
		folderNumText.setLayoutData(fd_folderNumText);

		final Label label_5 = new Label(group_4, SWT.NONE);
		final FormData fd_label_5 = new FormData();
		fd_label_5.bottom = new FormAttachment(folderNumText, 0, SWT.BOTTOM);
		fd_label_5.top = new FormAttachment(fileNumText, 0, SWT.TOP);
		fd_label_5.left = new FormAttachment(label_1, 0, SWT.LEFT);
		label_5.setLayoutData(fd_label_5);
		label_5.setText("说\n\n明");

		descriptionText = new Text(group_4, SWT.BORDER|SWT.MULTI);	
		fd_label_5.right = new FormAttachment(descriptionText, -5, SWT.LEFT);
		fd_label_1.bottom = new FormAttachment(descriptionText, -5, SWT.TOP);
		descriptionText.setEditable(false);
		final FormData fd_descriptionText = new FormData();
		fd_descriptionText.bottom = new FormAttachment(label_5, 0, SWT.BOTTOM);
		fd_descriptionText.right = new FormAttachment(createDateText, 0, SWT.RIGHT);
		fd_descriptionText.top = new FormAttachment(label_5, 0, SWT.TOP);
		fd_descriptionText.left = new FormAttachment(0, 195);
		descriptionText.setLayoutData(fd_descriptionText);
		rightSashForm.setWeights(new int[] { 1000 - 165000 / shell.getClientArea().height , 165000 / shell.getClientArea().height });
		rootSashForm.setWeights(new int[] { 2, 8 });
		leftSashForm.setWeights(new int[] { 62, 100 });
		shell.layout();	
		
		/**
		 * 主窗口监听
		 */
		shell.addControlListener(new ControlAdapter() {
			public void controlResized(final ControlEvent e) {
				Shell shell = (Shell) e.widget;
				if (shell.getBounds().height <= 300) {
					shell.setSize(shell.getBounds().width, 300);
				}
				if (shell.getBounds().width <= 400) {
					shell.setSize(400, shell.getBounds().height);
				}
				rightSashForm.setWeights(new int[] { 1000 - 165000 / shell.getClientArea().height , 165000 / shell.getClientArea().height });
				
				fd_button.right = new FormAttachment(100, -5);
				fd_button.left = new FormAttachment(100, - 50);
				searchButton.setLayoutData(fd_button);
				
				fd_cdSearchText.top = new FormAttachment(0, 10);
				fd_cdSearchText.right = new FormAttachment(100, -60);
				fd_cdSearchText.left = new FormAttachment(100, -240);
				cdSearchText.setLayoutData(fd_cdSearchText);

				fd_toolBar.bottom = new FormAttachment(100, 0);
				fd_toolBar.left = new FormAttachment(0, 0);
				fd_toolBar.right = new FormAttachment(100, - 250);
				fd_toolBar.top = new FormAttachment(0, 0);
				toolBar.setLayoutData(fd_toolBar);

				fd_toobarGroup.bottom = new FormAttachment(0, 60);
				fd_toobarGroup.right = new FormAttachment(100,- 5);
				toobarGroup.setLayoutData(fd_toobarGroup);

				fd_group.bottom = new FormAttachment(100, -5);
				fd_group.right = new FormAttachment(100, -5);
				group.setLayoutData(fd_group);
			}
		});
	}

	/**
	 * 根据根节点初始化albumTree;
	 */
	public void initialAlbumTree(TreeItem item, Album album) {

		ArrayList<Album> albumTree = album.getAlbums();
		TreeItem albumItem;
		Album temp;
		CD cd;
		TreeItem cdItem;
		for (int i = 0; i < albumTree.size(); i++) {
			temp = albumTree.get(i);
			albumItem = new TreeItem(item, SWT.SINGLE);
			albumItem.setImage(SWTResourceManager.getImage(MainGUI.class,
					ImageFactory.ALBUM));
			albumItem.setText(temp.getName());
			albumMap.put(albumItem, temp);
			initialAlbumTree(albumItem, temp);
		}

		ArrayList<CD> cdTree = album.getCDs();
		for (int j = 0; j < cdTree.size(); ++j) {
			cd = cdTree.get(j);
			cdItem = new TreeItem(item, SWT.SINGLE);
			cdItem.setImage(SWTResourceManager.getImage(MainGUI.class,
					ImageFactory.CD));
			cdItem.setText(cd.getName());
			CDMap.put(cdItem, cd);
		}
	}
	
	/**
	 * 在表格中显示搜索结果
	 */
	public void displaySearch(){
		try {
			table.removeAll();
			MainGUI.tableMap.clear();
			String keyword = cdSearchText.getText().trim();
			if (keyword.length() >= 2) {
				ArrayList<Document> result = CDManager.action.search(keyword,
						Search.CD_SEARCH);
				TableItem tableItem;
				long size = 0;
				String s;
				Document doc;
				int count = result.size();
				DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.MEDIUM);
				for (int i = 0; i < count; i++) {
					doc = result.get(i);
					tableItem = new TableItem(table, SWT.NONE);
					if (doc.get("isLeaf").equals("f")) {
						tableItem.setText(new String[] { doc.get("name"),
								"",dateFormat.format(new Date(Long.parseLong(doc.get("date")))),CDManager.action.getBelongCDName(doc),doc.get("path") });
						tableItem.setImage(SWTResourceManager.getImage(
								MainGUI.class, ImageFactory.FOLDER));
						MainGUI.tableMap.put(tableItem, doc);
					} else if (doc.get("isLeaf").equals("t")) {
						size = Long.parseLong(doc.get("size"));
						size /= 1024;
						s = String.format("%,d KB", ++size);
						tableItem.setText(new String[] { doc.get("name"),
								s,dateFormat.format(new Date(Long.parseLong(doc.get("date")))),CDManager.action.getBelongCDName(doc),doc.get("path") });
						tableItem.setImage(SWTResourceManager.getImage(
								MainGUI.class, ImageFactory.FILE));
						MainGUI.tableMap.put(tableItem, doc);
					}
				}
			}
		} catch (NumberFormatException e) {
			
			e.printStackTrace();
		} catch (MyException e) {
			MessageBox msgBox = new MessageBox(table.getShell(), SWT.ICON_ERROR
					| SWT.OK);
			msgBox.setText("错误");
			msgBox.setMessage("您输入的关键词太过模糊,请重新输入!");
			msgBox.open();
			return;
		}
	}
	
	/********************************************************
	 *****************   Register Listener  *******************
	 *******************************************************/
	public void addListeners(){
		
		shell.addShellListener(minCloseListener);   
		
		trayItem.addListener(SWT.DefaultSelection, trayListener);
		trayItem.addListener(SWT.MenuDetect, trayListener);
		trayOpenItem.addSelectionListener(openListener);
		trayAboutItem.addSelectionListener(aboutListener);
		trayHelpItem.addSelectionListener(helpListener);
		trayExitItem.addSelectionListener(exitListener);		
		
		addAlbumMenuItem.addSelectionListener(newAlbumListener);
		addCDMenuItem.addSelectionListener(newCDListener);
		passworfdMenuItem.addSelectionListener(setPassListener);
		exportIndexItem.addSelectionListener(exportListener);
		exitMenuItem.addSelectionListener(exitListener);

		renameMenuItem.addSelectionListener(renameListener); 
		addNoteMenuItem.addSelectionListener(addDescriptionListener);
		
		scanMenuItem.addSelectionListener(hardDiskSacnListener);
		logMenuItem.addSelectionListener(logListener);

		helpMenuItemF1.addSelectionListener(helpListener);
		aboutMenuItem.addSelectionListener(aboutListener);
		
		newAlbumToolItem.addSelectionListener(newAlbumListener);
		newCDToolItem.addSelectionListener(newCDListener);
		searchToolItem.addSelectionListener(hardDiskSacnListener);
		passwordToolItem.addSelectionListener(setPassListener);
		logToolItem.addSelectionListener(logListener);
		upToolItem.addSelectionListener(upToolListener);
		helpToolItem.addSelectionListener(helpListener);
		exitToolItem.addSelectionListener(exitListener);
		
		cdSearchText.addFocusListener(cdSearchFocuseListener);
		cdSearchText.addModifyListener(cdSearchModifyListener);
		searchButton.addMouseListener(searchButtonListener);
	
		albumTree.addTreeListener(albumTreeListener);
		albumTree.addMouseListener(albumTreeMouseListener);
	
		treeDragSource.addDragListener(treeDragListener);
		treeDropTarget.addDropListener(treeDropListener);
		
		newAlbumPopItem.addSelectionListener(newAlbumListener);
		deleteAlbumPopItem.addSelectionListener(deleteAlbumListener);
		newCDPopItem.addSelectionListener(newCDListener);
		modifyCDPopItem.addSelectionListener(addDescriptionListener);
		deleteCDPopItem.addSelectionListener(deleteCDListener);
		renameCDPopItem.addSelectionListener(renameListener);
	
		documentTree.addMouseListener(docTreeMouseListener);
		documentTree.addTreeListener(docTreeListener);
		documentTree.addSelectionListener(docTreeSelectionListener);
	
		table.addMouseListener(tableMouseListener);
	}
	
	/**************************************************************
	 ********************* Listener *******************************
	 *************************************************************/
	
	/**
	 * 托盘菜单项事件
	 */
	private Listener trayListener = new Listener(){
		
		public void handleEvent(Event event) {
			
			if(event.type == SWT.DefaultSelection){		
				event.display.getShells()[0].setVisible(!event.display.getShells()[0].getVisible());

⌨️ 快捷键说明

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