-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathProgressDialog.java
More file actions
75 lines (62 loc) · 2.2 KB
/
ProgressDialog.java
File metadata and controls
75 lines (62 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package nodebox.client;
import javax.swing.*;
import java.awt.*;
public class ProgressDialog extends JDialog {
private JProgressBar progressBar;
private JLabel progressLabel;
private JLabel messageLabel;
private int tasksCompleted;
private int taskCount;
public ProgressDialog(Frame owner, String title) {
super(owner, title, false);
getRootPane().putClientProperty("Window.style", "small");
setResizable(false);
setLayout(null);
Container contentPane = getContentPane();
contentPane.setLayout(null);
tasksCompleted = 0;
this.taskCount = 0;
progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, taskCount);
progressBar.setIndeterminate(true);
progressBar.setBounds(10, 10, 300, 32);
contentPane.add(progressBar);
progressLabel = new JLabel();
progressLabel.setBounds(320, 10, 50, 32);
progressLabel.setVisible(false);
contentPane.add(progressLabel);
messageLabel = new JLabel();
messageLabel.setBounds(10, 40, 380, 32);
contentPane.add(messageLabel);
updateProgress();
setSize(400, 100);
SwingUtils.centerOnScreen(this, owner);
}
public void setTaskCount(int taskCount) {
this.taskCount = taskCount;
this.tasksCompleted = 0;
progressBar.setIndeterminate(false);
progressBar.setMaximum(taskCount);
progressLabel.setVisible(true);
}
public void reset() {
setTaskCount(this.taskCount);
}
public void updateProgress() {
updateProgress(this.tasksCompleted);
}
public void updateProgress(int tasksCompleted) {
progressBar.setValue(tasksCompleted);
double percentage = (double) (tasksCompleted) / (double) (taskCount);
int ip = (int) (percentage * 100);
progressLabel.setText(ip + " %");
repaint();
}
public void tick() {
// Increment the tasks completed, but it can never be higher than the number of tasks.
tasksCompleted = Math.min(tasksCompleted + 1, taskCount);
updateProgress();
}
public void setMessage(String message) {
messageLabel.setText(message);
}
}