1
23
24
25package org.jzuul.gdk.swt;
26
27
28import org.eclipse.swt.SWT;
29import org.eclipse.swt.graphics.Image;
30import org.eclipse.swt.layout.GridData;
31import org.eclipse.swt.layout.GridLayout;
32import org.eclipse.swt.widgets.Display;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.ProgressBar;
35import org.eclipse.swt.widgets.Shell;
36
37
44public class Splash {
45 private int percentPerTask;
46 private int numberOfTasks;
47 private int percent;
48 private Display display;
49 private Shell shell;
50 private Label taskName;
51 private ProgressBar bar;
52 private int currentCount = 0;
53
54 public Splash(Display display) {
55 this.percent = 0;
56 this.display = display;
57 }
58
59
65 public void show(int numberOfTasks, String firstTask) {
66 setNumberOfTasks(numberOfTasks);
67 shell = new Shell(display, SWT.ON_TOP);
68 shell.setText("Jzuul GDK");
69
70 GridLayout layout = new GridLayout();
71 layout.numColumns= 1;
72 layout.horizontalSpacing = 0;
73 layout.verticalSpacing = 0;
74 layout.marginHeight = 0;
75 layout.marginWidth = 0;
76
77
78 shell.setLayout(layout);
79
80 Label label = new Label(shell, SWT.NONE);
81 Image image =Util.getImagefromResource(display, "etc/artwork/logo-big.png");
82 if (image != null) label.setImage(image);
83
84 this.taskName = new Label(shell, SWT.BORDER);
85 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
86 this.taskName.setLayoutData(gridData);
87
88 this.bar = new ProgressBar(shell, SWT.HORIZONTAL);
89 this.bar.setMinimum(0);
90 this.bar.setMaximum(100);
91 gridData = new GridData(GridData.FILL_HORIZONTAL);
92 this.bar.setLayoutData(gridData);
93 taskName.setText(firstTask);
94 shell.pack();
95 Util.centerWindow(shell);
96 shell.open();
97
98 }
99
03 private void setNumberOfTasks(int number) {
04 this.numberOfTasks = number;
05 percentPerTask = Math.round(100f / number);
06 }
07
08
12 public void nextTask(String task) {
13 percent += percentPerTask;
14 taskName.setText(task);
15 this.bar.setSelection(percent);
16 currentCount++;
17
18 taskName.update();
19 this.bar.update();
20 if (numberOfTasks == currentCount) {
21 this.close();
22 }
23
24 }
25
26
30 public void close() {
31 if(shell != null && !shell.isDisposed())
32 shell.dispose();
33
34 }
35}
36