Search in sources :

Example 16 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project webtools.sourceediting by eclipse.

the class JSONSyntaxColoringPage method createContents.

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);
    fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Composite pageComponent = createComposite(parent, 2);
    /*
		 * PlatformUI .getWorkbench() .getHelpSystem() .setHelp(pageComponent,
		 * IHelpContextIds.JSON_PREFWEBX_STYLES_HELPID);
		 */
    Link link = new Link(pageComponent, SWT.WRAP);
    link.setText(SSEUIMessages.SyntaxColoring_Link);
    link.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
        }
    });
    GridData linkData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1);
    // only expand further if anyone else requires
    linkData.widthHint = 150;
    // it
    link.setLayoutData(linkData);
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    SashForm editor = new SashForm(pageComponent, SWT.VERTICAL);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData2.horizontalSpan = 2;
    editor.setLayoutData(gridData2);
    SashForm top = new SashForm(editor, SWT.HORIZONTAL);
    Composite styleEditor = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginRight = 5;
    ((GridLayout) styleEditor.getLayout()).marginLeft = 0;
    createLabel(styleEditor, JSONUIMessages.SyntaxColoringPage_0);
    fStylesViewer = createStylesViewer(styleEditor);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalIndent = 0;
    Iterator iterator = fStyleToDescriptionMap.values().iterator();
    while (iterator.hasNext()) {
        gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length()));
    }
    gridData.heightHint = convertHeightInCharsToPixels(5);
    fStylesViewer.getControl().setLayoutData(gridData);
    Composite editingComposite = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginLeft = 5;
    // $NON-NLS-1$
    createLabel(editingComposite, "");
    Button enabler = createCheckbox(editingComposite, JSONUIMessages.SyntaxColoringPage_2);
    enabler.setEnabled(false);
    enabler.setSelection(true);
    Composite editControls = createComposite(editingComposite, 2);
    ((GridLayout) editControls.getLayout()).marginLeft = 20;
    fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_);
    ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fForegroundLabel.setEnabled(false);
    fForegroundColorEditor = new ColorSelector(editControls);
    Button fForegroundColor = fForegroundColorEditor.getButton();
    GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fForegroundColor.setLayoutData(gd);
    fForegroundColorEditor.setEnabled(false);
    fForegroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Foreground_Color_Selector_Button;
        }
    });
    fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_);
    ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fBackgroundLabel.setEnabled(false);
    fBackgroundColorEditor = new ColorSelector(editControls);
    Button fBackgroundColor = fBackgroundColorEditor.getButton();
    gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fBackgroundColor.setLayoutData(gd);
    fBackgroundColorEditor.setEnabled(false);
    fBackgroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Background_Color_Selector_Button;
        }
    });
    fBold = createCheckbox(editControls, JSONUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, JSONUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, JSONUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, JSONUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    // $NON-NLS-1$ = "Restore Default"
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_);
    fClearStyle.setLayoutData(new GridData(SWT.BEGINNING));
    ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20;
    fClearStyle.setEnabled(false);
    Composite sampleArea = createComposite(editor, 1);
    ((GridLayout) sampleArea.getLayout()).marginLeft = 5;
    ((GridLayout) sampleArea.getLayout()).marginTop = 5;
    // $NON-NLS-1$ = "&Sample text:"
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_);
    fPreviewViewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    fText = fPreviewViewer.getTextWidget();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = convertWidthInCharsToPixels(20);
    gridData3.heightHint = convertHeightInCharsToPixels(5);
    gridData3.horizontalSpan = 2;
    fText.setLayoutData(gridData3);
    fText.setEditable(false);
    // $NON-NLS-1$
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForJSON.ContentTypeID_JSON);
    fDocument.set(getExampleText());
    initializeSourcePreviewColors(fPreviewViewer);
    fPreviewViewer.setDocument(fDocument);
    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    /*
		 * PlatformUI .getWorkbench() .getHelpSystem() .setHelp(pageComponent,
		 * IHelpContextIds.JSON_PREFWEBX_STYLES_HELPID);
		 */
    fStylesViewer.setInput(getStylePreferenceKeys());
    applyStyles();
    fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                activate(namedStyle);
                if (namedStyle == null)
                    return;
            }
        }
    });
    fForegroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[0];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                    }
                }
            }
        }
    });
    fBackgroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[1];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[1] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                        activate(namedStyle);
                    }
                }
            }
        }
    });
    fBold.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[2];
                String newValue = String.valueOf(fBold.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[2] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fItalic.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[3];
                String newValue = String.valueOf(fItalic.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[3] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fStrike.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[4];
                String newValue = String.valueOf(fStrike.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[4] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fUnderline.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[5];
                String newValue = String.valueOf(fUnderline.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[5] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fClearStyle.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (fStylesViewer.getSelection().isEmpty())
                return;
            String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString();
            getOverlayStore().setToDefault(namedStyle);
            applyStyles();
            fText.redraw();
            activate(namedStyle);
        }
    });
    return pageComponent;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SashForm(org.eclipse.swt.custom.SashForm) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) ColorSelector(org.eclipse.jface.preference.ColorSelector) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Link(org.eclipse.swt.widgets.Link)

Example 17 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project webtools.sourceediting by eclipse.

the class DTDSyntaxColoringPage method createContents.

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);
    fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Composite pageComponent = createComposite(parent, 2);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.DTD_PREFWEBX_STYLES_HELPID);
    Link link = new Link(pageComponent, SWT.WRAP);
    link.setText(SSEUIMessages.SyntaxColoring_Link);
    link.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
        }
    });
    GridData linkData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1);
    // only expand further if anyone else requires it
    linkData.widthHint = 150;
    link.setLayoutData(linkData);
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
    SashForm editor = new SashForm(pageComponent, SWT.VERTICAL);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData2.horizontalSpan = 2;
    editor.setLayoutData(gridData2);
    SashForm top = new SashForm(editor, SWT.HORIZONTAL);
    Composite styleEditor = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginRight = 5;
    ((GridLayout) styleEditor.getLayout()).marginLeft = 0;
    createLabel(styleEditor, DTDUIMessages.SyntaxColoringPage_0);
    fStylesViewer = createStylesViewer(styleEditor);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalIndent = 0;
    Iterator iterator = fStyleToDescriptionMap.values().iterator();
    while (iterator.hasNext()) {
        gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length()));
    }
    gridData.heightHint = convertHeightInCharsToPixels(5);
    fStylesViewer.getControl().setLayoutData(gridData);
    Composite editingComposite = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginLeft = 5;
    // $NON-NLS-1$
    createLabel(editingComposite, "");
    Button enabler = createCheckbox(editingComposite, DTDUIMessages.SyntaxColoringPage_2);
    enabler.setEnabled(false);
    enabler.setSelection(true);
    Composite editControls = createComposite(editingComposite, 2);
    ((GridLayout) editControls.getLayout()).marginLeft = 20;
    fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_);
    ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fForegroundLabel.setEnabled(false);
    fForegroundColorEditor = new ColorSelector(editControls);
    Button fForegroundColor = fForegroundColorEditor.getButton();
    GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fForegroundColor.setLayoutData(gd);
    fForegroundColorEditor.setEnabled(false);
    fForegroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Foreground_Color_Selector_Button;
        }
    });
    fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_);
    ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fBackgroundLabel.setEnabled(false);
    fBackgroundColorEditor = new ColorSelector(editControls);
    Button fBackgroundColor = fBackgroundColorEditor.getButton();
    gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fBackgroundColor.setLayoutData(gd);
    fBackgroundColorEditor.setEnabled(false);
    fBackgroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(final AccessibleEvent e) {
            e.result = SSEUIMessages.Background_Color_Selector_Button;
        }
    });
    fBold = createCheckbox(editControls, DTDUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, DTDUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, DTDUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, DTDUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    // $NON-NLS-1$ = "Restore Default"
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_);
    fClearStyle.setLayoutData(new GridData(SWT.BEGINNING));
    ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20;
    fClearStyle.setEnabled(false);
    Composite sampleArea = createComposite(editor, 1);
    ((GridLayout) sampleArea.getLayout()).marginLeft = 5;
    ((GridLayout) sampleArea.getLayout()).marginTop = 5;
    // $NON-NLS-1$ = "&Sample text:"
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_);
    fPreviewViewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    fText = fPreviewViewer.getTextWidget();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = convertWidthInCharsToPixels(20);
    gridData3.heightHint = convertHeightInCharsToPixels(5);
    gridData3.horizontalSpan = 2;
    fText.setLayoutData(gridData3);
    fText.setEditable(false);
    // $NON-NLS-1$
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForDTD.ContentTypeID_DTD);
    fDocument.set(getExampleText());
    initializeSourcePreviewColors(fPreviewViewer);
    fPreviewViewer.setDocument(fDocument);
    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.DTD_PREFWEBX_STYLES_HELPID);
    fStylesViewer.setInput(getStylePreferenceKeys());
    applyStyles();
    fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                activate(namedStyle);
                if (namedStyle == null)
                    return;
            }
        }
    });
    fForegroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[0];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                    }
                }
            }
        }
    });
    fBackgroundColorEditor.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
                String namedStyle = o.toString();
                String prefString = getOverlayStore().getString(namedStyle);
                String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[1];
                    // open color dialog to get new color
                    String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue());
                    if (!newValue.equals(oldValue)) {
                        stylePrefs[1] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                        activate(namedStyle);
                    }
                }
            }
        }
    });
    fBold.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[2];
                String newValue = String.valueOf(fBold.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[2] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fItalic.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[3];
                String newValue = String.valueOf(fItalic.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[3] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fStrike.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[4];
                String newValue = String.valueOf(fStrike.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[4] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fUnderline.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
            String namedStyle = o.toString();
            String prefString = getOverlayStore().getString(namedStyle);
            String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[5];
                String newValue = String.valueOf(fUnderline.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[5] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    fText.redraw();
                }
            }
        }
    });
    fClearStyle.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (fStylesViewer.getSelection().isEmpty())
                return;
            String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString();
            getOverlayStore().setToDefault(namedStyle);
            applyStyles();
            fText.redraw();
            activate(namedStyle);
        }
    });
    return pageComponent;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SashForm(org.eclipse.swt.custom.SashForm) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) ColorSelector(org.eclipse.jface.preference.ColorSelector) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Link(org.eclipse.swt.widgets.Link)

Example 18 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project dbeaver by serge-rider.

the class PrefPageConnectionTypes method createContents.

@Override
protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createComposite(parent, 1);
    {
        typeTable = new Table(composite, SWT.SINGLE | SWT.BORDER);
        typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        UIUtils.createTableColumn(typeTable, SWT.LEFT, CoreMessages.pref_page_connection_types_label_table_column_name);
        UIUtils.createTableColumn(typeTable, SWT.LEFT, CoreMessages.pref_page_connection_types_label_table_column_description);
        typeTable.setHeaderVisible(true);
        typeTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        typeTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                showSelectedType(getSelectedType());
            }
        });
        ToolBar toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL);
        final ToolItem newButton = new ToolItem(toolbar, SWT.NONE);
        newButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_ADD));
        deleteButton = new ToolItem(toolbar, SWT.NONE);
        deleteButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_DELETE));
        newButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String name;
                for (int i = 1; ; i++) {
                    name = "Type" + i;
                    boolean hasName = false;
                    for (DBPConnectionType type : changedInfo.keySet()) {
                        if (type.getName().equals(name)) {
                            hasName = true;
                            break;
                        }
                    }
                    if (!hasName) {
                        break;
                    }
                }
                DBPConnectionType newType = new DBPConnectionType(name.toLowerCase(), name, "255,255,255", "New type", true, false, true);
                addTypeToTable(newType, newType);
                typeTable.select(typeTable.getItemCount() - 1);
                typeTable.showSelection();
                showSelectedType(newType);
            }
        });
        this.deleteButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBPConnectionType connectionType = getSelectedType();
                if (!UIUtils.confirmAction(getShell(), CoreMessages.pref_page_connection_types_label_delete_connection_type, NLS.bind(CoreMessages.pref_page_connection_types_label_delete_connection_type_description, connectionType.getName(), DBPConnectionType.DEFAULT_TYPE.getName()))) {
                    return;
                }
                changedInfo.remove(connectionType);
                int index = typeTable.getSelectionIndex();
                typeTable.remove(index);
                if (index > 0)
                    index--;
                typeTable.select(index);
                showSelectedType(getSelectedType());
            }
        });
    }
    {
        Group groupSettings = UIUtils.createControlGroup(composite, CoreMessages.pref_page_connection_types_group_settings, 2, GridData.VERTICAL_ALIGN_BEGINNING, 300);
        groupSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
        typeId = UIUtils.createLabelText(groupSettings, CoreMessages.pref_page_connection_types_label_id, null);
        typeId.addModifyListener(e -> {
            getSelectedType().setId(typeId.getText());
            updateTableInfo();
        });
        typeName = UIUtils.createLabelText(groupSettings, CoreMessages.pref_page_connection_types_label_name, null);
        typeName.addModifyListener(e -> {
            getSelectedType().setName(typeName.getText());
            updateTableInfo();
        });
        typeDescription = UIUtils.createLabelText(groupSettings, CoreMessages.pref_page_connection_types_label_description, null);
        typeDescription.addModifyListener(e -> {
            getSelectedType().setDescription(typeDescription.getText());
            updateTableInfo();
        });
        {
            UIUtils.createControlLabel(groupSettings, CoreMessages.pref_page_connection_types_label_color);
            // Composite colorGroup = UIUtils.createPlaceholder(groupSettings, 2, 5);
            // colorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            colorPicker = new ColorSelector(groupSettings);
            // colorPicker.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            colorPicker.addListener(event -> {
                getSelectedType().setColor(StringConverter.asString(colorPicker.getColorValue()));
                updateTableInfo();
            });
        /*
                Button pickerButton = new Button(colorGroup, SWT.PUSH);
                pickerButton.setText("...");
                pickerButton.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e)
                    {
                        DBPConnectionType connectionType = getSelectedType();
                        ColorDialog colorDialog = new ColorDialog(parent.getShell());
                        colorDialog.setRGB(StringConverter.asRGB(connectionType.getColor()));
                        RGB rgb = colorDialog.open();
                        if (rgb != null) {
                            Color color = null;
                            int count = colorPicker.getItemCount();
                            for (int i = 0; i < count; i++) {
                                Color item = colorPicker.getColorItem(i);
                                if (item != null && item.getRGB().equals(rgb)) {
                                    color = item;
                                    break;
                                }
                            }
                            if (color == null) {
                                color = new Color(colorPicker.getDisplay(), rgb);
                                colorPicker.addColor(color);
                            }
                            colorPicker.select(color);
                            getSelectedType().setColor(StringConverter.asString(color.getRGB()));
                            updateTableInfo();
                        }
                    }
                });
*/
        }
        autocommitCheck = UIUtils.createCheckbox(groupSettings, CoreMessages.pref_page_connection_types_label_auto_commit_by_default, null, false, 2);
        autocommitCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                getSelectedType().setAutocommit(autocommitCheck.getSelection());
            }
        });
        confirmCheck = UIUtils.createCheckbox(groupSettings, CoreMessages.pref_page_connection_types_label_confirm_sql_execution, null, false, 2);
        confirmCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                getSelectedType().setConfirmExecute(confirmCheck.getSelection());
            }
        });
        confirmDataChange = UIUtils.createCheckbox(groupSettings, CoreMessages.pref_page_connection_types_label_confirm_data_change, CoreMessages.pref_page_connection_types_label_confirm_data_change_tip, false, 2);
        confirmDataChange.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                getSelectedType().setConfirmDataChange(confirmDataChange.getSelection());
            }
        });
        Button epButton = UIUtils.createDialogButton(groupSettings, "Edit permissions ...", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                EditConnectionPermissionsDialog dialog = new EditConnectionPermissionsDialog(getShell(), getSelectedType().getModifyPermission());
                if (dialog.open() == IDialogConstants.OK_ID) {
                    getSelectedType().setModifyPermissions(dialog.getAccessRestrictions());
                }
            }
        });
        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
        gd.horizontalSpan = 2;
        epButton.setLayoutData(gd);
    }
    performDefaults();
    return composite;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ColorSelector(org.eclipse.jface.preference.ColorSelector) ControlEvent(org.eclipse.swt.events.ControlEvent) DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SecurityUtils(org.jkiss.utils.SecurityUtils) DataSourceProviderRegistry(org.jkiss.dbeaver.registry.DataSourceProviderRegistry) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IAdaptable(org.eclipse.core.runtime.IAdaptable) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) NLS(org.eclipse.osgi.util.NLS) IWorkbenchPropertyPage(org.eclipse.ui.IWorkbenchPropertyPage) org.eclipse.swt.widgets(org.eclipse.swt.widgets) IWorkbenchPreferencePage(org.eclipse.ui.IWorkbenchPreferencePage) CoreMessages(org.jkiss.dbeaver.core.CoreMessages) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) List(java.util.List) Color(org.eclipse.swt.graphics.Color) EditConnectionPermissionsDialog(org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionPermissionsDialog) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SWT(org.eclipse.swt.SWT) StringConverter(org.eclipse.jface.resource.StringConverter) IWorkbench(org.eclipse.ui.IWorkbench) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPConnectionType(org.jkiss.dbeaver.model.connection.DBPConnectionType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) EditConnectionPermissionsDialog(org.jkiss.dbeaver.ui.dialogs.connection.EditConnectionPermissionsDialog)

Example 19 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project cubrid-manager by CUBRID.

the class ChartSettingDlg method createSeriesItem.

/**
	 * Create Series tab item
	 * 
	 */
private void createSeriesItem() {
    seriesItem.setText(Messages.tabItemSeriesTtl);
    Composite tabComp = new Composite(folder, SWT.NONE);
    tabComp.setLayout(new GridLayout());
    tabComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    seriesItem.setControl(tabComp);
    Group group = new Group(tabComp, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_BOTH));
    final List seriesSelectionList = new List(group, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    group.setText(Messages.seriesGroupTxt);
    GridData gd = new GridData(GridData.FILL_BOTH);
    GC gc = new GC(folder.getParent());
    gc.setFont(folder.getParent().getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 15);
    seriesSelectionList.setLayoutData(gd);
    for (Map.Entry<String, ShowSetting> entry : settingMap.entrySet()) {
        String key = entry.getKey();
        seriesSelectionList.add(key);
    }
    Composite optionsComp = new Composite(group, SWT.NONE);
    optionsComp.setLayout(new GridLayout());
    optionsComp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    Composite checkComposite = new Composite(optionsComp, SWT.NONE);
    checkComposite.setLayout(new GridLayout());
    checkComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    Composite colorComposite = new Composite(optionsComp, SWT.NONE);
    GridLayout colorlayout = new GridLayout(2, false);
    colorComposite.setLayout(colorlayout);
    colorComposite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false));
    final Button checkBtn = new Button(checkComposite, SWT.CHECK);
    checkBtn.setText(Messages.seriesCheckBtnLbl);
    checkBtn.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
    Label colorlbl = new Label(colorComposite, SWT.LEFT);
    colorlbl.setText(Messages.seriesColorLbl);
    colorlbl.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false));
    final ColorSelector seriesColorEditor = new ColorSelector(colorComposite);
    Button foregroundColorButton = seriesColorEditor.getButton();
    foregroundColorButton.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
    Composite widthComposite = new Composite(optionsComp, SWT.NONE);
    widthComposite.setLayout(new GridLayout());
    widthComposite.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false));
    final Label widthLbl = new Label(widthComposite, SWT.LEFT);
    widthScale = new Scale(widthComposite, SWT.HORIZONTAL);
    widthScale.setMinimum(1);
    widthScale.setMaximum(5);
    widthScale.setIncrement(1);
    widthScale.setPageIncrement(1);
    widthScale.setSelection(2);
    float width = ((float) widthScale.getSelection()) / 2;
    widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, width));
    seriesSelectionList.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent ex) {
            widgetSelected(ex);
        }

        public void widgetSelected(SelectionEvent ex) {
            int i = seriesSelectionList.getSelectionIndex();
            if (i == -1) {
                return;
            }
            if (seriesSelectionList.getSelectionCount() == 1) {
                String[] selection = seriesSelectionList.getSelection();
                for (Map.Entry<String, ShowSetting> entry : settingMap.entrySet()) {
                    String key = entry.getKey();
                    ShowSetting showSetting = entry.getValue();
                    if (key.equals(selection[0])) {
                        checkBtn.setSelection(showSetting.isChecked());
                        seriesColorEditor.setColorValue(showSetting.getSeriesRgb());
                        int widthInScale = (int) showSetting.getWidth() * 2;
                        widthScale.setSelection(widthInScale);
                        break;
                    }
                }
            } else {
                checkBtn.setSelection(false);
                Color colorBtnBg = seriesColorEditor.getButton().getBackground();
                seriesColorEditor.setColorValue(new RGB(colorBtnBg.getRed(), colorBtnBg.getGreen(), colorBtnBg.getBlue()));
                // default value
                widthScale.setSelection(2);
            }
            float width = ((float) widthScale.getSelection()) / 2;
            widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, width));
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent ex) {
            widgetSelected(ex);
        }

        public void widgetSelected(SelectionEvent ex) {
            int i = seriesSelectionList.getSelectionIndex();
            if (i == -1) {
                return;
            }
            RGB rgb = seriesColorEditor.getColorValue();
            float width = ((float) widthScale.getSelection()) / 2;
            boolean isChecked = checkBtn.getSelection();
            String[] selection = seriesSelectionList.getSelection();
            updateValueInSettingMap(rgb, width, isChecked, selection);
        }
    });
    checkBtn.addSelectionListener(new SelectionAdapter() {

        /**
			 * Sent when selection occurs in the control.
			 * 
			 * @param event an event containing information about the selection
			 */
        public void widgetSelected(SelectionEvent event) {
            widgetDefaultSelected(event);
        }

        /**
			 * Sent when default selection occurs in the control.
			 * 
			 * @param event an event containing information about the default
			 *        selection
			 */
        public void widgetDefaultSelected(SelectionEvent event) {
            int i = seriesSelectionList.getSelectionIndex();
            if (i == -1) {
                return;
            }
            RGB rgb = seriesColorEditor.getColorValue();
            float width = ((float) widthScale.getSelection()) / 2;
            boolean isChecked = checkBtn.getSelection();
            String[] selection = seriesSelectionList.getSelection();
            updateValueInSettingMap(rgb, width, isChecked, selection);
        }
    });
    widthScale.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            int i = seriesSelectionList.getSelectionIndex();
            if (i == -1) {
                return;
            }
            float width = ((float) widthScale.getSelection()) / 2;
            widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, width));
            RGB rgb = seriesColorEditor.getColorValue();
            boolean isChecked = checkBtn.getSelection();
            String[] selection = seriesSelectionList.getSelection();
            updateValueInSettingMap(rgb, width, isChecked, selection);
        }
    });
    if (seriesSelectionList.getItemCount() > 0) {
        seriesSelectionList.select(0);
        String[] selectedKey = seriesSelectionList.getSelection();
        ShowSetting setting = settingMap.get(selectedKey[0]);
        checkBtn.setSelection(setting.isChecked());
        seriesColorEditor.setColorValue(setting.getSeriesRgb());
        widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, setting.getWidth()));
        int widthInScale = (int) setting.getWidth() * 2;
        widthScale.setSelection(widthInScale);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) FontMetrics(org.eclipse.swt.graphics.FontMetrics) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) GC(org.eclipse.swt.graphics.GC) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Scale(org.eclipse.swt.widgets.Scale) RGB(org.eclipse.swt.graphics.RGB) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) Map(java.util.Map) TreeMap(java.util.TreeMap) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 20 with ColorSelector

use of org.eclipse.jface.preference.ColorSelector in project cubrid-manager by CUBRID.

the class ChartSettingDlg method createPlotItem.

/**
	 * Create plot appearance tab item
	 * 
	 */
public void createPlotItem() {
    CTabItem ttlItem = new CTabItem(folder, SWT.NONE);
    ttlItem.setText(Messages.tabItemPlotTtl);
    Composite tabComp = new Composite(folder, SWT.NONE);
    tabComp.setLayout(new GridLayout());
    tabComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    ttlItem.setControl(tabComp);
    Group group = new Group(tabComp, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_BOTH));
    group.setText(Messages.plotAppearanceGroupTxt);
    appearanceColorList = new List(group, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    GC gc = new GC(folder.getParent());
    gc.setFont(folder.getParent().getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 15);
    appearanceColorList.setLayoutData(gd);
    for (int i = 0; i < appearanceColorListModel.length; i++) {
        appearanceColorList.add(appearanceColorListModel[i][0]);
    }
    Composite stylesComposite = new Composite(group, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    Label colorlbl = new Label(stylesComposite, SWT.LEFT);
    colorlbl.setText(Messages.plotColorLbl);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    colorlbl.setLayoutData(gd);
    appearanceColorEditor = new ColorSelector(stylesComposite);
    Button foregroundColorButton = appearanceColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);
    appearanceColorList.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent ex) {
            widgetSelected(ex);
        }

        public void widgetSelected(SelectionEvent ex) {
            int i = appearanceColorList.getSelectionIndex();
            if (i == -1) {
                return;
            }
            RGB rgb = StringConverter.asRGB(appearanceColorListModel[i][1]);
            appearanceColorEditor.setColorValue(rgb);
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent ex) {
            widgetSelected(ex);
        }

        public void widgetSelected(SelectionEvent ex) {
            int i = appearanceColorList.getSelectionIndex();
            if (i == -1) {
                return;
            }
            RGB rgb = appearanceColorEditor.getColorValue();
            appearanceColorListModel[i][1] = StringConverter.asString(rgb);
        }
    });
    appearanceColorListModel[0][1] = plotBgColor;
    appearanceColorListModel[1][1] = plotDomainGridColor;
    appearanceColorListModel[2][1] = plotRangGridColor;
    if (appearanceColorListModel.length > 3) {
        appearanceColorListModel[3][1] = plotDateAxisColor;
    }
    if (appearanceColorListModel.length > 4) {
        appearanceColorListModel[4][1] = plotNumberAxisColor;
    }
    if (appearanceColorList.getItemCount() > 0) {
        appearanceColorList.select(0);
        RGB rgb = StringConverter.asRGB(appearanceColorListModel[0][1]);
        appearanceColorEditor.setColorValue(rgb);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) RGB(org.eclipse.swt.graphics.RGB) CTabItem(org.eclipse.swt.custom.CTabItem) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) FontMetrics(org.eclipse.swt.graphics.FontMetrics) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) GC(org.eclipse.swt.graphics.GC) ColorSelector(org.eclipse.jface.preference.ColorSelector) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ColorSelector (org.eclipse.jface.preference.ColorSelector)39 GridData (org.eclipse.swt.layout.GridData)37 Composite (org.eclipse.swt.widgets.Composite)31 GridLayout (org.eclipse.swt.layout.GridLayout)27 Label (org.eclipse.swt.widgets.Label)27 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 Button (org.eclipse.swt.widgets.Button)20 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)14 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)14 SelectionListener (org.eclipse.swt.events.SelectionListener)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12 Group (org.eclipse.swt.widgets.Group)11 Link (org.eclipse.swt.widgets.Link)10 SashForm (org.eclipse.swt.custom.SashForm)9 RGB (org.eclipse.swt.graphics.RGB)8 Iterator (java.util.Iterator)7 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7