Search in sources :

Example 1 with ButtonAction

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

the class SEDemoMouseState method doTransitionAction.

protected boolean doTransitionAction(TransitionSource source, int button, int state, int clickState) {
    AAction action = null;
    Set<DeviceType> deviceTypes = ui.design.getDeviceTypes();
    if (deviceTypes.contains(DeviceType.Mouse)) {
        MousePressType pt = null;
        switch(clickState) {
            case UP:
                pt = MousePressType.Up;
                break;
            case DOWN:
                pt = MousePressType.Down;
                break;
            case CLICK:
                pt = MousePressType.Click;
                break;
            case DOUBLE:
                pt = MousePressType.Double;
                break;
            case TRIPLE:
                pt = MousePressType.Triple;
                break;
            default:
                throw new IllegalArgumentException("Invalid click state received");
        }
        action = new ButtonAction(getActionButtonButton(button), pt, getActionButtonModifier(state));
    } else if (deviceTypes.contains(DeviceType.Touchscreen)) {
        TapPressType tt = null;
        switch(clickState) {
            case UP:
                tt = TapPressType.Up;
                break;
            case DOWN:
                tt = TapPressType.Down;
                break;
            case CLICK:
                tt = TapPressType.Tap;
                break;
            case DOUBLE:
                tt = TapPressType.DoubleTap;
                break;
            case TRIPLE:
                tt = TapPressType.TripleTap;
                break;
            default:
                throw new IllegalArgumentException("Invalid ClickState received");
        }
        action = new TapAction(tt);
    }
    if (clickState == CLICK) {
        if (source.getTransition(action) == null) {
            // Check to see if a doubleclick/doubletap is in the set of
            // transitions
            Iterator<AAction> iter = source.getTransitions().keySet().iterator();
            while (iter.hasNext()) {
                AAction act = iter.next();
                if ((act.getType() == ActionType.ButtonPress) && deviceTypes.contains(DeviceType.Mouse)) {
                } else if ((act.getType() == ActionType.Tap) && deviceTypes.contains(DeviceType.Touchscreen)) {
                }
            }
            if ((source instanceof IWidget) && ((IWidget) source).isStandard() && deviceTypes.contains(DeviceType.Mouse)) {
                WidgetType type = ((IWidget) source).getWidgetType();
                Object toggle = source.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
                Object isSep = source.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
                if ((type == WidgetType.Check) || (type == WidgetType.Radio) || ((type == WidgetType.PullDownItem) && NullSafe.equals(WidgetAttributes.NON_SEPARATOR, isSep)) || ((type == WidgetType.Button) && NullSafe.equals(WidgetAttributes.IS_TOGGLEABLE, toggle))) {
                    if (type == WidgetType.PullDownItem) {
                        ui.hideAllChildren();
                    }
                    AAction a = new ButtonAction(MouseButtonState.Left, MousePressType.Click, 0);
                    SEDemoUI.SelfTransition prms = new SEDemoUI.SelfTransition(ui.selection, source, a);
                    ui.performAction(SEDemoLID.InsertSelfTransition, prms);
                    return true;
                }
            }
            ui.showContextMenu(source);
        }
    }
    Transition transition = source.getTransition(action);
    if (transition != null) {
        SEDemoUI.FollowTransition prms = new SEDemoUI.FollowTransition(ui.selection, transition);
        ui.performAction(SEDemoLID.PerformTransition, prms);
        return true;
    }
    return false;
}
Also used : ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) TapAction(edu.cmu.cs.hcii.cogtool.model.TapAction) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) TapPressType(edu.cmu.cs.hcii.cogtool.model.TapPressType) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) MousePressType(edu.cmu.cs.hcii.cogtool.model.MousePressType) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) AAction(edu.cmu.cs.hcii.cogtool.model.AAction) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 2 with ButtonAction

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

the class ActionProperties method updateProperties.

public void updateProperties(TransitionDelay td, AAction action, TransitionSource transitionSource) {
    delayInSecs = td.getDelayInSecs();
    delayLabel = td.getDelayLabel();
    Transition tr = transitionSource.getTransitions().get(action);
    if (tr != null) {
        // null if self-transition
        transitionDestinationLabel = tr.getDestination().getName();
    }
    if (transitionSource instanceof IWidget) {
        // TODO: Must modify this when text fields are added.
        // Text fields may not use "ButtonAction"
        AAction.ActionVisitor widgetActionVisitor = new AAction.ActionVisitor() {

            @Override
            public void visit(ButtonAction but) {
                mouseButton = but.getButton();
                buttonAction = but.getPressType();
                if (buttonAction == MousePressType.Hover) {
                    mouseButton = null;
                }
                buttonState = but.getModifiers();
                useWhichParts = ActionProperties.USE_MOUSE;
            }

            @Override
            public void visit(TapAction tap) {
                tapAction = tap.getTapPressType();
                useWhichParts = ActionProperties.USE_TOUCHSCREEN;
            }

            @Override
            public void visit(KeyAction key) {
                keyboardString = key.getText();
                keyboardIsCmd = key.isCommand();
                keyboardAction = key.getPressType();
                useWhichParts = ActionProperties.USE_KEYBOARD;
            }

            @Override
            public void visit(GraffitiAction graffiti) {
                graffitiString = graffiti.getText();
                graffitiIsCmd = graffiti.isCommand();
                useWhichParts = ActionProperties.USE_GRAFFITI_WIDGET;
            }

            @Override
            public void visit(VoiceAction voice) {
                voiceString = voice.getText();
                voiceIsCmd = voice.isCommand();
                useWhichParts = ActionProperties.USE_VOICE;
            }
        };
        action.accept(widgetActionVisitor);
        String t = ((IWidget) transitionSource).getTitle();
        if (t.length() > 0) {
            transitionSourceLabel = t + " in " + ((IWidget) transitionSource).getFrame().getName();
        } else {
            transitionSourceLabel = ((IWidget) transitionSource).getName() + " in " + ((IWidget) transitionSource).getFrame().getName();
        }
    } else {
        InputDevice deviceSource = (InputDevice) transitionSource;
        DeviceType type = deviceSource.getDeviceType();
        if (type == DeviceType.Voice) {
            VoiceAction voiceAction = (VoiceAction) action;
            voiceString = voiceAction.getText();
            voiceIsCmd = voiceAction.isCommand();
            useWhichParts = ActionProperties.USE_VOICE;
        } else {
            KeyAction keyAction = (KeyAction) action;
            keyboardString = keyAction.getText();
            keyboardAction = keyAction.getPressType();
            keyboardIsCmd = keyAction.isCommand();
            useWhichParts = ActionProperties.USE_KEYBOARD;
        }
        transitionSourceLabel = "";
    }
}
Also used : InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) TapAction(edu.cmu.cs.hcii.cogtool.model.TapAction) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) VoiceAction(edu.cmu.cs.hcii.cogtool.model.VoiceAction) GraffitiAction(edu.cmu.cs.hcii.cogtool.model.GraffitiAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) KeyAction(edu.cmu.cs.hcii.cogtool.model.KeyAction) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 3 with ButtonAction

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

the class DesignExportToHTML method textSelect.

/**
	 * For checkboxes and radio buttons, clicking on the text should cause
	 * the widget to change selection.  The exception to this is when the
	 * widget already has a left-click transition defined that is not a
	 * self-transition, since then it would override the onclick property.
	 * @param widget
	 * @return
	 */
protected boolean textSelect(IWidget widget) {
    Iterator<Transition> transitions = widget.getTransitions().values().iterator();
    boolean leftClick = false;
    while (transitions.hasNext()) {
        Transition transition = transitions.next();
        AAction action = transition.getAction();
        if (action instanceof ButtonAction) {
            ButtonAction bAction = (ButtonAction) action;
            MouseButtonState buttonState = bAction.getButton();
            MousePressType pressType = bAction.getPressType();
            if (MouseButtonState.Left.equals(buttonState) && MousePressType.Click.equals(pressType)) {
                leftClick = true;
                if (transition.getDestination().equals(widget.getFrame())) {
                    return true;
                }
            }
        }
    }
    if (leftClick) {
        return false;
    }
    return true;
}
Also used : Transition(edu.cmu.cs.hcii.cogtool.model.Transition) ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) MousePressType(edu.cmu.cs.hcii.cogtool.model.MousePressType) AAction(edu.cmu.cs.hcii.cogtool.model.AAction) MouseButtonState(edu.cmu.cs.hcii.cogtool.model.MouseButtonState)

Example 4 with ButtonAction

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

the class DesignExportToHTML method getMenuMap.

/**
	 * Return an array of three strings, corresponding to the three possible
	 * mouse buttons, representing either the name of the frame transitioned to
	 * by that button, or 'null'.
	 * NOTE: Hover and multiple-click transitions don't work with menu items.
	 */
protected String getMenuMap(MenuItem child) {
    String result = "[";
    // TODO: onmouseup doesn't work for middle clicks...except
    // sometimes it does, may be related to focus?
    // Always use onmouseup instead of onclick because we need to check
    // for double click here too
    String[] mouseUpDests = new String[4];
    mouseUpDests[0] = "null";
    int mouseUpButton = 0;
    Iterator<Transition> transitions = child.getTransitions().values().iterator();
    while (transitions.hasNext()) {
        Transition transition = transitions.next();
        AAction action = transition.getAction();
        if (action instanceof ButtonAction) {
            ButtonAction bAction = (ButtonAction) action;
            MouseButtonState buttonState = bAction.getButton();
            MousePressType pressType = bAction.getPressType();
            int button = -1;
            String destName = getFrameURL(transition.getDestination(), ".html");
            if (!MousePressType.Hover.equals(pressType)) {
                if (MouseButtonState.Left.equals(buttonState)) {
                    button = LEFT_MOUSE;
                } else if (MouseButtonState.Middle.equals(buttonState)) {
                    button = MIDDLE_MOUSE;
                } else if (MouseButtonState.Right.equals(buttonState)) {
                    button = RIGHT_MOUSE;
                }
                /*if (MousePressType.Click.equals(pressType) &&
                        (button == LEFT_MOUSE))
                    {
                        //onAction = "onclick";
//                        clickDest = "'" + destName + "'";
                        mouseUpButton = button;
                        mouseUpDests[mouseUpButton] = "'" + destName + "'";
                    }
                    else */
                if (MousePressType.Up.equals(pressType) || MousePressType.Click.equals(pressType)) {
                    //onAction = "onmouseup";
                    mouseUpButton = button;
                    mouseUpDests[mouseUpButton] = "'" + destName + "'";
                }
            //                    else if (MousePressType.Double.equals(pressType)) {
            //                        //onAction = "ondblclick";
            //                        dblClickButton = button;
            //                        dblClickDests[dblClickButton] = "'" + destName + "'";
            //                    }
            //                  else if (MousePressType.Down.equals(pressType)) {
            //                      onAction = "onmousedown";
            //                  }
            }
        } else if (action instanceof TapAction) {
            TapAction bAction = (TapAction) action;
            TapPressType pressType = bAction.getTapPressType();
            String destName = getFrameURL(transition.getDestination(), ".html");
            if (!TapPressType.Hover.equals(pressType)) {
                if (TapPressType.Tap.equals(pressType)) {
                    // TODO: Behavior is undefined if both a left-click and
                    // tap transition are created from the same widget!
                    //onAction = "onclick";
                    //                        clickDest = "'" + destName + "'";
                    mouseUpButton = LEFT_MOUSE;
                    mouseUpDests[mouseUpButton] = "'" + destName + "'";
                }
            //                  else if (TapPressType.Up.equals(pressType)) {
            //                      onAction = "onmouseup";
            //                  }
            //                    else if (TapPressType.DoubleTap.equals(pressType)) {
            //                        //onAction = "ondblclick";
            //                        // TODO see tap
            //                        dblClickButton = LEFT_MOUSE;
            //                        dblClickDests[dblClickButton] = "'" + destName + "'";
            //                    }
            //                  else if (TapPressType.Down.equals(pressType)) {
            //                      //onAction = "onmousedown";
            //                  }
            }
        }
    }
    for (int i = 1; i < mouseUpDests.length; i++) {
        if (mouseUpDests[i] == null) {
            mouseUpDests[i] = "null";
        }
        //            if (dblClickDests[i] == null) {
        //                dblClickDests[i] = "null";
        //            }
        result += mouseUpDests[i];
        if (i < 3) {
            result += ", ";
        }
    }
    result += "]";
    return result;
}
Also used : TapPressType(edu.cmu.cs.hcii.cogtool.model.TapPressType) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) MousePressType(edu.cmu.cs.hcii.cogtool.model.MousePressType) TapAction(edu.cmu.cs.hcii.cogtool.model.TapAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AAction(edu.cmu.cs.hcii.cogtool.model.AAction) MouseButtonState(edu.cmu.cs.hcii.cogtool.model.MouseButtonState)

Example 5 with ButtonAction

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

the class DesignExportToHTML method parseTransitions.

/**
	 * Given the transitions from a widget, parse them and return 3 strings:
	 * first, the name of the destination frame of its hover transition;
	 * second, the map that defines its single click transitions;
	 * third, the map that defines its double click transitions.
	 * (See comments on the javascript functions for how these maps are used.)
	 */
protected String[] parseTransitions(IWidget w, boolean checkFocus, int ignoreButton) {
    String[] result = new String[2];
    result[0] = "null";
    result[1] = "[";
    // TODO: onmouseup doesn't work for middle clicks...except
    // sometimes it does, may be related to focus?
    // Always use onmouseup instead of onclick because we need to check
    // for double click here too
    Iterator<Transition> transitions = w.getTransitions().values().iterator();
    // If we are told to ignore transitions from a certain button, check
    // if the widget has any transitions defined from that button.  If not,
    // tell the javascript explicitly not to pop up the "does not help..."
    // message if that button is clicked with the IGNORE_LEFT_CLICK string
    // flag.
    boolean hasIgnoredButtonTransition = false;
    while (transitions.hasNext()) {
        Transition transition = transitions.next();
        AAction action = transition.getAction();
        if (action instanceof ButtonAction) {
            ButtonAction bAction = (ButtonAction) action;
            MouseButtonState buttonState = bAction.getButton();
            MousePressType pressType = bAction.getPressType();
            int button = -1;
            String destName = getFrameURL(transition.getDestination(), ".html");
            int modifiers = bAction.getModifiers();
            int numClicks = 0;
            if (MousePressType.Hover.equals(pressType)) {
                result[0] = "'" + destName + "'";
            } else {
                if (MouseButtonState.Left.equals(buttonState)) {
                    button = LEFT_MOUSE;
                    if (checkFocus) {
                        destName += buildFocusSearch(w, transition.getDestination());
                    }
                } else if (MouseButtonState.Middle.equals(buttonState)) {
                    button = MIDDLE_MOUSE;
                } else if (MouseButtonState.Right.equals(buttonState)) {
                    button = RIGHT_MOUSE;
                }
                if (MousePressType.Up.equals(pressType) || MousePressType.Click.equals(pressType)) {
                    numClicks = 1;
                    if ((button == ignoreButton) && (modifiers == AAction.NONE)) {
                        hasIgnoredButtonTransition = true;
                    }
                } else if (MousePressType.Double.equals(pressType)) {
                    numClicks = 2;
                } else if (MousePressType.Triple.equals(pressType)) {
                    numClicks = 3;
                }
                if (result[1].length() > 1) {
                    result[1] += ", ";
                }
                result[1] += "[" + button + ", " + numClicks + ", " + modifiers + ", '" + destName + "']";
            }
        } else if (action instanceof TapAction) {
            TapAction bAction = (TapAction) action;
            TapPressType pressType = bAction.getTapPressType();
            String destName = getFrameURL(transition.getDestination(), ".html");
            int numClicks = 0;
            if (TapPressType.Hover.equals(pressType)) {
                result[0] = "'" + destName + "'";
            } else {
                if (TapPressType.Up.equals(pressType) || TapPressType.Tap.equals(pressType)) {
                    // TODO: Behavior is undefined if both a left-click and
                    // tap transition are created from the same widget!
                    numClicks = 1;
                    if (ignoreButton == 1) {
                        hasIgnoredButtonTransition = true;
                    }
                } else //                  }
                if (TapPressType.DoubleTap.equals(pressType)) {
                    //onAction = "ondblclick";
                    // TODO see tap
                    numClicks = 2;
                } else if (TapPressType.TripleTap.equals(pressType)) {
                    // TODO see tap
                    numClicks = 3;
                }
                if (result[1].length() > 1) {
                    result[1] += ", ";
                }
                result[1] += "[" + LEFT_MOUSE + ", " + numClicks + ", " + AAction.NONE + ", '" + destName + "']";
            }
        }
    }
    if (!hasIgnoredButtonTransition) {
        // transition already defined
        if (result[1].length() > 1) {
            result[1] += ", ";
        }
        result[1] += "[" + ignoreButton + ", 1, 0, " + IGNORE_LEFT_CLICK + "]";
    }
    result[1] += "]";
    return result;
}
Also used : TapPressType(edu.cmu.cs.hcii.cogtool.model.TapPressType) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) ButtonAction(edu.cmu.cs.hcii.cogtool.model.ButtonAction) MousePressType(edu.cmu.cs.hcii.cogtool.model.MousePressType) TapAction(edu.cmu.cs.hcii.cogtool.model.TapAction) AAction(edu.cmu.cs.hcii.cogtool.model.AAction) MouseButtonState(edu.cmu.cs.hcii.cogtool.model.MouseButtonState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

AAction (edu.cmu.cs.hcii.cogtool.model.AAction)6 ButtonAction (edu.cmu.cs.hcii.cogtool.model.ButtonAction)6 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)6 MousePressType (edu.cmu.cs.hcii.cogtool.model.MousePressType)4 TapAction (edu.cmu.cs.hcii.cogtool.model.TapAction)4 MouseButtonState (edu.cmu.cs.hcii.cogtool.model.MouseButtonState)3 TapPressType (edu.cmu.cs.hcii.cogtool.model.TapPressType)3 DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)2 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 GraffitiAction (edu.cmu.cs.hcii.cogtool.model.GraffitiAction)1 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)1 KeyAction (edu.cmu.cs.hcii.cogtool.model.KeyAction)1 VoiceAction (edu.cmu.cs.hcii.cogtool.model.VoiceAction)1 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)1