Search in sources :

Example 46 with Frame

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

the class DesignEditorController method createDuplicateFrameAction.

protected IListenerAction createDuplicateFrameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            // From DesignEditorUI
            DesignEditorUI.DuplicateParameters parameters = (DesignEditorUI.DuplicateParameters) prms;
            Frame[] framesToDuplicate = parameters.selection.getSelectedFrames();
            if ((framesToDuplicate != null) && (framesToDuplicate.length > 0)) {
                FrameSubsetDuplicator duplicator = new FrameSubsetDuplicator(framesToDuplicate);
                Frame[] duplicatedFrames = new Frame[framesToDuplicate.length];
                for (int i = 0; i < framesToDuplicate.length; i++) {
                    Frame duplicatedFrame = duplicator.getOrDuplicate(framesToDuplicate[i]);
                    duplicatedFrames[i] = duplicatedFrame;
                    duplicatedFrame.moveFrameOrigin(parameters.dx, parameters.dy);
                }
                design.addFrames(duplicatedFrames);
                undoMgr.addEdit(createDuplicateFramesEdit(duplicatedFrames));
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) 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 47 with Frame

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

the class DesignEditorController method createFrame.

// addFrame
protected Frame createFrame(String frameName, double x, double y) {
    Frame frame = new Frame(frameName, design.getDeviceTypes());
    frame.setFrameOrigin(x, y);
    return frame;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame)

Example 48 with Frame

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

the class DesignEditorController method createEditFrameAction.

protected IListenerAction createEditFrameAction() {
    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)) {
                interaction.protestNoSelection();
                return false;
            }
            for (Frame frame : frames) {
                try {
                    FrameEditorController.openController(frame, design, project);
                } catch (GraphicsUtil.ImageException ex) {
                    interaction.protestInvalidImageFile();
                }
            }
            return true;
        }
    };
}
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) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)

Example 49 with Frame

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

the class DesignEditorController method createImportImageDirectory.

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

        public boolean performAction(Object actionParms) {
            // Ask for a directory of images
            String filePath = interaction.askForImageDir();
            if (filePath != null) {
                File dir = new File(filePath);
                if (dir.isDirectory()) {
                    final File[] files = dir.listFiles(new FileFilter() {

                        public boolean accept(File pathname) {
                            String name = pathname.getName();
                            Matcher imageFileNameMatcher = IMAGE_FILE_NAME.matcher(name);
                            if (imageFileNameMatcher.matches()) {
                                // Test for Mac resource forks
                                if (name.startsWith("._")) {
                                    String realName = name.substring(2);
                                    String fullPath = pathname.getParent() + FileUtil.FILE_SEP + realName;
                                    return !new File(fullPath).exists();
                                }
                                return true;
                            }
                            return false;
                        }
                    });
                    // Find an unoccupied starting position by cascading.
                    DoublePoint origin = new DoublePoint(10.0, 10.0);
                    // Check if only the default frame is present;
                    // if so, and it hasn't been significantly modified or
                    // used, indicate that it should be deleted when
                    // the images are imported.
                    Frame frameToDelete = design.getFrame(DesignEditorController.INITIAL_FRAME_NAME);
                    if ((frameToDelete == null) || (design.getFrames().size() > 1) || (frameToDelete.getWidgets().size() > 0) || (frameToDelete.getBackgroundImage() != null)) {
                        frameToDelete = null;
                    }
                    ImportImageDirThread workThread = new ImportImageDirThread(files, origin.x, origin.y, frameToDelete);
                    ThreadManager.startNewThread(workThread);
                }
            }
            return true;
        }
    };
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Matcher(java.util.regex.Matcher) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FileFilter(java.io.FileFilter) File(java.io.File)

Example 50 with Frame

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

the class DesignEditorController method getBackgroundImageData.

/**
	 * Returns a Map mapping IFrames to their current background image
	 * and bounds in an ImageData object
	 *
	 * @param frames an array of IFrames
	 * @return a Hashtable mapping IFrames to their current background images
	 */
protected Map<Frame, ImageData> getBackgroundImageData(Frame[] frames) {
    Map<Frame, ImageData> previousImagesData = new HashMap<Frame, ImageData>();
    for (Frame f : frames) {
        String imgPath = (String) f.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
        // Save previous data for undo operation
        previousImagesData.put(f, new ImageData(f.getBackgroundBounds(), f.getBackgroundImage(), imgPath));
    }
    return previousImagesData;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) HashMap(java.util.HashMap)

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