Examples of ProgressIndicator


Examples of com.lightcrafts.utils.ProgressIndicator

        setIntField(TIFF_PHOTOMETRIC_INTERPRETATION, TIFF_PHOTOMETRIC_RGB );

        setIntField(TIFF_TILE_WIDTH, image.getTileWidth());
        setIntField(TIFF_TILE_LENGTH, image.getTileHeight());

        final ProgressIndicator indicator;
        if (thread != null) {
            indicator = thread.getProgressIndicator();
            if ( indicator != null )
                indicator.setMaximum( image.getNumXTiles() * image.getNumYTiles() );
        } else
            indicator = null;

        for ( int tileX = 0; tileX < image.getNumXTiles(); tileX++ )
            for ( int tileY = 0; tileY < image.getNumYTiles(); tileY++ ) {
                if ( thread != null && thread.isCanceled() )
                    return;
                final int tileIndex = computeTile(tileX * image.getTileWidth(), tileY * image.getTileHeight(), 0, 0);
                final Raster tile = image.getTile(tileX, tileY);

                if (dataType == DataBuffer.TYPE_BYTE) {
                    final byte[] buffer = ((DataBufferByte) tile.getDataBuffer()).getData();

                    final int bytesWritten =  writeTileByte(
                        tileIndex, buffer, 0, buffer.length
                    );
                    if ( bytesWritten != buffer.length )
                        throw new LCImageLibException(
                            "something is wrong: " + bytesWritten + " != " + buffer.length
                        );
                } else {
                    final short[] buffer = ((DataBufferUShort) tile.getDataBuffer()).getData();

                    final int bytesWritten = writeTileShort(
                        tileIndex, buffer, 0, buffer.length * 2
                    );
                    if ( bytesWritten != buffer.length * 2 )
                        throw new LCImageLibException(
                            "something is wrong: " + bytesWritten + " != " + buffer.length * 2
                        );
                }
                if ( indicator != null )
                    indicator.incrementBy( 1 );
            }
        if ( indicator != null )
            indicator.setIndeterminate( true );
    }
View Full Code Here

Examples of com.lightcrafts.utils.ProgressIndicator

     * @param cs The {@link ColorSpace} to use.
     */
    private void readImage( ProgressThread thread, ColorSpace cs )
        throws LCImageLibException, UserCanceledException
    {
        ProgressIndicator indicator = null;
        if ( thread != null )
            indicator = thread.getProgressIndicator();
        if ( indicator != null )
            indicator.setMaximum( m_height );

        // todo: deal with color models other than rgb and grayscale

        if ( cs == null )
            cs = (m_colorsPerPixel == 1 ? JAIContext.gray22ColorSpace :
                  m_colorsPerPixel == 3 ? JAIContext.sRGBColorSpace :
                                          JAIContext.CMYKColorSpace);

        // Color model for the image (and everything else).
        final ComponentColorModel ccm = new ComponentColorModel(
            cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE
        );

        // Sample model for the readout buffer large enough to hold a tile or a
        // strip of the image.
        final SampleModel jpegTsm = ccm.createCompatibleSampleModel(
            m_width, JAIContext.TILE_HEIGHT
        );

        // The readout buffer itself.
        final DataBuffer db = new DataBufferByte(
            m_colorsPerPixel * m_width * JAIContext.TILE_HEIGHT
        );

        // Sample model for the output image.
        final SampleModel tsm = ccm.createCompatibleSampleModel(
            JAIContext.TILE_WIDTH, JAIContext.TILE_HEIGHT
        );

        // Layout of the output image.
        final ImageLayout layout = new ImageLayout(
            0, 0, m_width, m_height, 0, 0, JAIContext.TILE_WIDTH,
            JAIContext.TILE_HEIGHT, tsm, ccm
        );

        // The output image itself, directly allocated in the file cache.
        final CachedImage image =
            new CachedImage( layout, JAIContext.fileCache );

        // Load Image Data
        int tileY = 0;
        int totalLinesRead = 0;
        while ( totalLinesRead < m_height ) {
            if ( thread != null && thread.isCanceled() )
                throw new UserCanceledException();
            final int tileHeight =
                Math.min( JAIContext.TILE_HEIGHT, m_height - totalLinesRead );

            // Wrap the data buffer with a Raster representing the input data.
            final WritableRaster raster = Raster.createWritableRaster(
                jpegTsm, db, new Point( 0, tileY * JAIContext.TILE_HEIGHT )
            );

            final int linesRead = readScanLines(
                ((DataBufferByte)db).getData(), 0, tileHeight
            );
            if ( linesRead <= 0 ) {
                System.out.println("Problem with readScanLines, returned: " + linesRead );
                break;
            }

            if ( m_hasAdobeSegment && m_colorsPerPixel == 4 ) {
                //
                // CMYK JPEG images generated by Photoshop are inverted, so we
                // have to invert the data to make it look right.
                //
                final byte data[] = ((DataBufferByte) db).getData();
                for (int i = 0; i < data.length; i++)
                    data[i] = (byte)~data[i];
            }

            totalLinesRead += linesRead;
            tileY++;

            image.setData( raster );

            if ( indicator != null )
                indicator.incrementBy( linesRead );
        }
        if ( indicator != null )
            indicator.setIndeterminate( true );
        m_image = image;
    }
View Full Code Here

Examples of com.lightcrafts.utils.ProgressIndicator

        final int imageWidth = image.getWidth();
        final int imageHeight = image.getHeight();
        final Rectangle stripRect = new Rectangle();
        int stripHeight = 8;

        ProgressIndicator indicator = null;
        if ( thread != null )
            indicator = thread.getProgressIndicator();
        if ( indicator != null )
            indicator.setMaximum( imageHeight );

        final int bands = image.getSampleModel().getNumBands();
        final SampleModel sm =
            new PixelInterleavedSampleModel(
                DataBuffer.TYPE_BYTE,
                imageWidth, stripHeight, bands, bands * imageWidth,
                bands == 1 ? new int[]{ 0 } :
                    bands == 3 ? new int[]{ 0, 1, 2 } :
                        new int[]{ 0, 1, 2, 3 }
            );

        final ByteInterleavedRaster rasterBuffer = new ByteInterleavedRaster(sm, new Point(0, 0));

        for ( int y = 0; y < imageHeight; y += stripHeight ) {
            if ( thread != null && thread.isCanceled() )
                return;
            stripHeight = Math.min( stripHeight, imageHeight - y );
            stripRect.setBounds( 0, y, imageWidth, stripHeight );

            final ByteInterleavedRaster raster = (ByteInterleavedRaster) rasterBuffer.createTranslatedChild(0, y);

            // Prefetch tiles, uses all CPUs
            if (image instanceof PlanarImage)
                ((PlanarImage) image).getTiles(((PlanarImage) image).getTileIndices(raster.getBounds()));

            image.copyData(raster);

            final DataBufferByte db = (DataBufferByte)raster.getDataBuffer();

            final int[] offsets = raster.getDataOffsets();
            int offset = offsets[0];
            for (int i = 1; i < offsets.length; i++)
                offset = Math.min(offset, offsets[i]);

            if ( bands == 4 /* CMYK */ ) {
                //
                // A long-standing Photoshop bug is that CMYK images are stored
                // inverted.  To be compatible with Photoshop, we have to
                // invert CMYK images too.
                //
                final byte[] data = db.getData();
                for ( int i = 0; i < data.length; ++i )
                    data[i] = (byte)~data[i];
            }

            final int lineStride = raster.getScanlineStride();
            final int written = writeScanLines( db.getData(), offset, stripHeight, lineStride );

            if ( written != stripHeight )
                throw new LCImageLibException(
                    "something is wrong: " + written + " != " + stripHeight
                );

            if ( indicator != null )
                indicator.incrementBy( stripHeight );
        }

        if ( indicator != null )
            indicator.setIndeterminate( true );
    }
View Full Code Here

Examples of com.lightcrafts.utils.ProgressIndicator

        // The output image itself, directly allocated in the file cache
        CachedImage image = new CachedImage(layout, JAIContext.fileCache);

        final int maxTileX = image.getNumXTiles();

        ProgressIndicator indicator = null;
        if ( thread != null )
            indicator = thread.getProgressIndicator();
        if ( indicator != null )
            indicator.setMaximum( tf.tiles );

        int bandList[] = new int[tf.samplesPerPixel];
        for (int i = 0; i < tf.samplesPerPixel; i++)
            bandList[i] = i;

        Rectangle imageBounds = new Rectangle(0, 0, tf.imageWidth, tf.imageHeight);

        for ( int tile = 0; tile < tf.tiles; tile++ ) {
            if ( thread != null && thread.isCanceled() )
                throw new UserCanceledException();
            final int tileX = tf.tiled ? tile % maxTileX : 0;
            final int tileY = tf.tiled ? tile / maxTileX : tile;

            // The actual tile bounds, clipping on the image bounds
            Rectangle tileBounds = new Rectangle(tileX * tf.tiffTileWidth,
                                                 tileY * tf.tiffTileHeight,
                                                 tf.tiffTileWidth,
                                                 tf.tiffTileHeight).intersection(imageBounds);

            // the corresponding tile data
            int tileData = (tf.samplesPerPixel / tf.planes) * tileBounds.width * tileBounds.height * (tf.bitsPerSample == 8 ? 1 : 2);

            /* If the TIFF image is tiled and it doesn't have an alpha channel
               then we can read directly into the destination image buffer,
               don't allocate an intermediate raster */

            WritableRaster raster =
                    !tf.tiled || tf.hasAlpha
                    ? Raster.createWritableRaster(tf.tiffTsm, db, new Point(tileBounds.x, tileBounds.y))
                    : null;

            for ( int plane = 0; plane < tf.planes; plane++ ) {
                if ( tf.tiled ) {
                    if (!tf.hasAlpha)
                        raster = image.getWritableTile( tileX, tileY );

                    if ( tf.bitsPerSample == 8 ) {
                        final byte[] buffer =
                            ((DataBufferByte)raster.getDataBuffer()).getData(
                                plane );
                        int read = readTileByte( tile + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    } else {
                        final short[] buffer =
                            ((DataBufferUShort)raster.getDataBuffer()).getData(
                                plane );
                        int read = readTileShort( tile + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    }
                } else {
                    if ( tf.bitsPerSample == 8 ) {
                        final byte[] buffer =
                            ((DataBufferByte)db).getData( plane );
                        int read = readStripByte( tileY + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    } else {
                        final short[] buffer =
                            ((DataBufferUShort)db).getData( plane );
                        int read = readStripShort( tileY + plane * tf.tiles, buffer, 0, tileData );
                        if (read != tileData)
                            throw new LCImageLibException("Broken TIFF File");
                    }
                }
            }
            if (!tf.tiled || tf.hasAlpha)
                image.setData(raster.createChild(raster.getMinX(), raster.getMinY(),
                                                 raster.getWidth(), raster.getHeight(),
                                                 raster.getMinX(), raster.getMinY(),
                                                 bandList));
            if ( indicator != null )
                indicator.incrementBy( 1 );
        }
        if ( indicator != null )
            indicator.setIndeterminate( true );

        m_image = image;
    }
View Full Code Here

Examples of com.vaadin.ui.ProgressIndicator

        // t.refreshRowCache();
        // }
        // });
        // mainWindow.addComponent(button);

        ProgressIndicator pi = new ProgressIndicator();
        pi.setPollingInterval(1000);
        pi.setIndeterminate(true);
        mainWindow.addComponent(pi);

        Thread r = new Thread() {
            @Override
            public void run() {
View Full Code Here

Examples of com.vaadin.ui.ProgressIndicator

                }
                super.setPositionX(positionX);
            }
        };
        getMainWindow().addWindow(subWindow);
        ProgressIndicator pi = new ProgressIndicator();
        pi.setIndeterminate(true);
        pi.setPollingInterval(delay);
        addComponent(pi);
    }
View Full Code Here

Examples of com.vaadin.ui.ProgressIndicator

        final OptionGroup optionGroup = new OptionGroup("OptionGroup "
                + count++);
        test(layout, optionGroup);

        final ProgressIndicator pi = new ProgressIndicator();
        test(layout, pi);

        final RichTextArea rta = new RichTextArea();
        test(layout, rta);
View Full Code Here

Examples of com.vaadin.ui.ProgressIndicator

    @Override
    protected void setup(VaadinRequest request) {

        // Progress indicator for changing the value of the RTA
        ProgressIndicator pi = new ProgressIndicator() {
            {
                registerRpc(new ProgressIndicatorServerRpc() {

                    @Override
                    public void poll() {
                        rta.markAsDirty();
                    }
                });
            }
        };
        pi.setHeight("0px");
        addComponent(pi);

        rta = new RichTextArea();
        rta.setId("rta");
        rta.setImmediate(true);
View Full Code Here

Examples of com.vaadin.ui.ProgressIndicator

        }
    };

    @Override
    protected void setup(VaadinRequest request) {
        addComponent(new ProgressIndicator() {
            {
                registerRpc(new ProgressIndicatorServerRpc() {
                    @Override
                    public void poll() {
                        // System.out.println("Pausing poll request");
View Full Code Here

Examples of com.vaadin.ui.ProgressIndicator

        addComponent(new Button("Use ProgressIndicator",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        useComponent(new ProgressIndicator());
                    }
                }));

        addComponent(new Button("Stop background thread",
                new Button.ClickListener() {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.