Search in sources :

Example 11 with DeviceType

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

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

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

the class DesignCmd method addDevices.

public static boolean addDevices(Project project, Design design, Interaction interaction) {
    Interaction.DesignRequestData requestData = requestAddDevices(project, design, interaction);
    if (requestData == null) {
        // canceled!
        return false;
    }
    Set<DeviceType> existingDevices = design.addDeviceTypes(requestData.deviceTypes);
    if (requestData.deviceTypes.equals(existingDevices)) {
        // nothing to do
        return true;
    }
    Iterator<DeviceType> addDevices = requestData.deviceTypes.iterator();
    while (addDevices.hasNext()) {
        DeviceType devType = addDevices.next();
        addDevice(design, devType, existingDevices);
    }
    return true;
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction)

Example 14 with DeviceType

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

the class DesignEditorUI method updateView.

protected void updateView(boolean deselectAll) {
    if (view.isDisposed()) {
        return;
    }
    ActionPropertySet actionProps = view.getActionPropertySet();
    int selectedTransitionCount = selection.getSelectedTransitionCount();
    int selectedFrameCount = selection.getSelectedFrameCount();
    if (deselectAll || (selectedFrameCount + selectedTransitionCount == 0)) {
        actionProps.useParameters(ActionSet.USE_NONE);
    } else if (selectedTransitionCount == 1) {
        Transition transition = selection.getSelectedTransitions()[0];
        AAction action = transition.getAction();
        DeviceType type = action.getDefaultDeviceType();
        int device = ActionSet.USE_NONE;
        if (action instanceof GraffitiAction) {
            device = ActionSet.USE_GRAFFITI_WIDGET;
        } else if (type == DeviceType.Mouse) {
            device = ActionSet.USE_MOUSE;
        } else if (type == DeviceType.Touchscreen) {
            device = ActionSet.USE_TOUCHSCREEN;
        } else if (type == DeviceType.Keyboard) {
            device = ActionSet.USE_KEYBOARD;
        } else if (type == DeviceType.Voice) {
            device = ActionSet.USE_VOICE;
        } else if (type == null) {
            // Generally, a hover action; pick whichever is active
            if (actionProps.isMouseSelected()) {
                device = ActionSet.USE_MOUSE;
            } else if (actionProps.isTouchSelected()) {
                device = ActionSet.USE_TOUCHSCREEN;
            }
        }
        actionProps.setComposite(device);
        ActionProperties properties = view.getActionProperties();
        view.getDefaultProperties(properties);
        properties.updateProperties(transition, transition.getAction(), transition.getSource());
        int limitMode = ActionProperties.determineChangeActionMode(transition.getSource());
        actionProps.setLimitMode(limitMode, properties.useWhichParts);
        actionProps.setProperties(properties, properties.useWhichParts);
    } else if (selectedTransitionCount > 1) {
        actionProps.useParameters(ActionPropertySet.MULT_TRANS);
    }
    if (selectedFrameCount == 1) {
        actionProps.updateFrameComposite(selection.getSelectedFrames()[0]);
    } else if ((selectedFrameCount == 0) && (selectedTransitionCount == 0)) {
        actionProps.updateEmptyComposite(design, false);
    }
}
Also used : ActionPropertySet(edu.cmu.cs.hcii.cogtool.view.ActionPropertySet) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) GraffitiAction(edu.cmu.cs.hcii.cogtool.model.GraffitiAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) DesignEditorTransition(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition) Point(org.eclipse.draw2d.geometry.Point) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Aggregations

DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)14 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)6 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)5 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)5 AAction (edu.cmu.cs.hcii.cogtool.model.AAction)4 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)3 ButtonAction (edu.cmu.cs.hcii.cogtool.model.ButtonAction)2 GraffitiAction (edu.cmu.cs.hcii.cogtool.model.GraffitiAction)2 TapAction (edu.cmu.cs.hcii.cogtool.model.TapAction)2 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)2 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 PageInfo (edu.cmu.cs.hcii.cogtool.controller.WebCrawler.PageInfo)1 AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)1 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)1 ActionType (edu.cmu.cs.hcii.cogtool.model.ActionType)1 CheckBox (edu.cmu.cs.hcii.cogtool.model.CheckBox)1 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)1 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 Design (edu.cmu.cs.hcii.cogtool.model.Design)1