~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/util/ConfirmDialog.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.herac.tuxguitar.gui.util;
2
 
 
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;
13
 
 
14
 
public class ConfirmDialog {
15
 
        private Shell parent;
16
 
        private String message;
17
 
        private boolean confirm;
18
 
 
19
 
        public ConfirmDialog(Shell parent,String message){
20
 
                this.parent = parent;
21
 
                this.message = message;
22
 
                this.confirm = false;
23
 
        }
24
 
        
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));
28
 
                
29
 
                
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));    
34
 
                
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);
39
 
                
40
 
                
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));        
45
 
        
46
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
47
 
        data.minimumWidth = 80;
48
 
        data.minimumHeight = 25;    
49
 
                                
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) {
55
 
                dialog.dispose();
56
 
                confirm = true;
57
 
            }
58
 
        });
59
 
                
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) {
65
 
                dialog.dispose();
66
 
                confirm = false;
67
 
            }
68
 
        });             
69
 
        
70
 
        dialog.pack();
71
 
        dialog.open();
72
 
 
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);
76
 
        
77
 
        
78
 
        
79
 
                
80
 
                while (!dialog.isDisposed()) {
81
 
            if (!dialog.getDisplay().readAndDispatch()) {
82
 
                dialog.getDisplay().sleep();
83
 
            }
84
 
 
85
 
        }
86
 
                
87
 
                return this.confirm;
88
 
                
89
 
        }
90
 
 
91
 
}