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

Last change on this file since 1647 was 1647, checked in by stoecker, 15 years ago

fixed plugin handling a bit

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.awt.Component;
5import java.awt.GridBagLayout;
6import java.awt.event.ComponentEvent;
7import java.awt.event.ComponentListener;
8
9import javax.swing.BorderFactory;
10import javax.swing.BoundedRangeModel;
11import javax.swing.JButton;
12import javax.swing.JDialog;
13import javax.swing.JLabel;
14import javax.swing.JOptionPane;
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(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}
Note: See TracBrowser for help on using the repository browser.