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