Search in sources :

Example 21 with Transition

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

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

the class DesignEditorCmd method deleteFrame.

public static void deleteFrame(final Project project, final Design design, final DemoStateManager demoStateMgr, final Frame frame, CogToolLID lid, IUndoableEditSequence editSequence) {
    final Transition[] incidentTransitions = frame.removeIncidentTransitions();
    design.removeFrame(frame);
    DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(lid, demoStateMgr) {

        private boolean recoverMgr = true;

        @Override
        public void redo() {
            super.redo();
            recoverMgr = true;
            frame.removeIncidentTransitions();
            design.removeFrame(frame);
            demoStateMgr.noteFrameEdit(frame, this);
        }

        @Override
        public void undo() {
            super.undo();
            recoverMgr = false;
            design.addFrame(frame);
            addIncidentTransitions(incidentTransitions);
            demoStateMgr.noteFrameEdit(frame, this);
        }

        @Override
        public void die() {
            super.die();
            if (recoverMgr) {
                UndoManagerRecovery.recoverManagers(project, frame);
            }
        }
    };
    demoStateMgr.noteFrameEdit(frame, edit);
    editSequence.addEdit(edit);
}
Also used : Transition(edu.cmu.cs.hcii.cogtool.model.Transition) IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)

Example 23 with Transition

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

the class DesignEditorController method changeTransitionsAction.

protected boolean changeTransitionsAction(Transition[] transitions, AAction newAction, double delayInSecs, String delayLabel) {
    if ((transitions != null) && (transitions.length > 0)) {
        CompoundUndoableEdit editSequence = new CompoundUndoableEdit(changeAction, DesignEditorLID.ChangeWidgetAction);
        for (Transition transition : transitions) {
            changeTransitionAction(transition, newAction, delayInSecs, delayLabel, editSequence);
        }
        editSequence.end();
        // Only add the compound edit if it contains something
        if (editSequence.isSignificant()) {
            undoMgr.addEdit(editSequence);
        }
    }
    return true;
}
Also used : Transition(edu.cmu.cs.hcii.cogtool.model.Transition) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)

Example 24 with Transition

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

the class DesignEditorController method createEditTransitionAction.

// createEditDesignAction
protected IListenerAction createEditTransitionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.EditTransitionParameters parms = (DesignEditorUI.EditTransitionParameters) prms;
            Transition[] transitions = parms.selection.getSelectedTransitions();
            // Probably only one transition selected
            if ((transitions != null) && (transitions.length > 0)) {
                if (transitions.length == 1) {
                    TransitionSource source = transitions[0].getSource();
                    AAction action = transitions[0].getAction();
                    int limitMode = ActionProperties.determineChangeActionMode(source);
                    int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
                    if (!interaction.determineNewAction(transitions[0], properties, parms.useWhichParts, deviceTypes, limitMode, L10N.get("DE.ChangeActionType", "Change Action Type"))) {
                        return false;
                    }
                    action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
                    if (action == null) {
                        return false;
                    }
                    action = EditActionCmd.ensureActionIsUnique(source, action, properties, deviceTypes, limitMode, transitions[0], interaction);
                    if (action == null) {
                        return false;
                    }
                    return changeTransitionsAction(transitions, action, properties.delayInSecs, properties.delayLabel);
                } else {
                    interaction.protestMultipleTransitionSelection();
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) AAction(edu.cmu.cs.hcii.cogtool.model.AAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 25 with Transition

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

the class DesignEditorController method deleteTransitions.

protected void deleteTransitions(final Transition[] transitions) {
    // For redo, must save the corresponding source for each Transition
    if ((transitions != null) && (transitions.length > 0)) {
        final TransitionSource[] sources = new TransitionSource[transitions.length];
        for (int i = 0; i < transitions.length; i++) {
            Transition t = transitions[i];
            sources[i] = t.getSource();
            sources[i].removeTransition(t);
        }
        DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(DesignEditorLID.DeleteTransition, demoStateMgr) {

            @Override
            public String getPresentationName() {
                return (transitions.length > 1) ? deleteTransitions : deleteTransition;
            }

            @Override
            public void redo() {
                super.redo();
                for (int i = 0; i < transitions.length; i++) {
                    Transition t = transitions[i];
                    sources[i].removeTransition(t);
                }
                stateMgr.noteTransitionsEdit(transitions, this);
            }

            @Override
            public void undo() {
                super.undo();
                for (int i = 0; i < transitions.length; i++) {
                    Transition t = transitions[i];
                    sources[i].addTransition(t);
                }
                stateMgr.noteTransitionsEdit(transitions, this);
            }
        };
        demoStateMgr.noteTransitionsEdit(transitions, edit);
        undoMgr.addEdit(edit);
    }
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

Transition (edu.cmu.cs.hcii.cogtool.model.Transition)33 AAction (edu.cmu.cs.hcii.cogtool.model.AAction)13 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)11 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)7 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)7 ButtonAction (edu.cmu.cs.hcii.cogtool.model.ButtonAction)6 DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)5 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)5 MousePressType (edu.cmu.cs.hcii.cogtool.model.MousePressType)4 TapAction (edu.cmu.cs.hcii.cogtool.model.TapAction)4 DesignEditorTransition (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition)4 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)3 MouseButtonState (edu.cmu.cs.hcii.cogtool.model.MouseButtonState)3 TapPressType (edu.cmu.cs.hcii.cogtool.model.TapPressType)3 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 GraffitiAction (edu.cmu.cs.hcii.cogtool.model.GraffitiAction)2 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2