Search in sources :

Example 6 with SWTException

use of org.eclipse.swt.SWTException in project cogtool by cogtool.

the class FrameUIModel method setUpFrameContents.

/**
     * Set up the contents of the frame.
     * This creates the scalable figure and sets the initial scaling.
     *
     * The layout manager is also created with an XYLayout to allow absolute
     * positioning of elements.
     *
     * All structures needed to support drawing and selecting objects are
     * created here.
     *
     * @param double Scale: used to set the initial size of the contents.
     */
protected void setUpFrameContents(double scale) {
    // Set up the content pane
    // Create the underlying contents pane.
    // And set the contents pane's default widget color.
    contents = new ScalableFrameFigure(frame.getWidgetColor());
    contents.setScale(scale);
    contents.setLayoutManager(new XYLayout());
    // Create a new graphical widget for each widget in Frame.
    Iterator<IWidget> modelWidgets = frame.getWidgets().iterator();
    while (modelWidgets.hasNext()) {
        IWidget w = modelWidgets.next();
        createGraphicalWidget(w);
    }
    // Initialize the background image
    backgroundImage = new ImageFigure();
    final byte[] bgImg = frame.getBackgroundImage();
    if (bgImg != null) {
        if (lazyLoading) {
            // Use a thread to load the image, then set it later
            ThreadManager.IWorkThread imageLoadThread = new CogToolWorkThread() {

                protected Image img = null;

                public void doWork() {
                    // Performed by the scheduled thread
                    img = new Image(null, new ByteArrayInputStream(bgImg));
                }

                @Override
                public void doneCallback() {
                    // Performed by the main UI thread
                    if (img != null) {
                        if (isDisposed) {
                            img.dispose();
                        } else {
                            backgroundImage.setImage(img);
                        }
                    }
                    // TODO: We might want to add a real logging package
                    if (exBucket.containsExceptions()) {
                        // TODO: It is unclear what to do here.  Maybe
                        // we should just replace failed images with red
                        // Xs rather than popping up a dialog box
                        System.err.println(exBucket);
                    //                                RcvrExceptionHandler.recoverWorkThread(this,
                    //                                                                       interaction);
                    }
                }
            };
            ThreadManager.startNewThread(imageLoadThread, 2);
        } else {
            try {
                // = AUIModel.imageCache.get(frame);
                Image img = null;
                if (img == null) {
                    img = new Image(null, new ByteArrayInputStream(bgImg));
                //                        AUIModel.imageCache.put(frame, img);
                }
                backgroundImage.setImage(img);
            } catch (SWTException ex) {
                throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
            }
        }
        backgroundImage.setBounds(PrecisionUtilities.getDraw2DRectangle(frame.getBackgroundBounds()));
    }
    // Always align the picture to top left corner
    backgroundImage.setAlignment(PositionConstants.NORTH | PositionConstants.WEST);
    // Resize to preferred size.
    DoubleSize s = getPreferredSize();
    // Set the size of the contents area to fit all elements.
    contents.setSize(PrecisionUtilities.round(s.width), PrecisionUtilities.round(s.height));
    // Draw all widgets.
    drawWidgets();
}
Also used : Image(org.eclipse.swt.graphics.Image) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) CogToolWorkThread(edu.cmu.cs.hcii.cogtool.CogToolWorkThread) SWTException(org.eclipse.swt.SWTException) ByteArrayInputStream(java.io.ByteArrayInputStream) XYLayout(org.eclipse.draw2d.XYLayout) ImageFigure(org.eclipse.draw2d.ImageFigure) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) ThreadManager(edu.cmu.cs.hcii.cogtool.util.ThreadManager) ScalableFrameFigure(edu.cmu.cs.hcii.cogtool.view.ScalableFrameFigure) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 7 with SWTException

use of org.eclipse.swt.SWTException in project cogtool by cogtool.

the class GraphicalDevice method paintFigure.

/**
     * Override to perform drawing tasks common to all graphical sources
     */
@Override
protected void paintFigure(Graphics g) {
    Dimension size = getSize();
    // Workaround Draw2D's inability to draw 0-size images.
    int width = size.width;
    if (width == 0) {
        width = 1;
    }
    int height = size.height;
    if (height == 0) {
        height = 1;
    }
    Image scaled = null;
    try {
        // Draw foreground sheen (not selected)
        foreground.setAlpha(0, 0, displayAlpha.determineAlpha(false));
        // TODO: Can this be cached more efficiently?
        scaled = new Image(null, foreground.scaledTo(width, height));
        Point location = getLocation();
        g.drawImage(scaled, location.x, location.y);
    } catch (SWTException ex) {
        throw new RcvrImageException("Drawing device foreground image failed", ex);
    } finally {
        if (scaled != null) {
            scaled.dispose();
        }
    }
    super.paintFigure(g);
    button.paintFigure(g);
}
Also used : SWTException(org.eclipse.swt.SWTException) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.draw2d.geometry.Point)

Example 8 with SWTException

use of org.eclipse.swt.SWTException in project jop by jop-devel.

the class JOPBoardConfigurationTab method handleQuartusProjectButtonSelected.

/**
     * Handle selection of the Quartus project file button. 
     *
     */
protected void handleQuartusProjectButtonSelected() {
    FileDialog dialog = new FileDialog(getShell());
    IPath rootPath = fQuartusProjectLocation != null ? fQuartusProjectLocation.removeLastSegments(1) : ResourcesPlugin.getWorkspace().getRoot().getLocation();
    dialog.setFilterPath(rootPath.toString());
    dialog.setFilterExtensions(new String[] { "*.qpf" });
    try {
        dialog.open();
        if (dialog.getFileName().equals("")) {
            return;
        }
        IPath filterPath = new Path(dialog.getFilterPath());
        IPath fileName = new Path(dialog.getFileName());
        fQuartusProjectLocation = filterPath.append(fileName);
        fQuartusProjectText.setText(fQuartusProjectLocation.toString());
    } catch (SWTException e) {
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) SWTException(org.eclipse.swt.SWTException) IPath(org.eclipse.core.runtime.IPath) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 9 with SWTException

use of org.eclipse.swt.SWTException in project dbeaver by serge-rider.

the class ImageEditor method loadImage.

@Override
public boolean loadImage(InputStream inputStream) {
    super.loadImage(inputStream);
    try {
        SWTException lastError = getLastError();
        if (lastError != null) {
            messageLabel.setText(lastError.getMessage());
            messageLabel.setForeground(redColor);
            return false;
        } else {
            messageLabel.setText(getImageDescription());
            messageLabel.setForeground(blackColor);
            return true;
        }
    } finally {
        updateActions();
    }
}
Also used : SWTException(org.eclipse.swt.SWTException)

Example 10 with SWTException

use of org.eclipse.swt.SWTException in project dbeaver by serge-rider.

the class ImageViewCanvas method loadImage.

/**
	 * Reload image from a file
	 * @return swt image created from image file
	 */
public Image loadImage(InputStream inputStream) {
    if (sourceImage != null && !sourceImage.isDisposed()) {
        sourceImage.dispose();
        sourceImage = null;
        imageData = null;
    }
    this.error = null;
    if (inputStream != null) {
        try {
            imageData = new ImageData(inputStream);
            sourceImage = new Image(getDisplay(), imageData);
        } catch (SWTException e) {
            this.error = e;
        }
    }
    showOriginal();
    return sourceImage;
}
Also used : SWTException(org.eclipse.swt.SWTException) ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image)

Aggregations

SWTException (org.eclipse.swt.SWTException)11 Image (org.eclipse.swt.graphics.Image)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)2 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)2 Point (org.eclipse.swt.graphics.Point)2 Table (org.eclipse.swt.widgets.Table)2 StopWatch (alma.acs.util.StopWatch)1 CogToolWorkThread (edu.cmu.cs.hcii.cogtool.CogToolWorkThread)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)1 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 GensimLSASimilarity (edu.cmu.cs.hcii.cogtool.model.GensimLSASimilarity)1 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)1 ISitedTermSimilarity (edu.cmu.cs.hcii.cogtool.model.ISitedTermSimilarity)1 LSASimilarity (edu.cmu.cs.hcii.cogtool.model.LSASimilarity)1 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)1 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)1 ThreadManager (edu.cmu.cs.hcii.cogtool.util.ThreadManager)1 ScalableFrameFigure (edu.cmu.cs.hcii.cogtool.view.ScalableFrameFigure)1