Search in sources :

Example 21 with Frame

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

the class DesignEditorController method setBackgroundImageOnFrames.

/**
	 * Sets the background image for the array of frames
	 *
	 * @param frames an array of IFrames
	 * @param imageData the new image, or null if none
	 * @param imageURL the file path of the new image, or
	 * <code>WidgetAttributes.NO_IMAGE</code>
	 */
protected void setBackgroundImageOnFrames(final Frame[] frames, final byte[] imageData, final String imageURL, CogToolLID editLID) {
    try {
        // compute the size of the new image.
        final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
        // save previous data for undo/redo
        final Map<Frame, ImageData> previousImageData = getBackgroundImageData(frames);
        // do operation on all frames
        for (Frame frame : frames) {
            frame.setBackgroundImage(imageData, imageSize);
            frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
        }
        // Add the undo edit
        IUndoableEdit edit = new AUndoableEdit(editLID) {

            @Override
            public String getPresentationName() {
                return (imageData == null) ? removeBackgroundImage : setBackgroundImage;
            }

            @Override
            public void redo() {
                super.redo();
                // selected frames
                try {
                    for (Frame frame : frames) {
                        frame.setBackgroundImage(imageData, imageSize);
                        frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
                    }
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Redo set background image failed", ex);
                }
            }

            @Override
            public void undo() {
                super.undo();
                try {
                    // iterate through frames
                    Iterator<Entry<Frame, ImageData>> imageEntryIterator = previousImageData.entrySet().iterator();
                    while (imageEntryIterator.hasNext()) {
                        Entry<Frame, ImageData> imageEntry = imageEntryIterator.next();
                        Frame f = imageEntry.getKey();
                        ImageData id = imageEntry.getValue();
                        f.setBackgroundImage(id.data, id.bounds);
                        f.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, id.imageURL);
                    }
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Undo set background image failed", ex);
                }
            }
        };
        undoMgr.addEdit(edit);
        for (Frame frame : frames) {
            UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
            frameMgr.addEdit(edit);
        }
    } catch (GraphicsUtil.ImageException e) {
        // setBackgroundImage and GraphicsUtil.getImageBounds may
        // throw ImageException, translating any other exception.
        interaction.protestInvalidImageFile();
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Entry(java.util.Map.Entry) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)

Example 22 with Frame

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

the class DesignEditorController method createSetWidgetColorAction.

/**
	 * Create a ListenerAction to handle setting widget color on multiple frames
	 */
protected IListenerAction createSetWidgetColorAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            // Get selected frames from parameters
            FrameSelectionState seln = (FrameSelectionState) prms;
            Frame[] frames = seln.getSelectedFrames();
            // TODO: Which color to use as old widget color?
            int oldColor = (frames.length > 0) ? frames[0].getWidgetColor() : 128;
            // Pull up interaction to select a file
            Integer newColorChoice = interaction.selectColor(oldColor, selectWidgetColor);
            // Check if the dialog was canceled
            if (newColorChoice != null) {
                setWidgetColorForFrames(frames, newColorChoice.intValue());
                return true;
            }
            return false;
        }
    };
}
Also used : FrameSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 23 with Frame

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

the class DesignEditorController method deleteFrames.

// deleteFrame
protected void deleteFrames(final Frame[] frames) {
    if ((frames != null) && (frames.length > 0)) {
        final Transition[][] incidentTransitions = new Transition[frames.length][];
        for (int i = 0; i < frames.length; i++) {
            // Remove Transition instances that target this Frame
            incidentTransitions[i] = frames[i].removeIncidentTransitions();
        }
        for (Frame frame : frames) {
            design.removeFrame(frame);
        }
        DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(DesignEditorLID.DeleteFrame, demoStateMgr) {

            protected boolean recoverMgrs = true;

            @Override
            public String getPresentationName() {
                return (frames.length > 1) ? deleteFrames : deleteFrame;
            }

            @Override
            public void redo() {
                super.redo();
                recoverMgrs = true;
                for (Frame frame : frames) {
                    frame.removeIncidentTransitions();
                }
                for (Frame frame : frames) {
                    design.removeFrame(frame);
                }
                stateMgr.noteFramesEdit(frames, this);
            }

            @Override
            public void undo() {
                super.undo();
                recoverMgrs = false;
                for (int i = frames.length - 1; i >= 0; i--) {
                    design.addFrame(frames[i]);
                }
                for (int i = frames.length - 1; i >= 0; i--) {
                    DesignEditorCmd.addIncidentTransitions(incidentTransitions[i]);
                }
                stateMgr.noteFramesEdit(frames, this);
            }

            @Override
            public void die() {
                super.die();
                if (recoverMgrs) {
                    for (Frame frame : frames) {
                        recoverManagers(frame);
                    }
                }
            }
        };
        demoStateMgr.noteFramesEdit(frames, edit);
        undoMgr.addEdit(edit);
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 24 with Frame

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

the class DesignEditorController method createNewFrame.

protected Frame createNewFrame(double x, double y, IUndoableEditSequence editSequence) {
    String frameNamePrefix = DEFAULT_FRAME_PREFIX + " ";
    String frameName = frameNamePrefix + nextNewFrameSuffix;
    while (design.getFrame(frameName) != null) {
        frameName = frameNamePrefix + ++nextNewFrameSuffix;
    }
    Frame frame = createFrame(frameName, x, y);
    addFrame(frame, (editSequence != null) ? editSequence : undoMgr);
    return frame;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame)

Example 25 with Frame

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

the class DesignEditorController method assignActions.

@Override
public void assignActions() {
    super.assignActions();
    ui.setAction(DesignEditorLID.ExportDesignToHTML, createExportDesignToHTMLAction());
    ui.setAction(DesignEditorLID.ExportToXML, createExportDesignToXMLAction());
    ui.setAction(DesignEditorLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(DesignEditorLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    ui.setAction(DesignEditorLID.Paste, createPasteAction());
    ui.setAction(DesignEditorLID.CopyFrame, createCopyFrameAction());
    ui.setAction(DesignEditorLID.CutFrame, createCutFrameAction());
    ui.setAction(DesignEditorLID.ClearFrameTemplate, new AListenerAction() {

        public boolean performAction(Object prms) {
            FrameTemplateSupport.clearFrameTemplate(design);
            return true;
        }
    });
    ui.setAction(DesignEditorLID.DeselectAll, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SelectionState selection = (SelectionState) prms;
            selection.deselectAll();
            return true;
        }
    });
    ui.setAction(DesignEditorLID.MoveFrames, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.MoveParameters movePrms = (DesignEditorUI.MoveParameters) prms;
            if (movePrms != null) {
                return moveFrames(movePrms.dx, movePrms.dy, movePrms.selection);
            } else {
                throw new RcvrUIException("Cannot move frames without parameters.");
            }
        }
    });
    ui.setAction(DesignEditorLID.AddDesignDevices, createAddDevicesAction());
    ui.setAction(DesignEditorLID.NewFrame, createNewFrameAction());
    // Align selected frames
    ui.setAction(DesignEditorLID.AlignTop, new FrameAlignmentAction(AlignmentAction.TOP));
    ui.setAction(DesignEditorLID.AlignBottom, new FrameAlignmentAction(AlignmentAction.BOTTOM));
    ui.setAction(DesignEditorLID.AlignLeft, new FrameAlignmentAction(AlignmentAction.LEFT));
    ui.setAction(DesignEditorLID.AlignRight, new FrameAlignmentAction(AlignmentAction.RIGHT));
    ui.setAction(DesignEditorLID.AlignCenter, new FrameAlignmentAction(AlignmentAction.CENTER));
    ui.setAction(DesignEditorLID.AlignHorizCenter, new FrameAlignmentAction(AlignmentAction.HORIZ_CENTER));
    ui.setAction(DesignEditorLID.AlignVertCenter, new FrameAlignmentAction(AlignmentAction.VERT_CENTER));
    // Space selected frames equally
    ui.setAction(DesignEditorLID.SpaceVertically, new IListenerAction() {

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

        @SuppressWarnings("unchecked")
        public boolean performAction(Object prms) {
            Map<Frame, DoubleRectangle> frameMap = (Map<Frame, DoubleRectangle>) prms;
            // Equally space the widgets in the
            // vertical axis.
            final boolean VERTICAL = true;
            return spaceFramesEqually(frameMap, VERTICAL);
        }
    });
    ui.setAction(DesignEditorLID.SpaceHorizontally, new IListenerAction() {

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

        @SuppressWarnings("unchecked")
        public boolean performAction(Object prms) {
            Map<Frame, DoubleRectangle> frameMap = (Map<Frame, DoubleRectangle>) prms;
            // Equally space the widgets in the
            // horizontal axis.
            final boolean HORIZONTAL = false;
            return spaceFramesEqually(frameMap, HORIZONTAL);
        }
    });
    ui.setAction(DesignEditorLID.InitiateFrameRename, createInitiateFrameRenameAction());
    ui.setAction(DesignEditorLID.RenameFrame, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.FrameRenameParameters evt = (DesignEditorUI.FrameRenameParameters) prms;
            return renameFrame(evt.frame, evt.newName);
        }
    });
    ui.setAction(ProjectLID.RenameDesign, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.DesignRenameParameters evt = (DesignEditorUI.DesignRenameParameters) prms;
            return renameDesign(evt.design, evt.newText);
        }
    });
    ui.setAction(DesignEditorLID.NewTransition, createNewTransitionAction());
    ui.setAction(DesignEditorLID.EditFrame, createEditFrameAction());
    ui.setAction(DesignEditorLID.EditTransition, createEditTransitionAction());
    ui.setAction(DesignEditorLID.DeleteFrame, createDeleteFrameAction());
    ui.setAction(DesignEditorLID.DeleteTransition, createDeleteTransitionAction());
    // Nudge selected frame(s)
    ui.setAction(DesignEditorLID.NudgeLeft, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            double dx = -1.0 / ui.getZoom();
            return moveFrames(dx, 0.0, selection);
        }
    });
    ui.setAction(DesignEditorLID.NudgeRight, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            double dx = 1.0 / ui.getZoom();
            return moveFrames(dx, 0.0, selection);
        }
    });
    ui.setAction(DesignEditorLID.NudgeUp, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            double dy = -1.0 / ui.getZoom();
            return moveFrames(0.0, dy, selection);
        }
    });
    ui.setAction(DesignEditorLID.NudgeDown, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            double dy = 1.0 / ui.getZoom();
            return moveFrames(0.0, dy, selection);
        }
    });
    ui.setAction(DesignEditorLID.SelectAll, new AListenerAction() {

        public boolean performAction(Object prms) {
            ui.selectAllFrames();
            return true;
        }
    });
    ui.setAction(DesignEditorLID.ChangeTarget, createChangeTargetAction());
    ui.setAction(DesignEditorLID.ChangeSource, createChangeSourceAction());
    // The following 6 are also functionality in FrameEditorController
    ui.setAction(DesignEditorLID.SetBackgroundImage, createSetBackgroundImageAction());
    ui.setAction(DesignEditorLID.RemoveBackgroundImage, createRemoveBackgroundImageAction());
    ui.setAction(DesignEditorLID.CopyImageAsBackground, createCopyImageAsBkgAction());
    ui.setAction(DesignEditorLID.PasteBackgroundImage, createPasteBackgroundImageAction());
    ui.setAction(DesignEditorLID.SetWidgetColor, createSetWidgetColorAction());
    // Skins!
    ui.setAction(DesignEditorLID.SkinWireFrame, createSetSkinAction(SkinType.WireFrame, DesignEditorLID.SkinWireFrame));
    ui.setAction(DesignEditorLID.SkinMacOSX, createSetSkinAction(SkinType.MacOSX, DesignEditorLID.SkinMacOSX));
    ui.setAction(DesignEditorLID.SkinWinXP, createSetSkinAction(SkinType.WinXP, DesignEditorLID.SkinWinXP));
    ui.setAction(DesignEditorLID.SkinPalm, createSetSkinAction(SkinType.Palm, DesignEditorLID.SkinPalm));
    ui.setAction(CogToolLID.RenderAll, createRenderAllAction(true, CogToolLID.RenderAll));
    ui.setAction(CogToolLID.UnRender, createRenderAllAction(false, CogToolLID.UnRender));
    ui.setAction(DesignEditorLID.ImportImageDirectory, createImportImageDirectory());
    IListenerAction action = createChangeActionAction();
    ui.setAction(DesignEditorLID.ChangeWidgetAction, action);
    ui.setAction(DesignEditorLID.ChangeDeviceAction, action);
    ui.setAction(DesignEditorLID.DuplicateFrame, createDuplicateFrameAction());
    ui.setAction(DesignEditorLID.ChangeDelay, createChangeDelayAction());
}
Also used : FrameSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Map(java.util.Map) HashMap(java.util.HashMap) DesignEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignEditorSelectionState) SelectionState(edu.cmu.cs.hcii.cogtool.ui.SelectionState) FrameSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException)

Aggregations

Frame (edu.cmu.cs.hcii.cogtool.model.Frame)68 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)12 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)10 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)10 EventObject (java.util.EventObject)9 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)8 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)8 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)8 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)8 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 IOException (java.io.IOException)6 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)5 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)5 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)4 Design (edu.cmu.cs.hcii.cogtool.model.Design)4 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)4 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)4