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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

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.widgets.Display;
 
5
import org.eclipse.swt.widgets.Shell;
 
6
import org.herac.tuxguitar.gui.actions.ActionLock;
 
7
 
 
8
public class DialogUtils {
 
9
        
 
10
        public static final int OPEN_STYLE_WAIT = 0x01;
 
11
        
 
12
        public static final int OPEN_STYLE_PACK = 0x02;
 
13
        
 
14
        public static final int OPEN_STYLE_LAYOUT = 0x04;
 
15
        
 
16
        public static final int OPEN_STYLE_CENTER = 0x08;
 
17
        
 
18
        public static final int OPEN_STYLE_MAXIMIZED = 0x10;
 
19
        
 
20
        public static final Shell newDialog(Display display,int style){
 
21
                return new Shell(display, style);
 
22
        }
 
23
        
 
24
        public static final Shell newDialog(Shell parent,int style){
 
25
                parent.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
 
26
                return new Shell(parent, style);
 
27
        }
 
28
        
 
29
        public static final void openDialog(Shell dialog,int style){
 
30
                DialogUtils.openDialog(dialog,dialog.getParent().getShell(),style);
 
31
        }
 
32
        
 
33
        public static final void openDialog(Shell dialog,Shell parent,int style){
 
34
                Display display = dialog.getDisplay();
 
35
                if((style & OPEN_STYLE_PACK) != 0){
 
36
                        dialog.pack();
 
37
                }
 
38
                if((style & OPEN_STYLE_LAYOUT) != 0){
 
39
                        dialog.layout();
 
40
                }
 
41
                if((style & OPEN_STYLE_MAXIMIZED) != 0){
 
42
                        dialog.setMaximized(true);
 
43
                }
 
44
                else if((style & OPEN_STYLE_CENTER) != 0){
 
45
                        int x = Math.max(0,parent.getBounds().x + (parent.getBounds().width - dialog.getSize().x) / 2);
 
46
                        int y = Math.max(0,parent.getBounds().y + (parent.getBounds().height - dialog.getSize().y) / 2);
 
47
                        dialog.setLocation(x,y);
 
48
                }
 
49
                dialog.open();
 
50
                
 
51
                parent.setCursor(display.getSystemCursor(SWT.CURSOR_ARROW));
 
52
                
 
53
                if((style & OPEN_STYLE_WAIT) != 0){
 
54
                        if( (dialog.getStyle() & SWT.APPLICATION_MODAL) == 0 ){
 
55
                                ActionLock.unlock();
 
56
                        }
 
57
                        while (!display.isDisposed() && !dialog.isDisposed()) {
 
58
                                if (!display.readAndDispatch()) {
 
59
                                        display.sleep();
 
60
                                }
 
61
                        }
 
62
                }
 
63
        }
 
64
}