Search in sources :

Example 1 with AlertHandler

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

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

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addSelectionChangeListeners.

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

        public void handleAlert(EventObject alert) {
            FrameEditorSelectionState.SelectionChange evt = (FrameEditorSelectionState.SelectionChange) alert;
            if (evt != null) {
                // Set the state of corresponding graphical widgets
                GraphicalWidget<?> gw;
                // Alter state of all widgets in selection
                if (evt.changedElement == null) {
                    Iterator<GraphicalWidget<?>> widgetFigs = ((FrameEditorSelectionState) evt.getSource()).getSelectedWidgetFigures();
                    while (widgetFigs.hasNext()) {
                        gw = widgetFigs.next();
                        gw.setSelected(evt.selected);
                    }
                } else if (evt.changedElement instanceof GraphicalWidget<?>) {
                    // If an object was passed on the event, set its
                    // selected state to the event's selected state
                    gw = (GraphicalWidget<?>) evt.changedElement;
                    if (frame.getWidgets().contains(gw.getModel())) {
                        gw.setSelected(evt.selected);
                    }
                }
            }
            // Repaint the frame contents
            // This causes the resize handles to be redrawn.
            // Also causes the entire frame to be "refreshed"
            delayedRepainting.requestRepaint(REPAINT_ALL);
        // Add the following back when another window's actions
        // can cause changes to a Frame Editor's selection state
        // (such as something that deletes a widget)
        //                    updateView();
        }
    };
    selection.addHandler(this, FrameEditorSelectionState.SelectionChange.class, widgetSelectionHandler);
}
Also used : AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) EventObject(java.util.EventObject)

Example 4 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addBackgroundImageHandler.

/**
     * Registers a listener that enables/disables the
     * "remove background image" menu item as necessary.
     *
     * Also enable or disabled the capture Background button.
     * TODO: when capture background becomes a menu item, add to setEnabled
     */
protected void addBackgroundImageHandler() {
    AlertHandler backgroundEnabler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            // Checks to see if the frame has a background.
            // if so enable remove background and capture background
            // buttons.
            boolean enable = (frame.getBackgroundImage() == null) ? MenuUtil.DISABLED : MenuUtil.ENABLED;
            // Enable or disabled the remove background menu item
            setEnabled(CogToolLID.RemoveBackgroundImage, ListenerIdentifierMap.ALL, enable);
            // Enable or disabled the capture background button
            view.setIsBackgroundAvailable(enable);
        }
    };
    frame.addHandler(this, Frame.BackgroundImageChange.class, backgroundEnabler);
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject)

Example 5 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addWidgetShapeChangeHandler.

/**
     * Registers a listener that redraws the frame in response to changes in
     * the appearance of widgets
     *
     * When this event occurs, resize handles are redrawn, the window's size is
     * recomputed, and the display updated.
     *
     */
protected void addWidgetShapeChangeHandler() {
    AlertHandler widgetTitleChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameUIModel.WidgetTitleChange chg = (FrameUIModel.WidgetTitleChange) alert;
            // selected widget
            if (selection.getElementSelectionCount() == 1) {
                FrameElement elt = selection.getSelectedIFrameElements()[0];
                if (chg.widget == elt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR)) {
                    view.setRemoteLabelText(chg.widget.getTitle());
                }
            }
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetTitleChange.class, widgetTitleChangeHandler);
    AlertHandler widgetShapeChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            delayedRepainting.requestRepaint(SHAPE_CHANGE_REPAINT);
        // a FULL repaint is probably not needed
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetShapeImageChange.class, widgetShapeChangeHandler);
    AlertHandler widgetGroupChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameUIModel.WidgetGroupChange evt = (FrameUIModel.WidgetGroupChange) alert;
            if (evt.isAdd) {
                GraphicalWidget<?> gw = frameUI.getWidgetFigure(evt.widget);
                delayedWidgetSelection.addToSelection(evt.widget, gw);
            } else {
                delayedWidgetSelection.removeFromSelection(evt.widget);
                SimpleWidgetGroup group = evt.widget.getParentGroup();
                if (group.size() == 0) {
                    //evt.widget was the last widget in this group,
                    //so hide the halo for it
                    removeHalo(evt.widget);
                }
            }
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetGroupChange.class, widgetGroupChangeHandler);
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameUIModel(edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) EventObject(java.util.EventObject)

Aggregations

AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)21 EventObject (java.util.EventObject)21 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 Design (edu.cmu.cs.hcii.cogtool.model.Design)4 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)3 Set (java.util.Set)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)2 ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)2 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)2 PERTChartSelectionState (edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState)2 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)2 StructureViewUIModel (edu.cmu.cs.hcii.cogtool.uimodel.StructureViewUIModel)2 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)2 ActionPropertySet (edu.cmu.cs.hcii.cogtool.view.ActionPropertySet)2 SWTList (edu.cmu.cs.hcii.cogtool.view.SWTList)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2