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

📄 maingui.java

📁 CD Manager光盘资料管家婆源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package com.galaxyworkstation.view;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import org.apache.lucene.document.Document;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import com.galaxyworkstation.control.CDManager;
import com.galaxyworkstation.model.Album;
import com.galaxyworkstation.model.CD;
import com.galaxyworkstation.model.ImageFactory;
import com.galaxyworkstation.model.MyException;
import com.galaxyworkstation.model.SWTResourceManager;
import com.galaxyworkstation.model.Search;

public class MainGUI {

	private Group group;
	
	private Menu menu;
	private Menu fileMenu;
	private MenuItem fileMenuItem;	
	private MenuItem addAlbumMenuItem;
	private MenuItem addCDMenuItem;
	private MenuItem passworfdMenuItem;
	private MenuItem exportIndexItem;
	private MenuItem exitMenuItem;
	private Menu editMenu;
	private MenuItem editMenuItem;
	private MenuItem addNoteMenuItem;
	private MenuItem renameMenuItem;
	private Menu settingMenu;
	private MenuItem settingMenuItem;
	private MenuItem scanMenuItem;
	private MenuItem logMenuItem;
	private Menu helpMenu;
	private MenuItem helpMenuItem;
	private MenuItem helpMenuItemF1;
	private MenuItem aboutMenuItem;
	private ToolItem exitToolItem;
	
	private Group toobarGroup;
	private ToolBar toolBar;
	private ToolItem newAlbumToolItem;
	private ToolItem newCDToolItem;
	private ToolItem searchToolItem;
	private ToolItem logToolItem;
	private ToolItem passwordToolItem;
	private ToolItem upToolItem;
	private ToolItem helpToolItem;
	private Text cdSearchText;
	private Button searchButton;
	
	private Tree albumTree;
	private Menu albumTreeMenu;
	private MenuItem newAlbumPopItem;
	private MenuItem deleteAlbumPopItem;
	private MenuItem newCDPopItem;
	private MenuItem modifyCDPopItem;
	private MenuItem deleteCDPopItem;
	private MenuItem renameCDPopItem;
	private DragSource treeDragSource;
	private DropTarget treeDropTarget;
	private CD dragCD;
	private boolean dragResult;
	private Tree documentTree;
	
	private Text descriptionText;
	private Text folderNumText;
	private Text fileNumText;
	private Text createDateText;
	private Text belongAlbumText;
	private Text cdNameText;

	private SashForm rootSashForm;
	private Table table;
	
	private Tray tray;
	private TrayItem trayItem;
	private Menu trayMenu;
	private MenuItem trayOpenItem;
	private MenuItem trayHelpItem;
	private MenuItem trayAboutItem;
	private MenuItem trayExitItem;
	
	
	public static Shell shell;

	public static HashMap<TreeItem, Document> documentMap;
	public static HashMap<TreeItem, Album> albumMap;
	public static HashMap<TreeItem, CD> CDMap;
	public static HashMap<TableItem,Document> tableMap;
	public static boolean canUP;
	public static Document entranceDoc;
	/**
	 * Open the window
	 */
	public void open() {
		final Display display = Display.getDefault();
		shell = new Shell(SWT.MAX | SWT.MIN | SWT.RESIZE
				| SWT.BORDER);
		shell.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/cd.gif"));
		
		createContents(shell);
		addListeners();
		shell.open();
		if(CDManager.action.getConfig().isPasswordSetted()){
			new InputPasswdDialog(shell,SWT.NONE).open();
		}
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
		CDManager.action.exit();
	}

	/**
	 * Create contents of the window
	 */
	protected void createContents(Shell shell) {
		final int SCREEN_WIDTH = shell.getDisplay().getClientArea().width;
		final int SCREEN_HEIGHT = shell.getDisplay().getClientArea().height;
		final int width = 800;
		final int height = 600;

		shell.setMinimumSize(new Point(0, 0));
		shell.setLayout(new FormLayout());
		shell.setSize(width, height);
		shell.setLocation((SCREEN_WIDTH - width) / 2,
				(SCREEN_HEIGHT - height) / 2);
		shell.setText("CD Manager");

		menu = new Menu(shell, SWT.BAR);
		shell.setMenuBar(menu);
		
		tray = shell.getDisplay().getSystemTray();
		if(tray == null){
			MessageBox msgBox = new MessageBox(shell.getDisplay().getShells()[0], SWT.ICON_ERROR
					| SWT.OK);
			msgBox.setText("错误");
			msgBox.setMessage("本系统无法支持托盘!");
			msgBox.open();
			return ;
		}else{
			
			trayMenu = new Menu(shell,SWT.POP_UP);
			
			trayOpenItem = new MenuItem(trayMenu,SWT.PUSH);
			trayOpenItem.setText("打开");
			trayOpenItem.setImage(SWTResourceManager.getImage(MainGUI.class, ImageFactory.CD));
			
			new MenuItem(trayMenu,SWT.SEPARATOR);
			
			trayHelpItem = new MenuItem(trayMenu,SWT.PUSH);
			trayHelpItem.setText("帮助");
			
			trayAboutItem = new MenuItem(trayMenu,SWT.PUSH);
			trayAboutItem.setText("关于");
			
			new MenuItem(trayMenu,SWT.SEPARATOR);
			
			trayExitItem = new MenuItem(trayMenu,SWT.PUSH);
			trayExitItem.setText("退出");
			
			trayItem = new TrayItem(tray,SWT.NONE);
			trayItem.setVisible(false);
			trayItem.setToolTipText("CD Manager");
			trayItem.setImage(SWTResourceManager.getImage(MainGUI.class, ImageFactory.CD));
			
		}

		fileMenuItem = new MenuItem(menu, SWT.CASCADE);
		fileMenuItem.setAccelerator(SWT.CTRL | SWT.ALT | 'F');
		fileMenuItem.setText("文件(&F)");

		fileMenu = new Menu(fileMenuItem);
		fileMenu.setDefaultItem(null);
		fileMenu.setData("newKey", "");
		fileMenuItem.setMenu(fileMenu);

		addAlbumMenuItem = new MenuItem(fileMenu, SWT.NONE);
		addAlbumMenuItem.setAccelerator(SWT.CTRL | 'N');
		addAlbumMenuItem.setText("新建专辑(&N)");

		new MenuItem(fileMenu, SWT.SEPARATOR);

		addCDMenuItem = new MenuItem(fileMenu, SWT.NONE);
		addCDMenuItem.setAccelerator(SWT.CTRL | 'C');
		addCDMenuItem.setText("新建光盘(&C)");
		
		new MenuItem(fileMenu, SWT.SEPARATOR);

		passworfdMenuItem = new MenuItem(fileMenu, SWT.NONE);
		passworfdMenuItem.setAccelerator(SWT.CTRL | 'P');
		passworfdMenuItem.setText("设置密码(&P)");

		new MenuItem(fileMenu, SWT.SEPARATOR);

		exportIndexItem = new MenuItem(fileMenu, SWT.NONE);
		exportIndexItem.setAccelerator(SWT.CTRL | 'O');
		exportIndexItem.setText("导出索引(&O)");

		new MenuItem(fileMenu, SWT.SEPARATOR);

		exitMenuItem = new MenuItem(fileMenu, SWT.NONE);
		exitMenuItem.setAccelerator(SWT.CTRL | 'X');
		exitMenuItem.setText("退    出(&X)");


		editMenuItem = new MenuItem(menu, SWT.CASCADE);
		editMenuItem.setAccelerator(SWT.CTRL | SWT.ALT | 'E');
		editMenuItem.setText("编辑(&E)");

		editMenu = new Menu(editMenuItem);
		editMenuItem.setMenu(editMenu);

		addNoteMenuItem = new MenuItem(editMenu, SWT.NONE);
		addNoteMenuItem.setAccelerator(SWT.CTRL | 'D');
		addNoteMenuItem.setText("添加注释(&D)");
		
		new MenuItem(editMenu, SWT.SEPARATOR);
		
		renameMenuItem = new MenuItem(editMenu, SWT.NONE);
		renameMenuItem.setAccelerator(SWT.CTRL | 'R');
		renameMenuItem.setText("重 命 名(&R)");

		settingMenuItem = new MenuItem(menu, SWT.CASCADE);
		settingMenuItem.setAccelerator(SWT.CTRL | SWT.ALT | 'T');
		settingMenuItem.setText("工具(&T)");

		settingMenu = new Menu(settingMenuItem);
		settingMenuItem.setMenu(settingMenu);

		scanMenuItem = new MenuItem(settingMenu, SWT.NONE);
		scanMenuItem.setAccelerator(SWT.CTRL | 'S');
		scanMenuItem.setText("硬盘搜索(&S)");
		
		new MenuItem(settingMenu, SWT.SEPARATOR);
		
		logMenuItem = new MenuItem(settingMenu, SWT.NONE);
		logMenuItem.setAccelerator(SWT.CTRL | 'L');
		logMenuItem.setText("查看日志(&L)");
		
		helpMenuItem = new MenuItem(menu, SWT.CASCADE);
		helpMenuItem.setAccelerator(SWT.CTRL | SWT.ALT | 'H');
		helpMenuItem.setText("帮助(&H)");

		helpMenu = new Menu(helpMenuItem);
		helpMenuItem.setMenu(helpMenu);

		helpMenuItemF1 = new MenuItem(helpMenu, SWT.NONE);
		helpMenuItemF1.setAccelerator(SWT.F1);
		helpMenuItemF1.setText("帮    助(&F1)");

		new MenuItem(helpMenu, SWT.SEPARATOR);

		aboutMenuItem = new MenuItem(helpMenu, SWT.NONE);
		aboutMenuItem.setAccelerator(SWT.CTRL | 'A');
		aboutMenuItem.setText("关    于(&A)");

		toobarGroup = new Group(shell, SWT.NONE);
		final FormData fd_toobarGroup = new FormData();
		fd_toobarGroup.bottom = new FormAttachment(0, 60);
		fd_toobarGroup.top = new FormAttachment(0, 0);
		fd_toobarGroup.left = new FormAttachment(0, 5);
		fd_toobarGroup.right = new FormAttachment(100, - 5);
		toobarGroup.setLayoutData(fd_toobarGroup);
		toobarGroup.setLayout(new FormLayout());

		toolBar = new ToolBar(toobarGroup, SWT.NONE);
		final FormData fd_toolBar = new FormData();
		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);
		
        new ToolItem(toolBar,SWT.SEPARATOR);
        newAlbumToolItem = new ToolItem(toolBar, SWT.NONE);
        newAlbumToolItem.setToolTipText("新建专辑");
        newAlbumToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/album2.gif"));
		
        newCDToolItem = new ToolItem(toolBar, SWT.PUSH);
		newCDToolItem.setToolTipText("新建光盘");
		newCDToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/cd.gif"));
		
		searchToolItem = new ToolItem(toolBar, SWT.PUSH);
		searchToolItem.setToolTipText("硬盘搜索");
		searchToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/search.gif"));
		
        new ToolItem(toolBar,SWT.SEPARATOR);
		logToolItem = new ToolItem(toolBar, SWT.PUSH);
		logToolItem.setToolTipText("查看日志");
		logToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/log.gif"));

        new ToolItem(toolBar,SWT.SEPARATOR);
		passwordToolItem = new ToolItem(toolBar, SWT.PUSH);
		passwordToolItem.setToolTipText("设置密码");
		passwordToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/password.gif"));
		
        new ToolItem(toolBar,SWT.SEPARATOR);
		upToolItem = new ToolItem(toolBar, SWT.PUSH);
		upToolItem.setToolTipText("向上");
		upToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/up.gif"));
       
		helpToolItem = new ToolItem(toolBar, SWT.PUSH);
		helpToolItem.setToolTipText("帮助");
		helpToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/help2.png"));
		
    	exitToolItem = new ToolItem(toolBar, SWT.PUSH);
		exitToolItem.setToolTipText("退出");
		exitToolItem.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/exit.gif"));	


		cdSearchText = new Text(toobarGroup, SWT.BORDER);
		cdSearchText.setText("搜索光盘文件...");
		final FormData fd_cdSearchText = new FormData();
		fd_cdSearchText.top = new FormAttachment(0, 15);
		fd_cdSearchText.left = new FormAttachment(0,
				shell.getClientArea().width - 240);
		fd_cdSearchText.right = new FormAttachment(0,
				shell.getClientArea().width - 60);
		cdSearchText.setLayoutData(fd_cdSearchText);

		searchButton = new Button(toobarGroup, SWT.NONE);
		searchButton.setImage(SWTResourceManager.getImage(MainGUI.class, "../../../image/search16.gif"));
		final FormData fd_button = new FormData();
		fd_button.right = new FormAttachment(100, -5);
		fd_button.top = new FormAttachment(0, 8);
		fd_button.left = new FormAttachment(0, shell.getClientArea().width - 50);
		searchButton.setLayoutData(fd_button);

		group = new Group(shell, SWT.NONE);
		group.setLayout(new FillLayout());
		final FormData fd_group = new FormData();
		fd_group.bottom = new FormAttachment(0,
				shell.getClientArea().height - 5);
		fd_group.right = new FormAttachment(0, shell.getClientArea().width - 5);
		fd_group.left = new FormAttachment(0, 5);
		fd_group.top = new FormAttachment(0, 55);
		group.setLayoutData(fd_group);

		rootSashForm = new SashForm(group, SWT.SMOOTH);
		rootSashForm.setRedraw(true);
		rootSashForm.setLayout(new FormLayout());

		final SashForm leftSashForm = new SashForm(rootSashForm, SWT.VERTICAL
				| SWT.SMOOTH);

		final Composite topTreeComposite = new Composite(leftSashForm,
				SWT.BORDER);
		topTreeComposite.setLayout(new FillLayout());
		topTreeComposite.setBackground(Display.getCurrent().getSystemColor(
				SWT.COLOR_WHITE));
		albumTree = new Tree(topTreeComposite, SWT.SINGLE);
		albumTree.setFocus();
		

⌨️ 快捷键说明

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