1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.awt.event.ComponentEvent;
|
---|
7 | import java.awt.event.ComponentListener;
|
---|
8 |
|
---|
9 | import javax.swing.BorderFactory;
|
---|
10 | import javax.swing.BoundedRangeModel;
|
---|
11 | import javax.swing.JButton;
|
---|
12 | import javax.swing.JDialog;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JOptionPane;
|
---|
15 | import javax.swing.JPanel;
|
---|
16 | import javax.swing.JProgressBar;
|
---|
17 | import javax.swing.UIManager;
|
---|
18 |
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.tools.GBC;
|
---|
21 | import org.openstreetmap.josm.tools.I18n;
|
---|
22 |
|
---|
23 | public class PleaseWaitDialog extends JDialog {
|
---|
24 |
|
---|
25 | private final JProgressBar progressBar = new JProgressBar();
|
---|
26 |
|
---|
27 | public final JLabel currentAction = new JLabel(I18n.tr("Contacting the OSM server..."));
|
---|
28 | private final JLabel customText = new JLabel("");
|
---|
29 | public final BoundedRangeModel progress = progressBar.getModel();
|
---|
30 | public final JButton cancel = new JButton(I18n.tr("Cancel"));
|
---|
31 |
|
---|
32 | public PleaseWaitDialog(Component parent) {
|
---|
33 | super(JOptionPane.getFrameForComponent(parent), true);
|
---|
34 | setLayout(new GridBagLayout());
|
---|
35 | JPanel pane = new JPanel(new GridBagLayout());
|
---|
36 | pane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
---|
37 | pane.add(currentAction, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
38 | pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
39 | pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
40 | pane.add(cancel, GBC.eol().anchor(GBC.CENTER));
|
---|
41 | setContentPane(pane);
|
---|
42 | //setSize(Main.pref.getInteger("progressdialog.size",600),100);
|
---|
43 | setCustomText("");
|
---|
44 | setLocationRelativeTo(Main.parent);
|
---|
45 | addComponentListener(new ComponentListener() {
|
---|
46 | public void componentHidden(ComponentEvent e) {}
|
---|
47 | public void componentMoved(ComponentEvent e) {}
|
---|
48 | public void componentShown(ComponentEvent e) {}
|
---|
49 | public void componentResized(ComponentEvent ev) {
|
---|
50 | int w = getWidth();
|
---|
51 | if(w > 200)
|
---|
52 | Main.pref.putInteger("progressdialog.size",w);
|
---|
53 | }
|
---|
54 | });
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void setIndeterminate(boolean newValue) {
|
---|
58 | UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
|
---|
59 | progressBar.setIndeterminate(newValue);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Sets a custom text line below currentAction. Can be used to display additional information
|
---|
64 | * @param text
|
---|
65 | */
|
---|
66 | public void setCustomText(String text) {
|
---|
67 | if(text.length() == 0) {
|
---|
68 | customText.setVisible(false);
|
---|
69 | setSize(Main.pref.getInteger("progressdialog.size", 600), 100);
|
---|
70 | return;
|
---|
71 | }
|
---|
72 |
|
---|
73 | customText.setVisible(true);
|
---|
74 | customText.setText(text);
|
---|
75 | setSize(Main.pref.getInteger("progressdialog.size", 600), 120);
|
---|
76 | }
|
---|
77 | }
|
---|