Search in sources :

Example 6 with TransitionSource

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

the class FramePropertiesPane method update.

public void update(Frame frame) {
    Object pathObj = frame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
    if (NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
        imagePath.setVisible(false);
        imagePathText.setVisible(false);
    } else {
        String imgPath = (String) pathObj;
        imagePath.setVisible(true);
        imagePathText.setVisible(true);
        imagePathText.setText(imgPath);
        imagePathText.setSelection(imgPath.length());
    }
    Set<TransitionSource> children = new LinkedHashSet<TransitionSource>();
    children.addAll(frame.getWidgets());
    children.addAll(frame.getInputDevices());
    widgetUpdater.updateTree(children.iterator());
    if (eltGroupTreeLabel != null) {
        Set<FrameElementGroup> grps = frame.getEltGroups();
        if (!CogToolPref.NESTED_GROUPS_SHOWN_AT_TOP_LEVEL.getBoolean()) {
            grps = filterNestedGroups(grps);
        }
        eltGroupUpdater.updateTree(grps.iterator());
        Set<SimpleWidgetGroup> implicitGroups = new HashSet<SimpleWidgetGroup>();
        for (IWidget w : frame.getWidgets()) {
            SimpleWidgetGroup g = w.getParentGroup();
            if (g != null) {
                implicitGroups.add(g);
            }
        }
        implicitGroupUpdater.updateTree(implicitGroups.iterator());
    }
    setFrameName(frame);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with TransitionSource

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

the class HCIPACmd method buildActionStepInsert.

protected static void buildActionStepInsert(AUndertaking task, AScriptStep step, Demonstration demo, StringBuilder php) {
    int hcipaStep = task.getTaskGroup().getUndertakings().indexOf(task) + 1;
    Frame curFrame = step.getCurrentFrame();
    TransitionSource src = step.getStepFocus();
    String labelAction;
    if (src == null) {
        labelAction = "None";
    } else {
        labelAction = quotePHP(quoteSQL(src.getLabel()));
    }
    int order = demo.getSteps().indexOf(step) + 1;
    byte[] bkgImage = curFrame.getBackgroundImage();
    if (bkgImage != null) {
        ImageData imgData = new ImageData(new ByteArrayInputStream(bkgImage));
        bkgImage = GraphicsUtil.convertImageType(imgData, SWT.IMAGE_JPEG);
        int imgSize = bkgImage.length;
        String imgName = (String) curFrame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
        php.append("\t$imgType = \"'image/jpeg'\";\n\t");
        php.append("$imgLength = " + imgSize + ";\n\t");
        php.append("$bkgImage = '0x' . bin2hex(base64_decode(str_replace(array('.', '_', '-'), array('+', '/', '='), \"");
        php.append(Base64.encode(bkgImage));
        php.append("\")));\n\n\t");
        if ((imgName == null) || NullSafe.equals(WidgetAttributes.NO_IMAGE, imgName)) {
            php.append("$imgName = 'null';\n\t");
        } else {
            php.append("$imgName = \"'\" . mysql_real_escape_string(basename(\n<<<SQL__INSERT__STRING\n");
            php.append(imgName);
            php.append("\nSQL__INSERT__STRING\n)) . \"'\";\n\n\t");
        }
    } else {
        php.append("\t$imgType = 'null';\n\t");
        php.append("$imgLength = 'null';\n\t");
        php.append("$bkgImage = 'null';\n\t");
        php.append("$imgName = 'null';\n\n\t");
    }
    php.append("Add_Task_Action($deviceId,\n\t");
    php.append(hcipaStep + ",\n\t" + order + ",\n\t");
    php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
    php.append("\"" + quotePHP(quoteSQL(curFrame.getName())) + "\",\n\t");
    php.append("\"" + labelAction + "\");\n\n");
//        php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
//        php.append(SQL_INSERT + "HCIPA_Actions (hcipa_id,\n\thcipa_step,\n\t");
//        php.append("hcipa_order,\n\tImage,\n\tImage_Name,\n\tImage_Size,\n\tImage_Type,\n\t");
//        php.append("Next_User_Action,\n\tLabel_User_Action)\n\t");
//        php.append(SQL_VALUES + " ($deviceId,\n\t" + hcipaStep + ",\n\t" + order + ",\n\t");
//        php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
//        php.append("'" + quoteSQL(curFrame.getName()) + "',\n\t'" + labelAction + "'");
//        php.append(")\n");
//        php.append("SQL__INSERT__STRING\n;\n\n\t");
//        php.append("mysql_query($sqlStmt);\n\n");
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData)

Example 8 with TransitionSource

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

the class DemoScriptCmd method exportScriptToCSV.

public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
    Demonstration demo = script.getDemonstration();
    TaskApplication ta = demo.getTaskApplication();
    Design design = ta.getDesign();
    AUndertaking task = ta.getTask();
    String name = project.getName();
    name += "_" + design.getName();
    name += "_" + task.getName();
    File dest = null;
    if (interaction != null) {
        dest = interaction.selectCSVFileDest(name);
    } else {
        dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
    }
    if (dest == null) {
        return false;
    }
    FileWriter fw = null;
    BufferedWriter buffer = null;
    try {
        fw = new FileWriter(dest);
        buffer = new BufferedWriter(fw);
        CSVSupport.writeCell("Format version:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(FORMAT_VERSION, buffer);
        CSVSupport.addLineEnding(buffer);
        Date now = new Date();
        String date = DateFormat.getDateTimeInstance().format(now);
        CSVSupport.writeCell("Date and Time:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(date, buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Project Name:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(project.getName(), buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Design Name:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(design.getName(), buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Task Hierarchy:", buffer);
        String taskName = task.getFullName();
        String[] cells = taskName.split(":");
        for (String cell : cells) {
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(cell, buffer);
        }
        CSVSupport.addLineEnding(buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.addLineEnding(buffer);
        buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
        CSVSupport.addLineEnding(buffer);
        IWidget lastMovedToWidget = null;
        Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
        while (stepStates.hasNext()) {
            DefaultModelGeneratorState stepState = stepStates.next();
            AScriptStep step = stepState.getScriptStep();
            TransitionSource stepFocus = step.getStepFocus();
            String frameName = step.getCurrentFrame().getName();
            String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
            if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
                actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
            }
            lastMovedToWidget = stepState.getLastMovedToWidget();
            String widgetName = "";
            String widgetType = "";
            String widgetTitle = "";
            if (stepFocus != null) {
                widgetName = stepFocus.getName();
                if (stepFocus instanceof IWidget) {
                    IWidget w = (IWidget) stepFocus;
                    widgetType = w.getWidgetType().toString();
                    String s = w.getTitle();
                    if (s != null) {
                        widgetTitle = s;
                    }
                }
            }
            CSVSupport.writeCell(frameName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(actionName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetTitle, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetType, buffer);
            CSVSupport.addLineEnding(buffer);
        }
        Frame resultFrame = demo.getResultFrame();
        if (resultFrame != null) {
            CSVSupport.writeCell(resultFrame.getName(), buffer);
        }
        if (interaction != null) {
            interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
        }
    } catch (IOException e) {
        if (interaction != null) {
            interaction.reportProblem("File I/O Error", e.getMessage());
        } else {
            e.printStackTrace();
        }
        return false;
    } finally {
        try {
            if (buffer != null) {
                buffer.close();
            }
            if (fw != null) {
                fw.close();
            }
        } catch (IOException e) {
            if (interaction != null) {
                interaction.reportProblem("File I/O Error on Close", e.getMessage());
            } else {
                e.printStackTrace();
            }
            return false;
        }
    }
    return true;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) TextActionSegment(edu.cmu.cs.hcii.cogtool.model.TextActionSegment) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) LookAtScriptStep(edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 9 with TransitionSource

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

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

TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)16 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)7 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)5 AAction (edu.cmu.cs.hcii.cogtool.model.AAction)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)4 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)2 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 LinkedHashSet (java.util.LinkedHashSet)2 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)1 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 LookAtScriptStep (edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)1 TextActionSegment (edu.cmu.cs.hcii.cogtool.model.TextActionSegment)1