src/share/classes/javax/swing/ProgressMonitorInputStream.java

Print this page




  37 /**
  38  * Monitors the progress of reading from some InputStream. This ProgressMonitor
  39  * is normally invoked in roughly this form:
  40  * <pre>
  41  * InputStream in = new BufferedInputStream(
  42  *                          new ProgressMonitorInputStream(
  43  *                                  parentComponent,
  44  *                                  "Reading " + fileName,
  45  *                                  new FileInputStream(fileName)));
  46  * </pre><p>
  47  * This creates a progress monitor to monitor the progress of reading
  48  * the input stream.  If it's taking a while, a ProgressDialog will
  49  * be popped up to inform the user.  If the user hits the Cancel button
  50  * an InterruptedIOException will be thrown on the next read.
  51  * All the right cleanup is done when the stream is closed.
  52  *
  53  *
  54  * <p>
  55  *
  56  * For further documentation and examples see
  57  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html">How to Monitor Progress</a>,
  58  * a section in <em>The Java Tutorial.</em>
  59  *
  60  * @see ProgressMonitor
  61  * @see JOptionPane
  62  * @author James Gosling
  63  */
  64 public class ProgressMonitorInputStream extends FilterInputStream
  65 {
  66     private ProgressMonitor monitor;
  67     private int             nread = 0;
  68     private int             size = 0;
  69 
  70 
  71     /**
  72      * Constructs an object to monitor the progress of an input stream.
  73      *
  74      * @param message Descriptive text to be placed in the dialog box
  75      *                if one is popped up.
  76      * @param parentComponent The component triggering the operation
  77      *                        being monitored.




  37 /**
  38  * Monitors the progress of reading from some InputStream. This ProgressMonitor
  39  * is normally invoked in roughly this form:
  40  * <pre>
  41  * InputStream in = new BufferedInputStream(
  42  *                          new ProgressMonitorInputStream(
  43  *                                  parentComponent,
  44  *                                  "Reading " + fileName,
  45  *                                  new FileInputStream(fileName)));
  46  * </pre><p>
  47  * This creates a progress monitor to monitor the progress of reading
  48  * the input stream.  If it's taking a while, a ProgressDialog will
  49  * be popped up to inform the user.  If the user hits the Cancel button
  50  * an InterruptedIOException will be thrown on the next read.
  51  * All the right cleanup is done when the stream is closed.
  52  *
  53  *
  54  * <p>
  55  *
  56  * For further documentation and examples see
  57  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html">How to Monitor Progress</a>,
  58  * a section in <em>The Java Tutorial.</em>
  59  *
  60  * @see ProgressMonitor
  61  * @see JOptionPane
  62  * @author James Gosling
  63  */
  64 public class ProgressMonitorInputStream extends FilterInputStream
  65 {
  66     private ProgressMonitor monitor;
  67     private int             nread = 0;
  68     private int             size = 0;
  69 
  70 
  71     /**
  72      * Constructs an object to monitor the progress of an input stream.
  73      *
  74      * @param message Descriptive text to be placed in the dialog box
  75      *                if one is popped up.
  76      * @param parentComponent The component triggering the operation
  77      *                        being monitored.