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

📄 createcddialog.java

📁 CD Manager光盘资料管家婆源代码
💻 JAVA
字号:
package com.galaxyworkstation.view;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.Dialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import com.galaxyworkstation.model.SWTResourceManager;


public class CreateCDDialog extends Dialog {

	private Text pathText;
	private Text text_1;
	private Text text;
	private Button OK;
	private Button cancel;
	private Button choosePathButton;
	
	protected Object result;
	protected Shell shell;

	/**
	 * Create the dialog
	 * @param parent
	 * @param style
	 */
	public CreateCDDialog(Shell parent, int style) {
		super(parent, style);
	}

	/**
	 * Create the dialog
	 * @param parent
	 */
	public CreateCDDialog(Shell parent) {
		this(parent, SWT.NONE);
	}

	/**
	 * Open the dialog
	 * @return the result
	 */
	public Object open() {
		createContents();
		addListener();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return result;
	}

	/**
	 * Create contents of the dialog
	 */
	protected void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setImage(SWTResourceManager.getImage(CreateCDDialog.class, "../../../image/cd16.gif"));
		shell.setLayout(new FormLayout());
		shell.setSize(244, 344);
		shell.setLocation((shell.getDisplay().getClientArea().width - shell.getClientArea().width) / 2,
				(shell.getDisplay().getClientArea().height - shell.getClientArea().height) / 2);
		shell.setText("新建光盘");

		final Group group = new Group(shell, SWT.NONE);
		final FormData fd_group = new FormData();
		fd_group.bottom = new FormAttachment(100, -5);
		fd_group.top = new FormAttachment(0, 5);
		fd_group.right = new FormAttachment(100, -5);
		fd_group.left = new FormAttachment(0, 5);
		group.setLayoutData(fd_group);

		final Label label = new Label(group, SWT.NONE);
		label.setText("选择光驱:");
		label.setBounds(19, 32, 63, 20);

		final Label label_1 = new Label(group, SWT.NONE);
		label_1.setText("光盘名称:");
		label_1.setBounds(19, 71, 63, 20);

		text = new Text(group, SWT.BORDER);
		text.setBounds(88, 68, 121, 20);

		final Label label_2 = new Label(group, SWT.NONE);
		label_2.setText("光盘说明:");
		label_2.setBounds(19, 112, 63, 20);

		text_1 = new Text(group, SWT.BORDER);
		text_1.setBounds(19, 138, 190, 106);

		OK = new Button(group, SWT.NONE);
		OK.setText("确  定");
		OK.setBounds(52, 262, 48, 22);

		cancel = new Button(group, SWT.NONE);
		cancel.setText("取  消");
		cancel.setBounds(120, 262, 48, 22);

		choosePathButton = new Button(group, SWT.NONE);
		choosePathButton.setText("...");
		choosePathButton.setBounds(188, 32, 21, 20);

		pathText = new Text(group, SWT.BORDER);
		pathText.setEditable(false);
		pathText.setBounds(88, 32, 94, 20);
	}
	
	/*************************************************
	 ************Register Listener *******************
	 *************************************************/
	
	private void addListener(){
		
		OK.addSelectionListener(OKSelection);
		
		cancel.addSelectionListener(cancelSelection);		
		
		choosePathButton.addSelectionListener(choosePathSelection);
		
	}
	
	/*********************************************************
	 ******************* Listener ****************************
	 *********************************************************/	
	/**
	 * 选择光盘路径事件
	 */
	private SelectionListener choosePathSelection = new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent arg0) {
		}

		public void widgetSelected(SelectionEvent arg0) {
			
			final DirectoryDialog dirDialog = new DirectoryDialog(shell);
			dirDialog.setMessage("请选择将要建立索引的光盘...");
			dirDialog.setText("请选择需要建立索引的光盘..");
			String path = dirDialog.open();
			if (path != null) {
				pathText.setText(path);
			}
		}
		
	};
	
	/**
	 * 确定事件
	 */
	private SelectionListener OKSelection = new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent e) {
		}

		public void widgetSelected(SelectionEvent e) {
			
			String path = pathText.getText();
			if(path != "" && new File(path).getTotalSpace()>0){
				AddCDItem newItem = new AddCDItem();
				TreeItem treeItem = ((Tree)((Composite)((SashForm)((SashForm)((Group)e.display.getShells()[0].getChildren()[1])
				                     .getChildren()[0]).getChildren()[0]).getChildren()[0])
				                     .getChildren()[0]).getSelection()[0];
				newItem.setTreeItem(treeItem);
				newItem.setCDName(text.getText());
				newItem.setCDPath(path);
				newItem.setDescription(text_1.getText());
				e.display.getShells()[1].dispose();
				newItem.initial();
				
			}
			else{
				MessageBox msgBox = new MessageBox(shell,SWT.ICON_ERROR|SWT.OK);
				msgBox.setText("错误");
				msgBox.setMessage("光驱里没有光盘!");
				msgBox.open();
			}
		}
		
	};
	
	/**
	 * 取消事件
	 */
	private SelectionListener cancelSelection = new SelectionListener(){

		public void widgetDefaultSelected(SelectionEvent e) {
		}

		public void widgetSelected(SelectionEvent e) {
			
			shell.dispose();
		}
		
	};

}

⌨️ 快捷键说明

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