Search in sources :

Example 16 with DoubleRectangle

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

the class FrameUIModel method getRightGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getRightGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultX = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX > startX)) {
            if ((result == null) || (curX < resultX)) {
                result = cur;
                resultX = curX;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 17 with DoubleRectangle

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

the class FrameUIModel method getTopGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getTopGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultY = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startX, curX, GridButtonGroup.PIXEL_EPSILON) && (curY < startY)) {
            if ((result == null) || (curY > resultY)) {
                result = cur;
                resultY = curY;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 18 with DoubleRectangle

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

the class FrameUIModel method getLeftGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getLeftGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultX = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX < startX)) {
            if ((result == null) || (curX > resultX)) {
                result = cur;
                resultX = curX;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 19 with DoubleRectangle

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

the class ImportWebCrawlThread method doneCallback.

/**
     * For each page visited and parsed, create a corresponding Frame.
     * For each child link, create a corresponding Widget and Transition.
     */
@Override
public void doneCallback() {
    // Performed by the main UI thread
    try {
        // If an exception was thrown during the import, display error here
        if (RcvrExceptionHandler.recoverWorkThread(this, interaction)) {
            return;
        }
        if (isCanceled()) {
            return;
        }
        DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
        if (isPaused()) {
            DefaultCmd.setAttribute(design, demoStateMgr, WidgetAttributes.PAUSED_WEB_CRAWL_ATTR, importWeb.getURLsToCrawl(), interaction, editSequence);
        }
        // -1 means that the design already is part of the project
        if (insertBeforeIndex != EXISTING_DESIGN) {
            ProjectCmd.addNewDesign(project, design, insertBeforeIndex, IMPORT_WEB_DESIGN, editSequence);
        }
        Collection<PageInfo> crawledURLs = importWeb.getCrawledURLs();
        Iterator<PageInfo> pagesVisited = crawledURLs.iterator();
        Set<DeviceType> deviceTypes = design.getDeviceTypes();
        // Map (Link) IWidget to URL
        Map<IWidget, String> neededTransitions = new HashMap<IWidget, String>();
        int minFrameWidth = DesignUtil.getFrameMinWidth();
        int minFrameHeight = DesignUtil.getFrameMinHeight();
        double frameScale = DesignUtil.getFrameScaleFactor();
        DesignUtil.IFrameSituator frameSituator = new DesignUtil.ByRowFrameSituator(0.0, 0.0, 16.0, 16.0, minFrameWidth, minFrameHeight, CogToolPref.FRAMES_PER_ROW.getInt(), frameScale);
        while (pagesVisited.hasNext()) {
            ImportWebURL.ImportPageInfo page = (ImportWebURL.ImportPageInfo) pagesVisited.next();
            Frame newFrame = new Frame(page.url, deviceTypes);
            knownFrames.put(page.url, newFrame);
            if (page.background != null) {
                DoubleRectangle bds = new DoubleRectangle(page.bkgImageX, page.bkgImageY, page.bkgImageWidth, page.bkgImageHeight);
                newFrame.setBackgroundImage(page.background, bds);
            }
            int linkCount = 0;
            Iterator<URLLabeledLink> links = page.links.iterator();
            while (links.hasNext()) {
                URLPositionedLink link = (URLPositionedLink) links.next();
                // of the page)
                if ((Math.round(link.width) == 0.0) || (Math.round(link.height) == 0.0)) {
                    continue;
                }
                IWidget linkWidget = new Widget(new DoubleRectangle(link.left, link.top, link.width, link.height), WidgetType.Link);
                linkWidget.setName("Widget " + Integer.toString(++linkCount));
                linkWidget.setTitle(StringUtil.trimWhitespace(link.getLabel()));
                newFrame.addWidget(linkWidget);
                if (deviceTypes.contains(DeviceType.Mouse)) {
                    String linkURL = link.getURL();
                    Frame targetFrame = knownFrames.get(linkURL);
                    if (targetFrame != null) {
                        Transition t = new Transition(linkWidget, targetFrame, buildLinkAction());
                        IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
                        editSequence.addEdit(edit);
                    } else {
                        // Have to handle this in the second pass
                        neededTransitions.put(linkWidget, linkURL);
                    }
                }
            }
            Frame oldFrame = design.getFrame(newFrame.getName());
            if (pruneSameURLs) {
                if (oldFrame != null) {
                    makeFrameNameUnique(newFrame);
                }
            } else {
                // If oldFrame exists, remove but keep incident transitions
                if (oldFrame != null) {
                    Set<Transition> transitions = oldFrame.getIncidentTransitions();
                    synchronized (transitions) {
                        // them without upsetting the iterator
                        for (Transition transition : new ArrayList<Transition>(transitions)) {
                            DesignEditorCmd.changeTransitionTarget(demoStateMgr, transition, newFrame, editSequence);
                        }
                        //transitions=transitions2;
                        // Can't delete the transitive closure from here...sigh
                        DesignEditorCmd.deleteFrame(project, design, demoStateMgr, oldFrame, ProjectLID.ImportWebCrawl, editSequence);
                    }
                }
            }
            frameSituator.situateNextFrame(newFrame);
            DesignEditorCmd.addFrame(project, design, demoStateMgr, newFrame, editSequence);
        }
        // Each entry is IWidget --> URL string
        for (Map.Entry<IWidget, String> checkTransition : neededTransitions.entrySet()) {
            String transitionURL = checkTransition.getValue();
            Frame targetFrame = knownFrames.get(transitionURL);
            // processing is done (i.e., added during background processing).
            if (targetFrame == null) {
                targetFrame = design.getFrame(transitionURL);
            }
            // May just not be there; can't link if it's not there!
            if (targetFrame != null) {
                IWidget linkWidget = checkTransition.getKey();
                Transition t = new Transition(linkWidget, targetFrame, buildLinkAction());
                IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
                editSequence.addEdit(edit);
            }
        }
        editSequence.end();
        undoMgr.addEdit(editSequence);
    } finally {
        // Recover resources.
        importWeb.dispose();
        super.doneCallback();
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) HashMap(java.util.HashMap) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) ArrayList(java.util.ArrayList) DesignUtil(edu.cmu.cs.hcii.cogtool.model.DesignUtil) URLLabeledLink(edu.cmu.cs.hcii.cogtool.model.URLLabeledLink) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) PageInfo(edu.cmu.cs.hcii.cogtool.controller.WebCrawler.PageInfo) URLPositionedLink(edu.cmu.cs.hcii.cogtool.model.URLPositionedLink) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) HashMap(java.util.HashMap) Map(java.util.Map) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 20 with DoubleRectangle

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

the class FrameEditorController method setBackgroundImage.

/**
     * Sets the background image for the frame
     *
     * @param imageData the new image, or null if none
     */
private void setBackgroundImage(final byte[] imageData, final String imagePath) {
    try {
        // compute the size of the new image.
        final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
        // Get existing image
        final byte[] previousImageData = model.getBackgroundImage();
        final DoubleRectangle previmageSize = model.getBackgroundBounds();
        final String oldPath = (String) model.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
        // Perform operation
        model.setBackgroundImage(imageData, imageSize);
        model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
        CogToolLID lid = (imageData == null) ? FrameEditorLID.RemoveBackgroundImage : FrameEditorLID.SetBackgroundImage;
        // Add the undo edit
        IUndoableEdit edit = new AUndoableEdit(lid) {

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

            @Override
            public void redo() {
                super.redo();
                try {
                    model.setBackgroundImage(imageData, imageSize);
                    model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Redo set background image failed", ex);
                }
            }

            @Override
            public void undo() {
                super.undo();
                try {
                    model.setBackgroundImage(previousImageData, previmageSize);
                    model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, oldPath);
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Undo set background image failed", ex);
                }
            }
        };
        undoMgr.addEdit(edit);
    } catch (GraphicsUtil.ImageException e) {
        interaction.protestInvalidImageFile();
    }
}
Also used : CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) 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) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)

Aggregations

DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)31 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)13 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)9 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)8 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)6 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)5 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)5 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)5 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)5 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)4 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)4 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)4 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)3 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)3 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)3 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)3 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)3 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2