Search in sources :

Example 56 with IWidget

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

the class ChoiceWireRenderer method updateData.

@Override
public void updateData() {
    GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
    IWidget attributed = gw.getModel();
    if (kind == CHECK) {
        selected = RendererSupport.isSelected(attributed, attrOverride);
    } else {
        selected = RendererSupport.isRadioSelected(attributed, attrOverride);
    }
}
Also used : IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 57 with IWidget

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

the class SEDemoController method performTransition.

/**
     * Take the transition, and perform the action
     *
     * @param transition
     */
protected boolean performTransition(SEDemoSelectionState selection, Transition transition, CogToolLID lid) {
    AScriptStep stepToReplace = getDemoStep(selection);
    if (stepToReplace != null) {
        Frame currentFrame = stepToReplace.getCurrentFrame();
        if (transition.getDestination() == currentFrame) {
            return insertStep(new TransitionScriptStep(transition), stepToReplace, lid, PERFORM_TRANSITION);
        }
        if (!interaction.confirmDestructiveInsert()) {
            return false;
        }
    }
    AScriptStep newDemoStep = new TransitionScriptStep(transition);
    TransitionSource source = transition.getSource();
    if (source.getFrame() == transition.getDestination() && (source instanceof IWidget)) {
        toggleIfGermane((IWidget) source, newDemoStep, transition.getAction());
    }
    Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
    Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
    Demonstration demo = script.getDemonstration();
    final int atIndex = demo.replaceSteps(stepToReplace, newDemoSteps, oldDemoSteps);
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, stepToReplace, interaction);
    IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, oldDemoSteps, demoStateMgr) {

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

        @Override
        public void redo() {
            super.redo();
            demo.replaceSteps(atIndex, redoDemoSteps);
            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            demo.replaceSteps(atIndex, undoDemoSteps);
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PERFORM_TRANSITION, lid);
    editSequence.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
    }
    editSequence.end();
    undoMgr.addEdit(editSequence);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TransitionScriptStep(edu.cmu.cs.hcii.cogtool.model.TransitionScriptStep) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 58 with IWidget

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

the class ActionProperties method setInitialActionType.

/**
     * Base initial action type on given source
     */
public void setInitialActionType(TransitionSource source, Set<DeviceType> deviceTypes) {
    if (source instanceof InputDevice) {
        InputDevice device = (InputDevice) source;
        DeviceType devType = device.getDeviceType();
        if (devType == DeviceType.Keyboard) {
            useWhichParts = USE_KEYBOARD;
        } else if (devType == DeviceType.Mouse) {
            useWhichParts = USE_MOUSE;
        } else if (devType == DeviceType.Touchscreen) {
            useWhichParts = USE_TOUCHSCREEN;
        } else if (devType == DeviceType.Voice) {
            useWhichParts = USE_VOICE;
        }
    } else if (source instanceof IWidget) {
        IWidget widget = (IWidget) source;
        WidgetType widgetType = widget.getWidgetType();
        if (widgetType == WidgetType.Graffiti) {
            useWhichParts = USE_GRAFFITI_WIDGET;
        } else if (widgetType == WidgetType.TextBox) {
            useWhichParts = USE_KEYBOARD;
        } else {
            setInitialActionType(source, BASE_ACTION_ON_SOURCE, deviceTypes);
        }
    }
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 59 with IWidget

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

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

the class FrameEditorController method duplicateWidgetsAction.

// duplicateFrameEltGroup
private IListenerAction duplicateWidgetsAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.DuplicateParameters parameters = (FrameEditorUI.DuplicateParameters) prms;
            int elementCount = parameters.selection.getElementSelectionCount();
            // If selection is non zero, copy widgets
            if (elementCount > 0) {
                Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
                final Map<FrameElementGroup, FrameElementGroup> groupCopies = new LinkedHashMap<FrameElementGroup, FrameElementGroup>();
                widgetSituator.reset(widgetCopies, groupCopies);
                Set<FrameElement> selectedElements = getSelectedElements(parameters.selection, elementLevelComparator);
                Iterator<FrameElement> elements = selectedElements.iterator();
                // Iterate through the widgets and duplicate.
                while (elements.hasNext()) {
                    FrameElement elt = elements.next();
                    if (elt instanceof IWidget) {
                        duplicateWidget((IWidget) elt, parameters.selection, parameters.moveByX, parameters.moveByY);
                    } else if (elt instanceof FrameElementGroup) {
                        duplicateFrameEltGroup((FrameElementGroup) elt, parameters.moveByX, parameters.moveByY);
                    }
                }
                widgetSituator.completeWork();
                final Iterable<? extends IWidget> widgetDuplicates = new ReadOnlyList<IWidget>(new ArrayList<IWidget>(widgetCopies.values()));
                Iterator<? extends IWidget> copiedWidgets = widgetDuplicates.iterator();
                Set<GridButtonGroup> dupGridGroups = new HashSet<GridButtonGroup>();
                while (copiedWidgets.hasNext()) {
                    IWidget widgetCopy = copiedWidgets.next();
                    // Warning: it is important that each widget be added
                    // to the frame *before* we make the next widget name
                    // unique or we can end up with non-unique names.
                    makeWidgetNameUnique(widgetCopy);
                    model.addWidget(widgetCopy);
                    if (widgetCopy instanceof GridButton) {
                        GridButtonGroup gbg = (GridButtonGroup) widgetCopy.getParentGroup();
                        // for each grid button group
                        if (!dupGridGroups.contains(gbg)) {
                            gbg.recalculateOffsets();
                            dupGridGroups.add(gbg);
                        }
                    }
                }
                Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                while (copiedGroups.hasNext()) {
                    FrameElementGroup copiedGroup = copiedGroups.next();
                    // Ensure name is unique, then add to frame immediately
                    // Otherwise, it would be possible to generate presumed
                    // unique names that weren't.
                    makeEltGroupNameUnique(copiedGroup);
                    model.addEltGroup(copiedGroup);
                }
                DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<? extends IWidget> addCopies = widgetDuplicates.iterator();
                        while (addCopies.hasNext()) {
                            IWidget widgetCopy = addCopies.next();
                            model.addWidget(widgetCopy);
                        }
                        Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                        while (copiedGroups.hasNext()) {
                            model.addEltGroup(copiedGroups.next());
                        }
                        demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        Iterator<? extends IWidget> removeCopies = widgetDuplicates.iterator();
                        while (removeCopies.hasNext()) {
                            IWidget widgetCopy = removeCopies.next();
                            model.removeWidget(widgetCopy);
                        }
                        Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                        while (copiedGroups.hasNext()) {
                            model.removeEltGroup(copiedGroups.next());
                        }
                        demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
                    }
                };
                demoStateMgr.noteWidgetsEdit(widgetDuplicates, edit);
                undoMgr.addEdit(edit);
                return true;
            }
            // tell user to select something.
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) LinkedHashMap(java.util.LinkedHashMap) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HashSet(java.util.HashSet) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ReadOnlyList(edu.cmu.cs.hcii.cogtool.util.ReadOnlyList) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)93 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)29 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)20 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)19 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)15 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)15 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)12 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 Point (org.eclipse.draw2d.geometry.Point)11 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)9 HashSet (java.util.HashSet)8 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)7 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)7 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)7 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)7 Iterator (java.util.Iterator)7 EventObject (java.util.EventObject)6