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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
package NET.worlds.network;
import NET.worlds.console.Console;
import NET.worlds.console.MultiLineLabel;
import NET.worlds.console.PolledDialog;
import NET.worlds.core.IniFile;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Component;
import java.awt.Event;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Vector;
public class UpgradeDialog extends PolledDialog {
private static final long serialVersionUID = -6015193016188781866L;
private Button yesButton = new Button(Console.message("Yes-now"));
private Button noButton = new Button(Console.message("No-later"));
private Button moreInfo = new Button(Console.message("Show-me-more"));
private Checkbox startupCheck;
private boolean forceUpgrades = IniFile.gamma().getIniInt("forceUpgrades", 1) == 1;
private static String instructions = Console.message("Please-uncheck") + " \n" + " \n";
private static String forcedInstructions = Console.message("you-can-continue") + " \n" + " \n";
private static String title = Console.message("Upgrade");
private Vector<Checkbox> checkboxes;
private String info;
private Vector<String> list;
private Vector<Integer> bytes;
private boolean first;
private boolean chooseOne;
private String name;
private Component getsFocus;
private MultiLineLabel msgLabel;
public UpgradeDialog(Vector<String> list, Vector<Integer> bytes, boolean first, String name, String info, boolean chooseOne) {
super(Console.getFrame(), null, title, false);
this.setAlignment(1);
this.list = list;
this.info = info;
this.name = name;
this.first = first;
this.bytes = bytes;
this.chooseOne = chooseOne;
this.readySetGo();
}
@Override
protected void build() {
this.startupCheck = new Checkbox(Console.message("Check-for-up-each"), IniFile.gamma().getIniInt("CheckUpgrades", 1) != 0);
int count = this.list.size();
this.checkboxes = new Vector<Checkbox>();
Panel p = new Panel(new GridLayout(count, 1));
Checkbox chk = null;
for (int i = 0; i < count; i++) {
int b = this.bytes.elementAt(i);
String kb = NumberFormat.getInstance().format((long)(b / 1000));
Object[] arguments = new Object[]{new String(this.list.elementAt(i).toString()), new String(kb)};
String msg = MessageFormat.format(Console.message("Kbytes"), arguments);
chk = new Checkbox(msg, true);
if (!this.forceUpgrades) {
p.add(chk);
} else {
p.add(new MultiLineLabel(msg));
}
this.checkboxes.addElement(chk);
}
GridBagLayout gbag = new GridBagLayout();
this.setLayout(gbag);
GridBagConstraints c = new GridBagConstraints();
c.anchor = 10;
c.fill = 0;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 0;
c.gridheight = 1;
c.insets = new Insets(0, 15, 0, 15);
Object[] arguments = new Object[]{new String(this.name)};
String msg = this.first
? MessageFormat.format(Console.message("dont-have"), arguments)
: MessageFormat.format(Console.message("update-available"), arguments);
this.add(gbag, new MultiLineLabel(msg + "\n ", 5, 5), c);
if (count > 3) {
ScrollPane sp = new ScrollPane();
GridBagConstraints c2 = new GridBagConstraints();
c2.fill = 1;
c2.gridwidth = 0;
sp.setSize(280, 100);
sp.validate();
this.add(gbag, sp, c2);
sp.add(p);
} else {
this.add(gbag, p, c);
}
if (!this.forceUpgrades) {
this.add(gbag, this.startupCheck, c);
}
this.msgLabel = new MultiLineLabel(this.calcMsg(), 5, 5);
this.add(gbag, this.msgLabel, c);
c.gridwidth = 2;
this.add(gbag, this.getsFocus = this.yesButton, c);
if (!this.forceUpgrades || this.first) {
c.gridwidth = 0;
this.add(gbag, this.noButton, c);
c.insets.top = 5;
c.insets.bottom = 15;
this.add(gbag, this.moreInfo, c);
}
}
private String calcMsg() {
int totalBytes = 0;
if (this.bytes != null) {
for (int i = 0; i < this.bytes.size(); i++) {
if (this.checkboxes.elementAt(i).getState()) {
totalBytes += this.bytes.elementAt(i);
}
}
}
String msg = "";
String ins = this.forceUpgrades ? forcedInstructions : instructions;
if (totalBytes == 0) {
msg = Console.message("no-entries");
return "\n" + msg + " \n \n \n \n" + ins;
} else {
int modemMins = 10 * totalBytes / 288000 + 1;
String modemMinutes = modemMins / 10 + "." + modemMins % 10 + " " + (modemMins == 10 ? Console.message("minute") : Console.message("minutes"));
int cableMins = 10 * totalBytes / 1000000 + 1;
String cableMinutes = cableMins / 10 + "." + cableMins % 10 + " " + (cableMins == 10 ? Console.message("minute") : Console.message("minutes"));
NumberFormat nF = NumberFormat.getNumberInstance(Locale.getDefault());
String kb = nF.format((long)(totalBytes / 1000));
Object[] arguments = new Object[]{new String(kb), new String(cableMinutes), new String(modemMinutes)};
msg = MessageFormat.format(Console.message("entries-total"), arguments);
return msg + ins;
}
}
@Override
public void show() {
super.show();
this.getsFocus.requestFocus();
}
public synchronized boolean confirmUpgrade() {
while (this.isActive()) {
try {
this.wait();
} catch (InterruptedException var2) {
}
}
return this.getConfirmed();
}
public int confirmUpgradeFromList() {
if (!this.confirmUpgrade()) {
return 0;
} else {
int i = 0;
while (i < this.bytes.size() && this.checkboxes.elementAt(i).getState()) {
i++;
}
return i;
}
}
public Vector<String> rejectedList() {
if (!this.confirmUpgrade()) {
return this.list;
} else {
Vector<String> v = new Vector<String>();
for (int i = 0; i < this.bytes.size(); i++) {
if (!this.checkboxes.elementAt(i).getState()) {
v.addElement(this.list.elementAt(i));
}
}
return v;
}
}
@Override
protected synchronized boolean done(boolean confirmed) {
boolean retCode = super.done(confirmed);
this.notify();
return retCode;
}
@Override
public boolean action(Event event, Object what) {
if (event.target == this.yesButton) {
return this.done(true);
} else if (event.target == this.noButton) {
return this.done(false);
} else {
if (event.target == this.moreInfo) {
NetUpdate.showInfo(this.info);
} else if (event.target == this.startupCheck) {
IniFile.gamma().setIniInt("CheckUpgrades", this.startupCheck.getState() ? 1 : 0);
} else if (event.target instanceof Checkbox) {
if (this.chooseOne) {
int i = this.checkboxes.indexOf(event.target);
if (((Checkbox)event.target).getState()) {
while (--i >= 0) {
this.checkboxes.elementAt(i).setState(true);
}
} else {
while (++i < this.checkboxes.size()) {
this.checkboxes.elementAt(i).setState(false);
}
}
}
this.msgLabel.setLabel(this.calcMsg());
return true;
}
return false;
}
}
@Override
public boolean handleEvent(Event event) {
return this.forceUpgrades && event.id == 201 ? this.done(true) : super.handleEvent(event);
}
@Override
public boolean keyDown(Event event, int key) {
return !this.forceUpgrades && key == 27 ? this.done(false) : super.keyDown(event, key);
}
}
|