Search in sources :

Example 1 with AbstractInputStreamRunnable

use of org.csstudio.swt.widgets.util.AbstractInputStreamRunnable in project yamcs-studio by yamcs.

the class NativeButtonFigure method setImagePath.

@SuppressWarnings("nls")
public void setImagePath(final IPath path) {
    if (image != null) {
        image.dispose();
        image = null;
        button.setImage(null);
    }
    AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

        @Override
        public void runWithInputStream(InputStream stream) {
            image = new Image(null, stream);
            try {
                stream.close();
            } catch (IOException e) {
            }
            if (!button.isDisposed()) {
                button.setImage(image);
            }
        }
    };
    if (path != null && !path.isEmpty()) {
        ResourceUtil.pathToInputStreamInJob(path, uiTask, "Load Button Icon...", new IJobErrorHandler() {

            @Override
            public void handleError(Exception exception) {
                image = null;
                ErrorHandlerUtil.handleError("Failed to load button icon.", exception);
            }
        });
    }
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) IOException(java.io.IOException)

Example 2 with AbstractInputStreamRunnable

use of org.csstudio.swt.widgets.util.AbstractInputStreamRunnable in project yamcs-studio by yamcs.

the class GIFSymbolImage method loadAnimatedImage.

private void loadAnimatedImage(IJobErrorHandler errorHandler) {
    AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

        @Override
        public void runWithInputStream(InputStream stream) {
            synchronized (GIFSymbolImage.this) {
                ImageData[] dataArray = loader.load(stream);
                if (dataArray == null || dataArray.length < 1)
                    return;
                originalImageDataArray = dataArray;
                originalImageData = originalImageDataArray[0];
                animated = originalImageDataArray.length > 1;
                loadingImage = false;
                resetData();
                if (animated)
                    startAnimation();
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        fireSymbolImageLoaded();
                    }
                });
            }
        }
    };
    ResourceUtil.pathToInputStreamInJob(imagePath, uiTask, "Loading GIF Image...", errorHandler);
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable)

Example 3 with AbstractInputStreamRunnable

use of org.csstudio.swt.widgets.util.AbstractInputStreamRunnable in project yamcs-studio by yamcs.

the class PNGSymbolImage method loadImage.

private void loadImage(IJobErrorHandler errorHandler) {
    AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

        @Override
        public void runWithInputStream(InputStream stream) {
            synchronized (PNGSymbolImage.this) {
                Image tempImage = null;
                try {
                    tempImage = new Image(Display.getDefault(), stream);
                    ImageData imgData = tempImage.getImageData();
                    setOriginalImageData(imgData);
                } finally {
                    try {
                        stream.close();
                        if (tempImage != null && !tempImage.isDisposed()) {
                            tempImage.dispose();
                        }
                    } catch (IOException e) {
                        Activator.getLogger().log(Level.WARNING, "ERROR in closing PNG image stream ", e);
                    }
                }
                loadingImage = false;
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        fireSymbolImageLoaded();
                    }
                });
            }
        }
    };
    ResourceUtil.pathToInputStreamInJob(imagePath, uiTask, "Loading PNG Image...", errorHandler);
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image)

Example 4 with AbstractInputStreamRunnable

use of org.csstudio.swt.widgets.util.AbstractInputStreamRunnable in project yamcs-studio by yamcs.

the class ActionButtonFigure method setImagePath.

@SuppressWarnings("nls")
public void setImagePath(final IPath path) {
    dispose();
    AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

        @Override
        public void runWithInputStream(InputStream stream) {
            image = new Image(null, stream);
            try {
                stream.close();
            } catch (IOException e) {
            }
            if (label.isEnabled())
                label.setIcon(image);
            else {
                if (grayImage == null && image != null)
                    grayImage = new Image(null, image, SWT.IMAGE_GRAY);
                label.setIcon(grayImage);
            }
            calculateTextPosition();
        }
    };
    if (path != null && !path.isEmpty()) {
        this.imagePath = path;
        ResourceUtil.pathToInputStreamInJob(path, uiTask, "Load Action Button Icon...", new IJobErrorHandler() {

            @Override
            public void handleError(Exception exception) {
                image = null;
                Activator.getLogger().log(Level.WARNING, "Failed to load image from path" + path, exception);
            }
        });
    }
    if (label.isEnabled())
        label.setIcon(image);
    else {
        if (grayImage == null && image != null)
            grayImage = new Image(null, image, SWT.IMAGE_GRAY);
        label.setIcon(grayImage);
    }
    calculateTextPosition();
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException)

Example 5 with AbstractInputStreamRunnable

use of org.csstudio.swt.widgets.util.AbstractInputStreamRunnable in project yamcs-studio by yamcs.

the class TabFigure method setIconPath.

public void setIconPath(final int index, final IPath path, final IJobErrorHandler errorHandler) {
    dispose(index);
    if (path != null && !path.isEmpty()) {
        AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

            @Override
            public void runWithInputStream(InputStream stream) {
                Image image = new Image(null, stream);
                try {
                    stream.close();
                } catch (IOException e) {
                }
                getTabLabel(index).setIcon(image);
            }
        };
        ResourceUtil.pathToInputStreamInJob(path, uiTask, "Loading Tab Icon...", errorHandler);
    }
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image)

Aggregations

InputStream (java.io.InputStream)6 AbstractInputStreamRunnable (org.csstudio.swt.widgets.util.AbstractInputStreamRunnable)6 IOException (java.io.IOException)5 Image (org.eclipse.swt.graphics.Image)4 IJobErrorHandler (org.csstudio.swt.widgets.util.IJobErrorHandler)2 ImageData (org.eclipse.swt.graphics.ImageData)2 IntrospectionException (java.beans.IntrospectionException)1