Example usage for org.eclipse.jface.preference ColorSelector setColorValue

List of usage examples for org.eclipse.jface.preference ColorSelector setColorValue

Introduction

In this page you can find the example usage for org.eclipse.jface.preference ColorSelector setColorValue.

Prototype

public void setColorValue(RGB rgb) 

Source Link

Document

Set the current color value and update the control.

Usage

From source file:com.astra.ses.spell.gui.preferences.ui.pages.GUIColorsPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    // CONTAINER//from  w  ww  .j a  v  a 2 s  .  co  m
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.grabExcessHorizontalSpace = true;
    container.setLayout(layout);
    container.setLayoutData(layoutData);

    /*
     * Fill the widget with the color chooser controls
     */
    IConfigurationManager conf = getConfigurationManager();
    m_colorSelectors = new ColorSelector[GuiColorKey.values().length];
    for (GuiColorKey key : GuiColorKey.values()) {
        Label label = new Label(container, SWT.NONE);
        label.setText(key.description);
        label.setLayoutData(GridDataFactory.copyData(layoutData));

        ColorSelector selector = new ColorSelector(container);
        selector.setColorValue(conf.getGuiColor(key).getRGB());
        m_colorSelectors[key.ordinal()] = selector;
    }
    return container;
}

From source file:com.astra.ses.spell.gui.preferences.ui.pages.ProcedureColorsPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    // CONTAINER/*w w w. java  2 s.  c om*/
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.grabExcessHorizontalSpace = true;
    container.setLayout(layout);
    container.setLayoutData(layoutData);
    /*
     * Fill the widget with the color chooser controls
     */
    IConfigurationManager conf = getConfigurationManager();
    m_colorSelectors = new ColorSelector[ExecutorStatus.values().length];
    for (ExecutorStatus key : ExecutorStatus.values()) {
        Label label = new Label(container, SWT.NONE);
        label.setText(key.description);
        label.setLayoutData(GridDataFactory.copyData(layoutData));

        ColorSelector selector = new ColorSelector(container);
        selector.setColorValue(conf.getColor(ProcColorKey.getPreferenceName(key)).getRGB());
        m_colorSelectors[key.ordinal()] = selector;
    }
    return container;
}

From source file:com.astra.ses.spell.gui.preferences.ui.pages.StatusColorsPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    // CONTAINER/*from  ww  w  .ja v  a 2s  .co  m*/
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.grabExcessHorizontalSpace = true;
    container.setLayout(layout);
    container.setLayoutData(layoutData);
    /*
     * Fill the widget with the color chooser controls
     */
    IConfigurationManager conf = getConfigurationManager();
    m_colorSelectors = new ColorSelector[StatusColorKey.values().length];
    for (StatusColorKey key : StatusColorKey.values()) {
        Label label = new Label(container, SWT.NONE);
        label.setText(key.description);
        label.setLayoutData(GridDataFactory.copyData(layoutData));

        ColorSelector selector = new ColorSelector(container);
        selector.setColorValue(conf.getColor(key.getPreferenceName()).getRGB());
        m_colorSelectors[key.ordinal()] = selector;
    }
    return container;
}

From source file:com.siteview.mde.internal.ui.preferences.SyntaxColorTab.java

License:Open Source License

private void createElementTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    layout.marginWidth = layout.marginHeight = 0;
    container.setLayout(layout);//from   ww w .  j ava2s .co m
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label label = new Label(container, SWT.LEFT);
    label.setText(MDEUIMessages.SyntaxColorTab_elements);
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);

    fElementViewer = new TableViewer(container, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    fElementViewer.setLabelProvider(new LabelProvider());
    fElementViewer.setContentProvider(ArrayContentProvider.getInstance());
    fElementViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite colorComposite = new Composite(container, SWT.NONE);
    colorComposite.setLayout(new GridLayout(2, false));
    colorComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    label = new Label(colorComposite, SWT.LEFT);
    label.setText(MDEUIMessages.SyntaxColorTab_color);

    final ColorSelector colorSelector = new ColorSelector(colorComposite);
    Button colorButton = colorSelector.getButton();
    colorButton.setLayoutData(new GridData(GridData.BEGINNING));

    colorButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ColorElement item = getColorElement(fElementViewer);
            item.setColorValue(colorSelector.getColorValue());
        }
    });

    fBoldButton = new Button(colorComposite, SWT.CHECK);
    gd = new GridData();
    gd.horizontalSpan = 2;
    fBoldButton.setLayoutData(gd);
    fBoldButton.setText(MDEUIMessages.SyntaxColorTab_bold);
    fBoldButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ColorElement item = getColorElement(fElementViewer);
            item.setBold(fBoldButton.getSelection());
        }
    });

    fItalicButton = new Button(colorComposite, SWT.CHECK);
    gd = new GridData();
    gd.horizontalSpan = 2;
    fItalicButton.setLayoutData(gd);
    fItalicButton.setText(MDEUIMessages.SyntaxColorTab_italic);
    fItalicButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ColorElement item = getColorElement(fElementViewer);
            item.setItalic(fItalicButton.getSelection());
        }
    });

    fElementViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ColorElement item = getColorElement(fElementViewer);
            colorSelector.setColorValue(item.getColorValue());
            fBoldButton.setSelection(item.isBold());
            fItalicButton.setSelection(item.isItalic());
        }
    });
    fElementViewer.setInput(getColorData());
    fElementViewer.setComparator(new ViewerComparator());
    fElementViewer.setSelection(new StructuredSelection(fElementViewer.getElementAt(0)));
}

From source file:de.byteholder.geoclipse.mapprovider.DialogMPProfile.java

License:Open Source License

private void setColorValue(final ColorSelector colorSelector, int colorValue) {

    if (colorValue == -1) {
        colorValue = 0;//from  www  .j  a v  a 2s  . c o m
    }

    final RGB rgb = getRGB(colorValue);

    colorSelector.setColorValue(rgb);
    colorSelector.getButton().setToolTipText(rgb.toString());
}

From source file:eu.geclipse.traceview.preferences.EventPreferenceEditor.java

License:Open Source License

/**
 * Creates a new EventSubTypePreferenceEditor
 * //w  ww  .  j a  v a  2s .co m
 * @param composite
 * @param label
 * @param preference
 */
public EventPreferenceEditor(final Composite composite, final String label, final String preference) {
    this.label = label;
    this.preference = preference;
    this.store = Activator.getDefault().getPreferenceStore();
    // Label
    Label name = new Label(composite, SWT.NONE);
    name.setText(label);
    // ColorSelector
    ColorSelector colorSelector = new ColorSelector(composite);
    colorSelector
            .setColorValue(PreferenceConverter.getColor(this.store, preference + PreferenceConstants.P_COLOR));
    GridData gd = new GridData();
    gd.widthHint = 32;
    gd.heightHint = 16;
    colorSelector.getButton().setLayoutData(gd);
    colorSelector.addListener(new IPropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent event) {
            handleColorPropertyChangeEvent(event);
        }
    });
    // CheckBox
    this.drawButton = new Button(composite, SWT.CHECK);
    this.drawButton.setSelection(this.store.getBoolean(preference + PreferenceConstants.P_DRAW));
    this.drawButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            handleDrawPropertyChangeEvent();
        }
    });
    // ColorSelector
    colorSelector = new ColorSelector(composite);
    colorSelector.setColorValue(
            PreferenceConverter.getColor(this.store, preference + PreferenceConstants.P_FILL_COLOR));
    gd = new GridData();
    gd.widthHint = 32;
    gd.heightHint = 16;
    colorSelector.getButton().setLayoutData(gd);
    colorSelector.addListener(new IPropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent event) {
            handleFillColorPropertyChangeEvent(event);
        }
    });
    // CheckBox
    this.button = new Button(composite, SWT.CHECK);
    this.button.setSelection(this.store.getBoolean(preference + PreferenceConstants.P_FILL));
    this.button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            handleFillPropertyChangeEvent();
        }
    });
    // Type Combo
    this.combo = new Combo(composite, SWT.READ_ONLY);
    // int selection = this.store.getInt( this.name + PreferenceConstants.shape
    // );
    int selection = 0;
    switch (selection) {
    case IEventMarker.No_Event:
        selection = 0;
        break;
    case IEventMarker.Rectangle_Event:
        selection = 1;
        break;
    case IEventMarker.Ellipse_Event:
        selection = 2;
        break;
    case IEventMarker.Cross_Event:
        selection = 3;
        break;
    case IEventMarker.Triangle_Event:
        selection = 4;
        break;
    case IEventMarker.Diamond_Event:
        selection = 5;
        break;
    default:
        selection = 0;
    }
    this.combo.setItems(new String[] { "None", //$NON-NLS-1$
            "Rectangle", //$NON-NLS-1$
            "Circle", //$NON-NLS-1$
            "Cross", //$NON-NLS-1$
            "Triangle", //$NON-NLS-1$
            "Diamond" //$NON-NLS-1$
    });
    this.combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            handleSelectionEvent2();
        }
    });
    this.combo.select(selection);
}

From source file:eu.geclipse.traceview.preferences.PreferencesPage.java

License:Open Source License

private void createMessagesGroup(final Composite composite) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;//from w  ww .  j ava 2  s  .  c o m
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
    Group messageGroup = new Group(composite, SWT.NONE);
    messageGroup.setLayout(layout);
    messageGroup.setLayoutData(layoutData);
    messageGroup.setText(Messages.getString("PreferencePage.Messages")); //$NON-NLS-1$
    // Label
    Label name = new Label(messageGroup, SWT.NONE);
    name.setText(Messages.getString("PreferencePage.Message")); //$NON-NLS-1$
    // ColorSelector
    ColorSelector colorSelector = new ColorSelector(messageGroup);
    colorSelector.setColorValue(PreferenceConverter.getColor(this.store,
            PreferenceConstants.P_MESSAGE + PreferenceConstants.P_COLOR));
    GridData gd = new GridData();
    gd.widthHint = 32;
    gd.heightHint = 16;
    colorSelector.getButton().setLayoutData(gd);
    colorSelector.addListener(new IPropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent event) {
            if (event.getNewValue() instanceof RGB) {
                RGB rgb = (RGB) event.getNewValue();
                PreferenceConverter.setValue(PreferencesPage.this.store,
                        PreferenceConstants.P_MESSAGE + PreferenceConstants.P_COLOR, rgb);
            }
        }
    });
}

From source file:eu.geclipse.traceview.preferences.PreferencesPage.java

License:Open Source License

private void createSettingsGroup(final Composite composite) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;//from  www  . jav  a2 s.co  m
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
    Group settingsGroup = new Group(composite, SWT.NONE);
    settingsGroup.setLayout(layout);
    settingsGroup.setLayoutData(layoutData);
    settingsGroup.setText(Messages.getString("PreferencePage.Settings")); //$NON-NLS-1$
    // CheckBox
    layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
    layoutData.horizontalSpan = 2;
    this.button = new Button(settingsGroup, SWT.CHECK);
    this.button.setText(Messages.getString("PreferencePage.AntiAliasing")); //$NON-NLS-1$
    this.button.setSelection(this.store.getBoolean(PreferenceConstants.P_ANTI_ALIASING));
    this.button.setLayoutData(layoutData);
    this.button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            PreferencesPage.this.store.setValue(PreferenceConstants.P_ANTI_ALIASING,
                    PreferencesPage.this.button.getSelection());
        }
    });
    // Selection Color
    Label name = new Label(settingsGroup, SWT.NONE);
    name.setText(Messages.getString("PreferencePage.SelectionColor")); //$NON-NLS-1$
    // ColorSelector
    ColorSelector colorSelector = new ColorSelector(settingsGroup);
    colorSelector
            .setColorValue(PreferenceConverter.getColor(this.store, PreferenceConstants.P_SELECTION_COLOR));
    GridData gd = new GridData();
    gd.widthHint = 32;
    gd.heightHint = 16;
    colorSelector.getButton().setLayoutData(gd);
    colorSelector.addListener(new IPropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent event) {
            if (event.getNewValue() instanceof RGB) {
                RGB rgb = (RGB) event.getNewValue();
                PreferenceConverter.setValue(PreferencesPage.this.store, PreferenceConstants.P_SELECTION_COLOR,
                        rgb);
            }
        }
    });
}

From source file:eu.hydrologis.jgrass.annotationlayer.AnnotationsPropertiesView.java

License:Open Source License

public void createPartControl(Composite parent) {

    Composite propsComposite = new Composite(parent, SWT.None);
    propsComposite.setLayout(new RowLayout());
    propsComposite.setLayoutData(// w  ww . j  a v a 2  s .  co  m
            new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

    // stroke width
    Image img1 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_1.png").createImage();
    Image img2 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_2.png").createImage();
    Image img3 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_3.png").createImage();
    Image img4 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_4.png").createImage();
    Image img5 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_5.png").createImage();

    Composite strokeComposite = new Composite(propsComposite, SWT.None);
    strokeComposite.setLayout(new GridLayout(2, false));
    final ImageCombo strokeWidthCombo = new ImageCombo(strokeComposite, SWT.READ_ONLY);
    GridData gridDataWidth = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridDataWidth.widthHint = 30;
    strokeWidthCombo.setLayoutData(gridDataWidth);
    strokeWidthCombo.add("1", img1);
    strokeWidthCombo.add("2", img2);
    strokeWidthCombo.add("3", img3);
    strokeWidthCombo.add("4", img4);
    strokeWidthCombo.add("5", img5);
    strokeWidthCombo.select(0);
    strokeWidthCombo.setToolTipText("stroke width");
    strokeWidthCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = strokeWidthCombo.getSelectionIndex();
            int strokeWidth = STROKES[selectedIndex];

            AnnotationPlugin.getDefault().setCurrentStrokeWidth(strokeWidth);
            double scale = ApplicationGIS.getActiveMap().getViewportModel().getScaleDenominator();
            AnnotationPlugin.getDefault().setCurrentScale(scale);
        }
    });

    // alpha
    final Combo alphaCombo = new Combo(strokeComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    alphaCombo.setLayoutData(gridData2);
    String[] items = new String[ALPHAS.length];
    for (int i = 0; i < items.length; i++) {
        items[i] = ALPHAS[i] + "%";
    }
    alphaCombo.setItems(items);
    alphaCombo.select(ALPHAS.length - 1);
    alphaCombo.setToolTipText("stroke alpha");
    alphaCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = alphaCombo.getSelectionIndex();
            int alphaInPercent = ALPHAS[selectedIndex];
            int strokeAlpha = 255 * alphaInPercent / 100;

            Color c = AnnotationPlugin.getDefault().getCurrentStrokeColor();
            AnnotationPlugin.getDefault()
                    .setCurrentStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), strokeAlpha));
        }
    });

    // color
    // final Label strokeColLabel = new Label(propsComposite, SWT.NONE);
    // strokeColLabel.setText("Stroke color");
    final ColorSelector cs = new ColorSelector(propsComposite);
    RowData rd1 = new RowData();
    rd1.height = 30;
    rd1.width = 50;
    cs.getButton().setLayoutData(rd1);
    // new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    int[] cc = AnnotationPlugin.getDefault().getCurrentStrokeColorInt();
    cs.setColorValue(new RGB(cc[0], cc[1], cc[2]));
    cs.getButton().setToolTipText("stroke color");
    cs.getButton().addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            RGB rgb = cs.getColorValue();
            int alpha = AnnotationPlugin.getDefault().getCurrentStrokeColorInt()[3];
            AnnotationPlugin.getDefault().setCurrentStrokeColor(new Color(rgb.red, rgb.green, rgb.blue, alpha));
        }
    });

    // clear all
    ImageDescriptor clearID = AbstractUIPlugin.imageDescriptorFromPlugin(AnnotationPlugin.PLUGIN_ID,
            "icons/trash.gif"); //$NON-NLS-1$
    final Button clearButton = new Button(propsComposite, SWT.PUSH);
    // GridData gd1 = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    // clearButton.setLayoutData(gd1);
    RowData rd2 = new RowData();
    rd2.height = 30;
    rd2.width = 50;
    clearButton.setLayoutData(rd2);
    clearButton.setImage(clearID.createImage());
    clearButton.setToolTipText("clear the area from all drawings");
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean answer = MessageDialog.openQuestion(clearButton.getShell(), "Removal warning",
                    "Do you really want to remove all annotations?");
            if (!answer) {
                return;
            }

            AnnotationPlugin.getDefault().getStrokes().clear();
            JGrassCatalogUtilities.getMapgraphicLayerByClass(AnnotationLayerMapGraphic.class).refresh(null);
        }
    });

    // clear last
    ImageDescriptor clearLast = AbstractUIPlugin.imageDescriptorFromPlugin(AnnotationPlugin.PLUGIN_ID,
            "icons/trashlast.gif"); //$NON-NLS-1$
    Button clearLastButton = new Button(propsComposite, SWT.PUSH);
    RowData rd3 = new RowData();
    rd3.height = 30;
    rd3.width = 50;
    clearLastButton.setLayoutData(rd3);
    // GridData gd2 = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    // clearLastButton.setLayoutData(gd2);
    clearLastButton.setImage(clearLast.createImage());
    clearLastButton.setToolTipText("remove last stroke from annotations layer");
    clearLastButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            List<DressedWorldStroke> strokes = AnnotationPlugin.getDefault().getStrokes();
            int size = strokes.size();
            if (size < 1)
                return;
            strokes.remove(size - 1);
            JGrassCatalogUtilities.getMapgraphicLayerByClass(AnnotationLayerMapGraphic.class).refresh(null);
        }
    });

}

From source file:eu.hydrologis.jgrass.ui.utilities.editors.SimpleSWTImageEditor.java

License:Open Source License

/**
 * Constructor for the image editor./*from   w  ww  .  j  a v  a2 s . c o m*/
 * 
 * @param parent the parent composite.
 * @param style the swt style for the component.
 * @param preloadedLines a list of lines to be drawn.
 * @param backGroundImage a background image to use in the canvas.
 * @param minScroll the minimum dimension for the scrolling.
 * @param doZoom flag that defines if the zoom tools should be added.
 */
public SimpleSWTImageEditor(Composite parent, int style, List<DressedStroke> preloadedLines,
        Image backGroundImage, Point minScroll, boolean doZoom) {
    this.doZoom = doZoom;
    if (backGroundImage != null)
        this.backImage = backGroundImage;
    if (preloadedLines == null) {
        this.lines = new ArrayList<DressedStroke>();
    } else {
        this.lines = preloadedLines;
    }
    mainComposite = new Composite(parent, style);
    mainComposite.setLayout(new GridLayout());
    propsComposite = new Composite(mainComposite, style);
    propsComposite.setLayout(new RowLayout());
    propsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    // stroke width
    Image img1 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_1.png").createImage();
    Image img2 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_2.png").createImage();
    Image img3 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_3.png").createImage();
    Image img4 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_4.png").createImage();
    Image img5 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_5.png").createImage();

    Composite strokeComposite = new Composite(propsComposite, SWT.None);
    strokeComposite.setLayout(new GridLayout(2, false));

    final ImageCombo strokeWidthCombo = new ImageCombo(strokeComposite, SWT.READ_ONLY);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = 30;
    strokeWidthCombo.setLayoutData(gridData);
    strokeWidthCombo.add("1", img1);
    strokeWidthCombo.add("2", img2);
    strokeWidthCombo.add("3", img3);
    strokeWidthCombo.add("4", img4);
    strokeWidthCombo.add("5", img5);
    strokeWidthCombo.select(0);
    strokeWidthCombo.setToolTipText("stroke width");
    strokeWidthCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = strokeWidthCombo.getSelectionIndex();
            strokeWidth[0] = STROKES[selectedIndex];
        }
    });

    // alpha
    final Combo alphaCombo = new Combo(strokeComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    alphaCombo.setLayoutData(gridData2);
    String[] items = new String[ALPHAS.length];
    for (int i = 0; i < items.length; i++) {
        items[i] = ALPHAS[i] + "%";
    }
    alphaCombo.setItems(items);
    alphaCombo.select(ALPHAS.length - 1);
    alphaCombo.setToolTipText("stroke alpha");
    alphaCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = alphaCombo.getSelectionIndex();
            int alphaInPercent = ALPHAS[selectedIndex];
            strokeAlpha = 255 * alphaInPercent / 100;
        }
    });

    Composite buttonsComposite = new Composite(propsComposite, SWT.NONE);
    if (doZoom) {
        buttonsComposite.setLayout(new GridLayout(6, false));
    } else {
        buttonsComposite.setLayout(new GridLayout(3, false));
    }

    // color
    final ColorSelector cs = new ColorSelector(buttonsComposite);
    Button csButton = cs.getButton();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = 25;
    csButton.setLayoutData(gridData3);

    cs.setColorValue(new RGB(strokeRGB[0], strokeRGB[1], strokeRGB[2]));
    cs.getButton().setToolTipText("stroke color");
    cs.getButton().addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            RGB rgb = cs.getColorValue();
            strokeRGB = new int[] { rgb.red, rgb.green, rgb.blue };
        }
    });

    // clear all
    ImageDescriptor clearID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
            "icons/trash.gif"); //$NON-NLS-1$
    Button clearButton = new Button(buttonsComposite, SWT.BORDER | SWT.PUSH);
    clearButton.setImage(clearID.createImage());
    clearButton.setToolTipText("clear the area from drawings");
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            lines.removeAll(lines);
            drawArea.redraw();
        }
    });
    // clear shape
    ImageDescriptor removeID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
            "icons/close.gif"); //$NON-NLS-1$
    Button removeButton = new Button(buttonsComposite, SWT.BORDER | SWT.PUSH);
    removeButton.setImage(removeID.createImage());
    removeButton.setToolTipText("remove selected line");
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            isRemoveMode = true;
            final Cursor cursor = new Cursor(drawArea.getDisplay(), SWT.CURSOR_CROSS);
            drawArea.setCursor(cursor);
        }
    });

    if (doZoom) {
        // zoom all
        ImageDescriptor zoomAllID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
                "icons/zoom_all.gif"); //$NON-NLS-1$
        Button zoomAllButton = new Button(buttonsComposite, SWT.PUSH);
        zoomAllButton.setImage(zoomAllID.createImage());
        zoomAllButton.setToolTipText("zoom to the whole extend");
        zoomAllButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                calculateBaseScaleFactor();
                scaleFactor = baseScaleFactor;
                drawArea.redraw();
            }
        });

        // zoom in
        ImageDescriptor zoomInID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
                "icons/zoom_in.gif"); //$NON-NLS-1$
        Button zoomInButton = new Button(buttonsComposite, SWT.PUSH);
        zoomInButton.setImage(zoomInID.createImage());
        zoomInButton.setToolTipText("zoom in");
        zoomInButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                scaleFactor = scaleFactor * 1.2;
                drawArea.redraw();
            }
        });

        // zoom out
        ImageDescriptor zoomOutID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
                "icons/zoom_out.gif"); //$NON-NLS-1$
        Button zoomOutButton = new Button(buttonsComposite, SWT.PUSH);
        zoomOutButton.setImage(zoomOutID.createImage());
        zoomOutButton.setToolTipText("zoom out");
        zoomOutButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                scaleFactor = scaleFactor / 1.2;
                drawArea.redraw();
            }
        });
    }

    drawAreaScroller = new ScrolledComposite(mainComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    drawArea = new Canvas(drawAreaScroller, SWT.None);
    defaultCursor = drawArea.getCursor();
    drawAreaScroller.setContent(drawArea);
    drawAreaScroller.setExpandHorizontal(true);
    drawAreaScroller.setExpandVertical(true);
    if (minScroll != null) {
        drawAreaScroller.setMinWidth(minScroll.x);
        drawAreaScroller.setMinHeight(minScroll.y);
    }
    drawAreaScroller.setLayoutData(
            new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

    Listener drawListener = new Listener() {
        int lastX = 0, lastY = 0;
        List<Integer> line = null;
        GC gc = null;

        public void handleEvent(Event event) {

            /*
             * REMOVE MODE
             */
            if (isRemoveMode && event.type == SWT.MouseDown) {
                for (int i = 0; i < lines.size(); i++) {
                    DressedStroke stroke = lines.get(i);
                    int x = event.x;
                    int y = event.y;
                    int[] nodes = stroke.getScaledNodes(baseScaleFactor);
                    for (int j = 0; j < nodes.length - 1; j = j + 2) {
                        Point2f linePoint = new Point2f(nodes[j], nodes[j + 1]);
                        Point2f clickPoint = new Point2f(x, y);
                        int threshold = stroke.strokeWidth[0];
                        threshold = (int) Math.round((double) threshold * baseScaleFactor);
                        threshold = threshold < 10 ? 10 : threshold;
                        if (clickPoint.distance(linePoint) < threshold) {
                            lines.remove(i);
                            isRemoveMode = false;
                            drawArea.setCursor(defaultCursor);
                            drawArea.redraw();
                            return;
                        }
                    }

                }

            }
            if (isRemoveMode && (event.type == SWT.MouseMove || event.type == SWT.MouseUp)) {
                return;
            }

            /*
             * DRAWING MODE
             */
            if (scaleFactor == -1) {
                calculateBaseScaleFactor();
                scaleFactor = baseScaleFactor;
            }

            switch (event.type) {
            case SWT.Paint:
                if (drawnImage != null)
                    drawnImage.dispose();
                drawnImage = new Image(drawArea.getDisplay(), drawArea.getBounds());
                GC gcImage = new GC(drawnImage);
                // draw the background image
                if (backImage != null) {
                    Rectangle imgBounds = backImage.getBounds();
                    ImageData newImageData = backImage.getImageData().scaledTo(
                            (int) Math.round(imgBounds.width * scaleFactor),
                            (int) Math.round(imgBounds.height * scaleFactor));
                    Image newImage = new Image(drawArea.getDisplay(), newImageData);
                    gcImage.drawImage(newImage, 0, 0);
                }
                // draw the lines
                for (int i = 0; i < lines.size(); i = i + 1) {
                    DressedStroke tmpStroke = lines.get(i);
                    gcImage.setLineWidth((int) Math.round(tmpStroke.strokeWidth[0] * scaleFactor));
                    gcImage.setLineCap(SWT.CAP_ROUND);
                    gcImage.setLineJoin(SWT.JOIN_ROUND);
                    gcImage.setLineStyle(SWT.LINE_SOLID);
                    int[] rgb = tmpStroke.rgb;
                    gcImage.setForeground(new Color(drawArea.getDisplay(), rgb[0], rgb[1], rgb[2]));
                    gcImage.setAlpha(tmpStroke.strokeAlpha);
                    int[] nodes = tmpStroke.getScaledNodes(scaleFactor);
                    // at least 4 values to have two points
                    if (nodes.length > 3) {
                        Path p = new Path(drawArea.getDisplay());
                        p.moveTo(nodes[0], nodes[1]);
                        for (int j = 2; j < nodes.length - 1; j = j + 2) {
                            p.lineTo(nodes[j], nodes[j + 1]);
                        }
                        gcImage.drawPath(p);
                    }
                }
                gc = new GC(drawArea);
                gc.drawImage(drawnImage, 0, 0);

                gcImage.dispose();

                break;
            case SWT.MouseMove:
                if ((event.stateMask & SWT.BUTTON1) == 0)
                    break;
                if (line == null)
                    break;
                line.add(event.x);
                line.add(event.y);
                gc = new GC(drawArea);
                gc.setLineWidth((int) Math.round(strokeWidth[0] * scaleFactor));
                gc.setLineCap(SWT.CAP_ROUND);
                gc.setLineJoin(SWT.JOIN_ROUND);
                gc.setLineStyle(SWT.LINE_SOLID);
                Color color = new Color(drawArea.getDisplay(), strokeRGB[0], strokeRGB[1], strokeRGB[2]);
                gc.setForeground(color);
                gc.setAlpha(255 * strokeAlpha / 100);
                gc.drawLine(lastX, lastY, event.x, event.y);
                lastX = event.x;
                lastY = event.y;
                gc.dispose();
                color.dispose();
                break;
            case SWT.MouseDown:
                if (isRemoveMode) {
                    break;
                }
                lastX = event.x;
                lastY = event.y;
                line = new ArrayList<Integer>();
                line.add(lastX);
                line.add(lastY);
                isDrawMode = true;
                break;
            case SWT.MouseUp:
                if (isRemoveMode || !isDrawMode)
                    break;

                lastX = event.x;
                lastY = event.y;
                DressedStroke newLine = new DressedStroke();
                newLine.nodes = new int[line.size()];
                for (int i = 0; i < line.size(); i++) {
                    newLine.nodes[i] = (int) Math.round((double) line.get(i) / scaleFactor);
                }
                newLine.strokeAlpha = strokeAlpha;
                newLine.strokeWidth = new int[] { strokeWidth[0] };
                newLine.rgb = new int[] { strokeRGB[0], strokeRGB[1], strokeRGB[2] };
                lines.add(newLine);
                line.clear();
                drawArea.redraw();
                break;

            }
        }
    };

    drawArea.addListener(SWT.MouseDown, drawListener);
    drawArea.addListener(SWT.MouseMove, drawListener);
    drawArea.addListener(SWT.MouseUp, drawListener);
    drawArea.addListener(SWT.Paint, drawListener);

    // add popup menu
    MenuManager popManager = new MenuManager();
    Menu menu = popManager.createContextMenu(drawArea);
    drawArea.setMenu(menu);
    IAction menuAction = new SaveAction(this);
    popManager.add(menuAction);

}