1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.Font;
|
---|
8 | import java.awt.GridBagConstraints;
|
---|
9 | import java.awt.GridBagLayout;
|
---|
10 | import java.awt.Insets;
|
---|
11 | import java.awt.event.MouseAdapter;
|
---|
12 | import java.awt.event.MouseEvent;
|
---|
13 |
|
---|
14 | import javax.swing.JFrame;
|
---|
15 | import javax.swing.JLabel;
|
---|
16 | import javax.swing.JPanel;
|
---|
17 | import javax.swing.JProgressBar;
|
---|
18 | import javax.swing.JSeparator;
|
---|
19 | import javax.swing.border.Border;
|
---|
20 | import javax.swing.border.EmptyBorder;
|
---|
21 | import javax.swing.border.EtchedBorder;
|
---|
22 |
|
---|
23 | import org.openstreetmap.josm.data.Version;
|
---|
24 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
25 | import org.openstreetmap.josm.gui.progress.ProgressRenderer;
|
---|
26 | import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor;
|
---|
27 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Show a splash screen so the user knows what is happening during startup.
|
---|
31 | *
|
---|
32 | */
|
---|
33 | public class SplashScreen extends JFrame {
|
---|
34 |
|
---|
35 | private SplashScreenProgressRenderer progressRenderer;
|
---|
36 | private SwingRenderingProgressMonitor progressMonitor;
|
---|
37 |
|
---|
38 | public SplashScreen() {
|
---|
39 | super();
|
---|
40 | setUndecorated(true);
|
---|
41 |
|
---|
42 | // Add a nice border to the main splash screen
|
---|
43 | JPanel contentPane = (JPanel)this.getContentPane();
|
---|
44 | Border margin = new EtchedBorder(1, Color.white, Color.gray);
|
---|
45 | contentPane.setBorder(margin);
|
---|
46 |
|
---|
47 | // Add a margin from the border to the content
|
---|
48 | JPanel innerContentPane = new JPanel();
|
---|
49 | innerContentPane.setBorder(new EmptyBorder(10, 10, 2, 10));
|
---|
50 | contentPane.add(innerContentPane);
|
---|
51 | innerContentPane.setLayout(new GridBagLayout());
|
---|
52 |
|
---|
53 | // Add the logo
|
---|
54 | JLabel logo = new JLabel(ImageProvider.get("logo.png"));
|
---|
55 | GridBagConstraints gbc = new GridBagConstraints();
|
---|
56 | gbc.gridheight = 2;
|
---|
57 | innerContentPane.add(logo, gbc);
|
---|
58 |
|
---|
59 | // Add the name of this application
|
---|
60 | JLabel caption = new JLabel("JOSM - " + tr("Java OpenStreetMap Editor"));
|
---|
61 | caption.setFont(new Font("Helvetica", Font.BOLD, 20));
|
---|
62 | gbc.gridheight = 1;
|
---|
63 | gbc.gridx = 1;
|
---|
64 | gbc.insets = new Insets(30, 0, 0, 0);
|
---|
65 | innerContentPane.add(caption, gbc);
|
---|
66 |
|
---|
67 | // Add the version number
|
---|
68 | JLabel version = new JLabel(tr("Version {0}", Version.getInstance().getVersionString()));
|
---|
69 | gbc.gridy = 1;
|
---|
70 | gbc.insets = new Insets(0, 0, 0, 0);
|
---|
71 | innerContentPane.add(version, gbc);
|
---|
72 |
|
---|
73 | // Add a separator to the status text
|
---|
74 | JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
|
---|
75 | gbc.gridx = 0;
|
---|
76 | gbc.gridy = 2;
|
---|
77 | gbc.gridwidth = 2;
|
---|
78 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
---|
79 | gbc.insets = new Insets(15, 0, 5, 0);
|
---|
80 | innerContentPane.add(separator, gbc);
|
---|
81 |
|
---|
82 | // Add a status message
|
---|
83 | progressRenderer = new SplashScreenProgressRenderer();
|
---|
84 | gbc.gridy = 3;
|
---|
85 | gbc.insets = new Insets(5, 5, 10, 5);
|
---|
86 | innerContentPane.add(progressRenderer, gbc);
|
---|
87 | progressMonitor = new SwingRenderingProgressMonitor(progressRenderer);
|
---|
88 |
|
---|
89 | pack();
|
---|
90 |
|
---|
91 | // Center the splash screen
|
---|
92 | setLocationRelativeTo(null);
|
---|
93 |
|
---|
94 | // Add ability to hide splash screen by clicking it
|
---|
95 | addMouseListener(new MouseAdapter() {
|
---|
96 | @Override
|
---|
97 | public void mousePressed(MouseEvent event) {
|
---|
98 | setVisible(false);
|
---|
99 | }
|
---|
100 | });
|
---|
101 | }
|
---|
102 |
|
---|
103 | public ProgressMonitor getProgressMonitor() {
|
---|
104 | return progressMonitor;
|
---|
105 | }
|
---|
106 |
|
---|
107 | static private class SplashScreenProgressRenderer extends JPanel implements ProgressRenderer {
|
---|
108 | private JLabel lblTaskTitle;
|
---|
109 | private JLabel lblCustomText;
|
---|
110 | private JProgressBar progressBar;
|
---|
111 |
|
---|
112 | protected void build() {
|
---|
113 | setLayout(new GridBagLayout());
|
---|
114 | GridBagConstraints gc = new GridBagConstraints();
|
---|
115 | gc.gridx = 0;
|
---|
116 | gc.gridy = 0;
|
---|
117 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
118 | gc.weightx = 1.0;
|
---|
119 | gc.weighty = 0.0;
|
---|
120 | gc.insets = new Insets(5,0,0,5);
|
---|
121 | add(lblTaskTitle = new JLabel(""), gc);
|
---|
122 |
|
---|
123 | gc.gridx = 0;
|
---|
124 | gc.gridy = 1;
|
---|
125 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
126 | gc.weightx = 1.0;
|
---|
127 | gc.weighty = 0.0;
|
---|
128 | gc.insets = new Insets(5,0,0,5);
|
---|
129 | add(lblCustomText = new JLabel(""), gc);
|
---|
130 |
|
---|
131 | gc.gridx = 0;
|
---|
132 | gc.gridy = 2;
|
---|
133 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
134 | gc.weightx = 1.0;
|
---|
135 | gc.weighty = 0.0;
|
---|
136 | gc.insets = new Insets(5,0,0,5);
|
---|
137 | add(progressBar = new JProgressBar(JProgressBar.HORIZONTAL), gc);
|
---|
138 | }
|
---|
139 |
|
---|
140 | public SplashScreenProgressRenderer() {
|
---|
141 | build();
|
---|
142 | }
|
---|
143 |
|
---|
144 | public void setCustomText(String message) {
|
---|
145 | lblCustomText.setText(message);
|
---|
146 | repaint();
|
---|
147 | }
|
---|
148 |
|
---|
149 | public void setIndeterminate(boolean indeterminate) {
|
---|
150 | progressBar.setIndeterminate(indeterminate);
|
---|
151 | repaint();
|
---|
152 | }
|
---|
153 |
|
---|
154 | public void setMaximum(int maximum) {
|
---|
155 | progressBar.setMaximum(maximum);
|
---|
156 | repaint();
|
---|
157 | }
|
---|
158 |
|
---|
159 | public void setTaskTitle(String taskTitle) {
|
---|
160 | lblTaskTitle.setText(taskTitle);
|
---|
161 | repaint();
|
---|
162 | }
|
---|
163 |
|
---|
164 | public void setValue(int value) {
|
---|
165 | progressBar.setValue(value);
|
---|
166 | repaint();
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|