01: package jimm.datavision.gui;
02:
03: import jimm.util.I18N;
04: import java.awt.Frame;
05: import java.awt.Dimension;
06: import java.awt.BorderLayout;
07: import java.awt.event.ActionListener;
08: import java.awt.event.ActionEvent;
09: import javax.swing.*;
10:
11: /**
12: * An extremely simple status display dialog.
13: *
14: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
15: */
16: public class StatusDialog extends JDialog {
17:
18: protected JLabel label;
19: protected boolean cancelled;
20:
21: /**
22: * Constructor.
23: *
24: * @param parent parent frame; may be <code>null</code>
25: * @param title title string; may be <code>null</code>
26: * @param initialString initial string to display; may be <code>null</code>
27: */
28: public StatusDialog(Frame parent, String title,
29: boolean displayCancelButton, String initialString) {
30: super (parent, title, false);
31:
32: JPanel panel = new JPanel();
33: panel.setLayout(new BorderLayout());
34: panel.add(label = new JLabel(), BorderLayout.CENTER);
35: label.setHorizontalAlignment(SwingConstants.CENTER);
36:
37: if (displayCancelButton) {
38: JPanel buttonPanel = new JPanel();
39: JButton button = new JButton(I18N.get("GUI.cancel"));
40: buttonPanel.add(button);
41: button.addActionListener(new ActionListener() {
42: public void actionPerformed(ActionEvent e) {
43: cancelled = true;
44: update(I18N.get("StatusDialog.cancelling"));
45: }
46: });
47: panel.add(buttonPanel, BorderLayout.SOUTH);
48: }
49:
50: if (initialString != null)
51: label.setText(initialString);
52:
53: panel.setPreferredSize(new Dimension(300, 100));
54: getContentPane().add(panel);
55:
56: pack();
57: setVisible(true);
58: }
59:
60: public boolean isCancelled() {
61: return cancelled;
62: }
63:
64: public void update(String message) {
65: label.setText(message);
66: }
67:
68: }
|