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

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

improved deleting relations

  • Property svn:eol-style set to native
File size: 3.5 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 // make sure this dialog is always on top of the main JOSM window
56 // and all the other windows (relation editors, detached dialogs, etc.)
57 //
58 setAlwaysOnTop(true);
59 }
60
61 public PleaseWaitDialog(Frame parent) {
62 super(parent, true);
63 initDialog();
64 }
65
66 public PleaseWaitDialog(Dialog parent) {
67 super(parent, true);
68 initDialog();
69 }
70
71 public void setIndeterminate(boolean newValue) {
72 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
73 progressBar.setIndeterminate(newValue);
74 }
75
76 /**
77 * Sets a custom text line below currentAction. Can be used to display additional information
78 * @param text
79 */
80 public void setCustomText(String text) {
81 if(text.length() == 0) {
82 customText.setVisible(false);
83 setSize(Main.pref.getInteger("progressdialog.size", 600), 100);
84 return;
85 }
86
87 customText.setVisible(true);
88 customText.setText(text);
89 setSize(Main.pref.getInteger("progressdialog.size", 600), 120);
90 }
91
92 @Override
93 public void setVisible(boolean visible) {
94 super.setVisible(visible);
95 if (visible) {
96 // make sure this dialog is always on top of the main JOSM window
97 // and all the other windows (relation editors, detached dialogs, etc.)
98 //
99 toFront();
100 }
101 }
102}
Note: See TracBrowser for help on using the repository browser.