1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.dialogs;
17
18 import java.awt.BorderLayout;
19 import java.awt.Dimension;
20 import java.awt.Frame;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23
24 import javax.swing.JButton;
25 import javax.swing.JDialog;
26 import javax.swing.JLabel;
27 import javax.swing.JPanel;
28 import javax.swing.JProgressBar;
29 import javax.swing.SwingConstants;
30
31 import p3j.gui.dialogs.execstatus.ExecutionProgressDialog;
32 import p3j.misc.gui.GUI;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class SimpleProgressDialog extends JDialog {
49
50
51 private static final long serialVersionUID = 6832108832051608722L;
52
53
54 private static final int DIALOG_WIDTH = 400;
55
56
57 private static final int DIALOG_HEIGHT = 130;
58
59 final int waypoints;
60
61 final JProgressBar progressBar;
62
63
64 private JButton okButton = new JButton("OK");
65 {
66 okButton.addActionListener(new ActionListener() {
67 @Override
68 public void actionPerformed(ActionEvent e) {
69 setVisible(false);
70 }
71 });
72 }
73
74 public SimpleProgressDialog(Frame owner, String processName,
75 String detailedDescription, int numOfWaypoints) {
76 super(owner, processName, false);
77 setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
78 GUI.centerOnScreen(this);
79
80 waypoints = numOfWaypoints;
81 progressBar = new JProgressBar(0, numOfWaypoints);
82 okButton.setEnabled(false);
83
84 JPanel buttonPanel = new JPanel();
85 buttonPanel.add(okButton);
86
87 JPanel content = new JPanel(new BorderLayout(GUI.STD_LAYOUT_GAP,
88 GUI.STD_LAYOUT_GAP));
89 JLabel executionSummary = new JLabel(detailedDescription,
90 SwingConstants.CENTER);
91 content.add(executionSummary, BorderLayout.NORTH);
92 content.add(progressBar, BorderLayout.CENTER);
93 content.add(buttonPanel, BorderLayout.SOUTH);
94
95 progressBar.setStringPainted(true);
96 progressBar.setPreferredSize(new Dimension(0,
97 ExecutionProgressDialog.PREFERRED_HEIGHT_PROGBAR));
98 getContentPane().add(content);
99 }
100
101 public void taskFinished() {
102 updateProgress(waypoints, "Done");
103 okButton.setEnabled(true);
104 }
105
106 public void updateProgress(int waypoint, String status) {
107 progressBar.setValue(waypoint);
108 progressBar.setString(status);
109 }
110
111 public void incrementProgress(String status) {
112 updateProgress(progressBar.getValue() + 1, status);
113 }
114
115 }