summaryrefslogtreecommitdiff
path: root/NET/worlds/network/ProgressDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/network/ProgressDialog.java')
-rw-r--r--NET/worlds/network/ProgressDialog.java361
1 files changed, 361 insertions, 0 deletions
diff --git a/NET/worlds/network/ProgressDialog.java b/NET/worlds/network/ProgressDialog.java
new file mode 100644
index 0000000..5454c96
--- /dev/null
+++ b/NET/worlds/network/ProgressDialog.java
@@ -0,0 +1,361 @@
+/* */ package NET.worlds.network;
+/* */
+/* */ import NET.worlds.console.Console;
+/* */ import NET.worlds.console.GammaFrame;
+/* */ import NET.worlds.console.PolledDialog;
+/* */ import NET.worlds.core.Std;
+/* */ import java.awt.Event;
+/* */ import java.awt.GridBagConstraints;
+/* */ import java.awt.GridBagLayout;
+/* */ import java.awt.Insets;
+/* */ import java.awt.Label;
+/* */ import java.io.IOException;
+/* */ import java.text.MessageFormat;
+/* */ import java.text.NumberFormat;
+/* */ import java.util.Locale;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class ProgressDialog
+/* */ extends PolledDialog
+/* */ {
+/* */ private static final long serialVersionUID = 7533646170494183110L;
+/* 56 */ private static final String bytesMsg = Console.message("Bytes-remaining");
+/* */ private int bytesTotal;
+/* */ private int bytesLoaded;
+/* */ private ProgressBar progressBar;
+/* */ private Label progressBytes;
+/* */ private Label progressTime;
+/* 62 */ private int startTime = Std.getFastTime();
+/* */
+/* */ private CacheFile cf;
+/* */
+/* */ private boolean cancelled;
+/* 67 */ private int wholeFileBytes = 0;
+/* */
+/* */ public ProgressDialog(int totalSize)
+/* */ {
+/* 71 */ super(Console.getFrame(), null, Console.message("Download-Progress"), false);
+/* 72 */ this.bytesTotal = totalSize;
+/* 73 */ this.progressBar = new ProgressBar(240);
+/* */
+/* 75 */ NumberFormat nF = NumberFormat.getNumberInstance(Locale.getDefault());
+/* 76 */ String strSize = nF.format(totalSize);
+/* */
+/* 78 */ this.progressBytes = new Label(bytesMsg + strSize);
+/* 79 */ this.progressTime = new Label("");
+/* 80 */ setAlignment(1);
+/* */
+/* */
+/* */
+/* 84 */ readySetGo();
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean loadFiles(Vector<String> names, Vector<URL> urls)
+/* */ throws IOException
+/* */ {
+/* */ try
+/* */ {
+/* 95 */ int count = names.size();
+/* 96 */ for (int i = 0; i < count; i++) {
+/* 97 */ synchronized (this) {
+/* 98 */ if (this.cancelled) {
+/* 99 */ NetUpdate.warnUser("Upgrade cancelled.");
+/* 100 */ return false;
+/* */ }
+/* */
+/* 103 */ if (this.cf != null)
+/* 104 */ this.wholeFileBytes += this.cf.bytesLoaded();
+/* 105 */ this.cf = Cache.getFile((URL)urls.elementAt(i));
+/* */ }
+/* 107 */ this.cf.waitUntilLoaded();
+/* */
+/* 109 */ if (!this.cf.isActive()) {
+/* 110 */ this.cf.markTemporary();
+/* 111 */ NetUpdate.warnUser("Upgrade cancelled.");
+/* 112 */ return false; }
+/* 113 */ if (this.cf.error()) {
+/* 114 */ this.cf.markTemporary();
+/* */
+/* 116 */ NetUpdate.warnUser("Error getting upgrade info, try again later");
+/* 117 */ return false;
+/* */ }
+/* */
+/* */
+/* 121 */ copyFile(this.cf.getLocalName(), (String)names.elementAt(i));
+/* */
+/* 123 */ this.cf.markTemporary();
+/* 124 */ this.cf.close();
+/* */ }
+/* 126 */ return true;
+/* */ } finally {
+/* 128 */ done(true);
+/* */ }
+/* */ }
+/* */
+/* */ /* Error */
+/* */ public static boolean copyFile(String from, String to)
+/* */ {
+/* */ // Byte code:
+/* */ // 0: aload_1
+/* */ // 1: bipush 47
+/* */ // 3: invokevirtual 205 java/lang/String:lastIndexOf (I)I
+/* */ // 6: istore_2
+/* */ // 7: aload_1
+/* */ // 8: bipush 92
+/* */ // 10: invokevirtual 205 java/lang/String:lastIndexOf (I)I
+/* */ // 13: istore_3
+/* */ // 14: iload_3
+/* */ // 15: iload_2
+/* */ // 16: if_icmple +5 -> 21
+/* */ // 19: iload_3
+/* */ // 20: istore_2
+/* */ // 21: iload_2
+/* */ // 22: iflt +20 -> 42
+/* */ // 25: new 209 java/io/File
+/* */ // 28: dup
+/* */ // 29: aload_1
+/* */ // 30: iconst_0
+/* */ // 31: iload_2
+/* */ // 32: invokevirtual 211 java/lang/String:substring (II)Ljava/lang/String;
+/* */ // 35: invokespecial 215 java/io/File:<init> (Ljava/lang/String;)V
+/* */ // 38: invokevirtual 216 java/io/File:mkdirs ()Z
+/* */ // 41: pop
+/* */ // 42: aconst_null
+/* */ // 43: astore 4
+/* */ // 45: aconst_null
+/* */ // 46: astore 5
+/* */ // 48: new 219 java/io/FileInputStream
+/* */ // 51: dup
+/* */ // 52: aload_0
+/* */ // 53: invokespecial 221 java/io/FileInputStream:<init> (Ljava/lang/String;)V
+/* */ // 56: astore 4
+/* */ // 58: new 222 java/io/FileOutputStream
+/* */ // 61: dup
+/* */ // 62: aload_1
+/* */ // 63: invokespecial 224 java/io/FileOutputStream:<init> (Ljava/lang/String;)V
+/* */ // 66: astore 5
+/* */ // 68: sipush 1024
+/* */ // 71: newarray <illegal type>
+/* */ // 73: astore 6
+/* */ // 75: aload 4
+/* */ // 77: aload 6
+/* */ // 79: invokevirtual 225 java/io/FileInputStream:read ([B)I
+/* */ // 82: istore 7
+/* */ // 84: iload 7
+/* */ // 86: iconst_m1
+/* */ // 87: if_icmpne +6 -> 93
+/* */ // 90: goto +41 -> 131
+/* */ // 93: aload 5
+/* */ // 95: aload 6
+/* */ // 97: iconst_0
+/* */ // 98: iload 7
+/* */ // 100: invokevirtual 229 java/io/FileOutputStream:write ([BII)V
+/* */ // 103: goto -28 -> 75
+/* */ // 106: astore 8
+/* */ // 108: aload 5
+/* */ // 110: ifnull +8 -> 118
+/* */ // 113: aload 5
+/* */ // 115: invokevirtual 233 java/io/FileOutputStream:close ()V
+/* */ // 118: aload 4
+/* */ // 120: ifnull +8 -> 128
+/* */ // 123: aload 4
+/* */ // 125: invokevirtual 234 java/io/FileInputStream:close ()V
+/* */ // 128: aload 8
+/* */ // 130: athrow
+/* */ // 131: aload 5
+/* */ // 133: ifnull +8 -> 141
+/* */ // 136: aload 5
+/* */ // 138: invokevirtual 233 java/io/FileOutputStream:close ()V
+/* */ // 141: aload 4
+/* */ // 143: ifnull +8 -> 151
+/* */ // 146: aload 4
+/* */ // 148: invokevirtual 234 java/io/FileInputStream:close ()V
+/* */ // 151: iconst_1
+/* */ // 152: ireturn
+/* */ // 153: astore 6
+/* */ // 155: iconst_0
+/* */ // 156: ireturn
+/* */ // Line number table:
+/* */ // Java source line #138 -> byte code offset #0
+/* */ // Java source line #139 -> byte code offset #7
+/* */ // Java source line #140 -> byte code offset #14
+/* */ // Java source line #141 -> byte code offset #19
+/* */ // Java source line #142 -> byte code offset #21
+/* */ // Java source line #143 -> byte code offset #25
+/* */ // Java source line #145 -> byte code offset #42
+/* */ // Java source line #146 -> byte code offset #45
+/* */ // Java source line #149 -> byte code offset #48
+/* */ // Java source line #150 -> byte code offset #58
+/* */ // Java source line #151 -> byte code offset #68
+/* */ // Java source line #153 -> byte code offset #75
+/* */ // Java source line #154 -> byte code offset #84
+/* */ // Java source line #155 -> byte code offset #90
+/* */ // Java source line #156 -> byte code offset #93
+/* */ // Java source line #152 -> byte code offset #103
+/* */ // Java source line #158 -> byte code offset #106
+/* */ // Java source line #159 -> byte code offset #108
+/* */ // Java source line #160 -> byte code offset #113
+/* */ // Java source line #161 -> byte code offset #118
+/* */ // Java source line #162 -> byte code offset #123
+/* */ // Java source line #163 -> byte code offset #128
+/* */ // Java source line #159 -> byte code offset #131
+/* */ // Java source line #160 -> byte code offset #136
+/* */ // Java source line #161 -> byte code offset #141
+/* */ // Java source line #162 -> byte code offset #146
+/* */ // Java source line #164 -> byte code offset #151
+/* */ // Java source line #165 -> byte code offset #153
+/* */ // Java source line #166 -> byte code offset #155
+/* */ // Local variable table:
+/* */ // start length slot name signature
+/* */ // 0 157 0 from String
+/* */ // 0 157 1 to String
+/* */ // 6 26 2 lastSlash int
+/* */ // 13 7 3 lastBackslash int
+/* */ // 43 104 4 s java.io.FileInputStream
+/* */ // 46 91 5 d java.io.FileOutputStream
+/* */ // 73 23 6 buffer byte[]
+/* */ // 153 3 6 e IOException
+/* */ // 82 17 7 got int
+/* */ // 106 23 8 localObject Object
+/* */ // Exception table:
+/* */ // from to target type
+/* */ // 48 106 106 finally
+/* */ // 48 151 153 java/io/IOException
+/* */ }
+/* */
+/* */ protected void build()
+/* */ {
+/* 172 */ GridBagLayout gbag = new GridBagLayout();
+/* 173 */ setLayout(gbag);
+/* 174 */ GridBagConstraints c = new GridBagConstraints();
+/* 175 */ c.anchor = 10;
+/* 176 */ c.gridwidth = 0;
+/* 177 */ c.weightx = 1.0D;
+/* 178 */ c.weighty = 1.0D;
+/* 179 */ add(gbag, new Label(Console.message("Downloading-update")), c);
+/* 180 */ c.insets = new Insets(2, 2, 2, 2);
+/* 181 */ add(gbag, this.progressBar, c);
+/* 182 */ c.insets = new Insets(0, 2, 0, 2);
+/* 183 */ c.anchor = 17;
+/* 184 */ add(gbag, this.progressBytes, c);
+/* 185 */ c.fill = 2;
+/* 186 */ add(gbag, this.progressTime, c);
+/* */ }
+/* */
+/* */
+/* */
+/* */ protected synchronized void activeCallback()
+/* */ {
+/* 193 */ synchronized (this) {
+/* 194 */ int n = this.wholeFileBytes;
+/* 195 */ if (this.cf != null)
+/* 196 */ n += this.cf.bytesLoaded();
+/* */ }
+/* */ int n;
+/* 199 */ if (n != this.bytesLoaded) {
+/* 200 */ this.bytesLoaded = n;
+/* 201 */ this.progressBar.setProgress(this.bytesLoaded / this.bytesTotal);
+/* 202 */ int bytesRemaining = this.bytesTotal - this.bytesLoaded;
+/* */
+/* 204 */ NumberFormat nF = NumberFormat.getNumberInstance(
+/* 205 */ Locale.getDefault());
+/* 206 */ String strRemain = nF.format(bytesRemaining);
+/* 207 */ this.progressBytes.setText(bytesMsg + strRemain);
+/* */
+/* 209 */ int elapsed = (Std.getFastTime() - this.startTime) / 1000;
+/* 210 */ if (elapsed > 0) {
+/* 211 */ double bytesPerSec = this.bytesLoaded / elapsed;
+/* 212 */ if (bytesPerSec > 0.0D) {
+/* 213 */ String bps = formatTime((bytesRemaining / bytesPerSec));
+/* 214 */ Object[] arguments = { new String(bps) };
+/* */
+/* 216 */ this.progressTime.setText(MessageFormat.format(
+/* 217 */ Console.message("Time-remaining"), arguments));
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* 222 */ notify();
+/* */ }
+/* */
+/* */ protected boolean done(boolean confirmed)
+/* */ {
+/* 227 */ synchronized (this) {
+/* 228 */ this.cancelled = true;
+/* 229 */ if (this.cf != null)
+/* 230 */ this.cf.close();
+/* */ }
+/* 232 */ return super.done(confirmed);
+/* */ }
+/* */
+/* */ private static String fmtTwoDigit(long val) {
+/* 236 */ if (val < 10L)
+/* 237 */ return "0" + val;
+/* 238 */ return val;
+/* */ }
+/* */
+/* */ private static String formatTime(long secs) {
+/* 242 */ String result = "";
+/* 243 */ long hrs = secs / 3600L;
+/* 244 */ secs -= hrs * 3600L;
+/* 245 */ long mins = secs / 60L;
+/* 246 */ secs -= mins * 60L;
+/* 247 */ if (hrs > 0L)
+/* 248 */ result = result + hrs + ":";
+/* 249 */ return result + fmtTwoDigit(mins) + ":" + fmtTwoDigit(secs);
+/* */ }
+/* */
+/* */
+/* */ @Deprecated
+/* */ public boolean handleEvent(Event event)
+/* */ {
+/* 256 */ if (event.id == 1004) {
+/* 257 */ Console.getFrame().requestFocus();
+/* 258 */ return true;
+/* */ }
+/* 260 */ return super.handleEvent(event);
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\ProgressDialog.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file