1
2
3
4
5
6
7
8
9
10
11 package de.jaret.util.ui;
12
13 import java.io.InputStream;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.swt.graphics.Rectangle;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Shell;
24
25
26
27
28
29
30
31
32
33 public class Splash {
34 Image _image;
35 Shell _splashShell;
36 Label _label;
37 Label _msgLabel;
38 Display _display;
39
40
41
42
43
44
45
46 public Splash(String rscName, String messageString) {
47 Display display = new Display();
48 _display = display;
49 InputStream inStream = ClassLoader.getSystemResourceAsStream(rscName);
50 _image = new Image(display, inStream);
51 _splashShell = new Shell(SWT.ON_TOP);
52
53 GridLayout gridLayout = new GridLayout();
54 gridLayout.marginWidth = 1;
55 gridLayout.marginHeight = 1;
56 gridLayout.numColumns = 1;
57 _splashShell.setLayout(gridLayout);
58
59
60
61
62 GridData gd = new GridData(GridData.FILL_BOTH);
63
64
65 _label = new Label(_splashShell, SWT.NONE);
66 _label.setImage(_image);
67 _label.setLayoutData(gd);
68
69 gd = new GridData(GridData.FILL_HORIZONTAL);
70 _msgLabel = new Label(_splashShell, SWT.NONE);
71 _msgLabel.setLayoutData(gd);
72 _msgLabel.setBackground(new Color(_display, 255, 255, 255));
73 _msgLabel.setText(messageString);
74
75 _splashShell.pack();
76 Rectangle splashRect = _splashShell.getBounds();
77 Rectangle displayRect = display.getBounds();
78 int x = (displayRect.width - splashRect.width) / 2;
79 int y = (displayRect.height - splashRect.height) / 2;
80 _splashShell.setLocation(x, y);
81 _splashShell.open();
82 }
83
84 public void dispose() {
85 _splashShell.close();
86 _image.dispose();
87 _label.dispose();
88 }
89 }