Search in sources :

Example 51 with IWidget

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

the class FrameUIModel method getLeftGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getLeftGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultX = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX < startX)) {
            if ((result == null) || (curX > resultX)) {
                result = cur;
                resultX = curX;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 52 with IWidget

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

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

the class DesignEditorFrame method addTransitionChangeHandler.

public void addTransitionChangeHandler(AlertHandler handler) {
    Iterator<IWidget> sources = frame.getWidgets().iterator();
    while (sources.hasNext()) {
        IWidget widget = sources.next();
        widget.addHandler(this, TransitionSource.TransitionChange.class, handler);
    }
    Iterator<InputDevice> devices = frame.getInputDevices().iterator();
    while (devices.hasNext()) {
        InputDevice device = devices.next();
        device.addHandler(this, TransitionSource.TransitionChange.class, handler);
    }
    transitionChangeHandler = handler;
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 54 with IWidget

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

the class DesignEditorFrame method dispose.

public void dispose() {
    frameUIModel.removeAllHandlers(this);
    frameUIModel.dispose();
    Iterator<IWidget> sources = frame.getWidgets().iterator();
    while (sources.hasNext()) {
        IWidget widget = sources.next();
        widget.removeAllHandlers(this);
    }
    Iterator<InputDevice> devices = frame.getInputDevices().iterator();
    while (devices.hasNext()) {
        InputDevice device = devices.next();
        device.removeAllHandlers(this);
    }
    frame.removeAllHandlers(this);
    // Need to dispose all InputSources that were created by this class
    Iterator<GraphicalDevice> iter = inputDevices.values().iterator();
    while (iter.hasNext()) {
        GraphicalDevice d = iter.next();
        d.dispose();
    }
}
Also used : InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 55 with IWidget

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

the class ChoiceWireRenderer method paintForeground.

public void paintForeground(Graphics g) {
    g.pushState();
    try {
        GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
        IWidget attributed = gw.getModel();
        boolean isAuto = attributed.isStandard();
        //            this.choiceFigure.paintFigure(g);
        if (kind == CHECK) {
            g.drawRectangle(choiceX, choiceY, choiceWidth - 1, choiceHeight - 1);
            if (isAuto && selected) {
                int right = choiceX + choiceWidth;
                int bottom = choiceY + choiceHeight;
                g.drawLine(choiceX, choiceY, right, bottom);
                g.drawLine(right, choiceY, choiceX, bottom);
            }
        } else {
            g.drawOval(choiceX, choiceY, choiceWidth - 1, choiceHeight - 1);
            if (isAuto && selected) {
                g.setBackgroundColor(ColorConstants.black);
                int w = PrecisionUtilities.round((choiceWidth - 1) * 0.5);
                int h = PrecisionUtilities.round((choiceHeight - 1) * 0.5);
                int x = PrecisionUtilities.round((choiceWidth - w - 1) / 2.0);
                int y = PrecisionUtilities.round((choiceHeight - h - 1) / 2.0);
                x = choiceX + x;
                y = choiceY + y;
                g.fillOval(x, y, w, h);
            }
        }
        choiceLabel.paint(g);
    } finally {
        g.popState();
    }
}
Also used : IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)93 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)29 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)20 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)19 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)15 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)15 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)12 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 Point (org.eclipse.draw2d.geometry.Point)11 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)9 HashSet (java.util.HashSet)8 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)7 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)7 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)7 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)7 Iterator (java.util.Iterator)7 EventObject (java.util.EventObject)6