Search in sources :

Example 56 with Frame

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

the class DesignEditorController method createSetBackgroundImageAction.

/**
	 * Create a ListenerAction to handle setting frame background image on
	 * multiple frames
	 */
protected IListenerAction createSetBackgroundImageAction() {
    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();
            // this code is from FrameEditorController
            // load image
            // Pull up interaction to select a file
            String imageURL = interaction.selectImageFile();
            // Check if the dialog was cancelled
            if (imageURL != null) {
                byte[] imageData;
                try {
                    // Set the background to new image
                    imageData = GraphicsUtil.loadImageFromFile(imageURL);
                    setBackgroundImageOnFrames(frames, imageData, imageURL, DesignEditorLID.SetBackgroundImage);
                    return true;
                } catch (IOException e) {
                    interaction.protestUnreadableFile();
                    imageData = null;
                }
            }
            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) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) IOException(java.io.IOException)

Example 57 with Frame

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

the class DesignEditorController method createNewFrameAction.

protected IListenerAction createNewFrameAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            // Find an unoccupied starting position by cascading.
            DoublePoint origin = new DoublePoint(10.0, 10.0);
            DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
            Frame frame = createNewFrame(origin.x, origin.y);
            ui.initiateFrameRename(frame);
            return true;
        }
    };
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 58 with Frame

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

the class DesignEditorController method createDeleteFrameAction.

// createNewTransition
protected IListenerAction createDeleteFrameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            Frame[] frames = selection.getSelectedFrames();
            if ((frames != null) && (frames.length > 0)) {
                if (interaction.confirmDeleteFrames(frames)) {
                    deleteFrames(frames);
                    return true;
                }
            } else {
                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)

Example 59 with Frame

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

the class DesignEditorController method renameFrame.

protected boolean renameFrame(final Frame renamedFrame, String tryName) {
    final String oldName = renamedFrame.getName();
    boolean notDone = true;
    do {
        if (tryName.length() == 0) {
            tryName = interaction.protestNameCannotBeEmpty(DEFAULT_FRAME_PREFIX);
            // If canceled, indicate so; otherwise, test again
            if (tryName == null) {
                return false;
            }
        } else {
            Frame frameForName = design.getFrame(tryName);
            // then no change is necessary!
            if (frameForName == renamedFrame) {
                notDone = false;
            } else if (frameForName != null) {
                // A non-null frame for the tryName indicates a collision
                tryName = interaction.protestNameCollision(DEFAULT_FRAME_PREFIX);
                // If canceled, indicate so; otherwise, test again
                if (tryName == null) {
                    return false;
                }
            } else {
                // Not canceled, not empty, and not a collision
                notDone = false;
                final String newName = tryName;
                renamedFrame.setName(newName);
                IUndoableEdit edit = new AUndoableEdit(DesignEditorLID.RenameFrame) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Frame testFrame = design.getFrame(newName);
                        renamedFrame.setName(newName);
                        if (testFrame != null) {
                            makeFrameNameUnique(renamedFrame);
                        }
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        Frame testFrame = design.getFrame(oldName);
                        renamedFrame.setName(oldName);
                        if (testFrame != null) {
                            makeFrameNameUnique(renamedFrame);
                        }
                    }
                };
                undoMgr.addEdit(edit);
            }
        }
    } while (notDone);
    return true;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 60 with Frame

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

the class DesignExportToHTML method buildFrameList.

/**
	 * Build the map which holds the frame names for a design.
	 * Changes which design will be used for building HTML pages
	 */
protected void buildFrameList() {
    frameLookUp.clear();
    Set<String> usedNames = new HashSet<String>();
    Iterator<Frame> iter = design.getFrames().iterator();
    // Use a random generator if needed
    Random rand = new Random();
    while (iter.hasNext()) {
        Frame frame = iter.next();
        String name = cleanStringForFS(frame.getName());
        while (usedNames.contains(name)) {
            // Name is in use.
            // Append a random number.
            name = name.concat("+" + rand.nextInt(50));
        }
        // Now that the name is clean, use it.
        frameLookUp.put(frame, name);
        usedNames.add(name);
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Random(java.util.Random) HashSet(java.util.HashSet)

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