Search in sources :

Example 1 with Frame

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

the class SEDemoUI method addSelectionChangeListeners.

/**
     * Add the selection Change event listeners.
     */
protected void addSelectionChangeListeners() {
    SWTselectionChangeHandler = new SelectionListener() {

        public void widgetSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            for (TableItem selectedItem : selectedItems) {
                // TODO: Currently supports only single selection.
                Object data = selectedItem.getData();
                if (data instanceof Frame) {
                    selection.setSelectedState(null);
                } else {
                    // should be instanceof DefaultModelGeneratorState!!!
                    AScriptStep step = ((DefaultModelGeneratorState) data).getScriptStep();
                    if (step instanceof HearScriptStep) {
                        if (interaction.askEditFrame()) {
                            Frame f = step.getCurrentFrame();
                            performAction(DesignEditorLID.EditFrame, f);
                        }
                        TableItem previousSelectedRow = swtList.getRowItem(selection.getPreviousSelection());
                        selection.setSelectedState(previousSelectedRow);
                    } else {
                        selection.setSelectedState(selectedItem);
                    }
                }
            }
            centerSelectedRegion();
            setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
        // Let selection change handle changing the frame
        }

        public void widgetDefaultSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            // TODO: Currently supports only single selection.
            for (TableItem selectedItem : selectedItems) {
                Object data = selectedItem.getData();
                if (data instanceof DefaultModelGeneratorState) {
                    DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
                    AScriptStep step = stepState.getScriptStep();
                    // In case we need this; not a context selection
                    // in truth, but we can re-use the structure.
                    contextSelection.setSelectedState(stepState);
                    if (editable) {
                        if (step instanceof DelayScriptStep) {
                            performAction(SEDemoLID.ChangeWaitProperties, contextSelection);
                        } else if (step instanceof ThinkScriptStep) {
                            performAction(SEDemoLID.ChangeThinkProperties, contextSelection);
                        } else if (isEditable(step)) {
                            performAction(SEDemoLID.Edit, contextSelection);
                        }
                    }
                }
            }
        }
    };
    view.addSWTListSelectionHandler(SWTselectionChangeHandler);
    AlertHandler selectionChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
            if (event != null) {
                if (event.selected) {
                    DefaultModelGeneratorState stepState = event.changedState;
                    uiModel.setCurrentOverride(script, script.getPreviousState(stepState));
                    Frame resultFrame = null;
                    if (stepState != null) {
                        resultFrame = stepState.getScriptStep().getCurrentFrame();
                    } else {
                        resultFrame = script.getDemonstration().getResultFrame();
                    }
                    try {
                        setCurrentFrame(resultFrame);
                    } catch (GraphicsUtil.ImageException ex) {
                        throw new RcvrImageException("Changing current demonstration frame", ex);
                    }
                } else {
                    // deselect item.
                    uiModel.setCurrentOverride(script, script.getLastState());
                }
            }
        }
    };
    selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TableItem(org.eclipse.swt.widgets.TableItem) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) EventObject(java.util.EventObject) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HearScriptStep(edu.cmu.cs.hcii.cogtool.model.HearScriptStep) EventObject(java.util.EventObject) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with Frame

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

the class ScriptViewerUI method addSelectionChangeListeners.

/**
     * Add the selection Change event listeners.
     */
protected void addSelectionChangeListeners() {
    SWTselectionChangeHandler = new SelectionListener() {

        public void widgetSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            for (TableItem selectedItem : selectedItems) {
                // TODO: Currently supports only single selection.
                Object data = selectedItem.getData();
                if (data instanceof Frame) {
                    selection.setSelectedState(null);
                } else {
                    selection.setSelectedState(selectedItem);
                }
            }
            setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
        // Let selection change handle changing the frame
        }

        public void widgetDefaultSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            // TODO: Currently supports only single selection.
            for (TableItem selectedItem : selectedItems) {
                Object data = selectedItem.getData();
                if (data instanceof DefaultModelGeneratorState) {
                    Script s = (Script) selectedItem.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
                    DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
                    // In case we need this; not a context selection
                    // in truth, but we can re-use the structure.
                    contextSelection.setSelectedState(stepState);
                    performAction(ProjectLID.EditScript, s);
                }
            }
        }
    };
    view.addSWTListSelectionHandler(SWTselectionChangeHandler);
    AlertHandler selectionChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
            if (event != null) {
                if (event.selected) {
                    DefaultModelGeneratorState stepState = event.changedState;
                    Frame resultFrame = null;
                    Script script = getSelectedScript(stepState);
                    AUndertaking t = script.getDemonstration().getTaskApplication().getTask();
                    if (stepState != null) {
                        resultFrame = stepState.getScriptStep().getCurrentFrame();
                    } else if (script != null) {
                        resultFrame = script.getDemonstration().getResultFrame();
                    }
                    DefaultModelGeneratorState overrideState = script.getPreviousState(stepState);
                    if (overrideState == null) {
                        TaskGroup group = (TaskGroup) task;
                        List<AUndertaking> siblingTasks = group.getUndertakings();
                        int currentTaskIndex = siblingTasks.indexOf(t);
                        CognitiveModelGenerator modelGen = script.getModelGenerator();
                        while ((overrideState == null) && (0 <= --currentTaskIndex)) {
                            AUndertaking prevSibling = siblingTasks.get(currentTaskIndex);
                            TaskApplication ta = project.getTaskApplication(prevSibling, design);
                            if (ta != null) {
                                script = ta.getScript(modelGen);
                                if (script != null) {
                                    overrideState = script.getLastState();
                                }
                            }
                        }
                    }
                    uiModel.setCurrentOverride(script, overrideState);
                    try {
                        setCurrentFrame(resultFrame);
                    } catch (GraphicsUtil.ImageException ex) {
                        throw new RcvrImageException("Changing current demonstration frame", ex);
                    }
                }
            }
        }
    };
    selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TableItem(org.eclipse.swt.widgets.TableItem) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) EventObject(java.util.EventObject) SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EventObject(java.util.EventObject) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with Frame

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

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

the class DefaultSEUIModel method setCurrentFrame.

public boolean setCurrentFrame(Frame frame) {
    if ((currentFrame == null) || (frame != currentFrame.getFrame())) {
        if (currentFrame != null) {
            Frame oldFrame = currentFrame.getFrame();
            oldFrame.removeHandler(Frame.InputDeviceChange.class, inputDeviceChangeHandler);
            oldFrame.removeHandler(Frame.SpeakerChange.class, speakerChangeHandler);
            oldFrame.removeHandler(NameChangeAlert.class, renameHandler);
            if (widgetShapeChangeHandler != null) {
                currentFrame.removeHandler(FrameUIModel.WidgetShapeImageChange.class, widgetShapeChangeHandler);
            }
            currentFrame.dispose();
        }
        // When set in the InteractionEditor, it will rescale it
        currentFrame = new FrameUIModel(frame, this);
        frame.addHandler(this, NameChangeAlert.class, renameHandler);
        frame.addHandler(this, Frame.SpeakerChange.class, speakerChangeHandler);
        frame.addHandler(this, Frame.InputDeviceChange.class, inputDeviceChangeHandler);
        if (widgetShapeChangeHandler != null) {
            currentFrame.addHandler(this, FrameUIModel.WidgetShapeImageChange.class, widgetShapeChangeHandler);
        }
        setFrameHeader(frame);
        updateSpeakerDisplay();
        updateDeviceDisplay();
        return true;
    }
    return false;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame)

Example 5 with Frame

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

the class DefaultSEUIModel method updateSpeakerDisplay.

protected void updateSpeakerDisplay() {
    if (currentFrame != null) {
        Frame f = currentFrame.getFrame();
        if (listenTimeInSecs != null) {
            double frameListenTime;
            if (currentFrame != null) {
                frameListenTime = f.getListenTimeInSecs();
            } else {
                frameListenTime = Frame.NO_LISTEN_TIME;
            }
            if (frameListenTime == Frame.NO_LISTEN_TIME) {
                listenTimeInSecs.setText(NO_LISTEN_TIME_LABEL);
                listenTimeInSecs.setForeground(DISABLED_TEXT_COLOR);
            } else {
                listenTimeInSecs.setDoubleValue(frameListenTime);
                listenTimeInSecs.setForeground(ENABLED_TEXT_COLOR);
            }
        }
        if (speakerText != null) {
            String text = f.getSpeakerText();
            speakerText.setText(text);
            speakerText.setToolTipText(text);
        }
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame)

Aggregations

Frame (edu.cmu.cs.hcii.cogtool.model.Frame)68 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)12 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)10 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)10 EventObject (java.util.EventObject)9 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)8 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)8 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)8 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)8 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 IOException (java.io.IOException)6 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)5 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)5 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)4 Design (edu.cmu.cs.hcii.cogtool.model.Design)4 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)4 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)4