| [976] | 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 |
|
|---|
| [2865] | 14 | import javax.swing.JFrame;
|
|---|
| [976] | 15 | import javax.swing.JLabel;
|
|---|
| 16 | import javax.swing.JPanel;
|
|---|
| [2817] | 17 | import javax.swing.JProgressBar;
|
|---|
| [976] | 18 | import javax.swing.JSeparator;
|
|---|
| 19 | import javax.swing.border.Border;
|
|---|
| 20 | import javax.swing.border.EmptyBorder;
|
|---|
| 21 | import javax.swing.border.EtchedBorder;
|
|---|
| 22 |
|
|---|
| [2358] | 23 | import org.openstreetmap.josm.data.Version;
|
|---|
| [2817] | 24 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
|---|
| 25 | import org.openstreetmap.josm.gui.progress.ProgressRenderer;
|
|---|
| 26 | import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor;
|
|---|
| [993] | 27 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| [976] | 28 |
|
|---|
| 29 | /**
|
|---|
| 30 | * Show a splash screen so the user knows what is happening during startup.
|
|---|
| [1169] | 31 | *
|
|---|
| [976] | 32 | */
|
|---|
| [2865] | 33 | public class SplashScreen extends JFrame {
|
|---|
| [976] | 34 |
|
|---|
| [2817] | 35 | private SplashScreenProgressRenderer progressRenderer;
|
|---|
| 36 | private SwingRenderingProgressMonitor progressMonitor;
|
|---|
| [976] | 37 |
|
|---|
| [2817] | 38 | public SplashScreen() {
|
|---|
| [1169] | 39 | super();
|
|---|
| [2865] | 40 | setUndecorated(true);
|
|---|
| [976] | 41 |
|
|---|
| [1169] | 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);
|
|---|
| [976] | 46 |
|
|---|
| [1169] | 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());
|
|---|
| [976] | 52 |
|
|---|
| [1169] | 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);
|
|---|
| [976] | 58 |
|
|---|
| [1169] | 59 | // Add the name of this application
|
|---|
| [1179] | 60 | JLabel caption = new JLabel("JOSM - " + tr("Java OpenStreetMap Editor"));
|
|---|
| [1169] | 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);
|
|---|
| [976] | 66 |
|
|---|
| [1169] | 67 | // Add the version number
|
|---|
| [2358] | 68 | JLabel version = new JLabel(tr("Version {0}", Version.getInstance().getVersionString()));
|
|---|
| [1169] | 69 | gbc.gridy = 1;
|
|---|
| 70 | gbc.insets = new Insets(0, 0, 0, 0);
|
|---|
| 71 | innerContentPane.add(version, gbc);
|
|---|
| [976] | 72 |
|
|---|
| [1169] | 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);
|
|---|
| [976] | 81 |
|
|---|
| [1169] | 82 | // Add a status message
|
|---|
| [2817] | 83 | progressRenderer = new SplashScreenProgressRenderer();
|
|---|
| [1169] | 84 | gbc.gridy = 3;
|
|---|
| [2817] | 85 | gbc.insets = new Insets(5, 5, 10, 5);
|
|---|
| 86 | innerContentPane.add(progressRenderer, gbc);
|
|---|
| 87 | progressMonitor = new SwingRenderingProgressMonitor(progressRenderer);
|
|---|
| [976] | 88 |
|
|---|
| [1169] | 89 | pack();
|
|---|
| [976] | 90 |
|
|---|
| [1169] | 91 | // Center the splash screen
|
|---|
| [3181] | 92 | setLocationRelativeTo(null);
|
|---|
| [976] | 93 |
|
|---|
| [1169] | 94 | // Add ability to hide splash screen by clicking it
|
|---|
| 95 | addMouseListener(new MouseAdapter() {
|
|---|
| [2817] | 96 | @Override
|
|---|
| [1169] | 97 | public void mousePressed(MouseEvent event) {
|
|---|
| [2817] | 98 | setVisible(false);
|
|---|
| [1169] | 99 | }
|
|---|
| 100 | });
|
|---|
| [2817] | 101 | }
|
|---|
| [1169] | 102 |
|
|---|
| [2817] | 103 | public ProgressMonitor getProgressMonitor() {
|
|---|
| 104 | return progressMonitor;
|
|---|
| [1169] | 105 | }
|
|---|
| [976] | 106 |
|
|---|
| [2817] | 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);
|
|---|
| [1169] | 138 | }
|
|---|
| [976] | 139 |
|
|---|
| [2817] | 140 | public SplashScreenProgressRenderer() {
|
|---|
| 141 | build();
|
|---|
| 142 | }
|
|---|
| [1169] | 143 |
|
|---|
| [2817] | 144 | public void setCustomText(String message) {
|
|---|
| 145 | lblCustomText.setText(message);
|
|---|
| 146 | repaint();
|
|---|
| [1169] | 147 | }
|
|---|
| [2817] | 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 | }
|
|---|
| [1169] | 168 | }
|
|---|
| [976] | 169 | }
|
|---|