Search in sources :

Example 11 with ChildWidget

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

the class FrameEditorController method assignActions.

/**
     * Add the listeners for Menu Items, and other LID listeners
     */
@Override
public void assignActions() {
    // get the default actions from Default controller
    super.assignActions();
    // Enable undo & redo
    ui.setAction(FrameEditorLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(FrameEditorLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    // Enable cut copy and paste
    ui.setAction(FrameEditorLID.Paste, createPasteAction());
    ui.setAction(FrameEditorLID.SetFrameTemplate, createSetFrameTemplateAction());
    ui.setAction(FrameEditorLID.ClearFrameTemplate, new AListenerAction() {

        public boolean performAction(Object prms) {
            FrameTemplateSupport.clearFrameTemplate(design);
            return true;
        }
    });
    ui.setAction(FrameEditorLID.Copy, createCopyWidgetAction());
    ui.setAction(FrameEditorLID.Cut, createCutWidgetAction());
    ui.setAction(CogToolLID.CopyPath, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState seln = (FrameEditorSelectionState) prms;
            if (seln.getWidgetSelectionCount() != 1) {
                return false;
            }
            IWidget w = seln.getSelectedIWidgets()[0];
            Object pathObj = w.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
            if (!NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
                ClipboardUtil.copyTextData((String) pathObj);
            }
            return true;
        }
    });
    ui.setAction(FrameEditorLID.Rename, createInitiateRenameAction());
    ui.setAction(FrameEditorLID.Relabel, createInitiateRelabelAction());
    // Select all.
    ui.setAction(FrameEditorLID.SelectAll, new AListenerAction() {

        public boolean performAction(Object prms) {
            ui.selectAllWidgets();
            return true;
        }
    });
    // Creating a new widget
    // May be called from the menu item, or from mouseState
    ui.setAction(FrameEditorLID.NewWidget, createNewWidgetAction());
    ui.setAction(FrameEditorLID.NewWidgetJustWarn, createNewWidgetExplanationAction());
    // Delete an item.
    // Requires a selection state
    ui.setAction(FrameEditorLID.Delete, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Delete the item / add undo
            return deleteElements(selection);
        }
    });
    // Adjust image/color properties
    ui.setAction(FrameEditorLID.SetBackgroundImage, createSetBackgroundImageAction());
    // Clear the background of an image.
    ui.setAction(FrameEditorLID.RemoveBackgroundImage, new AListenerAction() {

        public boolean performAction(Object prms) {
            // Clear background, by saying use
            // "no" image.
            setBackgroundImage(null, WidgetAttributes.NO_IMAGE);
            return true;
        }
    });
    ui.setAction(FrameEditorLID.CopyImageAsBackground, createCopyImageAsBkgAction());
    ui.setAction(FrameEditorLID.PasteBackgroundImage, createPasteBackgroundImageAction());
    // Set the color of the widgets.
    ui.setAction(FrameEditorLID.SetWidgetColor, newSetWidgetColorAction());
    // Skins!
    ui.setAction(FrameEditorLID.SkinWireFrame, createSetSkinAction(SkinType.WireFrame, FrameEditorLID.SkinWireFrame));
    ui.setAction(FrameEditorLID.SkinMacOSX, createSetSkinAction(SkinType.MacOSX, FrameEditorLID.SkinMacOSX));
    ui.setAction(FrameEditorLID.SkinWinXP, createSetSkinAction(SkinType.WinXP, FrameEditorLID.SkinWinXP));
    ui.setAction(FrameEditorLID.SkinPalm, createSetSkinAction(SkinType.Palm, FrameEditorLID.SkinPalm));
    ui.setAction(CogToolLID.RenderAll, createRenderAllAction(true, CogToolLID.RenderAll));
    ui.setAction(CogToolLID.UnRender, createRenderAllAction(false, CogToolLID.UnRender));
    // Nudge selected widget(s)
    // requires selection
    ui.setAction(FrameEditorLID.NudgeLeft, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Displace left by 1 pixel scaled by
            // the zoom
            double dx = -1.0 / ui.getZoom();
            // Move by the point
            return moveElements(selection, dx, 0.0);
        }
    });
    ui.setAction(FrameEditorLID.NudgeRight, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Move by 1 pixel scaled by zoom right.
            double dx = 1.0 / ui.getZoom();
            return moveElements(selection, dx, 0.0);
        }
    });
    ui.setAction(FrameEditorLID.NudgeUp, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Move up 1 pixel scaled by zoom
            double dy = -1.0 / ui.getZoom();
            return moveElements(selection, 0.0, dy);
        }
    });
    ui.setAction(FrameEditorLID.NudgeDown, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // move down by 1 pixel scaled by zoom
            double dy = 1.0 / ui.getZoom();
            return moveElements(selection, 0.0, dy);
        }
    });
    // Align selected widgets
    ui.setAction(FrameEditorLID.AlignTop, new ElementAlignmentAction(AlignmentAction.TOP));
    ui.setAction(FrameEditorLID.AlignBottom, new ElementAlignmentAction(AlignmentAction.BOTTOM));
    ui.setAction(FrameEditorLID.AlignLeft, new ElementAlignmentAction(AlignmentAction.LEFT));
    ui.setAction(FrameEditorLID.AlignRight, new ElementAlignmentAction(AlignmentAction.RIGHT));
    ui.setAction(FrameEditorLID.AlignCenter, new ElementAlignmentAction(AlignmentAction.CENTER));
    ui.setAction(FrameEditorLID.AlignHorizCenter, new ElementAlignmentAction(AlignmentAction.HORIZ_CENTER));
    ui.setAction(FrameEditorLID.AlignVertCenter, new ElementAlignmentAction(AlignmentAction.VERT_CENTER));
    // Space selected widgets equally
    ui.setAction(FrameEditorLID.SpaceVertically, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Equally space the widgets in the
            // vertical axis.
            final boolean VERTICAL = true;
            return spaceElementsEqually(selection, VERTICAL);
        }
    });
    ui.setAction(FrameEditorLID.SpaceHorizontally, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Equally space the widgets in the
            // horizontal axis.
            final boolean HORIZONTAL = false;
            return spaceElementsEqually(selection, HORIZONTAL);
        }
    });
    // Adjust ordering of selected widget(s)
    ui.setAction(FrameEditorLID.BringToFront, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(BRING_TO_FRONT, FrameEditorLID.BringToFront);
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Get the list of selected widgets
            // Keep them in the same level ordering
            // they started in
            IWidget[] selected = getSelectedWidgets(selection, Widget.WidgetLevelComparator.ONLY);
            // set the level.
            for (IWidget element : selected) {
                // use MAX Value here
                // adjustWidgetLevel will tell the frame
                // and it will change MAX_VALUE to
                // be the correct number
                adjustWidgetLevel(Integer.MAX_VALUE, element, editSequence, editSequence.getLID());
            }
            editSequence.end();
            // Only add this edit if it is significant
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    });
    ui.setAction(FrameEditorLID.BringForward, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(BRING_FORWARD, FrameEditorLID.BringForward);
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Get the list of selected widgets
            // Keep them in the same level ordering
            // they started in
            IWidget[] selected = getSelectedWidgets(selection, Widget.WidgetLevelComparator.ONLY);
            // Fix corner case where all the widgets are
            // stacked downward from the top
            // IE: Prevent the current top most item
            // from moving.
            int maxLevel = model.getWidgets().size() - 1;
            // Traverse the list sorted by level in reverse order
            for (int i = selected.length - 1; i >= 0; i--, maxLevel--) {
                IWidget w = selected[i];
                int widgetLevel = w.getLevel();
                // try to increase it one.
                if (widgetLevel < maxLevel) {
                    adjustWidgetLevel(widgetLevel + 1, w, editSequence, editSequence.getLID());
                }
            }
            editSequence.end();
            // Only add this edit if it is significant
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    });
    ui.setAction(FrameEditorLID.SendBackward, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(SEND_BACKWARD, FrameEditorLID.SendBackward);
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Get the list of selected widgets
            // Keep them in the same level ordering
            // they started in
            IWidget[] selected = getSelectedWidgets(selection, Widget.WidgetLevelComparator.ONLY);
            // Fix corner case where all the widgets are
            // stacked upward from level 0
            int minLevel = 0;
            for (int i = 0; i < selected.length; i++, minLevel++) {
                IWidget w = selected[i];
                int widgetLevel = w.getLevel();
                // move the level down by 1
                if (widgetLevel > minLevel) {
                    adjustWidgetLevel(widgetLevel - 1, w, editSequence, editSequence.getLID());
                }
            }
            editSequence.end();
            // Only add this edit if it is significant
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    });
    ui.setAction(FrameEditorLID.SendToBack, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(SEND_TO_BACK, FrameEditorLID.SendToBack);
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Get the list of selected widgets
            // Keep them in the same level ordering
            // they started in
            IWidget[] selected = getSelectedWidgets(selection, Widget.WidgetLevelComparator.ONLY);
            // in the correct order
            for (int i = selected.length - 1; i >= 0; i--) {
                // try to move all towards 0.
                adjustWidgetLevel(0, selected[i], editSequence, editSequence.getLID());
            }
            editSequence.end();
            // Only add this edit if it is significant
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    });
    // Mouse operations on widgets
    ui.setAction(FrameEditorLID.MoveWidgets, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.MoveParameters.class;
        }

        public boolean performAction(Object prms) {
            // Get the move parameters.
            FrameEditorUI.MoveParameters movePrms = (FrameEditorUI.MoveParameters) prms;
            if (movePrms != null) {
                return moveElements(movePrms.selection, movePrms.moveByX, movePrms.moveByY, movePrms.moveAsGroup);
            }
            return false;
        }
    });
    ui.setAction(FrameEditorLID.Reorder, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.ReorderWidgetParameters.class;
        }

        public boolean performAction(Object prms) {
            // Get the parameters.
            FrameEditorUI.ReorderWidgetParameters rPrms = (FrameEditorUI.ReorderWidgetParameters) prms;
            if (rPrms != null) {
                if (rPrms.parent == null) {
                    return reorderWidget(rPrms.reorderWidget, rPrms.widgetGroup, rPrms.insertIndex);
                }
                return reorderChildWidget((ChildWidget) rPrms.reorderWidget, rPrms.widgetGroup, rPrms.insertIndex, rPrms.parent);
            }
            return false;
        }
    });
    ui.setAction(FrameEditorLID.InsertDuplicate, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.InsertDuplicateParameters.class;
        }

        public boolean performAction(Object prms) {
            // Get the parameters.
            FrameEditorUI.InsertDuplicateParameters iPrms = (FrameEditorUI.InsertDuplicateParameters) prms;
            if (iPrms != null) {
                return insertDuplicateWidget(iPrms.reorderWidget, iPrms.widgetGroup, iPrms.insertIndex, iPrms.parent, iPrms.moveByX, iPrms.moveByY);
            }
            return false;
        }
    });
    ui.setAction(FrameEditorLID.ResizeWidgets, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.ResizeParameters.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.ResizeParameters resizePrms = (FrameEditorUI.ResizeParameters) prms;
            if (prms != null) {
                // Resize the frame elements based on prms
                return resizeElements(resizePrms.oldX, resizePrms.oldY, resizePrms.newX, resizePrms.newY, resizePrms.ratioX, resizePrms.ratioY, resizePrms.selection);
            }
            return false;
        }
    });
    // Change properties of selected widget(s)
    ui.setAction(FrameEditorLID.ChangeShapeProperty, createChangeShapeAction());
    // Change the widget title.
    // The title is non unique.
    ui.setAction(FrameEditorLID.ChangeTitleProperty, createChangeTitlePropertyAction());
    ui.setAction(FrameEditorLID.ChangeAuxTextProperty, createChangeAuxTextPropertyAction());
    // Change the name. This requires a UNIQUE name.
    // Only one selected widget is expected.
    ui.setAction(DesignEditorLID.RenameFrame, new IListenerAction() {

        public Class<?> getParameterClass() {
            return DesignEditorUI.FrameRenameParameters.class;
        }

        public boolean performAction(Object prms) {
            DesignEditorUI.FrameRenameParameters p = (DesignEditorUI.FrameRenameParameters) prms;
            return updateFrameName(p.frame, p.newName);
        }
    });
    // Change the name. This requires a UNIQUE name.
    // Only one selected widget is expected.
    ui.setAction(FrameEditorLID.ChangeNameProperty, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.ActionStringParameters.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.ActionStringParameters p = (FrameEditorUI.ActionStringParameters) prms;
            // Check selection count
            int numWidgets = p.selection.getWidgetSelectionCount();
            if (numWidgets == 0) {
                interaction.protestNoSelection();
            } else if (numWidgets > 1) {
                interaction.protestTooManyWidgets();
            } else {
                IWidget[] selectedWidget = p.selection.getSelectedIWidgets();
                // Update widget's name
                return updateWidgetName(selectedWidget[0], p.newString);
            }
            return false;
        }
    });
    // Change the type of the widget.
    // TODO: this needs to be extended to invalidate transitions (e.g., if changed to Noninteractive)
    ui.setAction(FrameEditorLID.ChangeTypeProperty, createChangeTypeAction());
    ui.setAction(FrameEditorLID.SetRenderSkin, createSetRenderSkinAction());
    // Set the widget image property.
    ui.setAction(FrameEditorLID.SetImageProperty, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            // Apply to all selected items.
            Iterator<IWidget> selected = selection.getSelectedWidgetsIterator();
            // Prompt user for the new file
            String imageURL = interaction.selectImageFile();
            // Check if the user canceled the dialog
            if (imageURL != null) {
                try {
                    byte[] imageData = GraphicsUtil.loadImageFromFile(imageURL);
                    setWidgetImages(selected, imageData, imageURL);
                    return true;
                } catch (IOException e) {
                    // Tell the user if there was a
                    // problem reading the file.
                    interaction.protestUnreadableFile();
                }
            }
            return false;
        }
    });
    // Clear the image stored on a widget.
    ui.setAction(FrameEditorLID.RemoveImageProperty, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorSelectionState.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            Iterator<IWidget> selected = selection.getSelectedWidgetsIterator();
            // Remove all the images
            setWidgetImages(selected, null, WidgetAttributes.NO_IMAGE);
            return true;
        }
    });
    // capture the image under a widget..
    // IE: get its background.
    ui.setAction(FrameEditorLID.CaptureImageProperty, captureImageAction());
    ui.setAction(FrameEditorLID.Duplicate, duplicateWidgetsAction());
    ui.setAction(CogToolLID.SetAttribute, new IListenerAction() {

        public Class<?> getParameterClass() {
            return UI.SetAttributeParameters.class;
        }

        public boolean performAction(Object prms) {
            UI.SetAttributeParameters saprms = (UI.SetAttributeParameters) prms;
            return frameSetAttribute(saprms.target, saprms.attrName, saprms.value, undoMgr);
        }
    });
    ui.setAction(FrameEditorLID.SetSpeakerText, new IListenerAction() {

        public Class<?> getParameterClass() {
            return String.class;
        }

        public boolean performAction(Object prms) {
            return setSpeakerText((String) prms);
        }
    });
    ui.setAction(FrameEditorLID.SetSpeakerTime, new IListenerAction() {

        public Class<?> getParameterClass() {
            return Double.class;
        }

        public boolean performAction(Object prms) {
            double newTime = ((Double) prms).doubleValue();
            return setSpeakerDuration(newTime);
        }
    });
    ui.setAction(FrameEditorLID.AddDesignDevices, new AListenerAction() {

        public boolean performAction(Object prms) {
            return DesignCmd.addDevices(project, design, interaction);
        }
    });
    ui.setAction(FrameEditorLID.Group, createGroupElementsAction());
    ui.setAction(FrameEditorLID.Ungroup, createUngroupElementsAction());
    ui.setAction(FrameEditorLID.RenameEltGroup, new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.EltGroupRenameParameters.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.EltGroupRenameParameters p = (FrameEditorUI.EltGroupRenameParameters) prms;
            return renameEltGroup(p.eltGroup, p.newName);
        }
    });
    ui.setAction(FrameEditorLID.SetRemoteLabelText, createSetRemoteLabelTextAction());
    ui.setAction(FrameEditorLID.SetRemoteLabelType, createSetRemoteLabelTypeAction());
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) UI(edu.cmu.cs.hcii.cogtool.ui.UI) ZoomableUI(edu.cmu.cs.hcii.cogtool.ui.ZoomableUI) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) EmptyIterator(edu.cmu.cs.hcii.cogtool.util.EmptyIterator) Iterator(java.util.Iterator) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 12 with ChildWidget

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

the class FrameEditorController method insertDuplicateWidget.

/**
     * If group or parent is non-null, duplicate the widget within the given
     * group.  If they are both null, the widget was dragged to empty space, so
     * give it a new group.
     */
private boolean insertDuplicateWidget(IWidget widget, SimpleWidgetGroup group, int index, AParentWidget parent, double moveByX, double moveByY) {
    Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
    double startPosX = 0.0;
    double startPosY = 0.0;
    DoubleSize newSize;
    if (parent != null) {
        newSize = getNewWidgetSize(parent);
        newSize.height *= getHeightFactor(widget, parent.getChildren());
    } else if ((group == null) || (group.size() == 0)) {
        newSize = widget.getShape().getSize();
    } else {
        DoublePoint startPos = group.get(0).getShape().getOrigin();
        startPosX = startPos.x;
        startPosY = startPos.y;
        newSize = group.get(0).getShape().getSize();
        if (widget instanceof ListItem) {
            newSize.height *= getHeightFactor(widget, group);
        }
    }
    widgetSituator.reset(widgetCopies, null);
    IWidget newWidget = null;
    if (parent != null) {
        if (widget instanceof ChildWidget) {
            newWidget = ((ChildWidget) widget).duplicate(parent, lookupFrameDuplicator, widgetSituator, index);
            newWidget.setWidgetSize(newSize.width, newSize.height);
            if (newWidget instanceof AParentWidget) {
                resizeChildren(newWidget);
                DesignEditorCmd.repositionChildren((AParentWidget) newWidget);
            }
            DesignEditorCmd.repositionChildren(parent);
        }
    } else if (group != null) {
        if (widget instanceof MenuHeader) {
            newWidget = ((MenuHeader) widget).duplicate(group, lookupFrameDuplicator, widgetSituator, index);
        } else if (widget instanceof ListItem) {
            newWidget = ((ListItem) widget).duplicate(group, lookupFrameDuplicator, index);
        }
        newWidget.setWidgetSize(newSize.width, newSize.height);
        resizeChildren(newWidget);
        widgetSituator.placeInContext(widget, newWidget);
        DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
    } else {
        // Duplicating into space
        if ((widget instanceof MenuHeader) || (widget instanceof ListItem)) {
            SimpleWidgetGroup newGroup = null;
            if (widget instanceof MenuHeader) {
                newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
                newWidget = ((MenuHeader) widget).duplicate(newGroup, lookupFrameDuplicator, widgetSituator);
            } else {
                // (widget instanceof ListItem)
                newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
                newWidget = ((ListItem) widget).duplicate(newGroup, lookupFrameDuplicator);
            }
            group = newGroup;
            widgetSituator.placeInContext(widget, newWidget);
            newWidget.moveElement(moveByX, moveByY);
            group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(widget.isRendered()));
        }
    }
    widgetSituator.completeWork();
    Collection<IWidget> duplicateWidgets = widgetCopies.values();
    Iterator<IWidget> copies = duplicateWidgets.iterator();
    while (copies.hasNext()) {
        IWidget widgetCopy = copies.next();
        // Warning: it is important that each widget be added
        // to the frame *before* we make the next widget name
        // unique, or we can end up with non-unique names.
        makeWidgetNameUnique(widgetCopy);
        model.addWidget(widgetCopy);
    }
    SimpleWidgetGroup newGroup = (group != null) ? group : newWidget.getParentGroup();
    Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
    boolean groupRendered = ((Boolean) rendered).booleanValue();
    boolean widgetRendered = widget.isRendered();
    if (groupRendered != widgetRendered) {
        newWidget.setRendered(groupRendered);
    }
    insertDuplicateEdit(newWidget, new ReadOnlyList<IWidget>(new ArrayList<IWidget>(duplicateWidgets)), group, index, parent, startPosX, startPosY, undoMgr);
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) ArrayList(java.util.ArrayList) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) LinkedHashMap(java.util.LinkedHashMap) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 13 with ChildWidget

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

the class FrameEditorController method reorderChildWidget.

private boolean reorderChildWidget(final ChildWidget widget, final SimpleWidgetGroup newGroup, final int newIndex, final AParentWidget newParent) {
    final SimpleWidgetGroup prevGroup = widget.getParentGroup();
    final int prevIndex = prevGroup.indexOf(widget);
    int index = newIndex;
    if (prevGroup == newGroup) {
        if (prevIndex < newIndex) {
            index--;
        }
        if (index == prevIndex) {
            return true;
        }
    }
    final AParentWidget prevParent = widget.getParent();
    DoubleSize prevSize = widget.getShape().getSize();
    final double prevWidth = prevSize.width;
    final double prevHeight = prevSize.height;
    DoubleSize newSize = getNewWidgetSize(newParent);
    final double newWidth = newSize.width;
    final double newHeight = newSize.height * getHeightFactor(widget, newGroup);
    final boolean widgetRendered = widget.isRendered();
    reorderChildWidget(widget, newWidth, newHeight, index, prevParent, newParent);
    Object rendered = widget.getParentGroup().getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
    final boolean groupRendered = ((Boolean) rendered).booleanValue();
    if (widgetRendered != groupRendered) {
        widget.setRendered(groupRendered);
    }
    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {

        private ChildWidget child = widget;

        @Override
        public String getPresentationName() {
            return REORDER_WIDGET;
        }

        @Override
        public void redo() {
            super.redo();
            int index = newIndex;
            if (prevGroup == newGroup) {
                if (prevIndex < newIndex) {
                    index--;
                }
            }
            reorderChildWidget(child, newWidth, newHeight, index, prevParent, newParent);
            if (widgetRendered != groupRendered) {
                widget.setRendered(groupRendered);
            }
            noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), this);
        }

        @Override
        public void undo() {
            super.undo();
            reorderChildWidget(child, prevWidth, prevHeight, prevIndex, newParent, prevParent);
            if (widgetRendered != groupRendered) {
                widget.setRendered(widgetRendered);
            }
            noteEditCheckRegenerate(newParent.getChildren(), prevParent.getChildren(), this);
        }
    };
    noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), edit);
    undoMgr.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
    }
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 14 with ChildWidget

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

the class FrameEditorController method moveWidget.

private void moveWidget(ListenerIdentifier lid, String presentationLabel, IWidget widget, double widgetMoveByX, double widgetMoveByY, boolean moveAsGroup, Set<SimpleWidgetGroup> movedGroups, Set<IWidget> movedWidgets, IUndoableEditSequence editSequence) {
    if (movedWidgets.contains(widget)) {
        return;
    }
    movedWidgets.add(widget);
    SimpleWidgetGroup parentGroup = widget.getParentGroup();
    if ((parentGroup == null) || (!moveAsGroup)) {
        if (widget instanceof GridButton) {
            GridButton gb = (GridButton) widget;
            moveGridButton(lid, presentationLabel, gb, widgetMoveByX, widgetMoveByY, gb.getHorizSpace() + widgetMoveByX, gb.getVertSpace() + widgetMoveByY, editSequence);
        } else {
            moveWidget(lid, presentationLabel, widget, widgetMoveByX, widgetMoveByY, editSequence);
        }
    } else if (!(widget instanceof ChildWidget)) {
        // move entire group
        if (!movedGroups.contains(parentGroup)) {
            moveWidgetGroup(lid, presentationLabel, parentGroup, widgetMoveByX, widgetMoveByY, editSequence);
            movedGroups.add(parentGroup);
        }
    }
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 15 with ChildWidget

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

the class FrameEditorController method resizeChildren.

private void resizeChildren(IWidget widget) {
    if (widget instanceof AParentWidget) {
        AParentWidget parent = (AParentWidget) widget;
        DoubleSize size = parent.getShape().getSize();
        if (parent instanceof MenuHeader) {
            size.width *= FrameEditorUI.MENU_ITEM_RATIO;
        }
        int numItems = parent.itemCount();
        for (int i = 0; i < numItems; i++) {
            ChildWidget child = parent.getItem(i);
            double h = size.height;
            Object isSep = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
            if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
                h /= FrameEditorUI.SEPARATOR_RATIO;
            }
            child.setWidgetSize(size.width, h);
            resizeChildren(child);
        }
    }
}
Also used : MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)18 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)8 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)7 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)4 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)4 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)4 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)3 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)2 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)2 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)2 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)2 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)2 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)2 IOException (java.io.IOException)2 Point (org.eclipse.draw2d.geometry.Point)2