/
UploadProgress.java
209 lines (168 loc) · 5.96 KB
/
UploadProgress.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.gallery.GalleryRemote;
import com.gallery.GalleryRemote.util.DialogUtil;
import com.gallery.GalleryRemote.util.OsShutdown;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class UploadProgress extends JDialog implements StatusUpdate, ActionListener {
public static final String MODULE= "UploadProgress";
GridBagLayout gridBagLayout1 = new GridBagLayout();
JPanel jPanel1 = new JPanel();
JLabel jComputer1 = new JLabel();
JLabel jUploading = new JLabel();
JLabel jComputer2 = new JLabel();
JLabel jLabelGlobal = new JLabel();
JProgressBar jProgressGlobal = new JProgressBar();
JLabel jLabelDetail = new JLabel();
JProgressBar jProgressDetail = new JProgressBar();
JPanel jPanel2 = new JPanel();
JLabel jLabel[] = new JLabel[NUM_LEVELS];
JProgressBar jProgress[] = new JProgressBar[NUM_LEVELS];
MainFrame mf;
ActionListener cancelListener = null;
JButton jCancel = new JButton();
JCheckBox jShutdown = new JCheckBox();
public UploadProgress(MainFrame mf) {
super(mf);
this.mf = mf;
jbInit();
jLabel[LEVEL_UPLOAD_ONE] = jLabelDetail;
jLabel[LEVEL_UPLOAD_PROGRESS] = jLabelGlobal;
jProgress[LEVEL_UPLOAD_ONE] = jProgressDetail;
jProgress[LEVEL_UPLOAD_PROGRESS] = jProgressGlobal;
pack();
DialogUtil.center(this, mf);
setVisible(true);
}
private void jbInit() {
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(gridBagLayout1);
jComputer1.setIcon(MainFrame.iComputer);
jComputer2.setIcon(MainFrame.iComputer);
jUploading.setIcon(MainFrame.iUploading);
jLabelGlobal.setText("Uploading image n of m");
jLabelDetail.setText("Uploading img.gif");
jCancel.setText("Cancel");
jCancel.addActionListener(this);
jShutdown.setToolTipText("Shut down the computer when the transfer completes");
jShutdown.setText("Shutdown when done");
jPanel1.add(jComputer1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 0), 0, 0));
jPanel1.add(jUploading, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0));
jPanel1.add(jComputer2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 0, 10), 0, 0));
jPanel1.add(jLabelGlobal, new GridBagConstraints(0, 1, 3, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 0), 0, 0));
jPanel1.add(jProgressGlobal, new GridBagConstraints(0, 2, 3, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 15, 0, 15), 0, 0));
jPanel1.add(jLabelDetail, new GridBagConstraints(0, 3, 3, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 0, 0), 0, 0));
jPanel1.add(jProgressDetail, new GridBagConstraints(0, 4, 3, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 15, 0, 15), 0, 0));
jPanel1.add(jPanel2, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
if (OsShutdown.canShutdown()) {
jPanel2.add(jShutdown, null);
}
jPanel2.add(jCancel, null);
}
/* level-bound methods */
public void startProgress(int level, int minValue, int maxValue, String message, boolean undetermined) {
if (checkLevel(level)) {
jProgress[level].setMinimum(minValue);
jProgress[level].setMaximum(maxValue);
try {
jProgress[level].setIndeterminate(undetermined);
} catch (Throwable t) {}
jLabel[level].setText(message);
}
}
public void updateProgressValue(int level, int value) {
if (checkLevel(level)) {
jProgress[level].setValue(value);
}
}
public void updateProgressValue(int level, int value, int maxValue) {
if (checkLevel(level)) {
jProgress[level].setValue(value);
jProgress[level].setMaximum(maxValue);
}
}
public void updateProgressStatus(int level, String message) {
if (checkLevel(level)) {
jLabel[level].setText(message);
}
}
public void setUndetermined(int level, boolean undetermined) {
try {
jProgress[level].setIndeterminate(undetermined);
} catch (Throwable t) {}
}
public void stopProgress(int level, String message) {
if (checkLevel(level)) {
jProgress[level].setMaximum(jProgress[level].getMinimum());
jLabel[level].setText(message);
try {
jProgress[level].setIndeterminate(false);
} catch (Throwable t) {}
if (level == LEVEL_UPLOAD_PROGRESS) {
setVisible(false);
//dispose();
}
}
}
/* level-independant methods */
public void setInProgress(boolean inProgress) {
mf.setInProgress(inProgress);
}
public void error(String message) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
}
public void setStatus(String message) {
updateProgressStatus(LEVEL_GENERIC, message);
}
public int getProgressValue(int level) {
if (checkLevel(level)) {
return jProgress[level].getValue();
}
return 0;
}
public int getProgressMinValue(int level) {
if (checkLevel(level)) {
return jProgress[level].getMinimum();
}
return 0;
}
public int getProgressMaxValue(int level) {
if (checkLevel(level)) {
return jProgress[level].getMaximum();
}
return 0;
}
boolean checkLevel(int level) {
if (level == LEVEL_UPLOAD_ONE || level == LEVEL_UPLOAD_PROGRESS) {
return true;
} else {
Log.log(Log.ERROR, MODULE, "Bad level");
Log.logStack(Log.ERROR, MODULE);
return false;
}
}
public void actionPerformed(ActionEvent e) {
final ActionEvent fe = e;
new Thread() {
public void run() {
cancelListener.actionPerformed(fe);
}
}.start();
}
public void setCancelListener(ActionListener cancelListener) {
this.cancelListener = cancelListener;
}
public boolean isShutdown() {
return jShutdown.isSelected();
}
}