Search in sources :

Example 1 with FrameEditorSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState in project cogtool by cogtool.

the class FrameEditorController method createInitiateRenameAction.

private IListenerAction createInitiateRenameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            int selectedWidgetCount = selection.getWidgetSelectionCount();
            if (selectedWidgetCount == 1) {
                IWidget w = selection.getSelectedIWidgets()[0];
                ui.initiateWidgetRename(w);
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 2 with FrameEditorSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState in project cogtool by cogtool.

the class FrameEditorController method createGroupElementsAction.

private IListenerAction createGroupElementsAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            int selectedEltCount = selection.getElementSelectionCount();
            if (selectedEltCount > 1) {
                final FrameElementGroup newGroup = new FrameElementGroup();
                assignUniqueEltGroupName(newGroup);
                Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
                while (selectedElts.hasNext()) {
                    FrameElement rootElt = selectedElts.next().getRootElement();
                    // that the element is a member of the group
                    if (!newGroup.contains(rootElt)) {
                        newGroup.add(rootElt);
                    }
                }
                model.addEltGroup(newGroup);
                IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Group) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<FrameElement> groupElts = newGroup.iterator();
                        // back to the frame
                        while (groupElts.hasNext()) {
                            groupElts.next().addToEltGroup(newGroup);
                        }
                        model.addEltGroup(newGroup);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        model.removeEltGroup(newGroup);
                        Iterator<FrameElement> groupElts = newGroup.iterator();
                        // association from the element.
                        while (groupElts.hasNext()) {
                            groupElts.next().removeFromEltGroup(newGroup);
                        }
                    }
                };
                undoMgr.addEdit(edit);
                return true;
            }
            if (selectedEltCount == 1) {
                interaction.protestTooFewWidgets();
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 3 with FrameEditorSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState in project cogtool by cogtool.

the class FrameEditorController method createInitiateRelabelAction.

private IListenerAction createInitiateRelabelAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            int selectedWidgetCount = selection.getWidgetSelectionCount();
            if (selectedWidgetCount == 1) {
                IWidget w = selection.getSelectedIWidgets()[0];
                ui.initiateWidgetRetitle(w);
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 4 with FrameEditorSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState in project cogtool by cogtool.

the class FrameEditorController method createCutWidgetAction.

/**
     * Set up cut action, tests to ensure a cut is valid, and then
     * calls cut method.
     * @return
     */
private IListenerAction createCutWidgetAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState seln = (FrameEditorSelectionState) prms;
            // if non zero selected items copy them, then delete.
            if (seln.getElementSelectionCount() > 0) {
                // Copy the widgets, then delete them to perform a cut
                copyElements(seln, DesignEditorCmd.SAVE_TO_CLIPBOARD);
                return deleteElements(seln);
            }
            // Tell the user nothing was selected
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)

Example 5 with FrameEditorSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState in project cogtool by cogtool.

the class FrameEditorController method createSetFrameTemplateAction.

/**
     * Record the Widgets in the clipboard as the template to use
     * when creating new Frames.
     */
private IListenerAction createSetFrameTemplateAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState seln = (FrameEditorSelectionState) prms;
            // If selection is non zero, copy widgets
            if (seln.getElementSelectionCount() > 0) {
                copyElements(seln, DesignEditorCmd.SAVE_TO_TEMPLATE);
                interaction.setStatusMessage(templateCreated);
                return true;
            }
            // tell user to select something.
            interaction.setStatusMessage(noTemplateWidgets);
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)

Aggregations

FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)9 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)4 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)3 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)2 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)2 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)1 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)1 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)1 UI (edu.cmu.cs.hcii.cogtool.ui.UI)1 ZoomableUI (edu.cmu.cs.hcii.cogtool.ui.ZoomableUI)1 AListenerAction (edu.cmu.cs.hcii.cogtool.util.AListenerAction)1 EmptyIterator (edu.cmu.cs.hcii.cogtool.util.EmptyIterator)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1