1
package org.herac.tuxguitar.gui.util;
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.SelectionAdapter;
5
import org.eclipse.swt.events.SelectionEvent;
6
import org.eclipse.swt.layout.GridData;
7
import org.eclipse.swt.layout.GridLayout;
8
import org.eclipse.swt.widgets.Button;
9
import org.eclipse.swt.widgets.Composite;
10
import org.eclipse.swt.widgets.Label;
11
import org.eclipse.swt.widgets.Shell;
12
import org.herac.tuxguitar.gui.TuxGuitar;
14
public class ConfirmDialog {
16
private String message;
17
private boolean confirm;
19
public ConfirmDialog(Shell parent,String message){
21
this.message = message;
25
public boolean confirm(){
26
final Shell dialog = new Shell(this.parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
27
dialog.setLayout(new GridLayout(1, true));
30
//========================================================================
31
Composite labelComposite = new Composite(dialog, SWT.NONE);
32
labelComposite.setLayout(new GridLayout(2, false));
33
labelComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
35
Label icon = new Label(labelComposite, SWT.NONE);
36
Label message = new Label(labelComposite, SWT.NONE);
37
icon.setImage(parent.getDisplay().getSystemImage(SWT.ICON_QUESTION));
38
message.setText(this.message);
41
//========================================================================
42
Composite buttons = new Composite(dialog, SWT.NONE);
43
buttons.setLayout(new GridLayout(2,false));
44
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
46
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
47
data.minimumWidth = 80;
48
data.minimumHeight = 25;
50
Button buttonOk = new Button(buttons, SWT.PUSH);
51
buttonOk.setLayoutData(data);
52
buttonOk.setText(TuxGuitar.getProperty("yes"));
53
buttonOk.addSelectionListener(new SelectionAdapter() {
54
public void widgetSelected(SelectionEvent arg0) {
60
Button buttonCancel = new Button(buttons, SWT.PUSH);
61
buttonCancel.setLayoutData(data);
62
buttonCancel.setText(TuxGuitar.getProperty("no"));
63
buttonCancel.addSelectionListener(new SelectionAdapter() {
64
public void widgetSelected(SelectionEvent arg0) {
73
int x = this.parent.getBounds().x + (this.parent.getBounds().width - dialog.getSize().x) / 2;
74
int y = this.parent.getBounds().y + (this.parent.getBounds().height - dialog.getSize().y) / 2;
75
dialog.setLocation(x, y);
80
while (!dialog.isDisposed()) {
81
if (!dialog.getDisplay().readAndDispatch()) {
82
dialog.getDisplay().sleep();