X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=site%2Fj2s%2Fjavax%2Fswing%2FProgressMonitorInputStream.js;fp=site%2Fj2s%2Fjavax%2Fswing%2FProgressMonitorInputStream.js;h=e5857ce73fad305c808a739c1007ca47e942b28e;hb=4231d40261fef32ce4570a6bbad0d35df44e8baf;hp=0000000000000000000000000000000000000000;hpb=c07eb2c5794833bd0241000d6844d783fe10cb82;p=jalview.git diff --git a/site/j2s/javax/swing/ProgressMonitorInputStream.js b/site/j2s/javax/swing/ProgressMonitorInputStream.js new file mode 100644 index 0000000..e5857ce --- /dev/null +++ b/site/j2s/javax/swing/ProgressMonitorInputStream.js @@ -0,0 +1,74 @@ +Clazz.declarePackage ("javax.swing"); +Clazz.load (["java.io.FilterInputStream"], "javax.swing.ProgressMonitorInputStream", ["java.io.InterruptedIOException", "javax.swing.ProgressMonitor"], function () { +c$ = Clazz.decorateAsClass (function () { +this.monitor = null; +this.nread = 0; +this.size = 0; +Clazz.instantialize (this, arguments); +}, javax.swing, "ProgressMonitorInputStream", java.io.FilterInputStream); +Clazz.makeConstructor (c$, +function (parentComponent, message, $in) { +Clazz.superConstructor (this, javax.swing.ProgressMonitorInputStream, [$in]); +try { +this.size = $in.available (); +} catch (ioe) { +if (Clazz.exceptionOf (ioe, java.io.IOException)) { +this.size = 0; +} else { +throw ioe; +} +} +this.monitor = new javax.swing.ProgressMonitor (parentComponent, message, null, 0, this.size); +}, "java.awt.Component,~O,java.io.InputStream"); +Clazz.defineMethod (c$, "getProgressMonitor", +function () { +return this.monitor; +}); +Clazz.defineMethod (c$, "read", +function () { +var c = this.$in.read (); +if (c >= 0) this.monitor.setProgress (++this.nread); +if (this.monitor.isCanceled ()) { +var exc = new java.io.InterruptedIOException ("progress"); +exc.bytesTransferred = this.nread; +throw exc; +}return c; +}); +Clazz.defineMethod (c$, "read", +function (b) { +var nr = this.$in.read (b); +if (nr > 0) this.monitor.setProgress (this.nread += nr); +if (this.monitor.isCanceled ()) { +var exc = new java.io.InterruptedIOException ("progress"); +exc.bytesTransferred = this.nread; +throw exc; +}return nr; +}, "~A"); +Clazz.defineMethod (c$, "read", +function (b, off, len) { +var nr = this.$in.read (b, off, len); +if (nr > 0) this.monitor.setProgress (this.nread += nr); +if (this.monitor.isCanceled ()) { +var exc = new java.io.InterruptedIOException ("progress"); +exc.bytesTransferred = this.nread; +throw exc; +}return nr; +}, "~A,~N,~N"); +Clazz.overrideMethod (c$, "skip", +function (n) { +var nr = this.$in.skip (n); +if (nr > 0) this.monitor.setProgress (this.nread += nr); +return nr; +}, "~N"); +Clazz.overrideMethod (c$, "close", +function () { +this.$in.close (); +this.monitor.close (); +}); +Clazz.overrideMethod (c$, "reset", +function () { +this.$in.reset (); +this.nread = this.size - this.$in.available (); +this.monitor.setProgress (this.nread); +}); +});