Search in sources :

Example 1 with IFigure

use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.

the class ScalableGraphicalFigure method getChildrenUtilizedAreaUnscaled.

/**
     * Returns the area occupied by the children in UNSCALED coordinates
     */
public Rectangle getChildrenUtilizedAreaUnscaled() {
    Rectangle r = null;
    Iterator<?> iter = getChildren().iterator();
    while (iter.hasNext()) {
        IFigure fi = (IFigure) iter.next();
        if (r == null) {
            r = new Rectangle(fi.getBounds());
        } else {
            r.union(fi.getBounds());
        }
    }
    return (r == null) ? new Rectangle(0, 0, 0, 0) : r;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with IFigure

use of org.eclipse.draw2d.IFigure 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 3 with IFigure

use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.

the class DesignEditorMouseState method dealWithMouseDragged.

@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int eventX, int eventY, int state) {
    boolean goForward = super.dealWithMouseDragged(figure, button, eventX, eventY, state);
    if (goForward && mouseDown) {
        StandardDrawingEditor editor = ui.getViewEditor();
        // Update VIEW to ensure ME point is visible.
        // If outside of the visible canvas, up-click should cancel!
        stopMouseDragTimer = true;
        stopDynamic = editor.movePointNearEdge(eventX, eventY, updateDelta);
        switch(getMouseState()) {
            case PotentialMovingFrame:
            case PotentialMovingSelection:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(MovingFrames);
                // fall through!
                }
            case MovingFrames:
                {
                    updateDynamicMove(eventX, eventY, false);
                    break;
                }
            case PotentialTogglingSelection:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(TogglingSelection);
                // fall through!
                }
            case TogglingSelection:
                {
                    updateDynamicSelectionArea(eventX, eventY);
                    break;
                }
            case PotentialSelectingFrames:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(SelectingFrames);
                // fall through!
                }
            case SelectingFrames:
                {
                    updateDynamicSelectionArea(eventX, eventY);
                    break;
                }
            case PotentialCreatingTransition:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    // Do not allow transitions from menu headers or submenus
                    IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
                    if ((target instanceof GraphicalParentWidget<?, ?>) && (((GraphicalParentWidget<?, ?>) target).canHaveChildren())) {
                        break;
                    }
                    setMouseState(CreatingTransition);
                    // Ensures proper default action
                    selection.deselectAll();
                // fall through!
                }
            case CreatingTransition:
                {
                    dynamicTransition(eventX, eventY);
                    DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
                    if (targetFigure != potentialTarget) {
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(false);
                        }
                        potentialTarget = targetFigure;
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(true);
                        }
                    }
                    break;
                }
            case PotentialSelectTransition:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    handleMousePressed(StructureViewUIModel.NO_TRANSITION);
                    switch(getMouseState()) {
                        case PotentialMovingFrame:
                            {
                                setMouseState(MovingFrames);
                                updateDynamicMove(eventX, eventY, false);
                                break;
                            }
                        case PotentialSelectingFrames:
                            {
                                setMouseState(SelectingFrames);
                                updateDynamicSelectionArea(eventX, eventY);
                                break;
                            }
                        case PotentialCreatingTransition:
                            {
                                setMouseState(CreatingTransition);
                                dynamicTransition(eventX, eventY);
                                break;
                            }
                    }
                    break;
                }
            case PotentialToggleTransition:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    handleMousePressed(StructureViewUIModel.NO_TRANSITION);
                    setMouseState(TogglingSelection);
                    updateDynamicSelectionArea(eventX, eventY);
                    break;
                }
            case PotentialChangeTarget:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(ChangingTarget);
                    Point start = hitTransition.getStart();
                    hitTransition.setVisible(false);
                    double zoom = ui.getZoom();
                    double startX = start.x * zoom;
                    double startY = start.y * zoom;
                    ensureDynamicTransition(PrecisionUtilities.round(startX), PrecisionUtilities.round(startY));
                // fall through!
                }
            case ChangingTarget:
                {
                    dynamicTransitionTarget(eventX, eventY);
                    DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
                    if (targetFigure != potentialTarget) {
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(false);
                        }
                        potentialTarget = targetFigure;
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(true);
                        }
                    }
                    break;
                }
            case PotentialChangeSource:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(ChangingSource);
                    hitTransition.setVisible(false);
                    ensureDynamicTransition(mouseDownX, mouseDownY);
                    Point endPt = hitTransition.getEnd();
                    double zoom = ui.getZoom();
                    double endX = endPt.x * zoom;
                    double endY = endPt.y * zoom;
                    dynamicTransitionTarget(PrecisionUtilities.round(endX), PrecisionUtilities.round(endY));
                    break;
                }
            case ChangingSource:
                {
                    dynamicTransitionSource(eventX, eventY);
                    GraphicalSource<?> sourceFigure = ui.structureView.getSourceAtXY(eventX, eventY);
                    InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
                    if (sourceFigure != null) {
                        drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.DRAW_CURSOR));
                    } else {
                        drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
                    }
                    break;
                }
            case PotentialDuplicatingFrame:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    duplicatingDynamic = new ArrayList<RectangleFigure>();
                    //populate this from selection state
                    double zoom = ui.getZoom();
                    Iterator<DesignEditorFrame> selectedFrames = selection.getSelectedFrameFigures();
                    while (selectedFrames.hasNext()) {
                        RectangleFigure rect = new RectangleFigure();
                        DesignEditorFrame currFrame = selectedFrames.next();
                        //set size of new rectangle object
                        Rectangle frameSize = currFrame.getBounds();
                        frameSize.height = PrecisionUtilities.round(frameSize.height / zoom);
                        frameSize.width = PrecisionUtilities.round(frameSize.width / zoom);
                        frameSize.x = PrecisionUtilities.round(frameSize.x * zoom);
                        frameSize.y = PrecisionUtilities.round(frameSize.y * zoom);
                        rect.setBounds(frameSize);
                        //add new rectangle object to the array list
                        duplicatingDynamic.add(rect);
                        //display the new rectangle object
                        showSelectionArea(rect);
                    }
                    setMouseState(DuplicatingFrames);
                // fall through!
                }
            case DuplicatingFrames:
                {
                    updateDynamicDuplicate(eventX, eventY);
                    break;
                }
        }
        // Repeating timer for causing events to repeat.
        if ((updateDelta.x != 0) || (updateDelta.y != 0)) {
            if (rootFigure == null) {
                rootFigure = ui.getViewEditor().getInteractionFigure();
            }
            stopMouseDragTimer = false;
            // Determine the new point the mouse "moved" too.
            mouseDragTask.setNextMousePosition(eventX + updateDelta.x, eventY + updateDelta.y, button, state);
            // Queue the event for 0.1 sec.
            WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
        }
    }
    lastX = eventX;
    lastY = eventY;
    cleanup();
    return goForward;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) StandardDrawingEditor(edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalSource(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 4 with IFigure

use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.

the class DesignEditorMouseState method dealWithMouseDoubleClicked.

@Override
protected boolean dealWithMouseDoubleClicked(IFigure figure, int button, int x, int y, int state) {
    boolean goForward = super.dealWithMouseDoubleClicked(figure, button, x, y, state);
    ui.confirmRenameFrame();
    if (goForward) {
        IFigure target = ui.structureView.getFigureAtXY(x, y, StructureViewUIModel.FRAME_LABEL);
        if (target instanceof DesignEditorFrame.FrameLabel) {
            DesignEditorFrame.FrameLabel frameLabel = (DesignEditorFrame.FrameLabel) target;
            ui.initiateFrameRename(frameLabel.getFrameFigure());
        } else if (target instanceof DesignEditorFrame) {
            Frame frame = ((DesignEditorFrame) target).getFrame();
            ui.performAction(DesignEditorLID.EditFrame, new SingleFrameSelection(frame));
        }
    }
    setMouseState(MouseUp);
    cleanup();
    return goForward;
}
Also used : DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with IFigure

use of org.eclipse.draw2d.IFigure in project cogtool by cogtool.

the class DesignEditorUI method showContextMenu.

// Context menu stuff
@Override
public void showContextMenu(int x, int y) {
    // Check which region was hit
    IFigure fig = structureView.getFigureAtXY(x, y, StructureViewUIModel.NO_SOURCE);
    // Invocation in empty space
    if (fig == null) {
        contextSelection.deselectAll();
        showContextMenu(contextSelection, View.CONTEXT);
    } else // Invocation on a Transition
    if (fig instanceof DesignEditorTransition) {
        DesignEditorTransition transitionFig = (DesignEditorTransition) fig;
        //fig.setToolTip(null);
        if (transitionFig.isSelected()) {
            showContextMenu();
        } else {
            // Populate the context selection
            contextSelection.setSelectedTransition(transitionFig);
            showContextMenu(contextSelection, View.CONTEXT);
        }
    } else // Invocation on a Frame
    {
        // fig instanceof DesignEditorFrame
        DesignEditorFrame frameFig = (DesignEditorFrame) fig;
        if (frameFig.isSelected()) {
            // Indicate the selection to be used visually
            Iterator<DesignEditorFrame> figs = selection.getSelectedFrameFigures();
            while (figs.hasNext()) {
                frameFig = figs.next();
                frameFig.dynamicHighlight(true);
            }
            showContextMenu();
        } else {
            // Indicate the context selection visually
            frameFig.dynamicHighlight(true);
            // Populate the context selection
            contextSelection.setSelectedFrame(frameFig);
            showContextMenu(contextSelection, View.CONTEXT);
        }
        view.getEditor().getLWS().getUpdateManager().performUpdate();
    }
}
Also used : DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) Iterator(java.util.Iterator) DesignEditorTransition(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

IFigure (org.eclipse.draw2d.IFigure)440 Rectangle (org.eclipse.draw2d.geometry.Rectangle)120 Point (org.eclipse.draw2d.geometry.Point)77 Dimension (org.eclipse.draw2d.geometry.Dimension)56 Figure (org.eclipse.draw2d.Figure)38 List (java.util.List)37 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)35 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)32 Graphics (org.eclipse.draw2d.Graphics)17 Iterator (java.util.Iterator)15 ArrayList (java.util.ArrayList)14 EditPart (org.eclipse.gef.EditPart)13 StackLayout (org.eclipse.draw2d.StackLayout)12 DefaultSizeNodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure)12 NodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure)12 Insets (org.eclipse.draw2d.geometry.Insets)11 INodeFigure (org.whole.lang.ui.figures.INodeFigure)11 MarginBorder (org.eclipse.draw2d.MarginBorder)10 ToolbarLayout (org.eclipse.draw2d.ToolbarLayout)10 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)10