Search in sources :

Example 1 with ShapeType

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

the class FrameEditorController method createChangeShapeAction.

/**
     * Create a listener for changing the shape of a widget.
     *
     * @return
     */
private IListenerAction createChangeShapeAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            // Get the parameters to change the shape into
            final FrameEditorUI.ShapeChangeParameters p = (FrameEditorUI.ShapeChangeParameters) prms;
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_WIDGET_SHAPE, FrameEditorLID.ChangeShapeProperty);
            // Loop through all selected widgets.
            while (selected.hasNext()) {
                final IWidget w = selected.next();
                final ShapeType oldShapeType = w.getShape().getShapeType();
                final ShapeType newShapeType = p.newShapeType;
                // Don't make a non-changing edit!
                if (!oldShapeType.equals(newShapeType)) {
                    w.setShapeType(newShapeType);
                    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ChangeShapeProperty, demoStateMgr) {

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

                        @Override
                        public void redo() {
                            super.redo();
                            w.setShapeType(p.newShapeType);
                            noteEditCheckRegenerate(w, this);
                        }

                        @Override
                        public void undo() {
                            super.undo();
                            w.setShapeType(oldShapeType);
                            noteEditCheckRegenerate(w, this);
                        }
                    };
                    noteEditCheckRegenerate(w, edit);
                    editSequence.addEdit(edit);
                }
            }
            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) ShapeType(edu.cmu.cs.hcii.cogtool.model.ShapeType) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 ShapeType (edu.cmu.cs.hcii.cogtool.model.ShapeType)1 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)1 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)1 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)1