Search in sources :

Example 1 with Point

use of org.eclipse.swt.graphics.Point in project cogtool by cogtool.

the class ProjectUI method computeColumnArea.

protected Rectangle computeColumnArea(TreeColumn column) {
    if (column != null) {
        Point size = tree.getSize();
        Rectangle treeArea = new Rectangle(0, 0, size.x, size.y);
        int[] columnOrdering = uiModel.getCurrentDesignOrdering();
        int i = 0;
        TreeColumn nextCol = tree.getColumn(i++);
        while (nextCol != column) {
            treeArea.x += nextCol.getWidth();
            //                if (OSUtils.MACOSX) {
            //                    // XXX: dirty hacks around SWT bugs
            //                    treeArea.x += 30;
            //                }
            nextCol = tree.getColumn(columnOrdering[i++]);
        }
        treeArea.width = column.getWidth();
        if (OSUtils.MACOSX) {
            // XXX: dirty hacks around SWT bugs
            int off = ((numExpandedLevels(tree.getItems()) - 1) * 24);
            treeArea.x += off;
            //     treeArea.width += 1;
            treeArea.y += 1;
            treeArea.height -= 16;
            treeArea.x += 4;
        }
        return treeArea;
    }
    return null;
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 2 with Point

use of org.eclipse.swt.graphics.Point in project cogtool by cogtool.

the class ProjectUI method showContextMenu.

// Override to set the correct context menu on the frame
//    item  item-selected column design  where          selection to use
//(a)  ok        n/a        ok     ok    cell           temporary cell
//(b)  ok        yes        ok    null   task           normal selection
//(c)  ok        no         ok    null   task           temporary task
//(d)  ok        n/a       null    n/a   right of cells temporary task
//(e) null       n/a        ok     ok    design         temporary design
//(f) null       n/a        ok    null   bottom-left    no selection
//(g) null       n/a       null    n/a   bottom-right   no selection
// TODO: dfm -- make the code match the above!!!!!
@Override
public void showContextMenu(int x, int y) {
    // Clear any stale state
    contextSelection.deselectAll();
    // Check which region of the frame was hit
    TreeItem item = tree.getItem(new Point(x, y));
    TreeColumn column = findColumn(x);
    // See if the context invocation was made beyond all designs
    if (column == null) {
        if (item == null) {
            // see (g) above
            showContextMenu();
        } else {
            // see (d) above
            selectOverBox(item.getBounds());
            contextSelection.addSelectedTask((AUndertaking) item.getData());
            showContextMenu(contextSelection, View.CONTEXT);
        }
    } else // If not, the invocation occurred somewhere within the table
    {
        Design design = (Design) column.getData();
        // Detect a context invocation in the table header/footer
        if (item == null) {
            // Detect a context invocation under the "tasks" heading
            if (design == null) {
                // see (f) above
                showContextMenu();
            } else // Otherwise the invocation lies under a design heading
            {
                // see (e) above
                // TODO: Really?  What if something else was selected?
                selectOverBox(computeColumnArea(column));
                contextSelection.setSelectedDesign(design);
                showContextMenu(contextSelection, View.CONTEXT);
            }
        } else // Detect a context invocation inside the table body
        {
            AUndertaking undertaking = (AUndertaking) item.getData();
            // Check for context invocation under the "tasks" column
            if (design == null) {
                // Set up the contextual selection state as necessary
                if (selection.isTaskSelected(undertaking)) {
                    // see (b) above
                    showContextMenu();
                } else {
                    // see (c) above
                    selectOverBox(item.getBounds());
                    contextSelection.addSelectedTask(undertaking);
                    showContextMenu(contextSelection, View.CONTEXT);
                }
            } else // Otherwise at the intersection of a task and a design
            {
                // see (a) above
                selection.setSelectedCell(item, column);
                Rectangle bounds = item.getBounds(tree.indexOf(column));
                if (OSUtils.MACOSX) {
                    // XXX: DIRTY HACK TO fix SWT bug.
                    bounds.y -= 1;
                    bounds.height += 1;
                }
                selectOverBox(bounds);
                // TODO: instead of the following, pass undertaking and
                //       design in to showContextMenuForIntersection()
                Menu contextMenu = view.getContextMenuForIntersection(project, undertaking, design);
                // Set up the contextual selection state as necessary
                contextSelection.setSelectedDesign(design);
                contextSelection.addSelectedTask(undertaking);
                setViewEnabledState(contextSelection, ListenerIdentifierMap.CONTEXT);
                contextMenu.setVisible(true);
            }
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with Point

use of org.eclipse.swt.graphics.Point in project cogtool by cogtool.

the class ProjectMouseState method dealWithMouseDoubleClick.

@Override
protected void dealWithMouseDoubleClick(MouseEvent me) {
    super.dealWithMouseDoubleClick(me);
    TreeItem item = ui.tree.getItem(new Point(me.x, me.y));
    TreeColumn column = ui.findColumn(me.x);
    // check to see if the group visibility should toggle
    if ((item != null) && (column == null)) {
        // Toggle tree expand when a TaskGroup is double-clicked,
        // but not if double-clicking on the first column to edit the name
        AUndertaking u = (AUndertaking) item.getData();
        if (u.isTaskGroup()) {
            item.setExpanded(!item.getExpanded());
        }
    }
    // If on a valid cell, either edit script or open the script viewer
    if ((item != null) && (column != null) && (column.getData() != null)) {
        AUndertaking u = (AUndertaking) item.getData();
        // At the intersection of a task and design
        ProjectContextSelectionState seln = new ProjectContextSelectionState(ui.getProject());
        seln.setSelectedDesign((Design) column.getData());
        seln.addSelectedTask(u);
        if (u.isTaskGroup()) {
            TaskGroup group = (TaskGroup) u;
            if (GroupNature.SUM.equals(group.getNature())) {
                item.setExpanded(true);
                ui.cleanupTaskEditor();
                //TODO: won't work since repaint won't occur until after we're all done.
                ui.performAction(ProjectLID.ViewGroupScript, seln);
            }
        } else {
            ui.cleanupTaskEditor();
            //TODO: won't work since repaint won't occur until after we're all done.
            ui.performAction(ProjectLID.EditScript, seln);
        }
    } else if ((item != null) && (column != null) && (column.getData() == null)) {
        // In a valid row, first column
        if (ui.treeOperationOccurred == 0) {
            ui.initiateTaskRename(item, true);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Point(org.eclipse.swt.graphics.Point) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 4 with Point

use of org.eclipse.swt.graphics.Point in project cogtool by cogtool.

the class ManagedCombo method replaceSelection.

protected void replaceSelection(String withString) {
    if (withString != null) {
        Point selection = getSelection();
        String allText = getText();
        setText(allText.substring(0, selection.x) + withString + allText.substring(selection.y));
        selection.y = selection.x + withString.length();
        setSelection(selection);
    }
}
Also used : Point(org.eclipse.swt.graphics.Point)

Example 5 with Point

use of org.eclipse.swt.graphics.Point in project cogtool by cogtool.

the class ActionPropertySet method layoutHelper.

@Override
public void layoutHelper() {
    actionSettings = new Composite(parent, SWT.BORDER);
    actionSettings.setLayout(actionSettingsLayout);
    propLabel = new Label(parent, SWT.CENTER);
    propLabel.setText(designPropertiesLabel);
    Font labelFont = FontUtils.getAdjustedFont(propLabel.getFont(), SWT.BOLD);
    propLabel.setFont(labelFont);
    actionType = new DisplayLabel(parent, SWT.NONE);
    actionType.setText(actionTypeLabel);
    actionChoices = new ComboWithEnableFix(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    actionChoices.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent evt) {
            int currentSelection = actionChoices.getSelectionIndex();
            if (currentSelection != chosenActionType) {
                editTransitionParms.useWhichParts = choiceUseIndexes[currentSelection];
                chosenActionType = currentSelection;
                view.performAction(DesignEditorLID.EditTransition, editTransitionParms, true);
            }
        }
    });
    delayLabelLabel = new DisplayLabel(parent, SWT.NONE);
    delayLabelLabel.setText(DELAY_LABEL_LABEL);
    delayLabel = new View.PerformActionText(parent, SWT.SINGLE | SWT.BORDER) {

        @Override
        protected void onFocus() {
            super.onFocus();
            view.getTransmuter().setLIDEnabledState();
        }

        @Override
        protected boolean doChangeAction() {
            Point labelSelection = getSelection();
            if ("".equals(getText())) {
                setText(TransitionDelay.DEFAULT_DELAY_LABEL);
                labelSelection = null;
            }
            if (view.performAction(DesignEditorLID.ChangeDelay)) {
                if (labelSelection != null) {
                    setSelection(labelSelection);
                }
                return true;
            }
            return false;
        }
    };
    delayInSecsLabel = new DisplayLabel(parent, SWT.NONE);
    delayInSecsLabel.setText(DELAY_DURATION_LABEL + ":");
    secondsUnit = new Label(parent, SWT.NONE);
    secondsUnit.setText(SECONDS);
    delayInSecs = new View.PerformActionDouble(parent, SWT.SINGLE | SWT.BORDER) {

        @Override
        protected void onFocus() {
            super.onFocus();
            view.getTransmuter().setLIDEnabledState();
        }

        @Override
        protected void onModify() {
            super.onModify();
            delayLabel.setEnabled(getDoubleValue() > 0.0);
        }

        @Override
        protected boolean doChangeAction() {
            Point delaySelection = getSelection();
            if (getDoubleValue() == 0.0) {
                setText("");
                delaySelection = null;
            }
            if (view.performAction(DesignEditorLID.ChangeDelay)) {
                if (delaySelection != null) {
                    setSelection(delaySelection);
                }
                return true;
            }
            return false;
        }
    };
    delayInSecs.setAllowNegative(false);
    delayInSecs.setDecimalPlaces(3);
    delayInSecs.moveAbove(delayLabel.getOuter());
    FormData data = new FormData();
    data.left = leftAttachment;
    data.right = new FormAttachment(100, -5);
    propLabel.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(actionChoices, 0, SWT.CENTER);
    actionType.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(actionType, 5, SWT.RIGHT);
    data.right = new FormAttachment(100, -5);
    data.top = new FormAttachment(propLabel, 5, SWT.BOTTOM);
    actionChoices.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(actionChoices, 5, SWT.BOTTOM);
    data.right = new FormAttachment(100, -5);
    actionSettings.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(actionSettings, 5, SWT.BOTTOM);
    delayInSecsLabel.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(delayInSecsLabel, 5, SWT.BOTTOM);
    data.width = 100;
    delayInSecs.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(delayInSecs.getOuter(), 5, SWT.RIGHT);
    data.top = new FormAttachment(delayInSecs.getOuter(), 0, SWT.CENTER);
    secondsUnit.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(delayInSecs.getOuter(), 5, SWT.BOTTOM);
    delayLabelLabel.setLayoutData(data);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(delayLabelLabel, 5, SWT.BOTTOM);
    data.right = new FormAttachment(100, -5);
    delayLabel.setLayoutData(data);
    emptyParms = createEmptyComposite();
    layOutEmptyComposite();
    multTransParms = new Composite(actionSettings, SWT.NONE);
    multTransParms.setLayout(new FormLayout());
    Label multTransLabel = new Label(multTransParms, SWT.WRAP);
    multTransLabel.setText(noActionAvailableText);
    data = new FormData();
    data.left = leftAttachment;
    data.top = new FormAttachment(0, 5);
    data.right = new FormAttachment(100, -5);
    multTransLabel.setLayoutData(data);
    frameParms = createFrameComposite();
}
Also used : FormData(org.eclipse.swt.layout.FormData) FormLayout(org.eclipse.swt.layout.FormLayout) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DisplayLabel(edu.cmu.cs.hcii.cogtool.util.DisplayLabel) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) DisplayLabel(edu.cmu.cs.hcii.cogtool.util.DisplayLabel) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ComboWithEnableFix(edu.cmu.cs.hcii.cogtool.util.ComboWithEnableFix) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

Point (org.eclipse.swt.graphics.Point)583 Rectangle (org.eclipse.swt.graphics.Rectangle)132 SelectionEvent (org.eclipse.swt.events.SelectionEvent)83 FormData (org.eclipse.swt.layout.FormData)82 Composite (org.eclipse.swt.widgets.Composite)81 GC (org.eclipse.swt.graphics.GC)79 GridData (org.eclipse.swt.layout.GridData)78 Button (org.eclipse.swt.widgets.Button)78 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 Control (org.eclipse.swt.widgets.Control)75 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)64 CLabel (org.eclipse.swt.custom.CLabel)53 GridLayout (org.eclipse.swt.layout.GridLayout)49 Node (org.talend.designer.core.ui.editor.nodes.Node)49 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)45 Event (org.eclipse.swt.widgets.Event)43 Label (org.eclipse.swt.widgets.Label)42 Text (org.eclipse.swt.widgets.Text)42 ArrayList (java.util.ArrayList)41 TableItem (org.eclipse.swt.widgets.TableItem)40