source: josm/trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java@ 2284

Last change on this file since 2284 was 2050, checked in by Gubaer, 15 years ago

fixed #3390: Opening file -> false map position

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.awt.Dialog;
5import java.awt.Frame;
6import java.awt.GridBagLayout;
7import java.awt.event.ComponentEvent;
8import java.awt.event.ComponentListener;
9
10import javax.swing.BorderFactory;
11import javax.swing.BoundedRangeModel;
12import javax.swing.JButton;
13import javax.swing.JDialog;
14import javax.swing.JLabel;
15import javax.swing.JPanel;
16import javax.swing.JProgressBar;
17import javax.swing.UIManager;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.tools.GBC;
21import org.openstreetmap.josm.tools.I18n;
22
23public class PleaseWaitDialog extends JDialog {
24
25 private final JProgressBar progressBar = new JProgressBar();
26
27 public final JLabel currentAction = new JLabel("");
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 private void initDialog() {
33 setLayout(new GridBagLayout());
34 JPanel pane = new JPanel(new GridBagLayout());
35 pane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
36 pane.add(currentAction, GBC.eol().fill(GBC.HORIZONTAL));
37 pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL));
38 pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL));
39 pane.add(cancel, GBC.eol().anchor(GBC.CENTER));
40 setContentPane(pane);
41 //setSize(Main.pref.getInteger("progressdialog.size",600),100);
42 setCustomText("");
43 setLocationRelativeTo(Main.parent);
44 addComponentListener(new ComponentListener() {
45 public void componentHidden(ComponentEvent e) {}
46 public void componentMoved(ComponentEvent e) {}
47 public void componentShown(ComponentEvent e) {}
48 public void componentResized(ComponentEvent ev) {
49 int w = getWidth();
50 if(w > 200) {
51 Main.pref.putInteger("progressdialog.size",w);
52 }
53 }
54 });
55 }
56
57 public PleaseWaitDialog(Frame parent) {
58 super(parent, true);
59 initDialog();
60 }
61
62 public PleaseWaitDialog(Dialog parent) {
63 super(parent, true);
64 initDialog();
65 }
66
67 public void setIndeterminate(boolean newValue) {
68 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
69 progressBar.setIndeterminate(newValue);
70 }
71
72 /**
73 * Sets a custom text line below currentAction. Can be used to display additional information
74 * @param text
75 */
76 public void setCustomText(String text) {
77 if(text.length() == 0) {
78 customText.setVisible(false);
79 setSize(Main.pref.getInteger("progressdialog.size", 600), 100);
80 return;
81 }
82
83 customText.setVisible(true);
84 customText.setText(text);
85 setSize(Main.pref.getInteger("progressdialog.size", 600), 120);
86 }
87}
Note: See TracBrowser for help on using the repository browser.