Search in sources :

Example 1 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project cogtool by cogtool.

the class ActionPropertySet method layOutKeyboardComposite.

@Override
public void layOutKeyboardComposite() {
    // Align checkbox 5 pixels from the left edge
    FormData data = new FormData();
    data.top = new FormAttachment(keyboardText.getOuter(), 5);
    data.left = leftAttachment;
    keyboardIsCmd.setLayoutData(data);
    // Attach label to 5 pixels from the properties left
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = leftAttachment;
    keyboardTextLabel.setLayoutData(data);
    // Attach device command text to 5 pixels below the text label
    // Attach right of combo to 5 before the edge
    // Align left with the acceptable key label
    data = new FormData();
    data.top = new FormAttachment(keyboardTextLabel, 5);
    data.left = new FormAttachment(keyboardTextLabel, 0, SWT.LEFT);
    data.right = new FormAttachment(100, -5);
    keyboardText.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(transitionDestinationNameKeyboard, 0, SWT.CENTER);
    transitionDestinationLabelKeyboard.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(transitionDestinationLabelKeyboard, 5, SWT.RIGHT);
    data.right = new FormAttachment(100, -5);
    data.top = new FormAttachment(keyboardIsCmd, 5);
    transitionDestinationNameKeyboard.setLayoutData(data);
    transitionDestinationNameKeyboard.setVisible(true);
    if (keyboardActionCombo != null) {
        // Attach key action label to 5 pixels from the properties left
        // Add some extra white space between this label and the checkbox
        data = new FormData();
        data.top = new FormAttachment(transitionDestinationNameKeyboard, 20);
        data.left = new FormAttachment(keyboardTextLabel, 0, SWT.LEFT);
        keyboardActionLabel.setLayoutData(data);
        // Attach key action combo with device command text
        // Attach key action combo to 5 pixels below the action label
        // Attach right of combo to end of the properties space
        data = new FormData();
        data.top = new FormAttachment(keyboardActionLabel, 5);
        data.left = new FormAttachment(keyboardTextLabel, 0, SWT.LEFT);
        data.right = new FormAttachment(100, -5);
        keyboardActionCombo.setLayoutData(data);
    }
    SelectionListener setResetListener = new SetResetDefaultsListener(setAsDefaultKeyboard, restoreDefaultsKeyboard) {

        @Override
        protected boolean haveValuesChanged() {
            return isKeyboardChanged(originalProperties);
        }

        @Override
        protected void enableDefaultButtons(boolean isReset) {
            boolean defaultChanged = isKeyboardChanged(defaultProperties);
            setAsDefaults.setEnabled(defaultChanged);
            resetDefaults.setEnabled((!isReset) && haveValuesChanged());
        }

        @Override
        protected void setDefaults(boolean isReset) {
            String cmd = isReset ? originalProperties.keyboardString : getKeyboardString();
            setKeyboardDefaults(getKeyboardPressType(), cmd, isKeyboardCmd());
        }

        @Override
        protected void resetDefaults() {
            resetKeyboard();
        }
    };
    addDefaultButtons(keyboardParms, keyboardSpecials.DOWN, setAsDefaultKeyboard, restoreDefaultsKeyboard, setResetListener);
}
Also used : FormData(org.eclipse.swt.layout.FormData) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project cogtool by cogtool.

the class ActionPropertySet method layOutTouchComposite.

@Override
public void layOutTouchComposite() {
    // Attach button action label to 5 pixels from the properties left
    FormData data = new FormData();
    data.top = new FormAttachment(touchActionCombo, 0, SWT.CENTER);
    data.left = leftAttachment;
    touchActionLabel.setLayoutData(data);
    // Attach button action combo 5 below the label
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(touchActionLabel, 5, SWT.RIGHT);
    data.right = new FormAttachment(100, -5);
    touchActionCombo.setLayoutData(data);
    SelectionListener setResetListener = new SetResetDefaultsListener(setAsDefaultTouch, restoreDefaultsTouch) {

        @Override
        protected boolean haveValuesChanged() {
            return isTouchChanged(originalProperties);
        }

        @Override
        protected void setDefaults(boolean isReset) {
            setTouchDefaults(getTapPressType());
        }

        @Override
        protected void resetDefaults() {
            resetTouch();
        }
    };
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(transitionSourceNameTouch, 0, SWT.CENTER);
    transitionSourceLabelTouch.setLayoutData(data);
    transitionSourceLabelTouch.setVisible(true);
    data = new FormData();
    data.left = new FormAttachment(transitionDestinationLabelTouch, 5, SWT.RIGHT);
    data.right = new FormAttachment(100, -5);
    data.top = new FormAttachment(touchActionCombo, 5);
    transitionSourceNameTouch.setLayoutData(data);
    transitionSourceNameTouch.setVisible(true);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(transitionDestinationNameTouch, 0, SWT.CENTER);
    transitionDestinationLabelTouch.setLayoutData(data);
    transitionDestinationLabelTouch.setVisible(true);
    data = new FormData();
    data.left = new FormAttachment(transitionDestinationLabelTouch, 5, SWT.RIGHT);
    data.right = new FormAttachment(100, -5);
    data.top = new FormAttachment(transitionSourceNameTouch, 5);
    transitionDestinationNameTouch.setLayoutData(data);
    transitionDestinationNameTouch.setVisible(true);
    addDefaultButtons(touchParms, transitionDestinationNameTouch, setAsDefaultTouch, restoreDefaultsTouch, setResetListener);
}
Also used : FormData(org.eclipse.swt.layout.FormData) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project cogtool by cogtool.

the class ActionSet method createKeyComposite.

protected Composite createKeyComposite() {
    Composite keyComp = new Composite(actionSettings, SWT.NONE);
    keyComp.setLayout(new FormLayout());
    keyboardTextLabel = new DisplayLabel(keyComp, SWT.NONE);
    keyboardTextLabel.setText(L10N.get("DE.KeyboardTextCaption", "Text") + ":");
    keyboardText = createKeyboardText(keyComp);
    keyboardText.setFont(FontUtils.SYMBOL_FONT);
    keyboardIsCmd = new Button(keyComp, SWT.CHECK);
    keyboardIsCmd.setText(L10N.get("DE.IsCommand", "Is Command"));
    keyboardIsCmd.addSelectionListener(deviceActionChange);
    // TODO Why is this here rather than in its natural home in the
    //      overridden method in ActionPropertySet?
    transitionDestinationLabelKeyboard = createTransitionDestinationLabel(keyComp);
    transitionDestinationNameKeyboard = createTransitionDestinationName(keyComp);
    /* TODO: add back in when single character stuff is straightened out
        this.keyboardActionLabel = new DisplayLabel(keyComp, SWT.NONE);
        this.keyboardActionLabel.setText(L10N.get("DE.KeyActionCaption",
                                                  "Action")
                                            + ":");

        this.keyboardActionCombo =
            new ComboWithEnableFix(keyComp,
                                   SWT.DROP_DOWN | SWT.READ_ONLY);

        for (int i = 0; i < KeyPressType.DISPLAY.length; i++) {
            this.keyboardActionCombo.add(KeyPressType.DISPLAY[i].toString());
        }

        this.keyboardActionCombo.select(0);
        this.keyboardActionCombo.addSelectionListener(this.deviceActionChange);
*/
    SelectionListener insertSpecial = new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            Control source = (Control) e.getSource();
            keyboardText.insert((String) source.getData());
            Point selection = keyboardText.getSelection();
            keyboardText.setFocus();
            keyboardText.setSelection(selection);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    };
    // TODO: replace alignTo with this.keyboardActionCombo when the above TODO is done!
    // can't assign using ?: because Java is stupid
    Control alignTo;
    if (vertical) {
        alignTo = transitionDestinationNameKeyboard;
    } else {
        alignTo = keyboardText.getOuter();
    }
    keyboardSpecials = new KeyboardSpecialChars(alignTo, insertSpecial, vertical);
    return keyComp;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point) DisplayLabel(edu.cmu.cs.hcii.cogtool.util.DisplayLabel) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with SelectionListener

use of org.eclipse.swt.events.SelectionListener 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 5 with SelectionListener

use of org.eclipse.swt.events.SelectionListener 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)

Aggregations

SelectionListener (org.eclipse.swt.events.SelectionListener)711 SelectionEvent (org.eclipse.swt.events.SelectionEvent)665 GridData (org.eclipse.swt.layout.GridData)411 Button (org.eclipse.swt.widgets.Button)409 Composite (org.eclipse.swt.widgets.Composite)381 GridLayout (org.eclipse.swt.layout.GridLayout)374 Label (org.eclipse.swt.widgets.Label)256 Text (org.eclipse.swt.widgets.Text)152 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)140 Group (org.eclipse.swt.widgets.Group)137 ModifyListener (org.eclipse.swt.events.ModifyListener)113 ModifyEvent (org.eclipse.swt.events.ModifyEvent)112 Combo (org.eclipse.swt.widgets.Combo)101 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)69 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)69 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)69 FormData (org.eclipse.swt.layout.FormData)69 Event (org.eclipse.swt.widgets.Event)69 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 ArrayList (java.util.ArrayList)57