Search in sources :

Example 1 with PredefinedColorMap

use of org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap 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 PredefinedColorMap

use of org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap 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)

Example 3 with PredefinedColorMap

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

the class ColorMapProperty method readValueFromXML.

@Override
public ColorMap readValueFromXML(Element propElement) {
    ColorMap result = new ColorMap();
    result.setInterpolate(Boolean.parseBoolean(propElement.getChild(XML_ELEMENT_INTERPOLATE).getValue()));
    result.setAutoScale(Boolean.parseBoolean(propElement.getChild(XML_ELEMENT_AUTOSCALE).getValue()));
    if (propElement.getChild(XML_ELEMENT_MAP).getChildren().size() == 0) {
        PredefinedColorMap p = PredefinedColorMap.fromIndex(Integer.parseInt(propElement.getChild(XML_ELEMENT_MAP).getValue()));
        result.setPredefinedColorMap(p);
    } else {
        LinkedHashMap<Double, RGB> map = new LinkedHashMap<Double, RGB>();
        for (Object o : propElement.getChild(XML_ELEMENT_MAP).getChildren()) {
            Element e = (Element) o;
            map.put(Double.parseDouble(e.getValue()), new RGB(Integer.parseInt(e.getAttributeValue(XML_ATTRIBUTE_RED)), Integer.parseInt(e.getAttributeValue(XML_ATTRIBUTE_GREEN)), Integer.parseInt(e.getAttributeValue(XML_ATTRIBUTE_BLUE))));
        }
        result.setColorMap(map);
    }
    return result;
}
Also used : ColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap) PredefinedColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap) PredefinedColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap) Element(org.jdom.Element) RGB(org.eclipse.swt.graphics.RGB) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)3 PredefinedColorMap (org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap)3 ColorMap (org.csstudio.swt.widgets.datadefinition.ColorMap)2 ColorTuple (org.csstudio.swt.widgets.datadefinition.ColorTuple)2 RGB (org.eclipse.swt.graphics.RGB)2 Entry (java.util.Map.Entry)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 ToolBar (org.eclipse.swt.widgets.ToolBar)1 Element (org.jdom.Element)1