Search in sources :

Example 16 with IWidget

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

the class FrameEditorMouseState method dynamicResizeGroup.

protected void dynamicResizeGroup(Association<?> group, double ratioX, double ratioY, double newLeft, double newTop, boolean childrenToo) {
    Iterator<? extends FrameElement> groupElts = group.iterator();
    while (groupElts.hasNext()) {
        FrameElement elt = groupElts.next();
        if (elt instanceof IWidget) {
            IWidget w = (IWidget) elt;
            GraphicalWidget<?> gw = ui.frameUI.getWidgetFigure(w);
            dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
            if (childrenToo && (w instanceof AParentWidget)) {
                AParentWidget pw = (AParentWidget) w;
                SimpleWidgetGroup children = pw.getChildren();
                if (children != null) {
                    dynamicResizeGroup(children, ratioX, ratioY, newLeft, newTop, childrenToo);
                }
            }
        } else if (elt instanceof Association<?>) {
            dynamicResizeGroup((Association<?>) elt, ratioX, ratioY, newLeft, newTop, childrenToo);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) Association(edu.cmu.cs.hcii.cogtool.model.Association) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 17 with IWidget

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

the class FrameEditorMouseState method dealWithMouseReleased.

/**
     * A mouse up event was called.
     * Checks for context selection, then performs actions as dictated
     * by the FSM.
     */
@Override
protected boolean dealWithMouseReleased(IFigure figure, int button, int x, int y, int state) {
    boolean goForward = super.dealWithMouseReleased(figure, button, x, y, state);
    // Clear any mouse drag timer, that may be running
    stopMouseDragTimer = true;
    if (goForward && isMouseDownValid) {
        // Record the mouse down position
        double zoom = ui.getZoom();
        // The current mouse down position (scaled)
        double currentScaledX = x / zoom;
        double currentScaledY = y / zoom;
        switch(getMouseState()) {
            case PotentialCreatingWidget:
            case PotentialMovingWidget:
            case PotentialResizingWidget:
                {
                    // Nothing to do; any action necessary was taken on "down".
                    break;
                }
            case PotentialReorderWidget:
            case PotentialMovingSelection:
                {
                    // Get whatever graphical widget under original down x,y
                    GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
                    MoveHalo halo = null;
                    FrameElement data = null;
                    if (wf == null) {
                        halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
                        if (halo != null) {
                            data = halo.getData();
                            if (data instanceof SimpleWidgetGroup) {
                                IWidget[] widgets = selection.getSelectedIWidgets();
                                SimpleWidgetGroup group = (SimpleWidgetGroup) data;
                                for (IWidget widget : widgets) {
                                    if (widget.getParentGroup() != group) {
                                        selection.deselectElement(widget);
                                    }
                                }
                                break;
                            }
                            if (data instanceof IWidget) {
                                wf = ui.frameUI.getWidgetFigure((IWidget) data);
                            }
                        }
                    }
                    if (wf != null) {
                        selection.setSelectedSelnFig(wf);
                    } else {
                        if (halo == null) {
                            halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
                            if (halo != null) {
                                data = halo.getData();
                            }
                        }
                        if ((data != null) && (data instanceof FrameElementGroup)) {
                            selection.setSelectedSelnFig((FrameEltGroupHalo) halo);
                        }
                    }
                    break;
                }
            case PotentialTogglingSelection:
                {
                    // If mouse down on a widget, toggle selection.
                    GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
                    MoveHalo halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
                    FrameElement data = null;
                    if (halo != null) {
                        data = halo.getData();
                    }
                    if (wf == null) {
                        if (data instanceof IWidget) {
                            wf = ui.frameUI.getWidgetFigure((IWidget) data);
                        }
                    }
                    if (wf != null) {
                        // If the widget is already selected, unselect it.
                        if (selection.isSelectionFigureSelected(wf)) {
                            selection.deselectSelnFig(wf);
                        } else {
                            selection.selectSelnFig(wf);
                        }
                    } else if (data instanceof SimpleWidgetGroup) {
                        Iterator<IWidget> widgets = ((SimpleWidgetGroup) data).iterator();
                        while (widgets.hasNext()) {
                            IWidget w = widgets.next();
                            selection.deselectElement(w);
                        }
                    } else if ((halo instanceof FrameEltGroupHalo) && (data instanceof FrameElementGroup)) {
                        FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
                        if (selection.isElementSelected(data)) {
                            selection.deselectSelnFig(groupHalo);
                        } else {
                            selection.selectSelnFig(groupHalo);
                        }
                    } else {
                        selection.deselectAll();
                    }
                    break;
                }
            // Move is complete, so apply changes to the model.
            case MovingWidgets:
                {
                    // Get selection, and use the difference between current
                    // and start location.
                    double moveByX = currentScaledX - scaledMouseDownX;
                    double moveByY = currentScaledY - scaledMouseDownY;
                    FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection);
                    ui.performAction(CogToolLID.MoveWidgets, prms);
                    break;
                }
            case ReorderWidget:
                {
                    boolean reorder = reorderWidget(x, y, reorderParms);
                    ui.clearUISupport(true);
                    isReordering = false;
                    if (reorder) {
                        ui.performAction(FrameEditorLID.Reorder, reorderParms);
                    } else {
                        selection.deselectElement(lastClickedWidget);
                    }
                    InteractionDrawingEditor editor = ui.getViewEditor();
                    editor.removeInteractionFigure(reorderFigure);
                    editor.removeInteractionFigure(dividerLine);
                    break;
                }
            // since the user may have flipped the orientation.
            case ResizingWidget:
                {
                    // Switch to quality mode rendering for graphical widgets
                    setWidgetFastRenderMode(false);
                    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 width = Math.abs(currentScaledX - mouseFixedResizeX);
                    double height = Math.abs(currentScaledY - mouseFixedResizeY);
                    FrameEditorUI.ResizeParameters prms = new FrameEditorUI.ResizeParameters(initialResizeArea.x, initialResizeArea.y, Math.min(currentScaledX, mouseFixedResizeX), Math.min(currentScaledY, mouseFixedResizeY), width / initialResizeArea.width, height / initialResizeArea.height, selection);
                    ui.performAction(CogToolLID.ResizeWidgets, prms);
                    break;
                }
            // Finished a mouse drag operation to create a new widget
            case CreatingWidget:
                {
                    if (currentScaledX < 0.0) {
                        currentScaledX = 0.0;
                    }
                    if (currentScaledY < 0.0) {
                        currentScaledY = 0.0;
                    }
                    double width = Math.abs(scaledMouseDownX - currentScaledX);
                    double height = Math.abs(scaledMouseDownY - currentScaledY);
                    double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
                    double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
                    // Turn off the bounding box drawn.
                    ui.stopDrawingTemporaryFigure();
                    // Create a rectangle for the new region.
                    DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
                    // width of 0. Probably this should be less then 2.
                    if ((region.width != 0.0) && (region.height != 0.0)) {
                        ui.performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(region, ui.getCurrentWidgetType(), ui.view.isAutomaticCreation()));
                    }
                    break;
                }
            // Finished a mouse drag operation to select a set of widgets
            case TogglingSelection:
                {
                    // Get the total area selected
                    double width = Math.abs(scaledMouseDownX - currentScaledX);
                    double height = Math.abs(scaledMouseDownY - currentScaledY);
                    // Get top left point.
                    double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
                    double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
                    // Turn off the bounding box drawn.
                    ui.stopDrawingTemporaryFigure();
                    // Create the final region's area
                    DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
                    // Loop through all figures and check for intersections
                    Iterator<GraphicalWidget<?>> gwFigures = ui.getFrameUI().getFigureListIterator();
                    while (gwFigures.hasNext()) {
                        GraphicalWidget<?> gw = gwFigures.next();
                        if (!(gw instanceof GraphicalChildWidget<?, ?>)) {
                            Rectangle bounds = gw.getBounds();
                            if (region.intersects(bounds.x, bounds.y, bounds.width, bounds.height)) {
                                // If the widget is already selected, deselect it.
                                if (selection.isSelectionFigureSelected(gw)) {
                                    selection.deselectSelnFig(gw);
                                } else {
                                    selection.selectSelnFig(gw);
                                }
                            }
                        }
                    }
                    break;
                }
            case PotentialInsertDuplicateWidget:
            case PotentialDuplicatingWidget:
                {
                    GraphicalWidget<?> widgetFig = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
                    selection.setSelectedSelnFig(widgetFig);
                    break;
                }
            case DuplicatingWidgets:
                {
                    double dx = currentScaledX - scaledMouseDownX;
                    double dy = currentScaledY - scaledMouseDownY;
                    // Remove all the rectangle figures from the display, clear the list
                    clearRectFigures();
                    ui.performAction(FrameEditorLID.Duplicate, new FrameEditorUI.DuplicateParameters(dx, dy, selection));
                    break;
                }
            case InsertDuplicateWidget:
                {
                    double dx = currentScaledX - scaledMouseDownX;
                    double dy = currentScaledY - scaledMouseDownY;
                    isReordering = false;
                    if (reorderWidget(x, y, insertDuplicateParms)) {
                        insertDuplicateParms.moveByX = dx;
                        insertDuplicateParms.moveByY = dy;
                        ui.performAction(FrameEditorLID.InsertDuplicate, insertDuplicateParms);
                    } else {
                        selection.deselectElement(lastClickedWidget);
                    }
                    InteractionDrawingEditor editor = ui.getViewEditor();
                    editor.removeInteractionFigure(reorderFigure);
                    editor.removeInteractionFigure(dividerLine);
                    break;
                }
            case PotentialMovingGridButtons:
                {
                    if (movedGridButtons != null) {
                        movedGridButtons = NO_GRID_BUTTONS;
                    }
                    break;
                }
            case MovingGridButtons:
                {
                    // Get selection, and use the difference between current
                    // and start location.
                    double moveByX;
                    double moveByY;
                    GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
                    GridButton gb = (GridButton) gw.getModel();
                    DoublePoint start = gb.getShape().getOrigin();
                    if (moveIsVertical) {
                        moveByX = 0.0;
                        if (currentScaledY < minY) {
                            moveByY = (minY - start.y);
                        } else {
                            moveByY = currentScaledY - scaledMouseDownY;
                        }
                    } else {
                        moveByY = 0.0;
                        if (currentScaledX < minX) {
                            moveByX = (minX - start.x);
                        } else {
                            moveByX = currentScaledX - scaledMouseDownX;
                        }
                    }
                    if ((moveByX != 0.0) || (moveByY != 0.0)) {
                        FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection, false);
                        ui.performAction(CogToolLID.MoveWidgets, prms);
                    }
                    break;
                }
        }
        // Clear the values used.
        lastClickedWidget = null;
        isMouseDownValid = false;
        setMouseState(MouseUp);
    }
    cleanup();
    return goForward;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) InteractionDrawingEditor(edu.cmu.cs.hcii.cogtool.view.InteractionDrawingEditor) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) Iterator(java.util.Iterator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 18 with IWidget

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

the class ActionProperties method updateProperties.

public void updateProperties(TransitionDelay td, AAction action, TransitionSource transitionSource) {
    delayInSecs = td.getDelayInSecs();
    delayLabel = td.getDelayLabel();
    Transition tr = transitionSource.getTransitions().get(action);
    if (tr != null) {
        // null if self-transition
        transitionDestinationLabel = tr.getDestination().getName();
    }
    if (transitionSource instanceof IWidget) {
        // TODO: Must modify this when text fields are added.
        // Text fields may not use "ButtonAction"
        AAction.ActionVisitor widgetActionVisitor = new AAction.ActionVisitor() {

            @Override
            public void visit(ButtonAction but) {
                mouseButton = but.getButton();
                buttonAction = but.getPressType();
                if (buttonAction == MousePressType.Hover) {
                    mouseButton = null;
                }
                buttonState = but.getModifiers();
                useWhichParts = ActionProperties.USE_MOUSE;
            }

            @Override
            public void visit(TapAction tap) {
                tapAction = tap.getTapPressType();
                useWhichParts = ActionProperties.USE_TOUCHSCREEN;
            }

            @Override
            public void visit(KeyAction key) {
                keyboardString = key.getText();
                keyboardIsCmd = key.isCommand();
                keyboardAction = key.getPressType();
                useWhichParts = ActionProperties.USE_KEYBOARD;
            }

            @Override
            public void visit(GraffitiAction graffiti) {
                graffitiString = graffiti.getText();
                graffitiIsCmd = graffiti.isCommand();
                useWhichParts = ActionProperties.USE_GRAFFITI_WIDGET;
            }

            @Override
            public void visit(VoiceAction voice) {
                voiceString = voice.getText();
                voiceIsCmd = voice.isCommand();
                useWhichParts = ActionProperties.USE_VOICE;
            }
        };
        action.accept(widgetActionVisitor);
        String t = ((IWidget) transitionSource).getTitle();
        if (t.length() > 0) {
            transitionSourceLabel = t + " in " + ((IWidget) transitionSource).getFrame().getName();
        } else {
            transitionSourceLabel = ((IWidget) transitionSource).getName() + " in " + ((IWidget) transitionSource).getFrame().getName();
        }
    } else {
        InputDevice deviceSource = (InputDevice) transitionSource;
        DeviceType type = deviceSource.getDeviceType();
        if (type == DeviceType.Voice) {
            VoiceAction voiceAction = (VoiceAction) action;
            voiceString = voiceAction.getText();
            voiceIsCmd = voiceAction.isCommand();
            useWhichParts = ActionProperties.USE_VOICE;
        } else {
            KeyAction keyAction = (KeyAction) action;
            keyboardString = keyAction.getText();
            keyboardAction = keyAction.getPressType();
            keyboardIsCmd = keyAction.isCommand();
            useWhichParts = ActionProperties.USE_KEYBOARD;
        }
        transitionSourceLabel = "";
    }
}
Also used : InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) TapAction(edu.cmu.cs.hcii.cogtool.model.TapAction) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) VoiceAction(edu.cmu.cs.hcii.cogtool.model.VoiceAction) GraffitiAction(edu.cmu.cs.hcii.cogtool.model.GraffitiAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) KeyAction(edu.cmu.cs.hcii.cogtool.model.KeyAction) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 19 with IWidget

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

the class FrameEditorMouseState method reorderAllowed.

protected boolean reorderAllowed(IWidget targetWidget) {
    // Ensure the targetWidget is not a child of the last clicked widget
    while (targetWidget instanceof ChildWidget) {
        IWidget parent = ((ChildWidget) targetWidget).getParent();
        if (parent == lastClickedWidget) {
            return false;
        }
        targetWidget = parent;
    }
    return true;
}
Also used : GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 20 with IWidget

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

the class FrameEditorMouseState method reorderWidget.

protected boolean reorderWidget(int x, int y, FrameEditorUI.ReorderWidgetParameters prms) {
    GraphicalWidget<?> wf = ui.widgetLocatedAtXY(x, y);
    if ((wf == null) && withinReorder(x, y)) {
        wf = lastHoveredWidget;
    }
    prms.widgetGroup = null;
    prms.insertIndex = -1;
    prms.parent = null;
    prms.reorderWidget = lastClickedWidget;
    if (wf != null) {
        IWidget targetWidget = wf.getModel();
        if (!ui.areCompatible(lastClickedWidget, targetWidget)) {
            return false;
        }
        if (!reorderAllowed(targetWidget)) {
            return false;
        }
        prms.insertIndex = getInsertIndex(targetWidget, x, y);
        if (prms.insertIndex < 0) {
            return false;
        }
        if (lastClickedWidget instanceof ChildWidget) {
            if (targetWidget instanceof ChildWidget) {
                prms.widgetGroup = targetWidget.getParentGroup();
                prms.parent = ((ChildWidget) targetWidget).getParent();
            } else if (targetWidget instanceof AParentWidget) {
                // "else if" because only MenuItems are both, and for them
                // we want the ChildWidget behavior (to add the item to
                // a submenu, drag it over the potential figure)
                prms.parent = (AParentWidget) targetWidget;
                prms.widgetGroup = prms.parent.getChildren();
                prms.insertIndex = 0;
            }
        } else {
            // moving around menu headers or list items
            prms.widgetGroup = targetWidget.getParentGroup();
        }
        return true;
    }
    PotentialFigure pf = ui.potentialWidgetUnderXY(x, y);
    if (pf != null) {
        GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
        if (owner instanceof GraphicalMenuItem) {
            if (pf == ui.potentialUIFig.getRightFigure()) {
                prms.parent = (MenuItem) owner.getModel();
                prms.widgetGroup = prms.parent.getChildren();
                prms.insertIndex = 0;
                return true;
            }
        } else {
            if ((owner instanceof GraphicalParentWidget<?, ?>) && (pf == ui.potentialUIFig.getBottomFigure())) {
                prms.parent = (AParentWidget) owner.getModel();
                prms.widgetGroup = prms.parent.getChildren();
                prms.insertIndex = 0;
            } else {
                IWidget widget = owner.getModel();
                prms.widgetGroup = widget.getParentGroup();
                prms.insertIndex = prms.widgetGroup.indexOf(widget) + 1;
            }
            return true;
        }
    }
    // out in space
    return ((!prms.requiresTarget()) && !(lastClickedWidget instanceof ChildWidget));
}
Also used : GraphicalMenuItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)

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