Search in sources :

Example 16 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method createSetRenderSkinAction.

private IListenerAction createSetRenderSkinAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.SetRenderSkinParameters p = (FrameEditorUI.SetRenderSkinParameters) prms;
            // Iterate through selected objects.
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(CHG_WIDGET_RENDERED, FrameEditorLID.SetRenderSkin);
            while (selected.hasNext()) {
                IWidget w = selected.next();
                if (w instanceof TraversableWidget) {
                    AParentWidget parent = null;
                    if (w instanceof MenuItem) {
                        parent = ((MenuItem) w).getTopHeader();
                        if (parent == null) {
                            // parent is a context menu
                            parent = ((MenuItem) w).getParent();
                        }
                    } else if (w instanceof ChildWidget) {
                        parent = ((ChildWidget) w).getParent();
                    } else if (w instanceof AParentWidget) {
                        parent = (AParentWidget) w;
                    }
                    if (parent != null) {
                        SimpleWidgetGroup group = parent.getParentGroup();
                        if (group != null) {
                            //menu header
                            renderGroup(group, p.rendered, parent.isRendered(), editSeq);
                        } else {
                            //pull down header
                            renderWidget(parent, p.rendered, parent.isRendered(), editSeq);
                            renderChildren(parent, p.rendered, parent.isRendered(), editSeq);
                        }
                    } else if (w.getParentGroup() != null) {
                        //list box item or radio button
                        renderGroup(w.getParentGroup(), p.rendered, w.isRendered(), editSeq);
                    }
                } else {
                    renderWidget(w, p.rendered, w.isRendered(), editSeq);
                }
            }
            editSeq.end();
            // Only add this edit if it is significant
            if (editSeq.isSignificant()) {
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 17 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method createChangeTitlePropertyAction.

// changeTitleProperty
private IListenerAction createChangeTitlePropertyAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.ActionStringParameters p = (FrameEditorUI.ActionStringParameters) prms;
            // While the UI should suppress
            // multiple selection for setting
            // titles, the selection supports it
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_DISPLAYED_LABEL, FrameEditorLID.ChangeTitleProperty);
            String newTitle = p.newString;
            // Loop through each item and set the title
            while (selected.hasNext()) {
                IWidget widget = selected.next();
                changeTitleProperty(FrameEditorLID.ChangeTitleProperty, CHG_DISPLAYED_LABEL, widget, newTitle, p.isSeparator, editSequence);
            }
            editSequence.end();
            // Don't add empty edits!
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 18 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method createNewWidgetAction.

/**
     * Create a ListenerAction to handle creating a new Widget.
     *
     */
private IListenerAction createNewWidgetAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            // TODO: Should we provide more input to this default widget?
            // Dialog box with option?
            // Current/last palette setting
            // TODO: Bonnie wanted to have new widgets show up under the
            // mouse.  To do that we need to do something like
            // getCursorLocation() (from display)
            // offset based on the (0,0) of the window
            // Might want to get that based on GetCursorControl().
            // If working with the control, you need to walk the tree to
            // get the actual offset from 0,0, in the display.
            //
            // Alternatively, in specialize, get the mouse pointer position
            // from mousestate (but that would require tracking the mouse
            // state -- on hover at least).
            // Instantiate the appropriate widget. If the class was passed
            // a prms, use that to dictate what to do.
            Widget widget = null;
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(NEW_WIDGET, FrameEditorLID.NewWidget);
            if (prms instanceof FrameEditorUI.NewWidgetParameters) {
                FrameEditorUI.NewWidgetParameters nwp = (FrameEditorUI.NewWidgetParameters) prms;
                // widget
                if (nwp.parent != null) {
                    if (nwp.type == WidgetType.MenuItem) {
                        // Create menu item; may become a submenu through
                        // user interaction later
                        widget = new MenuItem((AMenuWidget) nwp.parent, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.PullDownItem) {
                        widget = new PullDownItem((PullDownHeader) nwp.parent, nwp.bounds, nwp.widgetTitle);
                        boolean rendered = nwp.parent.isRendered();
                        SimpleWidgetGroup group = widget.getParentGroup();
                        group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(rendered));
                    }
                } else // widget group
                if (nwp.parentGroup != null) {
                    if (nwp.type == WidgetType.Menu) {
                        widget = new MenuHeader(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.ListBoxItem) {
                        widget = new ListItem(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.Radio) {
                        widget = new RadioButton((RadioButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.Check) {
                        widget = new CheckBox((GridButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    }
                } else {
                    widget = createWidget(nwp.type, nwp.bounds, nwp.widgetTitle, nwp.isAutomatic);
                }
                if (nwp.isSeparator) {
                    frameSetAttribute(widget, WidgetAttributes.IS_SEPARATOR_ATTR, WidgetAttributes.IS_SEPARATOR, editSequence);
                }
            }
            //                if (widget.getWidgetType() == WidgetType.TextBox) {
            //                    widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR,
            //                                        WidgetAttributes.IS_CUSTOM);
            //                }
            // Auto-generate a unique name for the widget
            widget.setName(generateUniqueWidgetName());
            // Build the widget: check for uniqueness and add to the frame
            boolean result = addCreatedWidget(widget, editSequence);
            editSequence.end();
            undoMgr.addEdit(editSequence);
            return result;
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) AMenuWidget(edu.cmu.cs.hcii.cogtool.model.AMenuWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AMenuWidget(edu.cmu.cs.hcii.cogtool.model.AMenuWidget) RadioButton(edu.cmu.cs.hcii.cogtool.model.RadioButton) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) CheckBox(edu.cmu.cs.hcii.cogtool.model.CheckBox) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 19 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method createPasteAction.

// createSetFrameTemplateAction
/**
     * The paste action for inserting copied information.
     * Currently no checks are made to ensure that the paste is valid XML.
     * @return
     */
private IListenerAction createPasteAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            try {
                if (CogToolClipboard.hasCogToolObjects()) {
                    // Get the XML text from the clipboard
                    Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
                    if ((objects != null) && (objects.size() > 0)) {
                        CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PASTE, FrameEditorLID.Paste);
                        int numPasted = DesignEditorCmd.pasteElements(design, model, objects, demoStateMgr, editSequence);
                        if (numPasted > 0) {
                            editSequence.end();
                            undoMgr.addEdit(editSequence);
                            interaction.setStatusMessage(numPasted + " " + pasteComplete);
                        } else {
                            interaction.setStatusMessage(nothingPasted);
                        }
                    }
                    return true;
                } else {
                    interaction.setStatusMessage(nothingPasted);
                }
            } catch (IOException e) {
                throw new RcvrClipboardException(e);
            } catch (ParserConfigurationException e) {
                throw new RcvrClipboardException(e);
            } catch (SAXException e) {
                throw new RcvrClipboardException(e);
            } catch (ClipboardUtil.ClipboardException e) {
                throw new RcvrClipboardException(e);
            }
            return false;
        }
    };
}
Also used : ClipboardUtil(edu.cmu.cs.hcii.cogtool.util.ClipboardUtil) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SAXException(org.xml.sax.SAXException)

Example 20 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class DesignEditorController method moveFrames.

protected boolean moveFrames(double dx, double dy, FrameSelectionState selection) {
    Frame[] frames = selection.getSelectedFrames();
    if ((frames != null) && (frames.length > 0)) {
        String editLabel;
        if (frames.length > 1) {
            editLabel = moveFrames;
        } else {
            editLabel = moveFrame;
        }
        CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, DesignEditorLID.MoveFrames);
        for (Frame frame : frames) {
            moveFrame(frame, dx, dy, editSequence);
        }
        editSequence.end();
        undoMgr.addEdit(editSequence);
    }
    return true;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)

Aggregations

CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)42 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)19 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)13 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)13 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)12 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)10 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)9 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)7 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)6 Design (edu.cmu.cs.hcii.cogtool.model.Design)6 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)6 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)6 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)5 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)4 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)4