Search in sources :

Example 6 with SimpleWidgetGroup

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

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

the class FrameEditorUI method removeHalo.

// addSelectionChangeListeners
// TODO: Currently works only for IWidget
protected void removeHalo(IWidget w) {
    MoveHalo halo = halosUIFig.getMoveHalo(w);
    if (halo != null) {
        SimpleWidgetGroup group = w.getParentGroup();
        if (group != null) {
            IWidget[] widgets = selection.getSelectedIWidgets();
            // Avoid removing if another sibling/cousin is selected
            for (IWidget widget : widgets) {
                if ((widget.getParentGroup() == group) && (widget != w)) {
                    return;
                }
            }
        }
        halosUIFig.hideHalo(halo);
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 8 with SimpleWidgetGroup

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

the class FrameEditorUI method addWidgetShapeChangeHandler.

/**
     * Registers a listener that redraws the frame in response to changes in
     * the appearance of widgets
     *
     * When this event occurs, resize handles are redrawn, the window's size is
     * recomputed, and the display updated.
     *
     */
protected void addWidgetShapeChangeHandler() {
    AlertHandler widgetTitleChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameUIModel.WidgetTitleChange chg = (FrameUIModel.WidgetTitleChange) alert;
            // selected widget
            if (selection.getElementSelectionCount() == 1) {
                FrameElement elt = selection.getSelectedIFrameElements()[0];
                if (chg.widget == elt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR)) {
                    view.setRemoteLabelText(chg.widget.getTitle());
                }
            }
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetTitleChange.class, widgetTitleChangeHandler);
    AlertHandler widgetShapeChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            delayedRepainting.requestRepaint(SHAPE_CHANGE_REPAINT);
        // a FULL repaint is probably not needed
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetShapeImageChange.class, widgetShapeChangeHandler);
    AlertHandler widgetGroupChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameUIModel.WidgetGroupChange evt = (FrameUIModel.WidgetGroupChange) alert;
            if (evt.isAdd) {
                GraphicalWidget<?> gw = frameUI.getWidgetFigure(evt.widget);
                delayedWidgetSelection.addToSelection(evt.widget, gw);
            } else {
                delayedWidgetSelection.removeFromSelection(evt.widget);
                SimpleWidgetGroup group = evt.widget.getParentGroup();
                if (group.size() == 0) {
                    //evt.widget was the last widget in this group,
                    //so hide the halo for it
                    removeHalo(evt.widget);
                }
            }
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetGroupChange.class, widgetGroupChangeHandler);
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameUIModel(edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) EventObject(java.util.EventObject)

Example 9 with SimpleWidgetGroup

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

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

the class FrameEditorUI method moveHaloUnderXY.

/**
     * Find a move halo at x, y
     */
public MoveHalo moveHaloUnderXY(int x, int y) {
    MoveHalo halo = view.moveHaloUnderXY(x, y);
    if (halo != null) {
        GraphicalWidget<?> clickedFigure = widgetLocatedAtXY(x, y);
        if (clickedFigure != null) {
            SimpleWidgetGroup group;
            IWidget haloWidget;
            FrameElement data = halo.getData();
            if (data instanceof IWidget) {
                haloWidget = (IWidget) data;
                group = haloWidget.getParentGroup();
            } else if (data instanceof SimpleWidgetGroup) {
                group = (SimpleWidgetGroup) data;
                haloWidget = group.get(0);
            } else {
                return halo;
            }
            IWidget clickedWidget = clickedFigure.getModel();
            if ((group != null) && (group.contains(clickedWidget))) {
                return null;
            }
            int haloLevel = haloWidget.getLevel();
            int clickedLevel = clickedWidget.getLevel();
            if (haloLevel < clickedLevel) {
                return null;
            }
        }
        return halo;
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)45 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)32 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)16 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)14 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)13 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)10 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 HashSet (java.util.HashSet)8 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)7 Point (org.eclipse.draw2d.geometry.Point)7 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)6 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)6 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)6 Iterator (java.util.Iterator)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)5 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)4 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)4 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)4 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)4