Search in sources :

Example 1 with DeviceType

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

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

the class DefaultSEUIModel method updateDeviceDisplay.

public void updateDeviceDisplay() {
    if ((currentFrame != null) && (devicesFooter != null)) {
        Control[] deviceLabels = devicesFooter.getChildren();
        double midIndex = 0.5 * (deviceLabels.length - 1);
        for (int i = 0; i < deviceLabels.length; i++) {
            DeviceType deviceType = (DeviceType) deviceLabels[i].getData(DEVICE_TYPE_KEY);
            if (deviceType != null) {
                Frame currentFrameModel = currentFrame.getFrame();
                InputDevice inputDevice = currentFrameModel.getInputDevice(deviceType);
                String text = AbstractGraphicalSource.buildToolTipText(inputDevice, deviceType.toString());
                text = KeyDisplayUtil.convertActionToMenuText(text);
                deviceLabels[i].setToolTipText(" " + text + " ");
                deviceLabels[i].setData(inputDevice);
                FormData formData = new FormData();
                formData.top = new FormAttachment(0, 0);
                formData.bottom = new FormAttachment(100, 0);
                formData.width = DesignUtil.DEVICE_WIDTH;
                double ii = i;
                if (ii == (midIndex - 0.5)) {
                    formData.right = new FormAttachment(50, -(DEVICE_MARGIN / 2));
                } else if (ii < midIndex) {
                    formData.right = new FormAttachment(deviceLabels[i + 1], -DEVICE_MARGIN, SWT.LEFT);
                } else if (ii == midIndex) {
                    formData.left = new FormAttachment(50, -(DesignUtil.DEVICE_WIDTH / 2));
                } else if (ii == (midIndex + 0.5)) {
                    formData.left = new FormAttachment(50, DEVICE_MARGIN / 2);
                } else {
                    // ii > midIndex
                    formData.left = new FormAttachment(deviceLabels[i - 1], DEVICE_MARGIN, SWT.RIGHT);
                }
                deviceLabels[i].setLayoutData(formData);
            }
        }
        devicesFooter.layout();
    }
}
Also used : FormData(org.eclipse.swt.layout.FormData) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) Control(org.eclipse.swt.widgets.Control) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) InputDevice(edu.cmu.cs.hcii.cogtool.model.InputDevice) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 3 with DeviceType

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

the class ProjectController method createNewDesignForImport.

// createNewDesignAction
// Action for NewDesign2, createNewDesignForImport
protected IListenerAction createNewDesignForImport() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return DesignSelectionState.class;
        // return Class.class;
        }

        public boolean performAction(Object prms) {
            //call convert on the converter file
            Class<ImportConverter> translatorClass = CogToolLID.NewDesignFromImport.getClassAttribute();
            //CogToolLID.NewDesignFromImport.setClassAttribute(null);
            Object converter = null;
            try {
                converter = translatorClass.newInstance();
            } catch (InstantiationException e) {
                throw new RcvrImportException("Translator class cannot be instantiated.");
            } catch (IllegalAccessException e) {
                throw new RcvrImportException("The translator class is not accessible.");
            }
            Design design = null;
            Method isInputFileDirectory = null;
            try {
                isInputFileDirectory = translatorClass.getMethod("isInputFileDirectory", new Class[0]);
            } catch (SecurityException e) {
                throw new RcvrImportException("The security manager does not allow access to this method.");
            } catch (NoSuchMethodException e) {
                // TODO Auto-generated catch block
                throw new RcvrImportException("isInputFileDirectory does not exist in the converter file.");
            }
            boolean reqDir = false;
            try {
                reqDir = (Boolean) isInputFileDirectory.invoke(converter);
            } catch (IllegalArgumentException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            } catch (IllegalAccessException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            } catch (InvocationTargetException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
            //parameters needed to be passed to importDesign. A file and design are passed.
            Class<?>[] parameters = new Class<?>[2];
            parameters[0] = File.class;
            parameters[1] = Design.class;
            Method importDesignMethod = null;
            try {
                importDesignMethod = translatorClass.getMethod("importDesign", parameters);
            } catch (SecurityException e) {
                throw new RcvrImportException("The security manager does not allow access to this method.");
            } catch (NoSuchMethodException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String designName = "";
            /*Instead of a inputFile, a directory was specified. Every file in the directory
                  needs to be parsed */
            Method allowedExtsMethod = null;
            try {
                allowedExtsMethod = translatorClass.getMethod("allowedExtensions", new Class[0]);
            } catch (SecurityException e) {
                throw new RcvrImportException("The security manager does not allow access to this method.");
            } catch (NoSuchMethodException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String[] extensions = null;
            try {
                extensions = (String[]) allowedExtsMethod.invoke(converter);
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (reqDir) {
                /*TODO: Need to confirm that directory name is guaranteed to only accept a directory*/
                String directoryName = interaction.askUserForDirectory("Choose a directory of files", "This directory contains the files that you wish to import.");
                if (directoryName != null) {
                    File directory = new File(directoryName);
                    if (directory != null) {
                        //TODO: What to do about importing it twice, designName [2];
                        designName = directory.getName();
                        Set<DeviceType> deviceTypeSet = new HashSet<DeviceType>();
                        Method selectedDevicesMethod = null;
                        try {
                            selectedDevicesMethod = translatorClass.getMethod("selectedDevices", new Class[0]);
                        } catch (SecurityException e) {
                            throw new RcvrImportException("The security manager does not allow access to this method.");
                        } catch (NoSuchMethodException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        try {
                            deviceTypeSet = (Set<DeviceType>) selectedDevicesMethod.invoke(converter);
                        } catch (IllegalArgumentException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (IllegalAccessException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (InvocationTargetException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        ProjectInteraction.DesignRequestData requestData = new ProjectInteraction.DesignRequestData();
                        requestData.designName = designName;
                        requestData.deviceTypes = deviceTypeSet;
                        //TODO: may need to keep checking the value that this returns
                        interaction.requestNewDesignName(requestData, false, project, false);
                        design = new Design(requestData.designName, requestData.deviceTypes);
                        makeDesignNameUnique(design);
                        // Collection<DeviceType> deviceTypes = (Collection<DeviceType>)
                        // designLoader.createCollection(design, Design.deviceTypesVAR, 1);
                        // Collection<?> frames =
                        //designLoader.createCollection(design, Design.framesVAR, 1);
                        File[] directoryContents = directory.listFiles();
                        for (File file : directoryContents) {
                            String fileName = file.getName();
                            //If there is no extension then null is the file extension
                            String fileExt = (fileName.lastIndexOf(".") == -1) ? null : fileName.substring(fileName.lastIndexOf('.'));
                            //Example: ".txt" will now be "txt" and . will now be ""
                            if (fileExt != null) {
                                fileExt = (fileExt.length()) > 1 ? fileExt = fileExt.substring(1) : "";
                            }
                            for (String extension : extensions) {
                                if (extension == null || extension.equalsIgnoreCase(fileExt)) {
                                    try {
                                        importDesignMethod.invoke(converter, file, design);
                                        break;
                                    /* Break is needed if the converter author placed the same
                                             * extension in the array twice then this conversion will
                                             * not occur more than once. */
                                    } catch (IllegalArgumentException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    } catch (IllegalAccessException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    } catch (InvocationTargetException e) {
                                        //throw new RcvrImportXmlException("Not a valid XML file to parse.");
                                        //ignore
                                        System.out.println("fileName " + fileName);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                File importFile = interaction.selectFile(true, null, extensions);
                try {
                    designName = importFile.getName();
                    //TODO: ask user for design name since it can be different from the filename
                    Set<DeviceType> deviceTypeSet = new HashSet<DeviceType>();
                    design = new Design(designName, deviceTypeSet);
                    makeDesignNameUnique(design);
                    //Collection<DeviceType> deviceTypes = (Collection<DeviceType>)
                    //designLoader.createCollection(design, Design.deviceTypesVAR, 1);
                    //Collection<?> frames =
                    // designLoader.createCollection(design, Design.framesVAR, 1);
                    System.out.println("design " + design.getName());
                    importDesignMethod.invoke(converter, importFile, design);
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            //change inputfile to the specific file
            }
            if (design != null) {
                ProjectCmd.addNewDesign(project, design, ((DesignSelectionState) prms).getSelectedDesign(), NEW_DESIGN, undoMgr);
            }
            return true;
        }
    };
}
Also used : ImportConverter(edu.cmu.cs.hcii.cogtool.model.ImportConverter) ProjectInteraction(edu.cmu.cs.hcii.cogtool.ui.ProjectInteraction) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState) HashSet(java.util.HashSet) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) File(java.io.File)

Example 4 with DeviceType

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

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

the class DesignEditorUI method getDefaultProperties.

public void getDefaultProperties(TransitionSource source, ActionProperties properties) {
    view.getDefaultProperties(properties);
    ActionType transitionType = getCurrentActionType();
    Set<DeviceType> deviceTypes = uiModel.getDesign().getDeviceTypes();
    properties.setInitialActionType(source, transitionType, deviceTypes);
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) ActionType(edu.cmu.cs.hcii.cogtool.model.ActionType)

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