Search in sources :

Example 6 with GraphicalWidget

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

Example 7 with GraphicalWidget

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

the class FrameEditorUI method addFrameWidgetHandler.

/**
     * Registers a listener that adjusts selection state in response to
     * widget additions or removals
     */
protected void addFrameWidgetHandler() {
    AlertHandler frameWidgetHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.WidgetChange chg = (Frame.WidgetChange) alert;
            IWidget chgWidget = chg.getChangeElement();
            if (chg != null) {
                // Check what action was performed
                switch(chg.action) {
                    // Switch the selection to the newly-added widget
                    case Frame.WidgetChange.ELEMENT_ADD:
                        {
                            GraphicalWidget<?> gw = frameUI.getWidgetFigure(chgWidget);
                            gw.addChangeHandler(widgetChangeHandler, Widget.WidgetChange.class);
                            gw.addChangeHandler(widgetChangeHandler, IAttributed.AttributeChange.class);
                            gw.addChangeHandler(widgetChangeHandler, IAttributed.AuthorityChange.class);
                            delayedWidgetSelection.addToSelection(chgWidget, gw);
                            view.requestRename();
                            break;
                        }
                    // Reflect the change in selection state
                    case Frame.WidgetChange.ELEMENT_DELETE:
                        {
                            // Cannot depend on the frameUI to have removed
                            // this widget's graphical version.
                            // Call deselect with the model itself.
                            selection.deselectElement(chgWidget);
                            delayedWidgetSelection.removeFromSelection(chgWidget);
                            // call to clean up any resize handles.
                            delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
                            break;
                        }
                }
            }
        }
    };
    frame.addHandler(this, Frame.WidgetChange.class, frameWidgetHandler);
    AlertHandler frameEltHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
        }
    };
    // Do the above for both widget and association changes!
    frame.addHandler(this, Frame.ElementChange.class, frameEltHandler);
    AlertHandler frameAssocHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.FrameEltGrpChange chg = (Frame.FrameEltGrpChange) alert;
            if (chg.action == Frame.FrameEltGrpChange.ELEMENT_DELETE) {
                selection.deselectElement(chg.getChangeElement());
            } else if (chg.action == Frame.FrameEltGrpChange.ELEMENT_ADD) {
                selection.setSelectedSelnFig(uiModel.getGroupHalo(chg.getChangeElement()));
            }
        }
    };
    frame.addHandler(this, Frame.FrameEltGrpChange.class, frameAssocHandler);
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) EventObject(java.util.EventObject) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 8 with GraphicalWidget

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

the class FrameEditorUI method setUpDropImageSupport.

protected void setUpDropImageSupport(final Canvas editorSubstrate) {
    ExternalImageDropTarget dropTarget = new ExternalImageDropTarget() {

        protected GraphicalWidget<?> dropTargetWidget = null;

        @Override
        protected void cancelHighlight(DropTargetEvent evt) {
            if (dropTargetWidget != null) {
                dropTargetWidget.dynamicHighlight(false);
            }
        }

        @Override
        protected void highlight(DropTargetEvent evt) {
            org.eclipse.swt.graphics.Point pt = editorSubstrate.toControl(evt.x, evt.y);
            GraphicalWidget<?> widgetFig = widgetLocatedAtXY(pt.x, pt.y);
            if (dropTargetWidget != widgetFig) {
                cancelHighlight(evt);
                if (widgetFig != null) {
                    widgetFig.dynamicHighlight(true);
                }
                dropTargetWidget = widgetFig;
            }
        }

        @Override
        protected Object buildParameters(DropTargetEvent evt, byte[] imgData) {
            org.eclipse.swt.graphics.Point pt = editorSubstrate.toControl(evt.x, evt.y);
            GraphicalWidget<?> widgetFig = widgetLocatedAtXY(pt.x, pt.y);
            IWidget selectedWidget = (widgetFig != null) ? widgetFig.getModel() : null;
            return new FrameEditorUI.CopyImageAsBackgroundParms(imgData, selectedWidget);
        }
    };
    setUpDropImage(editorSubstrate, dropTarget);
}
Also used : DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)8 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)5 FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 EventObject (java.util.EventObject)3 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)2 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)2 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)2 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)2 GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)2 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)2 Iterator (java.util.Iterator)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)1 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)1 FrameEltSelnFig (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig)1 InteractionDrawingEditor (edu.cmu.cs.hcii.cogtool.view.InteractionDrawingEditor)1