Repackage ProgressOutputStream to net.sf.openrocket.gui.util
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 22 Dec 2011 02:33:43 +0000 (02:33 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 22 Dec 2011 02:33:43 +0000 (02:33 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@242 180e2498-e6e9-4542-8430-84ac67f01cd8

src/net/sf/openrocket/gui/util/ProgressOutputStream.java [new file with mode: 0644]
src/net/sf/openrocket/gui/util/SaveCSVWorker.java
src/net/sf/openrocket/gui/util/SaveFileWorker.java
src/net/sf/openrocket/util/ProgressOutputStream.java [deleted file]

diff --git a/src/net/sf/openrocket/gui/util/ProgressOutputStream.java b/src/net/sf/openrocket/gui/util/ProgressOutputStream.java
new file mode 100644 (file)
index 0000000..2293573
--- /dev/null
@@ -0,0 +1,73 @@
+package net.sf.openrocket.gui.util;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+
+import javax.swing.SwingWorker;
+
+import net.sf.openrocket.util.MathUtil;
+
+
+public abstract class ProgressOutputStream extends FilterOutputStream {
+
+       private final int totalBytes;
+       private final SwingWorker<?,?> worker;
+       private int writtenBytes = 0;
+       private int progress = -1;
+       
+       public ProgressOutputStream(OutputStream out, int estimate, SwingWorker<?,?> worker) {
+               super(out);
+               this.totalBytes = estimate;
+               this.worker = worker;
+       }
+
+       @Override
+       public void write(byte[] b, int off, int len) throws IOException {
+               out.write(b, off, len);
+               writtenBytes += len;
+               setProgress();
+               if (worker.isCancelled()) {
+                       throw new InterruptedIOException("SaveFileWorker was cancelled");
+               }
+       }
+
+       @Override
+       public void write(byte[] b) throws IOException {
+               out.write(b);
+               writtenBytes += b.length;
+               setProgress();
+               if (worker.isCancelled()) {
+                       throw new InterruptedIOException("SaveFileWorker was cancelled");
+               }
+       }
+
+       @Override
+       public void write(int b) throws IOException {
+               out.write(b);
+               writtenBytes++;
+               setProgress();
+               if (worker.isCancelled()) {
+                       throw new InterruptedIOException("SaveFileWorker was cancelled");
+               }
+       }
+       
+       
+       private void setProgress() {
+               int p = MathUtil.clamp(writtenBytes * 100 / totalBytes, 0, 100);
+               if (progress != p) {
+                       progress = p;
+                       setProgress(progress);
+               }
+       }
+       
+       /**
+        * Set the current progress.  The value of <code>progress</code> is guaranteed
+        * to be between 0 and 100, inclusive.
+        * 
+        * @param progress      the current progress in the range 0-100.
+        */
+       protected abstract void setProgress(int progress);
+
+}
\ No newline at end of file
index 55ef4da7cd6b3706fe160816559c6ced080ec6ca..efa7d13d952d3da8da27e327befa8c8f152a8787 100644 (file)
@@ -18,7 +18,6 @@ import net.sf.openrocket.simulation.FlightDataType;
 import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.unit.Unit;
 import net.sf.openrocket.util.BugException;
-import net.sf.openrocket.util.ProgressOutputStream;
 
 
 public class SaveCSVWorker extends SwingWorker<Void, Void> {
index 9e5f411743fdc676a5aaab814fd48d353032897e..1ccc3145b70d2f98997af4f201b4f13907df61e6 100644 (file)
@@ -9,7 +9,6 @@ import javax.swing.SwingWorker;
 import net.sf.openrocket.document.OpenRocketDocument;
 import net.sf.openrocket.file.RocketSaver;
 import net.sf.openrocket.startup.Application;
-import net.sf.openrocket.util.ProgressOutputStream;
 
 public class SaveFileWorker extends SwingWorker<Void, Void> {
 
diff --git a/src/net/sf/openrocket/util/ProgressOutputStream.java b/src/net/sf/openrocket/util/ProgressOutputStream.java
deleted file mode 100644 (file)
index c52a212..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.sf.openrocket.util;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.io.OutputStream;
-
-import javax.swing.SwingWorker;
-
-
-public abstract class ProgressOutputStream extends FilterOutputStream {
-
-       private final int totalBytes;
-       private final SwingWorker<?,?> worker;
-       private int writtenBytes = 0;
-       private int progress = -1;
-       
-       public ProgressOutputStream(OutputStream out, int estimate, SwingWorker<?,?> worker) {
-               super(out);
-               this.totalBytes = estimate;
-               this.worker = worker;
-       }
-
-       @Override
-       public void write(byte[] b, int off, int len) throws IOException {
-               out.write(b, off, len);
-               writtenBytes += len;
-               setProgress();
-               if (worker.isCancelled()) {
-                       throw new InterruptedIOException("SaveFileWorker was cancelled");
-               }
-       }
-
-       @Override
-       public void write(byte[] b) throws IOException {
-               out.write(b);
-               writtenBytes += b.length;
-               setProgress();
-               if (worker.isCancelled()) {
-                       throw new InterruptedIOException("SaveFileWorker was cancelled");
-               }
-       }
-
-       @Override
-       public void write(int b) throws IOException {
-               out.write(b);
-               writtenBytes++;
-               setProgress();
-               if (worker.isCancelled()) {
-                       throw new InterruptedIOException("SaveFileWorker was cancelled");
-               }
-       }
-       
-       
-       private void setProgress() {
-               int p = MathUtil.clamp(writtenBytes * 100 / totalBytes, 0, 100);
-               if (progress != p) {
-                       progress = p;
-                       setProgress(progress);
-               }
-       }
-       
-       /**
-        * Set the current progress.  The value of <code>progress</code> is guaranteed
-        * to be between 0 and 100, inclusive.
-        * 
-        * @param progress      the current progress in the range 0-100.
-        */
-       protected abstract void setProgress(int progress);
-
-}
\ No newline at end of file