Search in sources :

Example 1 with ColorTuple

use of org.csstudio.swt.widgets.datadefinition.ColorTuple in project yamcs-studio by yamcs.

the class ColorMapEditDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite parent_Composite = (Composite) super.createDialogArea(parent);
    final Composite mainComposite = new Composite(parent_Composite, SWT.None);
    mainComposite.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 300;
    mainComposite.setLayoutData(gridData);
    final Composite leftComposite = new Composite(mainComposite, SWT.None);
    leftComposite.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 250;
    leftComposite.setLayoutData(gd);
    createLabel(leftComposite, "Color Map:");
    Composite toolBarComposite = new Composite(leftComposite, SWT.BORDER);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    gridLayout.marginBottom = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolBarComposite.setLayout(gridLayout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    toolBarComposite.setLayoutData(gd);
    ToolBarManager toolbarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolbarManager.createControl(toolBarComposite);
    GridData grid = new GridData();
    grid.horizontalAlignment = GridData.FILL;
    grid.verticalAlignment = GridData.BEGINNING;
    toolBar.setLayoutData(grid);
    createActions();
    toolbarManager.add(addAction);
    toolbarManager.add(copyAction);
    toolbarManager.add(removeAction);
    toolbarManager.add(moveUpAction);
    toolbarManager.add(moveDownAction);
    toolbarManager.update(true);
    colorListViewer = createColorListViewer(toolBarComposite);
    colorListViewer.setInput(colorList);
    Composite rightComposite = new Composite(mainComposite, SWT.NONE);
    rightComposite.setLayout(new GridLayout(1, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 340;
    rightComposite.setLayoutData(gd);
    this.createLabel(rightComposite, "Use predefined color map:");
    preDefinedMapCombo = new Combo(rightComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    preDefinedMapCombo.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false));
    preDefinedMapCombo.setItems(PredefinedColorMap.getStringValues());
    int i = 0;
    for (PredefinedColorMap colorMap : PredefinedColorMap.values()) {
        if (predefinedColorMap == colorMap)
            break;
        else
            i++;
    }
    preDefinedMapCombo.select(i);
    final Button InterpolateCheckBox = new Button(rightComposite, SWT.CHECK);
    InterpolateCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false));
    InterpolateCheckBox.setSelection(interpolate);
    InterpolateCheckBox.setText("Interpolate");
    final Button autoScaleCheckBox = new Button(rightComposite, SWT.CHECK);
    autoScaleCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false));
    autoScaleCheckBox.setSelection(autoScale);
    autoScaleCheckBox.setText("Auto Scale");
    autoScaleCheckBox.setToolTipText("Scale the color map values to the range of" + " (" + min + ", " + max + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ").");
    Group group = new Group(rightComposite, SWT.None);
    group.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    group.setLayout(new GridLayout(2, false));
    // $NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-3$
    group.setText("Output" + " (" + min + "~" + max + ")");
    colorMapLabel = new Label(group, SWT.None);
    colorMapLabel.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    refreshGUI();
    preDefinedMapCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            predefinedColorMap = PredefinedColorMap.values()[preDefinedMapCombo.getSelectionIndex()];
            if (preDefinedMapCombo.getSelectionIndex() != 0) {
                LinkedHashMap<Double, RGB> map = PredefinedColorMap.values()[preDefinedMapCombo.getSelectionIndex()].getMap();
                colorList.clear();
                for (Entry<Double, RGB> entry : map.entrySet()) colorList.add(new ColorTuple(entry.getKey(), entry.getValue()));
                colorListViewer.refresh();
            }
            refreshGUI();
        }
    });
    InterpolateCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            interpolate = InterpolateCheckBox.getSelection();
            refreshGUI();
        }
    });
    autoScaleCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            autoScale = autoScaleCheckBox.getSelection();
            refreshGUI();
        }
    });
    return parent_Composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ToolBarManager(org.eclipse.jface.action.ToolBarManager) LinkedHashMap(java.util.LinkedHashMap) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Entry(java.util.Map.Entry) ColorTuple(org.csstudio.swt.widgets.datadefinition.ColorTuple) Button(org.eclipse.swt.widgets.Button) PredefinedColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with ColorTuple

use of org.csstudio.swt.widgets.datadefinition.ColorTuple in project yamcs-studio by yamcs.

the class ColorMapEditDialog method createActions.

/**
 * Creates the actions.
 */
private void createActions() {
    addAction = new Action("Add") {

        @Override
        public void run() {
            ColorTuple tuple = new ColorTuple(0, new RGB(0, 0, 0));
            colorList.add(tuple);
            refreshColorListViewerForAction(tuple);
        }
    };
    addAction.setToolTipText("Add a color tuple");
    addAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/add.gif"));
    copyAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) colorListViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ColorTuple) {
                ColorTuple o = (ColorTuple) selection.getFirstElement();
                ColorTuple tuple = new ColorTuple(o.value, o.rgb);
                colorList.add(tuple);
                refreshColorListViewerForAction(tuple);
            }
        }
    };
    copyAction.setText("Copy");
    copyAction.setToolTipText("Copy the selected color tuple");
    copyAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/copy.gif"));
    copyAction.setEnabled(false);
    removeAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) colorListViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ColorTuple) {
                colorList.remove(selection.getFirstElement());
                refreshColorListViewerForAction(null);
                this.setEnabled(false);
            }
        }
    };
    removeAction.setText("Remove");
    removeAction.setToolTipText("Remove the selected color tuple from the list");
    removeAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/delete.gif"));
    removeAction.setEnabled(false);
    moveUpAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) colorListViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ColorTuple) {
                ColorTuple tuple = (ColorTuple) selection.getFirstElement();
                int i = colorList.indexOf(tuple);
                if (i > 0) {
                    colorList.remove(tuple);
                    colorList.add(i - 1, tuple);
                    refreshColorListViewerForAction(tuple);
                }
            }
        }
    };
    moveUpAction.setText("Move Up");
    moveUpAction.setToolTipText("Move up the selected color tuple");
    moveUpAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_prev.gif"));
    moveUpAction.setEnabled(false);
    moveDownAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) colorListViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ColorTuple) {
                ColorTuple tuple = (ColorTuple) selection.getFirstElement();
                int i = colorList.indexOf(tuple);
                if (i < colorList.size() - 1) {
                    colorList.remove(tuple);
                    colorList.add(i + 1, tuple);
                    refreshColorListViewerForAction(tuple);
                }
            }
        }
    };
    moveDownAction.setText("Move Down");
    moveDownAction.setToolTipText("Move down the selected color tuple");
    moveDownAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_next.gif"));
    moveDownAction.setEnabled(false);
}
Also used : Action(org.eclipse.jface.action.Action) ColorTuple(org.csstudio.swt.widgets.datadefinition.ColorTuple) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RGB(org.eclipse.swt.graphics.RGB)

Example 3 with ColorTuple

use of org.csstudio.swt.widgets.datadefinition.ColorTuple in project yamcs-studio by yamcs.

the class ColorMapEditDialog method refreshToolbarOnSelection.

/**
 * Refreshes the enabled-state of the actions.
 */
private void refreshToolbarOnSelection() {
    IStructuredSelection selection = (IStructuredSelection) colorListViewer.getSelection();
    if (!selection.isEmpty() && selection.getFirstElement() instanceof ColorTuple) {
        removeAction.setEnabled(true);
        moveUpAction.setEnabled(true);
        moveDownAction.setEnabled(true);
        copyAction.setEnabled(true);
    } else {
        removeAction.setEnabled(false);
        moveUpAction.setEnabled(false);
        moveDownAction.setEnabled(false);
        copyAction.setEnabled(false);
    }
}
Also used : ColorTuple(org.csstudio.swt.widgets.datadefinition.ColorTuple) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with ColorTuple

use of org.csstudio.swt.widgets.datadefinition.ColorTuple in project yamcs-studio by yamcs.

the class ColorMapEditDialog method getOutput.

public ColorMap getOutput() {
    ColorMap result = new ColorMap();
    if (predefinedColorMap == PredefinedColorMap.None) {
        LinkedHashMap<Double, RGB> map = new LinkedHashMap<Double, RGB>();
        for (ColorTuple tuple : colorList) map.put(tuple.value, tuple.rgb);
        result.setColorMap(map);
    }
    result.setAutoScale(autoScale);
    result.setInterpolate(interpolate);
    result.setPredefinedColorMap(predefinedColorMap);
    return result;
}
Also used : ColorTuple(org.csstudio.swt.widgets.datadefinition.ColorTuple) ColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap) PredefinedColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap) RGB(org.eclipse.swt.graphics.RGB) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ColorTuple (org.csstudio.swt.widgets.datadefinition.ColorTuple)4 LinkedHashMap (java.util.LinkedHashMap)2 PredefinedColorMap (org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 RGB (org.eclipse.swt.graphics.RGB)2 Entry (java.util.Map.Entry)1 ColorMap (org.csstudio.swt.widgets.datadefinition.ColorMap)1 Action (org.eclipse.jface.action.Action)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1