source: josm/trunk/src/org/openstreetmap/josm/gui/SplashScreen.java@ 1048

Last change on this file since 1048 was 1048, checked in by cbrill, 17 years ago

fix bug #1655 (disable splash screen)

Patch by mcdmx@…

File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7import java.awt.Dimension;
8import java.awt.Font;
9import java.awt.GridBagConstraints;
10import java.awt.GridBagLayout;
11import java.awt.Insets;
12import java.awt.Toolkit;
13import java.awt.event.MouseAdapter;
14import java.awt.event.MouseEvent;
15
16import javax.swing.JLabel;
17import javax.swing.JPanel;
18import javax.swing.JSeparator;
19import javax.swing.JWindow;
20import javax.swing.SwingUtilities;
21import javax.swing.border.Border;
22import javax.swing.border.EmptyBorder;
23import javax.swing.border.EtchedBorder;
24
25import org.openstreetmap.josm.actions.AboutAction;
26import org.openstreetmap.josm.tools.ImageProvider;
27
28/**
29 * Show a splash screen so the user knows what is happening during startup.
30 *
31 * @author cbrill
32 */
33public class SplashScreen extends JWindow {
34
35 private JLabel status;
36 private boolean visible;
37
38 private Runnable closerRunner;
39
40 public SplashScreen(boolean visible) {
41 super();
42 this.visible=visible;
43
44 if (!visible)
45 return;
46
47 // Add a nice border to the main splash screen
48 JPanel contentPane = (JPanel)this.getContentPane();
49 Border margin = new EtchedBorder(1, Color.white, Color.gray);
50 contentPane.setBorder(margin);
51
52 // Add a margin from the border to the content
53 JPanel innerContentPane = new JPanel();
54 innerContentPane.setBorder(new EmptyBorder(10, 10, 2, 10));
55 contentPane.add(innerContentPane);
56 innerContentPane.setLayout(new GridBagLayout());
57
58 // Add the logo
59 JLabel logo = new JLabel(ImageProvider.get("logo.png"));
60 GridBagConstraints gbc = new GridBagConstraints();
61 gbc.gridheight = 2;
62 innerContentPane.add(logo, gbc);
63
64 // Add the name of this application
65 JLabel caption = new JLabel(tr("JOSM - Java OpenStreetMap Editor"));
66 caption.setFont(new Font("Helvetica", Font.BOLD, 20));
67 gbc.gridheight = 1;
68 gbc.gridx = 1;
69 gbc.insets = new Insets(30, 0, 0, 0);
70 innerContentPane.add(caption, gbc);
71
72 // Add the version number
73 JLabel version = new JLabel(tr("Version {0}", AboutAction.version));
74 gbc.gridy = 1;
75 gbc.insets = new Insets(0, 0, 0, 0);
76 innerContentPane.add(version, gbc);
77
78 // Add a separator to the status text
79 JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
80 gbc.gridx = 0;
81 gbc.gridy = 2;
82 gbc.gridwidth = 2;
83 gbc.fill = GridBagConstraints.HORIZONTAL;
84 gbc.insets = new Insets(15, 0, 5, 0);
85 innerContentPane.add(separator, gbc);
86
87 // Add a status message
88 status = new JLabel();
89 gbc.gridy = 3;
90 gbc.insets = new Insets(0, 0, 0, 0);
91 innerContentPane.add(status, gbc);
92 setStatus(tr("Initializing"));
93
94 pack();
95
96 // Center the splash screen
97 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
98 Dimension labelSize = contentPane.getPreferredSize();
99 setLocation(screenSize.width / 2 - (labelSize.width / 2),
100 screenSize.height / 2 - (labelSize.height / 2));
101
102 // Method to close the splash screen when being clicked or when closeSplash is called
103 closerRunner = new Runnable() {
104 public void run() {
105 setVisible(false);
106 dispose();
107 }
108 };
109
110 // Add ability to hide splash screen by clicking it
111 addMouseListener(new MouseAdapter() {
112 public void mousePressed(MouseEvent event) {
113 try {
114 closerRunner.run();
115 } catch (Exception e) {
116 e.printStackTrace();
117 // can catch InvocationTargetException
118 // can catch InterruptedException
119 }
120 }
121 });
122 setVisible(true);
123 }
124
125 /**
126 * This method sets the status message. It should be called prior to
127 * actually doing the action.
128 *
129 * @param message
130 * the message to be displayed
131 */
132 public void setStatus(String message) {
133 if (!visible)
134 return;
135 status.setText(message + " ...");
136 }
137
138 /**
139 * Closes the splashscreen. Call once you are done starting.
140 */
141 public void closeSplash() {
142 if (!visible)
143 return;
144 try {
145 SwingUtilities.invokeAndWait(closerRunner);
146 } catch (Exception e) {
147 e.printStackTrace();
148 // can catch InvocationTargetException
149 // can catch InterruptedException
150 }
151 }
152
153}
Note: See TracBrowser for help on using the repository browser.