Removed unused exports and finished UpdateChecker.
[FinalKeyGui.git] / src / fkgui / PermitCountDownDialog.java
1 package fkgui;
2
3 import org.eclipse.swt.graphics.Point;
4 import org.eclipse.swt.widgets.Dialog;
5 import org.eclipse.swt.widgets.Display;
6 import org.eclipse.swt.widgets.Shell;
7 import org.eclipse.swt.widgets.Label;
8 import org.eclipse.swt.SWT;
9
10 public class PermitCountDownDialog extends Dialog {
11
12         protected Object result;
13         protected Shell shell;
14         public Display display;
15
16         String msg;
17         int msLeft;
18         private Label lblTimeLeft;
19         /**
20          * Create the dialog.
21          * @param parent
22          * @param style
23          */
24         public PermitCountDownDialog(Shell parent, int style, String title, String m, int msL) {
25                 super(parent, style);
26                 setText(title);
27                 msLeft = msL;
28                 msg = m;
29         
30         }
31
32         /**
33          * Open the dialog.
34          * @return the result
35          */
36         public Object open() {
37                 createContents();
38                 Point p = getParent().getSize();
39                 p.x /= 2;
40                 p.y /= 2;
41                 p.x -= shell.getSize().x/2;
42                 p.y -= shell.getSize().y/2;
43                 p.x += getParent().getLocation().x;
44                 p.y += getParent().getLocation().y;
45                 shell.setLocation( p );
46                 shell.setLayout(null);
47                 
48                 Label lblMsg = new Label(shell, SWT.NONE);
49                 lblMsg.setBounds(48, 10, 461, 54);
50                 lblMsg.setText(msg);
51                 
52                 lblTimeLeft = new Label(shell, SWT.NONE);
53                 lblTimeLeft.setBounds(48, 56, 201, 32);
54                 
55                 Animation animation = new Animation(shell, SWT.NONE, 4);
56                 animation.setBounds(10, 32, 32, 32);
57                 animation.setVisible(true);
58                 animation.setPlaying(true);
59                 
60                 
61
62                 shell.open();
63                 
64                 shell.layout();
65                 display = getParent().getDisplay();
66                                 
67                 animate();
68                 shell.setActive();
69                 
70                 while (!shell.isDisposed()) {
71                         if (!display.readAndDispatch()) {
72                                 display.sleep();
73                         }
74                 }
75                 return result;
76         }
77
78         private void animate() {
79                 display.timerExec(1000, new Runnable() {
80                         
81                         @Override
82                         public void run() {
83                                 if( !shell.isDisposed() )
84                                 {
85
86                                         lblTimeLeft.setText( Math.round(msLeft/1000) + Messages.PermitCountDownDialog_0);
87
88                                         display.update();
89                                         msLeft -= 1000;
90                                         if( msLeft<1)
91                                         {
92                                                 shell.close();
93                                                 
94                                         } else {                                
95                                                 animate();
96                                         }
97                                         
98                                 }
99                         }
100                 });
101                 
102         }
103
104         /**
105          * Create contents of the dialog.
106          */
107         private void createContents() {
108                 shell = new Shell(getParent(), getStyle());
109                 shell.setSize(521, 125);
110                 shell.setText(getText());
111         }
112 }