Search in sources :

Example 16 with DoublePoint

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

the class FrameEditorController method moveGridButton.

/**
     * Special case of moveWidget; moves all buttons below or to the right of
     * gb in its group and updates the horizontal and vertical offsets as
     * necessary.
     */
private void moveGridButton(ListenerIdentifier lid, String presentationLabel, GridButton gb, double widgetMoveByX, double widgetMoveByY, double newHoriz, double newVert, IUndoableEditSequence editSequence) {
    // move the list of buttons affected
    DoublePoint oldLocation = gb.getShape().getOrigin();
    double oldX = oldLocation.x;
    double oldY = oldLocation.y;
    GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
    boolean vertical = (widgetMoveByX == 0);
    double oldHoriz = gb.getHorizSpace();
    double oldVert = gb.getVertSpace();
    ReadOnlyList<? extends GridButton> movedButtons = gbg.getMovedButtons(vertical, oldX, oldY);
    for (int i = 0; i < movedButtons.size(); i++) {
        GridButton g = movedButtons.get(i);
        DoublePoint p = g.getShape().getOrigin();
        double tempX = Math.max(p.x + widgetMoveByX, 0.0);
        double tempY = Math.max(p.y + widgetMoveByY, 0.0);
        g.setWidgetOrigin(tempX, tempY);
    }
    if (vertical) {
        gb.setVertSpace(newVert);
    } else {
        List<GridButton> column = gbg.getColumn(gb);
        for (int i = 0; i < column.size(); i++) {
            GridButton g = column.get(i);
            g.setHorizSpace(newHoriz);
        }
    }
    DemoStateManager.IDesignUndoableEdit edit = moveGridButtonsEdit(lid, presentationLabel, movedButtons, widgetMoveByX, widgetMoveByY, oldHoriz, oldVert, newHoriz, newVert, gb);
    editSequence.addEdit(edit);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 17 with DoublePoint

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

the class DesignEditorCmd method getFirstChildPosition.

private static DoublePoint getFirstChildPosition(AParentWidget parent) {
    AShape parentShape = parent.getShape();
    DoublePoint pos = parentShape.getOrigin();
    DoubleSize extent = parentShape.getSize();
    switch(parent.getChildrenLocation()) {
        case AParentWidget.CHILDREN_BELOW:
            {
                pos.y += extent.height;
                break;
            }
        case AParentWidget.CHILDREN_RIGHT:
            {
                pos.x += extent.width;
                break;
            }
        case AParentWidget.CHILDREN_CENTER:
            {
                pos.x += extent.width / 2.0;
                pos.y += extent.height / 2.0;
                break;
            }
    }
    return pos;
}
Also used : DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AShape(edu.cmu.cs.hcii.cogtool.model.AShape) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 18 with DoublePoint

use of edu.cmu.cs.hcii.cogtool.model.DoublePoint 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 19 with DoublePoint

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

the class Controller method assignActions.

/**
     * Registers the set of <code>IListenerAction</code> instances
     * that implement the semantic actions that are possible.
     * <p>
     * For this class, this consists of the actions that all windows support.
     *
     * @author mlh
     */
protected void assignActions() {
    UI ui = getUI();
    if (ui != null) {
        ui.setAction(CogToolLID.About, ui.popAboutBox());
        // Set "open" action
        ui.setAction(CogToolLID.OpenProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                // open expects null in that case.
                if (!(prms instanceof DoublePoint)) {
                    prms = null;
                }
                // Ask the user to select a CogTool project to open
                File[] openLocs = getUI().getStandardInteraction().selectFileSources();
                return open((DoublePoint) prms, openLocs);
            }
        });
        ui.setAction(CogToolLID.OpenProjectFile, new IListenerAction() {

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

            public boolean performAction(Object actionParms) {
                File[] openLoc = { new File((String) actionParms) };
                return open(null, openLoc);
            }
        });
        // Set "new project" action
        ui.setAction(CogToolLID.NewProject, createNewProjectAction());
        // Set "quit/exit" action
        ui.setAction(CogToolLID.ExitApplication, createExitAction());
        ui.setAction(CogToolLID.ClearRecent, new AListenerAction() {

            public boolean performAction(Object actionParms) {
                CogToolPref.clearRecent();
                Interaction interaction = getUI().getStandardInteraction();
                interaction.setStatusMessage(L10N.get("AC.RecentClear", "Recent file data cleared."));
                return true;
            }
        });
    }
}
Also used : UI(edu.cmu.cs.hcii.cogtool.ui.UI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) File(java.io.File)

Example 20 with DoublePoint

use of edu.cmu.cs.hcii.cogtool.model.DoublePoint 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)

Aggregations

DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)23 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)6 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)6 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)5 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)4 AListenerAction (edu.cmu.cs.hcii.cogtool.util.AListenerAction)4 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)3 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)3 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)3 FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)3 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)3 Iterator (java.util.Iterator)3 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)2 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)2 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)2 Interaction (edu.cmu.cs.hcii.cogtool.ui.Interaction)2 UI (edu.cmu.cs.hcii.cogtool.ui.UI)2