Plug-in 对话框
来源:互联网 发布:easymule mac 编辑:程序博客网 时间:2024/06/03 19:24
Plug-in 对话框
首先申明下,本文为笔者学习《Eclipse插件开发学习笔记》的笔记,并加入笔者自己的理解和归纳总结。
1、标准消息对话框
MessageBox可以方便地生成标准消息对话框。setText方法设置MessageBox的标题,setMessage方法设置显示消息。
MessageBox的图标样式,
- ICON_ERROR,显示错误消息。
- ICON_WARNING,显示警告消息。
- ICON_INFORMATION,显示提示信息。
- ICON_WORKING,显示正在进行信息。
- ICON_QUESTION,显示问题信息。
- SWT.OK | SWT.CANCEL,确定 | 取消
- SWT.YES | SWT.NO | SWT.CANCEL,是 | 否 | 取消
- SWT.ABORT | SWT.RETRY | SWT.IGNORE,中止 | 重试 | 忽略
Button defaultButton = new Button(shell, SWT.NONE);defaultButton.setText("MessageBox");defaultButton.setBounds(10, 10, 150, 25);defaultButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageBox mb = new MessageBox(shell, SWT.ICON_SEARCH);mb.setText("MessageBox");mb.setMessage("MessageBox open, MessageBox open!");mb.open();}});Button okOrCancelButton = new Button(shell, SWT.NONE);okOrCancelButton.setText("Ok|Cancel");okOrCancelButton.setBounds(10, 45, 150, 25);okOrCancelButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageBox mb = new MessageBox(shell,SWT.ICON_ERROR|SWT.OK|SWT.CANCEL);mb.setText("Error");mb.setMessage("A error occur!");mb.open();}});Button yesOrNoButton = new Button(shell, SWT.NONE);yesOrNoButton.setText("yes|no");yesOrNoButton.setBounds(10, 80, 150, 25);yesOrNoButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageBox mb = new MessageBox(shell,SWT.ICON_INFORMATION|SWT.YES|SWT.NO|SWT.CANCEL);mb.setText("Information");mb.setMessage("You got a message!");mb.open();}});Button retryButton = new Button(shell, SWT.NONE);retryButton.setText("Retry");retryButton.setBounds(10, 115, 150, 25);retryButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageBox mb = new MessageBox(shell,SWT.ICON_QUESTION|SWT.ABORT|SWT.RETRY|SWT.IGNORE);mb.setText("Question");mb.setMessage("Do you want to try again?");int result = mb.open();if (result == SWT.ABORT) {System.out.println("ABORT Pressed");} else if (result == SWT.RETRY) {System.out.println("RETRY Pressed");} else if (result == SWT.IGNORE) {System.out.println("IGNORE Pressed");} else {System.out.println(result + " Pressed");}}});显示如下
2、文本和目录对话框
FileDialog是文本对话框,有三种样式可以选择,SWT.OPEN|SWT.MULTI|SWT.SAVE。样式是OPEN和MULTI时,显示为打开。样式是SAVE时,显示为另存为。setFilterNames和setFilterExtensions为文件对话框设置过滤器,setFilterPath方法设置默认打开目录。
DirectoryDialog是目录对话框,setFilterPath方法设置默认打开目录。
Button openButton = new Button(shell, SWT.NONE);openButton.setText("Open");openButton.setBounds(10, 10, 150, 25);openButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {FileDialog dialog = new FileDialog(shell);dialog.setFilterPath("C:\\");dialog.setFilterNames(new String[]{"Java Files", "Class Files", "All Files"});dialog.setFilterExtensions(new String[]{"*.java", "*.class", "*.*"});String result = dialog.open();System.out.println(result);}});Button multiButton = new Button(shell, SWT.NONE);multiButton.setText("Multi");multiButton.setBounds(10, 45, 150, 25);multiButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {FileDialog dialog = new FileDialog(shell, SWT.MULTI);String result = dialog.open();if (result != null) {for (String fileName : dialog.getFileNames()) {System.out.println(fileName);}}}});Button saveButton = new Button(shell, SWT.NONE);saveButton.setText("Save");saveButton.setBounds(10, 80, 150, 25);saveButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {FileDialog dialog = new FileDialog(shell, SWT.SAVE);dialog.setFilterPath("d:\\");String result = dialog.open();System.out.println(result);}});Button dirButton = new Button(shell, SWT.NONE);dirButton.setText("Directory");dirButton.setBounds(10, 115, 150, 25);dirButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {DirectoryDialog dialog = new DirectoryDialog(shell);dialog.setFilterPath("d:\\");String result = dialog.open();System.out.println(result);}});
显示如下
3、颜色对话框
颜色对话框显示一个调色板并允许用户选择其中一种颜色。final Button colorButton = new Button(shell, SWT.NONE);colorButton.setText("Color Dialog");colorButton.setBounds(10, 10, 150, 25);colorButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {ColorDialog dialog = new ColorDialog(shell);RGB rgb = dialog.open();if (rgb != null) {System.out.println(rgb.red + ":" + rgb.green + ":" + rgb.blue);Color newColor = new Color(display, rgb);shell.setBackground(newColor);if (color != null) color.dispose();color = newColor;}}});... ...if (color != null) {color.dispose();}
显示如下
4、字体对话框
字体对话框显示当前系统中所有可用字体供用户选择。final Button fontButton = new Button(shell, SWT.NONE);fontButton.setText("Font Dialog");fontButton.setBounds(10, 10, 150, 25);fontButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {FontDialog dialog = new FontDialog(shell);FontData fd = dialog.open();if (fd != null) {Font newFont = new Font(display, fd);fontButton.setFont(newFont);if (font != null) font.dispose();font = newFont;}}});... ...if (font != null) {font.dispose();}
显示如下
5、MessageDialog
MessageDialog对话框有多种形式。其中confirm和question需要通过返回值来判断结果。Button confirmButton = new Button(shell, SWT.NONE);confirmButton.setText("Confirm Dialog");confirmButton.setBounds(10, 10, 150, 25);confirmButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {boolean result = MessageDialog.openConfirm(shell,"MessageDialog", "Confirm Dialog");System.out.println(result);}});Button errorButton = new Button(shell, SWT.NONE);errorButton.setText("Error Dialog");errorButton.setBounds(10, 45, 150, 25);errorButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageDialog.openError(shell, "MessageDialog", "Error Dialog");}});Button infoButton = new Button(shell, SWT.NONE);infoButton.setText("Info Dialog");infoButton.setBounds(10, 80, 150, 25);infoButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageDialog.openInformation(shell, "MessageDialog", "Info Dialog");}});Button questionButton = new Button(shell, SWT.NONE);questionButton.setText("Qurstion Dialog");questionButton.setBounds(10, 115, 150, 25);questionButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {boolean result = MessageDialog.openQuestion(shell,"MessageDialog", "Qurstion Dialog");System.out.println(result);}});Button warningButton = new Button(shell, SWT.NONE);warningButton.setText("Warning Dialog");warningButton.setBounds(10, 150, 150, 25);warningButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {MessageDialog.openWarning(shell, "MessageDialog", "Warning Dialog");}});
显示如下
6、InputDialog对话框接受输入
Button inputButton = new Button(shell, SWT.NONE);inputButton.setText("Input Dialog");inputButton.setBounds(10, 10, 150, 25);inputButton.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {InputDialog dialog = new InputDialog(shell, "输入", "3 + 5 = ?", "", null);int result = dialog.open();if (result == InputDialog.OK) {System.out.println(dialog.getValue());}}});
显示如下
0 0
- Plug-in 对话框
- plug-in
- plug-in网址
- C# Plug-in resources
- Eclipse plug-in
- plug in, Basic idea
- ZDA plug-in,删无赦!
- datawindow plug-in
- powerbuilder window plug-in
- Nagios plug-in开发
- 瞎扯plug-in
- PI Achive Plug-In
- Plug-in插件技术
- Plug-In 1.1
- 关于jquery plug-in
- java plug in
- 什么是Java Plug-in
- Codeforce # A Plug-in
- C++中this->的作用
- HttpServletRequest对象的详解
- 关于消息队列的使用----ActiveMQ,RabbitMQ,ZeroMQ,Kafka,MetaMQ,RocketMQ
- c++第五次实验
- Difference between $.extend and $.fn.extend
- Plug-in 对话框
- 类加载的过程(详细)
- 单例模式 (两种)及多线程下的优化
- JSON介绍及Android最全面解析方法(Gson、AS自带org.son、Jackson解析)
- 一句话讲明白 pthread_key_t和pthread_key_create()
- 手把手教你如何加入到github的开源世界!
- C++——必须使用复制构造函数的情况
- iOS: 富文本AttributedString的详解
- maven jetty 输出中文乱码