Search in sources :

Example 46 with IWidget

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

the class FrameUIModel method getNextInGroup.

public GraphicalWidget<?> getNextInGroup(GraphicalWidget<?> fromWidgetFig) {
    IWidget modelWidget = fromWidgetFig.getModel();
    SimpleWidgetGroup group = modelWidget.getParentGroup();
    if (group != null) {
        int widgetIndex = group.indexOf(modelWidget);
        if (widgetIndex < group.size() - 1) {
            return getWidgetFigure(group.get(widgetIndex + 1));
        }
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point)

Example 47 with IWidget

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

the class FrameUIModel method getLastInGroup.

public GraphicalWidget<?> getLastInGroup(GraphicalWidget<?> fromWidgetFig) {
    IWidget modelWidget = fromWidgetFig.getModel();
    SimpleWidgetGroup group = modelWidget.getParentGroup();
    if (group != null) {
        int widgetIndex = group.size() - 1;
        return getWidgetFigure(group.get(widgetIndex));
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point)

Example 48 with IWidget

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

the class FrameUIModel method getRightGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getRightGridFigure(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 49 with IWidget

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

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

the class FrameUIModel method getTopGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getTopGridFigure(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 resultY = 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(startX, curX, GridButtonGroup.PIXEL_EPSILON) && (curY < startY)) {
            if ((result == null) || (curY > resultY)) {
                result = cur;
                resultY = curY;
            }
        }
    }
    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)

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