/* */ 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; /* 78 */ private Button yesButton = new Button(Console.message("Yes-now")); /* */ /* */ /* 81 */ private Button noButton = new Button(Console.message("No-later")); /* */ /* */ /* 84 */ private Button moreInfo = new Button(Console.message("Show-me-more")); /* */ /* */ private Checkbox startupCheck; /* */ /* 88 */ private boolean forceUpgrades = IniFile.gamma().getIniInt("forceUpgrades", /* 89 */ 1) == 1; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 109 */ private static String instructions = Console.message("Please-uncheck") + /* 110 */ " \n" + " \n"; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 119 */ private static String forcedInstructions = Console.message("you-can-continue") + " \n" + " \n"; /* */ /* */ /* 122 */ private static String title = Console.message("Upgrade"); /* */ /* */ private Vector checkboxes; /* */ /* */ private String info; /* */ /* */ private Vector list; /* */ /* */ private Vector bytes; /* */ /* */ private boolean first; /* */ /* */ private boolean chooseOne; /* */ /* */ private String name; /* */ /* */ private Component getsFocus; /* */ /* */ private MultiLineLabel msgLabel; /* */ /* */ /* */ public UpgradeDialog(Vector list, Vector bytes, boolean first, String name, String info, boolean chooseOne) /* */ { /* 145 */ super(Console.getFrame(), null, title, false); /* 146 */ setAlignment(1); /* 147 */ this.list = list; /* 148 */ this.info = info; /* 149 */ this.name = name; /* 150 */ this.first = first; /* 151 */ this.bytes = bytes; /* 152 */ this.chooseOne = chooseOne; /* */ /* */ /* 155 */ readySetGo(); /* */ } /* */ /* */ protected void build() { /* 159 */ this.startupCheck = new Checkbox(Console.message("Check-for-up-each"), /* 160 */ IniFile.gamma().getIniInt("CheckUpgrades", 1) != 0); /* */ /* */ /* 163 */ int count = this.list.size(); /* */ /* 165 */ this.checkboxes = new Vector(); /* */ /* 167 */ Panel p = new Panel(new GridLayout(count, 1)); /* */ /* 169 */ Checkbox chk = null; /* */ /* 171 */ for (int i = 0; i < count; i++) { /* 172 */ int b = ((Integer)this.bytes.elementAt(i)).intValue(); /* */ /* 174 */ String kb = NumberFormat.getInstance().format(b / 1000); /* 175 */ Object[] arguments = { new String(((String)this.list.elementAt(i)).toString()), /* 176 */ new String(kb) }; /* 177 */ String msg = MessageFormat.format(Console.message("Kbytes"), /* 178 */ arguments); /* 179 */ chk = new Checkbox(msg, true); /* */ /* 181 */ if (!this.forceUpgrades) { /* 182 */ p.add(chk); /* */ } else { /* 184 */ p.add(new MultiLineLabel(msg)); /* */ } /* 186 */ this.checkboxes.addElement(chk); /* */ } /* */ /* */ /* 190 */ GridBagLayout gbag = new GridBagLayout(); /* 191 */ setLayout(gbag); /* 192 */ GridBagConstraints c = new GridBagConstraints(); /* 193 */ c.anchor = 10; /* 194 */ c.fill = 0; /* 195 */ c.weightx = 1.0D; /* 196 */ c.weighty = 1.0D; /* 197 */ c.gridwidth = 0; /* 198 */ c.gridheight = 1; /* 199 */ c.insets = new Insets(0, 15, 0, 15); /* */ /* */ /* */ /* 203 */ Object[] arguments = { new String(this.name) }; /* 204 */ String msg = this.first ? MessageFormat.format( /* 205 */ Console.message("dont-have"), arguments) : /* 206 */ MessageFormat.format(Console.message("update-available"), arguments); /* */ /* */ /* */ /* */ /* */ /* 212 */ add(gbag, new MultiLineLabel(msg + "\n ", 5, 5), c); /* */ /* 214 */ if (count > 3) { /* 215 */ ScrollPane sp = new ScrollPane(); /* */ /* 217 */ GridBagConstraints c2 = new GridBagConstraints(); /* 218 */ c2.fill = 1; /* 219 */ c2.gridwidth = 0; /* 220 */ sp.setSize(280, 100); /* 221 */ sp.validate(); /* */ /* 223 */ add(gbag, sp, c2); /* 224 */ sp.add(p); /* */ } else { /* 226 */ add(gbag, p, c); /* */ } /* */ /* 229 */ if (!this.forceUpgrades) { /* 230 */ add(gbag, this.startupCheck, c); /* */ } /* 232 */ this.msgLabel = new MultiLineLabel(calcMsg(), 5, 5); /* 233 */ add(gbag, this.msgLabel, c); /* */ /* 235 */ c.gridwidth = 2; /* 236 */ add(gbag, this.getsFocus = this.yesButton, c); /* */ /* 238 */ if ((!this.forceUpgrades) || (this.first)) { /* 239 */ c.gridwidth = 0; /* 240 */ add(gbag, this.noButton, c); /* */ /* 242 */ c.insets.top = 5; /* 243 */ c.insets.bottom = 15; /* 244 */ add(gbag, this.moreInfo, c); /* */ } /* */ } /* */ /* */ private String calcMsg() { /* 249 */ int totalBytes = 0; /* 250 */ if (this.bytes != null) { /* 251 */ for (int i = 0; i < this.bytes.size(); i++) /* 252 */ if (((Checkbox)this.checkboxes.elementAt(i)).getState()) /* 253 */ totalBytes += ((Integer)this.bytes.elementAt(i)).intValue(); /* */ } /* 255 */ String msg = ""; /* */ /* 257 */ String ins = this.forceUpgrades ? forcedInstructions : instructions; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 266 */ if (totalBytes == 0) { /* 267 */ msg = Console.message("no-entries"); /* */ /* */ /* */ /* */ /* 272 */ return "\n" + msg + " \n \n \n \n" + ins; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* 280 */ int modemMins = 10 * totalBytes / 288000 + 1; /* */ /* 282 */ String modemMinutes = /* 283 */ modemMins / /* 284 */ 10 + /* 285 */ "." + /* 286 */ modemMins % /* 287 */ 10 + /* 288 */ " " + ( /* 289 */ modemMins == 10 ? Console.message("minute") : /* 290 */ Console.message("minutes")); /* */ /* */ /* */ /* */ /* 295 */ int cableMins = 10 * totalBytes / 1000000 + 1; /* */ /* 297 */ String cableMinutes = /* 298 */ cableMins / /* 299 */ 10 + /* 300 */ "." + /* 301 */ cableMins % /* 302 */ 10 + /* 303 */ " " + ( /* 304 */ cableMins == 10 ? Console.message("minute") : /* 305 */ Console.message("minutes")); /* */ /* */ /* */ /* */ /* */ /* 311 */ NumberFormat nF = NumberFormat.getNumberInstance(Locale.getDefault()); /* 312 */ String kb = nF.format(totalBytes / 1000); /* */ /* 314 */ Object[] arguments = { new String(kb), new String(cableMinutes), /* 315 */ new String(modemMinutes) }; /* 316 */ msg = MessageFormat.format(Console.message("entries-total"), arguments); /* */ /* 318 */ return msg + ins; /* */ } /* */ /* */ /* */ /* */ public void setVisible(boolean visible) /* */ { /* 325 */ super.setVisible(visible); /* 326 */ if (visible) { /* 327 */ this.getsFocus.requestFocus(); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public synchronized boolean confirmUpgrade() /* */ { /* 340 */ while (isActive()) { /* */ try { /* 342 */ wait(); /* */ } /* */ catch (InterruptedException localInterruptedException) {} /* */ } /* 346 */ return getConfirmed(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public int confirmUpgradeFromList() /* */ { /* 359 */ if (!confirmUpgrade()) { /* 360 */ return 0; /* */ } /* */ /* 363 */ for (int i = 0; i < this.bytes.size(); i++) /* 364 */ if (!((Checkbox)this.checkboxes.elementAt(i)).getState()) /* */ break; /* 366 */ return i; /* */ } /* */ /* */ /* */ /* */ public Vector rejectedList() /* */ { /* 373 */ if (!confirmUpgrade()) { /* 374 */ return this.list; /* */ } /* 376 */ Vector v = new Vector(); /* */ /* 378 */ for (int i = 0; i < this.bytes.size(); i++) /* 379 */ if (!((Checkbox)this.checkboxes.elementAt(i)).getState()) /* 380 */ v.addElement((String)this.list.elementAt(i)); /* 381 */ return v; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ protected synchronized boolean done(boolean confirmed) /* */ { /* 390 */ boolean retCode = super.done(confirmed); /* 391 */ notify(); /* 392 */ return retCode; /* */ } /* */ /* */ /* */ @Deprecated /* */ public boolean action(Event event, Object what) /* */ { /* 399 */ if (event.target == this.yesButton) /* 400 */ return done(true); /* 401 */ if (event.target == this.noButton) /* 402 */ return done(false); /* 403 */ if (event.target == this.moreInfo) { /* 404 */ NetUpdate.showInfo(this.info); /* 405 */ } else if (event.target == this.startupCheck) { /* 406 */ IniFile.gamma().setIniInt("CheckUpgrades", /* 407 */ this.startupCheck.getState() ? 1 : 0); /* 408 */ } else if ((event.target instanceof Checkbox)) /* */ { /* 410 */ if (this.chooseOne) /* */ { /* 412 */ int i = this.checkboxes.indexOf(event.target); /* 413 */ if (((Checkbox)event.target).getState()) { /* */ do { /* 415 */ ((Checkbox)this.checkboxes.elementAt(i)).setState(true);i--; /* 414 */ } while (i >= 0); /* */ } else { /* */ do /* */ { /* 418 */ ((Checkbox)this.checkboxes.elementAt(i)).setState(false);i++; /* 417 */ } while (i < this.checkboxes.size()); /* */ } /* */ } /* */ /* 421 */ this.msgLabel.setLabel(calcMsg()); /* 422 */ return true; /* */ } /* 424 */ return false; /* */ } /* */ /* */ @Deprecated /* */ public boolean handleEvent(Event event) /* */ { /* 430 */ if ((this.forceUpgrades) && (event.id == 201)) { /* 431 */ return done(true); /* */ } /* 433 */ return super.handleEvent(event); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ @Deprecated /* */ public boolean keyDown(Event event, int key) /* */ { /* 446 */ if ((!this.forceUpgrades) && /* 447 */ (key == 27)) { /* 448 */ return done(false); /* */ } /* 450 */ return super.keyDown(event, key); /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\UpgradeDialog.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */