Search in sources :

Example 1 with TraversableWidget

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

the class FrameEditorUI method confirmRenameFigure.

protected void confirmRenameFigure() {
    if ((editor != null) && editor.inUse()) {
        String newTitle = editor.getText();
        editor.cleanup();
        // figure whose title is currently being edited
        IFigure figure = (IFigure) editor.getData();
        if (figure instanceof PotentialFigure) {
            if ("".equals(newTitle)) {
                // nothing to do if empty string on potential item!
                return;
            }
            GraphicalTraversableWidget<?> parent = potentialUIFig.getFigureOwner();
            TraversableWidget parentModel = (TraversableWidget) parent.getModel();
            boolean isRightPotentialFigure = (figure == potentialUIFig.getRightFigure());
            WidgetType type = null;
            AParentWidget header = null;
            SimpleWidgetGroup group = null;
            boolean isSeparator = false;
            if (parentModel instanceof MenuItem) {
                type = WidgetType.MenuItem;
                MenuItem parentItem = (MenuItem) parentModel;
                if (isRightPotentialFigure) {
                    // position of selected figure is on the right
                    // parent menuitem becomes a submenu; figure to be
                    // created becomes a child of the submenu
                    parentItem.setSubmenu(true);
                    header = parentItem;
                } else {
                    // if position is on the bottom and the parent is not a
                    // header, put the new widget in the same menu as the
                    // parent item
                    header = parentItem.getParent();
                    // previous item should hide children if it's a submenu
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                }
                if (parentModel.getWidgetType() != WidgetType.Submenu) {
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ContextMenu) {
                header = (ContextMenu) parentModel;
                type = WidgetType.MenuItem;
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof MenuHeader) {
                // and hide children of the previous header
                if (isRightPotentialFigure) {
                    type = WidgetType.Menu;
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                    group = parentModel.getParentGroup();
                } else {
                    header = (MenuHeader) parentModel;
                    type = WidgetType.MenuItem;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownItem) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    PullDownItem parentItem = (PullDownItem) parentModel;
                    header = parentItem.getParent();
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownHeader) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    header = (PullDownHeader) parentModel;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ListItem) {
                type = WidgetType.ListBoxItem;
                group = parentModel.getParentGroup();
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof GridButton) {
                type = parentModel.getWidgetType();
                group = parentModel.getParentGroup();
            }
            Rectangle r = ((PotentialFigure) figure).getUnscaledBounds();
            DoubleRectangle bounds = new DoubleRectangle(r.x, r.y, r.width, r.height);
            performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(bounds, header, type, view.isAutomaticCreation(), newTitle, group, isSeparator));
        } else {
            boolean isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            performAction(FrameEditorLID.ChangeTitleProperty, new FrameEditorUI.ActionStringParameters(newTitle, selection, isSeparator), true);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) GraphicalMenuHeader(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuHeader) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) GraphicalContextMenu(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalContextMenu) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with TraversableWidget

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

the class FrameEditorUI method moveWidgetGroup.

// moveFrameElementGroup
/**
     * Assumes gw's model is a traversable widget but not a child widget.
     */
public void moveWidgetGroup(double offsetX, double offsetY, GraphicalTraversableWidget<?> gw) {
    // No easier way to do this (hard to make getTopHeader call generic)
    TraversableWidget groupWidget = null;
    if (gw instanceof GraphicalMenuWidget<?>) {
        groupWidget = ((AMenuWidget) gw.getModel()).getTopHeader();
    } else if ((gw instanceof GraphicalListItem) || (gw instanceof GraphicalGridButton)) {
        groupWidget = (TraversableWidget) gw.getModel();
    } else {
        return;
    }
    SimpleWidgetGroup headerGroup = groupWidget.getParentGroup();
    // Ensure top-left header doesn't scroll off-screen
    groupWidget = (TraversableWidget) headerGroup.get(0);
    DoublePoint p = groupWidget.getShape().getOrigin();
    // Prevent the ability to move a widget to an origin less than 0,0
    if (offsetX + p.x < 0.0) {
        offsetX = -p.x;
    }
    if (offsetY + p.y < 0.0) {
        offsetY = -p.y;
    }
    Point newOrigin = new Point(0, 0);
    int index = 1;
    int headerCount = headerGroup.size();
    do {
        newOrigin.setLocation(PrecisionUtilities.round(p.x + offsetX), PrecisionUtilities.round(p.y + offsetY));
        frameUI.getWidgetFigure(groupWidget).setLocation(newOrigin);
        // Stop when we've moved the last header!
        if (index >= headerCount) {
            break;
        }
        groupWidget = (TraversableWidget) headerGroup.get(index++);
        p = groupWidget.getShape().getOrigin();
    } while (true);
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalMenuWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 3 with TraversableWidget

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

the class FrameEditorController method createSetRenderSkinAction.

private IListenerAction createSetRenderSkinAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.SetRenderSkinParameters p = (FrameEditorUI.SetRenderSkinParameters) prms;
            // Iterate through selected objects.
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(CHG_WIDGET_RENDERED, FrameEditorLID.SetRenderSkin);
            while (selected.hasNext()) {
                IWidget w = selected.next();
                if (w instanceof TraversableWidget) {
                    AParentWidget parent = null;
                    if (w instanceof MenuItem) {
                        parent = ((MenuItem) w).getTopHeader();
                        if (parent == null) {
                            // parent is a context menu
                            parent = ((MenuItem) w).getParent();
                        }
                    } else if (w instanceof ChildWidget) {
                        parent = ((ChildWidget) w).getParent();
                    } else if (w instanceof AParentWidget) {
                        parent = (AParentWidget) w;
                    }
                    if (parent != null) {
                        SimpleWidgetGroup group = parent.getParentGroup();
                        if (group != null) {
                            //menu header
                            renderGroup(group, p.rendered, parent.isRendered(), editSeq);
                        } else {
                            //pull down header
                            renderWidget(parent, p.rendered, parent.isRendered(), editSeq);
                            renderChildren(parent, p.rendered, parent.isRendered(), editSeq);
                        }
                    } else if (w.getParentGroup() != null) {
                        //list box item or radio button
                        renderGroup(w.getParentGroup(), p.rendered, w.isRendered(), editSeq);
                    }
                } else {
                    renderWidget(w, p.rendered, w.isRendered(), editSeq);
                }
            }
            editSeq.end();
            // Only add this edit if it is significant
            if (editSeq.isSignificant()) {
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 4 with TraversableWidget

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

the class FrameEditorController method resizeElement.

// deleteWidget
private void resizeElement(FrameElement elt, double oldResizeX, double oldResizeY, double newResizeX, double newResizeY, double ratioX, double ratioY, Set<SimpleWidgetGroup> resizedGroups, boolean childrenToo, CompoundUndoableEdit editSequence) {
    if (elt instanceof IWidget) {
        IWidget widget = (IWidget) elt;
        SimpleWidgetGroup group = widget.getParentGroup();
        if ((widget instanceof TraversableWidget) && (group != null)) {
            if (!resizedGroups.contains(group)) {
                resizeGroup(group, oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, childrenToo, editSequence);
                resizedGroups.add(group);
            }
        } else {
            // Resize the actual widget.
            resizeWidget(widget, oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, childrenToo, editSequence);
        }
    } else if (elt instanceof SimpleWidgetGroup) {
        Iterator<IWidget> widgets = ((SimpleWidgetGroup) elt).iterator();
        while (widgets.hasNext()) {
            resizeElement(widgets.next(), oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, resizedGroups, childrenToo, editSequence);
        }
    } else if (elt instanceof FrameElementGroup) {
        Iterator<FrameElement> members = ((FrameElementGroup) elt).iterator();
        while (members.hasNext()) {
            resizeElement(members.next(), oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, resizedGroups, true, editSequence);
        }
    }
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) EmptyIterator(edu.cmu.cs.hcii.cogtool.util.EmptyIterator) Iterator(java.util.Iterator) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 5 with TraversableWidget

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

the class FrameEditorMouseState method dynamicResizeWidgets.

/**
     * Utility to help with dynamic resize of selected widgets.
     *
     * @param selectedWFs the set of selected graphical widget figures
     * @param currentScaledX scaled X location of the current mouse position
     * @param currentScaledY scaled Y location of the current mouse position
     * @author mlh/alex
     */
protected void dynamicResizeWidgets(Iterator<FrameEltSelnFig<?>> selectedWFs, double currentScaledX, double currentScaledY) {
    // an origin less then 0.0,0.0
    if (currentScaledX < 0.0) {
        currentScaledX = 0.0;
    }
    if (currentScaledY < 0.0) {
        currentScaledY = 0.0;
    }
    // Deal with any anchoring issues
    if (ui.resizeHandlesUIFig.isTopLeftAnchored()) {
        switch(currentResizeHandleType) {
            case FrameEditorUI.TOP_RIGHT:
                {
                    // Cannot change Y position
                    currentScaledY = initialResizeArea.y;
                    break;
                }
            case FrameEditorUI.BOTTOM_LEFT:
                {
                    // Cannot change X position
                    currentScaledX = initialResizeArea.x;
                    break;
                }
            default:
                {
                    break;
                }
        }
        // Cannot move left of top-left
        if (currentScaledX < initialResizeArea.x) {
            currentScaledX = initialResizeArea.x;
        }
        // Cannot move above of top-left
        if (currentScaledY < initialResizeArea.y) {
            currentScaledY = initialResizeArea.y;
        }
    }
    double newWidth = Math.abs(currentScaledX - mouseFixedResizeX);
    double newHeight = Math.abs(currentScaledY - mouseFixedResizeY);
    double newLeft = Math.min(currentScaledX, mouseFixedResizeX);
    double newTop = Math.min(currentScaledY, mouseFixedResizeY);
    double ratioX = newWidth / initialResizeArea.width;
    double ratioY = newHeight / initialResizeArea.height;
    // Iterate through selected widgets
    while (selectedWFs.hasNext()) {
        FrameEltSelnFig<?> f = selectedWFs.next();
        if (f instanceof GraphicalWidget<?>) {
            GraphicalWidget<?> gw = (GraphicalWidget<?>) f;
            IWidget w = gw.getModel();
            SimpleWidgetGroup group = w.getParentGroup();
            if ((w instanceof TraversableWidget) && (group != null)) {
                dynamicResizeGroup(group, ratioX, ratioY, newLeft, newTop, false);
            } else {
                dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
            }
        } else if (f instanceof FrameEltGroupHalo) {
            dynamicResizeGroup(((FrameEltGroupHalo) f).getModel(), ratioX, ratioY, newLeft, newTop, true);
        }
    }
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)5 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)5 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)3 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)2 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)2 GraphicalGridButton (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton)2 GraphicalListItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)1 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)1 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)1 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)1 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1 PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)1 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)1