Search in sources :

Example 6 with DoubleSize

use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.

the class DesignEditorUI method resetVisibleArea.

// createTransitionSelectionHandler
public void resetVisibleArea() {
    StandardDrawingEditor e = view.getEditor();
    e.getLWS().getUpdateManager().performUpdate();
    DoubleSize extent = structureView.getPreferredSize();
    e.setMinVisibleArea(PrecisionUtilities.round(extent.width), PrecisionUtilities.round(extent.height), false);
}
Also used : StandardDrawingEditor(edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 7 with DoubleSize

use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.

the class FrameUIModel method getPreferredSize.

/**
     * Compute the preferred size of the widgets based on a given scale.
     */
public DoubleSize getPreferredSize(double scaleFactor) {
    // Compute the area needed for all widgets
    Rectangle r = computeWidgetArea();
    // Add the background image area
    r.union(backgroundImage.getBounds());
    // Apply scaling to result.
    return new DoubleSize(r.width * scaleFactor, r.height * scaleFactor);
}
Also used : DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 8 with DoubleSize

use of edu.cmu.cs.hcii.cogtool.model.DoubleSize 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 9 with DoubleSize

use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.

the class DesignEditorFrame method getChildrenUtilizedAreaUnscaled.

public Rectangle getChildrenUtilizedAreaUnscaled() {
    DoubleSize size = computeFrameSize(1.0);
    int width = PrecisionUtilities.round(size.width);
    int height = PrecisionUtilities.round(size.height);
    return new Rectangle(0, 0, width, height);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 10 with DoubleSize

use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.

the class FrameEditorController method reorderWidget.

private boolean reorderWidget(final IWidget widget, final SimpleWidgetGroup newGroup, final int newIndex) {
    final SimpleWidgetGroup prevGroup = widget.getParentGroup();
    final int prevIndex = prevGroup.indexOf(widget);
    int index = newIndex;
    if (prevGroup == newGroup) {
        if (prevIndex < newIndex) {
            index--;
        }
        if (index == prevIndex) {
            return true;
        }
    }
    DoublePoint prevGroupStartPos = prevGroup.get(0).getShape().getOrigin();
    final double prevGroupStartX = prevGroupStartPos.x;
    final double prevGroupStartY = prevGroupStartPos.y;
    DoubleSize prevSize = widget.getShape().getSize();
    final double prevWidth = prevSize.width;
    final double prevHeight = prevSize.height;
    DoubleRectangle newBds = newGroup.get(0).getEltBounds();
    double heightFactor = (widget instanceof ListItem) ? getHeightFactor(widget, newGroup) : 1.0;
    final double newWidth = newBds.width;
    final double newHeight = newBds.height * heightFactor;
    final double newGroupStartX = newBds.x;
    final double newGroupStartY = newBds.y;
    Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
    final boolean groupRendered = ((Boolean) rendered).booleanValue();
    final boolean widgetRendered = widget.isRendered();
    reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
    if (widgetRendered != groupRendered) {
        widget.setRendered(groupRendered);
    }
    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {

        @Override
        public String getPresentationName() {
            return REORDER_WIDGET;
        }

        @Override
        public void redo() {
            super.redo();
            int index = newIndex;
            if (prevGroup == newGroup) {
                if (prevIndex < newIndex) {
                    index--;
                }
            }
            reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
            if (widgetRendered != groupRendered) {
                widget.setRendered(groupRendered);
            }
            noteEditCheckRegenerate(prevGroup, newGroup, this);
        }

        @Override
        public void undo() {
            super.undo();
            reorderGroupWidget(widget, prevWidth, prevHeight, prevIndex, newGroup, prevGroup, newGroupStartX, newGroupStartY, prevGroupStartX, prevGroupStartY);
            if (widgetRendered != groupRendered) {
                widget.setRendered(widgetRendered);
            }
            noteEditCheckRegenerate(newGroup, prevGroup, this);
        }
    };
    noteEditCheckRegenerate(prevGroup, newGroup, edit);
    undoMgr.addEdit(edit);
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem)

Aggregations

DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)17 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)4 StandardDrawingEditor (edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)3 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)3 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)3 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 ScalableFrameFigure (edu.cmu.cs.hcii.cogtool.view.ScalableFrameFigure)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 XYLayout (org.eclipse.draw2d.XYLayout)2 Image (org.eclipse.swt.graphics.Image)2 CogToolWorkThread (edu.cmu.cs.hcii.cogtool.CogToolWorkThread)1 AShape (edu.cmu.cs.hcii.cogtool.model.AShape)1 FrameUIModel (edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel)1 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)1 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)1