JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / javax / swing / ProgressMonitorInputStream.js
1 Clazz.declarePackage ("javax.swing");\r
2 Clazz.load (["java.io.FilterInputStream"], "javax.swing.ProgressMonitorInputStream", ["java.io.InterruptedIOException", "javax.swing.ProgressMonitor"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.monitor = null;\r
5 this.nread = 0;\r
6 this.size = 0;\r
7 Clazz.instantialize (this, arguments);\r
8 }, javax.swing, "ProgressMonitorInputStream", java.io.FilterInputStream);\r
9 Clazz.makeConstructor (c$, \r
10 function (parentComponent, message, $in) {\r
11 Clazz.superConstructor (this, javax.swing.ProgressMonitorInputStream, [$in]);\r
12 try {\r
13 this.size = $in.available ();\r
14 } catch (ioe) {\r
15 if (Clazz.exceptionOf (ioe, java.io.IOException)) {\r
16 this.size = 0;\r
17 } else {\r
18 throw ioe;\r
19 }\r
20 }\r
21 this.monitor =  new javax.swing.ProgressMonitor (parentComponent, message, null, 0, this.size);\r
22 }, "java.awt.Component,~O,java.io.InputStream");\r
23 Clazz.defineMethod (c$, "getProgressMonitor", \r
24 function () {\r
25 return this.monitor;\r
26 });\r
27 Clazz.defineMethod (c$, "read", \r
28 function () {\r
29 var c = this.$in.read ();\r
30 if (c >= 0) this.monitor.setProgress (++this.nread);\r
31 if (this.monitor.isCanceled ()) {\r
32 var exc =  new java.io.InterruptedIOException ("progress");\r
33 exc.bytesTransferred = this.nread;\r
34 throw exc;\r
35 }return c;\r
36 });\r
37 Clazz.defineMethod (c$, "read", \r
38 function (b) {\r
39 var nr = this.$in.read (b);\r
40 if (nr > 0) this.monitor.setProgress (this.nread += nr);\r
41 if (this.monitor.isCanceled ()) {\r
42 var exc =  new java.io.InterruptedIOException ("progress");\r
43 exc.bytesTransferred = this.nread;\r
44 throw exc;\r
45 }return nr;\r
46 }, "~A");\r
47 Clazz.defineMethod (c$, "read", \r
48 function (b, off, len) {\r
49 var nr = this.$in.read (b, off, len);\r
50 if (nr > 0) this.monitor.setProgress (this.nread += nr);\r
51 if (this.monitor.isCanceled ()) {\r
52 var exc =  new java.io.InterruptedIOException ("progress");\r
53 exc.bytesTransferred = this.nread;\r
54 throw exc;\r
55 }return nr;\r
56 }, "~A,~N,~N");\r
57 Clazz.overrideMethod (c$, "skip", \r
58 function (n) {\r
59 var nr = this.$in.skip (n);\r
60 if (nr > 0) this.monitor.setProgress (this.nread += nr);\r
61 return nr;\r
62 }, "~N");\r
63 Clazz.overrideMethod (c$, "close", \r
64 function () {\r
65 this.$in.close ();\r
66 this.monitor.close ();\r
67 });\r
68 Clazz.overrideMethod (c$, "reset", \r
69 function () {\r
70 this.$in.reset ();\r
71 this.nread = this.size - this.$in.available ();\r
72 this.monitor.setProgress (this.nread);\r
73 });\r
74 });\r