Example usage for javax.swing ProgressMonitor getMinimum

List of usage examples for javax.swing ProgressMonitor getMinimum

Introduction

In this page you can find the example usage for javax.swing ProgressMonitor getMinimum.

Prototype

public int getMinimum() 

Source Link

Document

Returns the minimum value -- the lower end of the progress value.

Usage

From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java

/**
 * DOCUMENT ME!/*from w  w w.j  av  a2  s.  co  m*/
 *
 * @param   fileName  DOCUMENT ME!
 *
 * @return  DOCUMENT ME!
 *
 * @throws  Exception  DOCUMENT ME!
 */
private BufferedImage downloadImageFromWebDAV(final String fileName) throws Exception {
    final InputStream iStream = webdavHelper.getFileFromWebDAV(fileName, webdavDirectory,
            getConnectionContext());
    try {
        final ImageInputStream iiStream = ImageIO.createImageInputStream(iStream);
        final Iterator<ImageReader> itReader = ImageIO.getImageReaders(iiStream);
        if (itReader.hasNext()) {
            final ImageReader reader = itReader.next();
            final ProgressMonitor monitor = new ProgressMonitor(this, "Bild wird bertragen...", "", 0, 100);
            //            monitor.setMillisToPopup(500);
            reader.addIIOReadProgressListener(new IIOReadProgressListener() {

                @Override
                public void sequenceStarted(final ImageReader source, final int minIndex) {
                }

                @Override
                public void sequenceComplete(final ImageReader source) {
                }

                @Override
                public void imageStarted(final ImageReader source, final int imageIndex) {
                    monitor.setProgress(monitor.getMinimum());
                }

                @Override
                public void imageProgress(final ImageReader source, final float percentageDone) {
                    if (monitor.isCanceled()) {
                        try {
                            iiStream.close();
                        } catch (final IOException ex) {
                            // NOP
                        }
                    } else {
                        monitor.setProgress(Math.round(percentageDone));
                    }
                }

                @Override
                public void imageComplete(final ImageReader source) {
                    monitor.setProgress(monitor.getMaximum());
                }

                @Override
                public void thumbnailStarted(final ImageReader source, final int imageIndex,
                        final int thumbnailIndex) {
                }

                @Override
                public void thumbnailProgress(final ImageReader source, final float percentageDone) {
                }

                @Override
                public void thumbnailComplete(final ImageReader source) {
                }

                @Override
                public void readAborted(final ImageReader source) {
                    monitor.close();
                }
            });

            final ImageReadParam param = reader.getDefaultReadParam();
            reader.setInput(iiStream, true, true);
            final BufferedImage result;
            try {
                result = reader.read(0, param);
            } finally {
                reader.dispose();
                iiStream.close();
            }
            return result;
        } else {
            return null;
        }
    } finally {
        IOUtils.closeQuietly(iStream);
    }
}