Search in sources :

Example 21 with IWidget

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

the class FrameEditorMouseState method setDividerBounds.

// dynamicMoveWidgets
protected void setDividerBounds(GraphicalWidget<?> widget, int x, int y) {
    double zoom = ui.getZoom();
    Rectangle bounds = widget.getBounds();
    int originX = bounds.x + (bounds.width / 2);
    int originY = bounds.y + (bounds.height / 2);
    originX = PrecisionUtilities.round(originX * zoom);
    originY = PrecisionUtilities.round(originY * zoom);
    double newX = bounds.x;
    double newY = bounds.y;
    double newH = bounds.height;
    double newW = bounds.width;
    int heightInc = 0;
    int widthInc = 0;
    if ((lastClickedWidget instanceof ChildWidget) && (widget instanceof GraphicalParentWidget<?, ?>) && (!(widget instanceof GraphicalMenuItem))) {
        AParentWidget parent = (AParentWidget) widget.getModel();
        int childrenLoc = parent.getChildrenLocation();
        switch(childrenLoc) {
            case AParentWidget.CHILDREN_BELOW:
            case AParentWidget.CHILDREN_CENTER:
                {
                    if (childrenLoc == AParentWidget.CHILDREN_CENTER) {
                        newX += newW / 2.0;
                        newY += newH / 2.0;
                    } else {
                        newY += newH;
                    }
                    if (parent.hasChildren()) {
                        IWidget child = parent.getItem(0);
                        DoubleSize childSize = child.getShape().getSize();
                        newW = childSize.width;
                        newH = childSize.height;
                        Object value = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
                        if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value)) {
                            newH *= FrameEditorUI.SEPARATOR_RATIO;
                        }
                    } else if (parent instanceof MenuHeader) {
                        newW *= FrameEditorUI.MENU_ITEM_RATIO;
                    }
                    newH /= 10.0;
                    newY -= newH / 2.0;
                    heightInc = 1;
                    break;
                }
            case AParentWidget.CHILDREN_RIGHT:
                {
                    newX += newW;
                    if (parent.hasChildren()) {
                        DoubleSize childSize = parent.getItem(0).getShape().getSize();
                        newW = childSize.width;
                        newH = childSize.height;
                    }
                    newW /= 20.0;
                    newX -= newW / 2.0;
                    widthInc = 1;
                    break;
                }
        }
    } else {
        switch(widget.getModel().getParentGroup().getOrientation()) {
            case SimpleWidgetGroup.HORIZONTAL:
                {
                    if (x > originX) {
                        newX += newW;
                    }
                    newW /= 20.0;
                    newX -= newW / 2.0;
                    widthInc = 1;
                    break;
                }
            case SimpleWidgetGroup.VERTICAL:
                {
                    if (y > originY) {
                        newY += newH;
                    }
                    newH /= 10.0;
                    Object value = widget.getModel().getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
                    if (WidgetAttributes.IS_SEPARATOR.equals(value)) {
                        newH *= FrameEditorUI.SEPARATOR_RATIO;
                    }
                    newY -= newH / 2.0;
                    heightInc = 1;
                    break;
                }
        }
    }
    newX *= zoom;
    newY *= zoom;
    double rightX = newX + (newW + widthInc) * zoom;
    double bottomY = newY + (newH + heightInc) * zoom;
    newW = PrecisionUtilities.round(rightX - newX);
    newH = PrecisionUtilities.round(bottomY - newY);
    newX = PrecisionUtilities.round(newX);
    newY = PrecisionUtilities.round(newY);
    dividerLine.setBounds(new Rectangle((int) newX, (int) newY, (int) newW, (int) newH));
    dividerLine.setVisible(true);
}
Also used : GraphicalMenuItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 22 with IWidget

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

the class FrameEditorController method getHeightFactor.

private double getHeightFactor(IWidget widget, SimpleWidgetGroup newGroup) {
    double heightFactor = 1.0;
    IWidget newWidget = null;
    if (newGroup != null) {
        if (newGroup.size() > 0) {
            newWidget = newGroup.get(0);
        }
        if (newWidget != null) {
            Object isSep = newWidget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
            if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
                heightFactor *= FrameEditorUI.SEPARATOR_RATIO;
            }
        }
    }
    Object isSep = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
    if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
        heightFactor *= 1.0 / FrameEditorUI.SEPARATOR_RATIO;
    }
    return heightFactor;
}
Also used : IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 23 with IWidget

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

the class FrameEditorController method sortSelectedMbrs.

private Iterator<IWidget> sortSelectedMbrs(SimpleWidgetGroup group, FrameEditorSelectionState s) {
    Set<IWidget> sortingSet = new TreeSet<IWidget>(groupMemberComparator);
    Iterator<IWidget> groupMbrs = group.iterator();
    while (groupMbrs.hasNext()) {
        IWidget member = groupMbrs.next();
        if ((s == null) || s.isElementSelected(member)) {
            sortingSet.add(member);
        }
    }
    return sortingSet.iterator();
}
Also used : TreeSet(java.util.TreeSet) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 24 with IWidget

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

the class FrameEditorController method createInitiateRenameAction.

private IListenerAction createInitiateRenameAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            int selectedWidgetCount = selection.getWidgetSelectionCount();
            if (selectedWidgetCount == 1) {
                IWidget w = selection.getSelectedIWidgets()[0];
                ui.initiateWidgetRename(w);
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 25 with IWidget

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

the class FrameEditorController method renderUnRenderAll.

public static void renderUnRenderAll(Design d, boolean render, CogToolLID lid, UndoManager mgr) {
    CompoundUndoableEdit edits = new CompoundUndoableEdit((render ? RENDER_ALL : UN_RENDER), lid);
    for (Frame f : d.getFrames()) {
        for (IWidget w : f.getWidgets()) {
            renderWidget(w, render, w.isRendered(), edits);
        }
    }
    edits.end();
    if (edits.isSignificant()) {
        mgr.addEdit(edits);
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

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