Search in sources :

Example 51 with Frame

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

the class DesignEditorController method setWidgetColorForFrames.

/**
	 * Sets the widget color on all widgets contained within the given frames
	 *
	 * @param frames an array of IFrames
	 * @param color integer containing new widget color
	 */
protected void setWidgetColorForFrames(final Frame[] frames, final int color) {
    // save previous data for undo/redo
    final Map<Frame, Integer> previousWidgetColorData = getWidgetColorData(frames);
    // do operation on all frames
    for (Frame frame : frames) {
        frame.setWidgetColor(color);
    }
    // Add the undo edit
    IUndoableEdit edit = new AUndoableEdit(DesignEditorLID.SetWidgetColor) {

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

        @Override
        public void redo() {
            super.redo();
            // selected frames
            for (Frame frame : frames) {
                frame.setWidgetColor(color);
            }
        }

        @Override
        public void undo() {
            super.undo();
            // Iterate through frames, resetting widget colors
            // to old values
            Iterator<Entry<Frame, Integer>> colorEntryIterator = previousWidgetColorData.entrySet().iterator();
            while (colorEntryIterator.hasNext()) {
                Entry<Frame, Integer> colorEntry = colorEntryIterator.next();
                Frame f = colorEntry.getKey();
                int oldColor = colorEntry.getValue().intValue();
                f.setWidgetColor(oldColor);
            }
        }
    };
    undoMgr.addEdit(edit);
    for (Frame frame : frames) {
        UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
        frameMgr.addEdit(edit);
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Entry(java.util.Map.Entry) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 52 with Frame

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

the class BalsamiqButtonAPIConverter method parseTransition.

/** Helper function used by parseWidget
	 * This method is used to parse the href tag that is a link from a widget
	 * to another frame
     * 
     * @param  destinationFrameName the name of the frame that the transition 
     *                               is going to
     * @param  widget               the widget that the transition starts from
     */
protected void parseTransition(String destFrameFileName, Widget widget) {
    String frameName = (destFrameFileName.lastIndexOf(".") == -1) ? destFrameFileName : destFrameFileName.substring(0, destFrameFileName.lastIndexOf('.'));
    /* getFrame() returns the frame for the specified string. If the string is null then
		a null frame is returned. */
    Frame destinationFrame = (frameName != null) ? getFrame(frameName) : null;
    if (destinationFrame != null) {
        //Default Mouse Click Transition
        //TODO: MAKE SURE THE MOUSE IS A DEVICE. check which devices are allowed and then make an action from there
        AAction action = new ButtonAction(MouseButtonState.Left, MousePressType.Click, AAction.NONE);
        //Create the transition and add it to the widget
        Transition t = new Transition(widget, destinationFrame, action);
        if (t != null) {
            widget.addTransition(t);
        }
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 53 with Frame

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

the class BalsamiqButtonAPIConverter method importDesign.

/** The new design is created and added to the project window.
     * This method must be implemented by the user.
     * 
     * @param  inputFile the specified directory or file
     * @param  design    The newly created design. The design is passed to 
     *                    the converter file so that frames may be added to it.
     *                    
     * @see              the new design in the project window.
     */
public void importDesign(File inputFile, Design newDesign) {
    this.design = newDesign;
    designName = this.design.getName();
    designPathName = inputFile.getParent();
    try {
        parseBalsamiqFile(inputFile);
        int minFrameWidth = DesignUtil.getFrameMinWidth();
        int minFrameHeight = DesignUtil.getFrameMinHeight();
        double frameScale = DesignUtil.getFrameScaleFactor();
        /*The frame situator spaces out the frames in the design window */
        DesignUtil.IFrameSituator frameSituator = new DesignUtil.ByRowFrameSituator(0.0, 0.0, 16.0, 16.0, minFrameWidth, minFrameHeight, CogToolPrefs.getFramesPerRow(), frameScale);
        //they were inserted is needed in order to keep a consistent behavior
        for (Frame frame : visitedFrames) {
            frameSituator.situateNextFrame(frame);
        }
    } catch (IOException e) {
        throw new RcvrImportException("importDesign() has encountered an exception " + e);
    }
}
Also used : DesignUtil(edu.cmu.cs.hcii.cogtool.model.DesignUtil) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) IOException(java.io.IOException)

Example 54 with Frame

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

the class DesignEditorController method copyFrames.

protected void copyFrames(Frame[] frames) {
    try {
        // Passing the set of frames as part of purpose allows us
        // to copy only those transitions that link those frames.
        ObjectSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyFrames, frames, CogToolClipboard.SAVE_TO_CLIPBOARD);
        for (Frame frame : frames) {
            s.saveObject(frame);
        }
        s.finish();
    } catch (IOException e) {
        throw new RcvrClipboardException(e);
    } catch (IllegalStateException e) {
        throw new RcvrClipboardException(e);
    } catch (OutOfMemoryError error) {
        throw new RcvrOutOfMemoryException("Copying Frames", error);
    }
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) IOException(java.io.IOException)

Example 55 with Frame

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

the class DesignEditorController method createCopyFrameAction.

protected IListenerAction createCopyFrameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState seln = (FrameSelectionState) prms;
            Frame[] frames = seln.getSelectedFrames();
            if ((frames != null) && (frames.length > 0)) {
                copyFrames(frames);
                if (frames.length == 1) {
                    interaction.setStatusMessage(FRAME_COPIED);
                } else {
                    interaction.setStatusMessage(FRAMES_COPIED);
                }
                return true;
            }
            interaction.protestNoSelection();
            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)

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