Search in sources :

Example 1 with GraphicalTraversableWidget

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget 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 GraphicalTraversableWidget

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget 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 GraphicalTraversableWidget

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget in project cogtool by cogtool.

the class FrameEditorMouseState method dynamicMoveWidgets.

/**
     * Utility to help with dynamic move 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 dynamicMoveWidgets(Iterator<FrameEltSelnFig<?>> selectedFigs, double currentScaledX, double currentScaledY) {
    ui.hideNondynamicSupport(true);
    // Iterate through list of selected objects
    while (selectedFigs.hasNext()) {
        FrameEltSelnFig<?> fig = selectedFigs.next();
        // Determine movement amount from initial points.
        double offsetX = currentScaledX - scaledMouseDownX;
        double offsetY = currentScaledY - scaledMouseDownY;
        if (fig instanceof GraphicalChildWidget<?, ?>) {
            continue;
        } else if (fig instanceof FrameEltGroupHalo) {
            ui.moveFrameElementGroup(offsetX, offsetY, ((FrameEltGroupHalo) fig).getModel());
        } else if (fig instanceof GraphicalWidget<?>) {
            GraphicalWidget<?> gw = (GraphicalWidget<?>) fig;
            if ((gw instanceof GraphicalTraversableWidget<?>) && (gw.getModel().getParentGroup() != null)) {
                ui.moveWidgetGroup(offsetX, offsetY, (GraphicalTraversableWidget<?>) gw);
            } else {
                DoublePoint p = gw.getModel().getShape().getOrigin();
                double tempX = offsetX + p.x;
                double tempY = offsetY + p.y;
                // Prevent moving a widget to an origin less than 0.0,0.0
                if (tempX < 0.0) {
                    tempX = 0.0;
                }
                if (tempY < 0.0) {
                    tempY = 0.0;
                }
                // Temporarily move the widget origin to new location.
                ui.setGraphicalWidgetOrigin(tempX, tempY, gw);
            }
        }
    }
}
Also used : DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)

Example 4 with GraphicalTraversableWidget

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget in project cogtool by cogtool.

the class FrameEditorMouseState method dynamicReorderWidget.

protected void dynamicReorderWidget(int x, int y, boolean duplicate) {
    int dx = x - lastX;
    int dy = y - lastY;
    Point frameOrigin = reorderFigure.getLocation();
    frameOrigin.x += dx;
    frameOrigin.y += dy;
    reorderFigure.setLocation(frameOrigin);
    GraphicalWidget<?> curWidgetFig = ui.widgetLocatedAtXY(x, y);
    PotentialFigure potential = ui.potentialWidgetUnderXY(x, y);
    ui.resizeHandlesUIFig.hide();
    dividerLine.setVisible(false);
    if ((curWidgetFig != null) && ui.areCompatible(lastClickedWidget, curWidgetFig.getModel()) && (duplicate || reorderAllowed(curWidgetFig.getModel()))) {
        boolean isChildWidget = lastClickedWidget instanceof ChildWidget;
        boolean changedWidget = curWidgetFig.getModel() != lastClickedWidget;
        lastHoveredWidget = curWidgetFig;
        // If the dragged widget is not a child, it won't make sense to
        // drag it onto a potential figure
        // MLHQ: How do you know this cast will succeed?
        ui.hideNonhaloSupport(!isChildWidget, changedWidget, (GraphicalTraversableWidget<?>) curWidgetFig);
        setDividerBounds(curWidgetFig, x, y);
        if (lastClickedWidget instanceof ChildWidget) {
            if (curWidgetFig instanceof GraphicalChildWidget<?, ?>) {
                GraphicalChildWidget<?, ?> child = (GraphicalChildWidget<?, ?>) curWidgetFig;
                child.getParentFigure().openChildren();
            }
            if (curWidgetFig instanceof GraphicalParentWidget<?, ?>) {
                if (changedWidget) {
                    ((GraphicalParentWidget<?, ?>) curWidgetFig).openChildren();
                }
            }
        }
    } else if (potential != null) {
        GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
        if (owner instanceof GraphicalChildWidget<?, ?>) {
            ((GraphicalChildWidget<?, ?>) owner).getParentFigure().openChildren();
        }
        ui.potentialUIFig.setSelection(potential);
    } else {
        if (withinReorder(x, y)) {
            setDividerBounds(lastHoveredWidget, x, y);
            if (lastHoveredWidget instanceof GraphicalChildWidget<?, ?>) {
                GraphicalChildWidget<?, ?> gcw = (GraphicalChildWidget<?, ?>) lastHoveredWidget;
                gcw.getParentFigure().openChildren();
            }
        } else if ((lastClickedWidget instanceof ChildWidget) || !duplicate) {
            ui.hideNondynamicSupport(true, false);
            InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
            drawLayer.setCursor(NOT_ALLOWED_CURSOR);
        }
    }
}
Also used : Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure)

Aggregations

GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)2 GraphicalGridButton (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton)2 GraphicalListItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem)2 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)2 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)2 Point (org.eclipse.draw2d.geometry.Point)2 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)1 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)1 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)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 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1 PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)1