Search in sources :

Example 26 with SWTException

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

the class Test_org_eclipse_swt_widgets_TableColumn method test_setMoveableZ.

@Test
public void test_setMoveableZ() {
    assertFalse(":a:", tableColumn.getMoveable());
    tableColumn.setMoveable(true);
    assertTrue(":b:", tableColumn.getMoveable());
    tableColumn.setMoveable(true);
    assertTrue(":c:", tableColumn.getMoveable());
    tableColumn.setMoveable(false);
    assertFalse(":d:", tableColumn.getMoveable());
    TableColumn tableColumn2 = new TableColumn(tableColumn.getParent(), SWT.NONE);
    tableColumn2.dispose();
    try {
        tableColumn2.getMoveable();
        fail("No exception thrown for widget is Disposed");
    } catch (SWTException ex) {
    }
    try {
        tableColumn2.setMoveable(true);
        fail("No exception thrown for widget is Disposed");
    } catch (SWTException ex) {
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) TableColumn(org.eclipse.swt.widgets.TableColumn) Test(org.junit.Test)

Example 27 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 28 with SWTException

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

the class FrameUIModel method addFrameChangeListeners.

/**
     * Add listeners for when things change on the frame.
     */
protected void addFrameChangeListeners() {
    AlertHandler frameChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.WidgetChange chg = (Frame.WidgetChange) alert;
            IWidget chgWidget = chg.getChangeElement();
            if (chg != null) {
                // action dictated by the change.
                switch(chg.action) {
                    // Add the graphical representation of the widget
                    case Frame.WidgetChange.ELEMENT_ADD:
                        createGraphicalWidget(chgWidget);
                        raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
                        break;
                    // Remove the graphical representation of the widget
                    case Frame.WidgetChange.ELEMENT_DELETE:
                        removeWidget(chgWidget);
                        raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
                        break;
                    // Update all existing widgets to the new color
                    case Frame.WidgetChange.WIDGET_COLORS_CHANGED:
                        Iterator<GraphicalWidget<?>> gws = figureList.values().iterator();
                        // Update graphical widgets
                        while (gws.hasNext()) {
                            GraphicalWidget<?> gw = gws.next();
                            gw.setColor(frame.getWidgetColor());
                        //                                    gw.setFastMode(false);
                        }
                        // Update potential temporary widget
                        contents.setWidgetColor(frame.getWidgetColor());
                        break;
                }
            }
            // Draw the viewable widgets.
            // Adds any new items from the lists.. or moves them
            drawWidgets();
        }
    };
    // Add the new handler for frame changes to the list of things to
    // alert to changes on the frame
    frame.addHandler(this, Frame.WidgetChange.class, frameChangeHandler);
    // A separate handler is required to take care of changes of the
    // background on the frame.
    AlertHandler frameBackgroundChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.BackgroundImageChange chg = (Frame.BackgroundImageChange) alert;
            if (chg != null) {
                // Dispose the old background image if there was one
                if (backgroundImage.getImage() != null) {
                    backgroundImage.getImage().dispose();
                }
                byte[] bgImg = frame.getBackgroundImage();
                // If the image is null, don't create it.
                if (bgImg != null) {
                    // the cache is probably out of date
                    try {
                        Image img = new Image(null, new ByteArrayInputStream(bgImg));
                        //                                AUIModel.imageCache.put(frame, img);
                        // set the new image to the background
                        backgroundImage.setImage(img);
                        // get the size of the image
                        org.eclipse.swt.graphics.Rectangle bounds = img.getBounds();
                        // resize background image with the new bounds
                        backgroundImage.setSize(bounds.width, bounds.height);
                    } catch (SWTException ex) {
                        throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
                    }
                } else {
                    // Clear the background image.
                    backgroundImage.setImage(null);
                    backgroundImage.setSize(0, 0);
                }
            }
            drawWidgets();
            // Need to raise Alert after draw widgets since
            // the alert call seems to reset the "bounds"
            raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, null));
        }
    };
    // Add this handler to the list for changes in the background image
    frame.addHandler(this, Frame.BackgroundImageChange.class, frameBackgroundChangeHandler);
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Image(org.eclipse.swt.graphics.Image) EventObject(java.util.EventObject) SWTException(org.eclipse.swt.SWTException) ByteArrayInputStream(java.io.ByteArrayInputStream) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 29 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 30 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)

Aggregations

SWTException (org.eclipse.swt.SWTException)57 Test (org.junit.Test)29 Image (org.eclipse.swt.graphics.Image)21 Rectangle (org.eclipse.swt.graphics.Rectangle)14 ImageData (org.eclipse.swt.graphics.ImageData)13 IOException (java.io.IOException)8 Region (org.eclipse.swt.graphics.Region)8 Display (org.eclipse.swt.widgets.Display)8 SWTError (org.eclipse.swt.SWTError)7 PaletteData (org.eclipse.swt.graphics.PaletteData)7 RGB (org.eclipse.swt.graphics.RGB)7 InputStream (java.io.InputStream)6 Point (org.eclipse.swt.graphics.Point)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Cursor (org.eclipse.swt.graphics.Cursor)4 ImageLoader (org.eclipse.swt.graphics.ImageLoader)4 FileDialog (org.eclipse.swt.widgets.FileDialog)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Shell (org.eclipse.swt.widgets.Shell)3