📄 exportindexdialog.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.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.control.CDManager;
import com.galaxyworkstation.model.CD;
import com.galaxyworkstation.model.SWTResourceManager;
public class ExportIndexDialog extends Dialog {
private Text text;
private Button choose;
private Button OK;
private Button cancel;
protected Object result;
protected Shell shell;
/**
* Create the dialog
* @param parent
* @param style
*/
public ExportIndexDialog(Shell parent, int style) {
super(parent, style);
}
/**
* Create the dialog
* @param parent
*/
public ExportIndexDialog(Shell parent) {
this(parent, SWT.NONE);
}
/**
* Open the dialog
*/
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.setLayout(new FormLayout());
shell.setSize(287, 128);
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.left = new FormAttachment(0, 5);
fd_group.bottom = new FormAttachment(100, -5);
fd_group.top = new FormAttachment(0, 0);
fd_group.right = new FormAttachment(100, -5);
group.setLayoutData(fd_group);
text = new Text(group, SWT.BORDER);
text.setEditable(false);
text.setBounds(10, 19, 149, 18);
choose = new Button(group, SWT.NONE);
choose.setImage(SWTResourceManager.getImage(SearchDialog.class, "../../../image/folder16.gif"));
choose.setText("请选择...");
choose.setBounds(174, 17, 87, 22);
OK = new Button(group, SWT.NONE);
OK.setText("确 定");
OK.setBounds(70, 56, 48, 22);
cancel = new Button(group, SWT.NONE);
cancel.setText("取 消");
cancel.setBounds(143, 56, 48, 22);
}
/*************************************************
************Register Listener *******************
*************************************************/
private void addListener(){
choose.addSelectionListener(chooseSelection);
OK.addSelectionListener(OKSelection);
cancel.addSelectionListener(cancelSelection);
}
/*********************************************************
******************* Listener ****************************
*********************************************************/
/**
* 选择事件
*/
private SelectionListener chooseSelection = new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
final DirectoryDialog dirDialog = new DirectoryDialog(shell);
dirDialog.setMessage("请选择将索引导出到的文件夹...");
String path = dirDialog.open();
if(path != null)
text.setText(path);
}
};
/**
* 确定事件
*/
private SelectionListener OKSelection = new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
if(text.getText() != ""){
TreeItem treeItem = ((Tree)((Composite)((SashForm)((SashForm)((Group)e.display.getShells()[0].getChildren()[1])
.getChildren()[0]).getChildren()[0]).getChildren()[0])
.getChildren()[0]).getSelection()[0];
CD cd = MainGUI.CDMap.get(treeItem);
CDManager.action.exportIndex(cd, text.getText());
MessageBox msgBox = new MessageBox(shell, SWT.ICON_INFORMATION
| SWT.OK);
msgBox.setText("成功");
msgBox.setMessage("索引成功导出为 " + text.getText() + File.separator + cd.getName() + ".txt 文件!" );
msgBox.open();
shell.dispose();
}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 + -