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

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

added diagnostic messages for #3109 - window order generally messed up?

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dialog;
7import java.awt.Frame;
8import java.awt.GridBagLayout;
9import java.awt.event.ComponentEvent;
10import java.awt.event.ComponentListener;
11
12import javax.swing.BorderFactory;
13import javax.swing.BoundedRangeModel;
14import javax.swing.JButton;
15import javax.swing.JDialog;
16import javax.swing.JLabel;
17import javax.swing.JPanel;
18import javax.swing.JProgressBar;
19import javax.swing.UIManager;
20
21import org.openstreetmap.josm.Main;
22import org.openstreetmap.josm.tools.GBC;
23import org.openstreetmap.josm.tools.I18n;
24
25public class PleaseWaitDialog extends JDialog {
26
27 private final JProgressBar progressBar = new JProgressBar();
28
29 public final JLabel currentAction = new JLabel("");
30 private final JLabel customText = new JLabel("");
31 public final BoundedRangeModel progress = progressBar.getModel();
32 public final JButton cancel = new JButton(I18n.tr("Cancel"));
33
34 private void initDialog() {
35 setLayout(new GridBagLayout());
36 JPanel pane = new JPanel(new GridBagLayout());
37 pane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
38 pane.add(currentAction, GBC.eol().fill(GBC.HORIZONTAL));
39 pane.add(customText, GBC.eol().fill(GBC.HORIZONTAL));
40 pane.add(progressBar, GBC.eop().fill(GBC.HORIZONTAL));
41 pane.add(cancel, GBC.eol().anchor(GBC.CENTER));
42 setContentPane(pane);
43 //setSize(Main.pref.getInteger("progressdialog.size",600),100);
44 setCustomText("");
45 setLocationRelativeTo(Main.parent);
46 addComponentListener(new ComponentListener() {
47 public void componentHidden(ComponentEvent e) {}
48 public void componentMoved(ComponentEvent e) {}
49 public void componentShown(ComponentEvent e) {}
50 public void componentResized(ComponentEvent ev) {
51 int w = getWidth();
52 if(w > 200) {
53 Main.pref.putInteger("progressdialog.size",w);
54 }
55 }
56 });
57 // make sure this dialog is always on top of the main JOSM window
58 // and all the other windows (relation editors, detached dialogs, etc.)
59 //
60 try {
61 setAlwaysOnTop(true);
62 } catch(SecurityException e) {
63 System.out.println(tr("Warning: failed to put ''please wait dialog'' always on top. Exception was: {0}", e.toString()));
64 }
65 }
66
67 public PleaseWaitDialog(Frame parent) {
68 super(parent, true);
69 initDialog();
70 }
71
72 public PleaseWaitDialog(Dialog parent) {
73 super(parent, true);
74 initDialog();
75 }
76
77 public void setIndeterminate(boolean newValue) {
78 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
79 progressBar.setIndeterminate(newValue);
80 }
81
82 /**
83 * Sets a custom text line below currentAction. Can be used to display additional information
84 * @param text
85 */
86 public void setCustomText(String text) {
87 if(text.length() == 0) {
88 customText.setVisible(false);
89 setSize(Main.pref.getInteger("progressdialog.size", 600), 100);
90 return;
91 }
92
93 customText.setVisible(true);
94 customText.setText(text);
95 setSize(Main.pref.getInteger("progressdialog.size", 600), 120);
96 }
97
98 @Override
99 public void setVisible(boolean visible) {
100 super.setVisible(visible);
101 if (visible) {
102 // make sure this dialog is always on top of the main JOSM window
103 // and all the other windows (relation editors, detached dialogs, etc.)
104 //
105 toFront();
106 }
107 }
108}
Note: See TracBrowser for help on using the repository browser.