Search in sources :

Example 91 with IWidget

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

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

the class FrameEditorUI method updateView.

/**
     * Update the visual contents based on the selected widgets.
     */
public void updateView() {
    int selectionCount = selection.getElementSelectionCount();
    // text boxes and pull downs with values.
    if (selectionCount == 1) {
        // preserve selected state if a whole text field is selected
        Text text = WindowUtil.getFocusedText();
        boolean restoreSel = false;
        if ((text != null) && (text.getSelectionCount() == text.getCharCount())) {
            restoreSel = true;
        }
        // get the selected item
        Iterator<FrameElement> iter = selection.getSelectedElementsIterator();
        // For each selected object, which there is only one.
        FrameElement elt = iter.next();
        if (elt instanceof IWidget) {
            IWidget widget = (IWidget) elt;
            view.useParameters(FrameEditorView.USE_SINGLE_SELECT);
            view.updateWidgetProperties(widget);
        } else if (elt instanceof FrameElementGroup) {
            FrameElementGroup eltGroup = (FrameElementGroup) elt;
            view.useParameters(FrameEditorView.USE_GROUP_SELECT);
            view.updateEltGroupProperties(eltGroup);
        }
        // Restore the selection state
        if (restoreSel) {
            text.selectAll();
        }
    } else if (selectionCount > 1) {
        // TODO: on multi selection, some values are left enabled
        // We need to set these to something or disable them.
        view.useParameters(FrameEditorView.USE_MULTI_SELECT);
    } else {
        view.useParameters(FrameEditorView.USE_NONE);
        view.updateFrameProperties(frame, false);
    }
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) Text(org.eclipse.swt.widgets.Text) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 93 with IWidget

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

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