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