Search in sources :

Example 1 with XYLayout

use of org.eclipse.draw2d.XYLayout in project cogtool by cogtool.

the class StructureViewUIModel method setUpContents.

protected void setUpContents() {
    contents = new ScalableFrameFigure(GraphicsUtil.defaultWidgetColor);
    contents.setScale(1.0);
    contents.setLayoutManager(new XYLayout());
    installFrames();
    // Resize to preferred size.
    DoubleSize s = getPreferredSize();
    contents.setSize(PrecisionUtilities.round(s.width), PrecisionUtilities.round(s.height));
}
Also used : XYLayout(org.eclipse.draw2d.XYLayout) ScalableFrameFigure(edu.cmu.cs.hcii.cogtool.view.ScalableFrameFigure) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 2 with XYLayout

use of org.eclipse.draw2d.XYLayout 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)

Aggregations

DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)2 ScalableFrameFigure (edu.cmu.cs.hcii.cogtool.view.ScalableFrameFigure)2 XYLayout (org.eclipse.draw2d.XYLayout)2 CogToolWorkThread (edu.cmu.cs.hcii.cogtool.CogToolWorkThread)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)1 ThreadManager (edu.cmu.cs.hcii.cogtool.util.ThreadManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ImageFigure (org.eclipse.draw2d.ImageFigure)1 SWTException (org.eclipse.swt.SWTException)1 Image (org.eclipse.swt.graphics.Image)1