?? dialogtest.java
字號:
package com.jiachun;
import org.eclipse.swt.SWT;
import java.io.*;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
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.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
//import org.eclipse.swt.widgets.List;
//import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.graphics.GC;
//import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
public class DialogTest {
private static Text listfileText;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell allDialogsTestShell = new Shell();
allDialogsTestShell.addShellListener(new ShellAdapter() {
public void shellClosed(final ShellEvent e) {
}
public void shellDeiconified(final ShellEvent e) {
boolean rsl=MessageDialog.openConfirm(allDialogsTestShell, "Confirm", "Confirm Dialog!");
if(rsl==true)
System.exit(0);
else
return;
}
});
allDialogsTestShell.setBackgroundMode(SWT.INHERIT_DEFAULT);
allDialogsTestShell.setImage(SWTResourceManager.getImage(DialogTest.class, "Icon.ico"));
allDialogsTestShell.setBackgroundImage(SWTResourceManager.getImage(DialogTest.class, "Background.jpg"));
allDialogsTestShell.setLayout(new FormLayout());
allDialogsTestShell.setSize(506, 407);
allDialogsTestShell.setText("All Dialog Test");
//
allDialogsTestShell.open();
final Button exitButton = new Button(allDialogsTestShell, SWT.NONE);
exitButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
System.exit(0);
}
});
final FormData fd_exitButton = new FormData();
fd_exitButton.right = new FormAttachment(0, 126);
fd_exitButton.left = new FormAttachment(0, 90);
exitButton.setLayoutData(fd_exitButton);
exitButton.setText("Exit");
final Group messagedialogGroup = new Group(allDialogsTestShell, SWT.NONE);
messagedialogGroup.setText("MessageDialog");
final FormData fd_messagedialogGroup = new FormData();
fd_messagedialogGroup.bottom = new FormAttachment(0, 170);
fd_messagedialogGroup.right = new FormAttachment(0, 230);
fd_messagedialogGroup.top = new FormAttachment(0, 90);
fd_messagedialogGroup.left = new FormAttachment(0, 10);
messagedialogGroup.setLayoutData(fd_messagedialogGroup);
messagedialogGroup.setLayout(new FormLayout());
final Label showLabel = new Label(allDialogsTestShell, SWT.SHADOW_NONE | SWT.BORDER);
showLabel.setForeground(SWTResourceManager.getColor(255, 0, 255));
showLabel.setFont(SWTResourceManager.getFont("宋體", 11, SWT.NONE));
showLabel.setAlignment(SWT.CENTER);
final FormData fd_showLabel = new FormData();
fd_showLabel.bottom = new FormAttachment(0, 367);
fd_showLabel.top = new FormAttachment(0, 350);
showLabel.setLayoutData(fd_showLabel);
showLabel.setText("This display show the result of dialogs.");
final Button okButton = new Button(messagedialogGroup, SWT.NONE);
okButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
MessageDialog.openInformation(allDialogsTestShell,"Hello!","Hello!");
showLabel.setText("return void");
}
});
final FormData fd_okButton = new FormData();
fd_okButton.top = new FormAttachment(0, 10);
fd_okButton.left = new FormAttachment(0, 10);
okButton.setLayoutData(fd_okButton);
okButton.setText("OK");
final Button cancelButton = new Button(messagedialogGroup, SWT.NONE);
cancelButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
boolean rsl=MessageDialog.openConfirm(allDialogsTestShell, "Confirm", "Confirm Dialog!");
showLabel.setText("return "+rsl);
}
});
final FormData fd_cancelButton = new FormData();
fd_cancelButton.top = new FormAttachment(okButton, 0, SWT.TOP);
fd_cancelButton.left = new FormAttachment(0, 45);
cancelButton.setLayoutData(fd_cancelButton);
cancelButton.setText("OkCancel");
final Button warningButton = new Button(messagedialogGroup, SWT.NONE);
warningButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
MessageDialog.openWarning(allDialogsTestShell, "Warning", "Warning Dialog!");
showLabel.setText("return void");
}
});
final FormData fd_warningButton = new FormData();
fd_warningButton.top = new FormAttachment(cancelButton, 0, SWT.TOP);
fd_warningButton.left = new FormAttachment(0, 130);
warningButton.setLayoutData(fd_warningButton);
warningButton.setText("warning");
final Button errorButton = new Button(messagedialogGroup, SWT.NONE);
errorButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
MessageDialog.openError(allDialogsTestShell, "Error", "Error Dialog");
showLabel.setText("return void");
}
});
final FormData fd_errorButton = new FormData();
fd_errorButton.top = new FormAttachment(okButton, 5, SWT.BOTTOM);
fd_errorButton.left = new FormAttachment(okButton, 0, SWT.LEFT);
errorButton.setLayoutData(fd_errorButton);
errorButton.setText("Error");
final Button questionButton = new Button(messagedialogGroup, SWT.NONE);
questionButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
boolean rsl=MessageDialog.openQuestion(allDialogsTestShell, "Question", "Question Dialog!");
showLabel.setText("return "+rsl);
}
});
final FormData fd_questionButton = new FormData();
fd_questionButton.bottom = new FormAttachment(cancelButton, 27, SWT.BOTTOM);
fd_questionButton.top = new FormAttachment(cancelButton, 5, SWT.BOTTOM);
fd_questionButton.right = new FormAttachment(0, 130);
fd_questionButton.left = new FormAttachment(0, 70);
questionButton.setLayoutData(fd_questionButton);
questionButton.setText("Question");
Group systemdialogGroup;
systemdialogGroup = new Group(allDialogsTestShell, SWT.NONE);
fd_exitButton.bottom = new FormAttachment(systemdialogGroup, 27, SWT.BOTTOM);
fd_exitButton.top = new FormAttachment(systemdialogGroup, 5, SWT.BOTTOM);
fd_showLabel.right = new FormAttachment(systemdialogGroup, 474, SWT.LEFT);
fd_showLabel.left = new FormAttachment(systemdialogGroup, 0, SWT.LEFT);
systemdialogGroup.setText("SystemDialog");
final FormData fd_systemdialogGroup = new FormData();
fd_systemdialogGroup.bottom = new FormAttachment(0, 260);
fd_systemdialogGroup.left = new FormAttachment(messagedialogGroup, -220, SWT.RIGHT);
fd_systemdialogGroup.right = new FormAttachment(messagedialogGroup, 0, SWT.RIGHT);
fd_systemdialogGroup.top = new FormAttachment(messagedialogGroup, 5, SWT.BOTTOM);
systemdialogGroup.setLayoutData(fd_systemdialogGroup);
systemdialogGroup.setLayout(new FormLayout());
final Button openfileButton = new Button(systemdialogGroup, SWT.NONE);
openfileButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
FileDialog fd = new FileDialog(allDialogsTestShell, SWT.OPEN);
fd.setText("Open");
fd.setFilterPath("C:/");
String[] filterExt = { "*.txt", "*.doc", ".rtf", "*.*" };
fd.setFilterExtensions(filterExt);
String selected = fd.open();
if(selected!=null){
showLabel.setText(selected);
}
else{
showLabel.setText("return null");
}
}
});
final FormData fd_openfileButton = new FormData();
fd_openfileButton.top = new FormAttachment(0, 10);
fd_openfileButton.left = new FormAttachment(0, 10);
openfileButton.setLayoutData(fd_openfileButton);
openfileButton.setText("OpenFile");
final Button savefileButton = new Button(systemdialogGroup, SWT.NONE);
savefileButton.addMouseListener(new MouseAdapter() {
public void mouseUp(final MouseEvent e) {
FileDialog fd = new FileDialog(allDialogsTestShell, SWT.SAVE);
fd.setText("Save");
fd.setFilterPath("C:/");
String[] filterExt = { "*.txt", "*.doc", ".rtf", "*.*" };
fd.setFilterExtensions(filterExt);
String selected = fd.open();
if(selected!=null){
showLabel.setText(selected);
}
else{
showLabel.setText("return null");
}
}
});
final FormData fd_savefileButton = new FormData();
fd_savefileButton.left = new FormAttachment(0, 82);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -