Example usage for org.eclipse.jface.resource JFaceResources getFont

List of usage examples for org.eclipse.jface.resource JFaceResources getFont

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getFont.

Prototype

public static Font getFont(String symbolicName) 

Source Link

Document

Returns the font in JFace's font registry with the given symbolic font name.

Usage

From source file:org.eclipse.wst.jsdt.internal.ui.text.java.hover.SourceViewerInformationControl.java

License:Open Source License

/**
 * Initialize the font to the Java editor font.
 * /*from   w w w  .ja  va  2 s  . c om*/
 * 
 */
private void initializeFont() {
    Font font = JFaceResources.getFont("org.eclipse.wst.jsdt.ui.editors.textfont"); //$NON-NLS-1$
    StyledText styledText = getViewer().getTextWidget();
    styledText.setFont(font);
}

From source file:org.eclipse.wst.json.ui.internal.preferences.JSONSyntaxColoringPage.java

License:Open Source License

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);//  w w w  .  j  a  va 2s. c o  m

    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);
    linkData.widthHint = 150; // only expand further if anyone else requires
    // 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;
    createLabel(editingComposite, ""); //$NON-NLS-1$
    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);
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default"
    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;
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:"
    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);
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    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;
}

From source file:org.eclipse.wst.json.ui.internal.preferences.JSONTemplatePreferencePage.java

License:Open Source License

SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
    SourceViewer viewer = null;/*  w  w  w.  jav  a  2 s.c  om*/
    String contentTypeID = ContentTypeIdForJSON.ContentTypeID_JSON;
    viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    IStructuredModel scratchModel = StructuredModelManager.getModelManager()
            .createUnManagedStructuredModelFor(contentTypeID);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(viewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}

From source file:org.eclipse.wst.xml.search.editor.internal.preferences.XMLReferencesSyntaxColoringPage.java

License:Open Source License

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);/*  www. j  a  v  a  2s .  co  m*/

    fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    final Composite pageComponent = createComposite(parent, 2);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent,
            IHelpContextIds.XML_PREFWEBX_STYLES_HELPID);

    fColorReferencedEnabled = createCheckbox(pageComponent, Messages.XMLReferencesSyntaxColoringPage_0);
    fColorReferencedEnabled.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateEnabled();
        }
    });
    fColorReferencedEnabled.setSelection(getOverlayStore().getBoolean(ENABLED_COLOR));

    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);
    linkData.widthHint = 150; // only expand further if anyone else requires
    // 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, XMLUIMessages.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;
    createLabel(editingComposite, ""); //$NON-NLS-1$
    Button enabler = createCheckbox(editingComposite, XMLUIMessages.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);

    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);

    fBold = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default"
    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;
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:"
    SourceViewer viewer = new SourceViewer(sampleArea, null,
            SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    fText = viewer.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);
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager()
            .createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML);
    fDocument.set(getExampleText());
    model = (IDOMModel) StructuredModelManager.getModelManager()
            .createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    model.setStructuredDocument(fDocument);
    viewer.setDocument(fDocument);
    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent,
            IHelpContextIds.XML_PREFWEBX_STYLES_HELPID);

    fStylesViewer.setInput(getStylePreferenceKeys());

    applyStyles();
    updateEnabled();

    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;
}

From source file:org.eclipse.wst.xml.ui.internal.preferences.XMLSyntaxColoringPage.java

License:Open Source License

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);// w ww  . jav  a2s  .c  om

    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.XML_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);
    linkData.widthHint = 150; // only expand further if anyone else requires 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, XMLUIMessages.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;
    createLabel(editingComposite, ""); //$NON-NLS-1$
    Button enabler = createCheckbox(editingComposite, XMLUIMessages.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, XMLUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default"
    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;
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:"
    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);
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager()
            .createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML);
    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.XML_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;
}

From source file:org.eclipse.wst.xml.ui.internal.preferences.XMLTemplatePreferencePage.java

License:Open Source License

SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
    SourceViewer viewer = null;//from w w  w .ja v a 2 s . c  o  m
    String contentTypeID = ContentTypeIdForXML.ContentTypeID_XML;
    viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    IStructuredModel scratchModel = StructuredModelManager.getModelManager()
            .createUnManagedStructuredModelFor(contentTypeID);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(viewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}

From source file:org.eclipse.wst.xml.ui.internal.wizards.NewXMLTemplatesWizardPage.java

License:Open Source License

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 * // w ww .j a va2 s  .  c  om
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {
        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML();

        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    IStructuredModel scratchModel = StructuredModelManager.getModelManager()
            .createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}

From source file:org.eclipse.wst.xquery.sse.ui.internal.preferences.XQDTSyntaxColoringPage.java

License:Open Source License

protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);//  ww  w  .ja va 2s.c  om

    fDefaultColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    Composite pageComponent = createComposite(parent, 2);
    // PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_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);
    linkData.widthHint = 150; // only expand further if anyone else requires it
    link.setLayoutData(linkData);

    Composite schemeComp = createComposite(pageComponent, 2);
    GridLayout compLayout = (GridLayout) schemeComp.getLayout();
    compLayout.marginBottom = compLayout.marginTop = 5;

    Label schemeLabel = createLabel(schemeComp, XQDTUIMessages.SyntaxColoringPage_SchemesLabel);
    ((GridData) schemeLabel.getLayoutData()).verticalAlignment = SWT.CENTER;

    fSchemeCombo = new Combo(schemeComp, SWT.SIMPLE | SWT.READ_ONLY | SWT.DROP_DOWN);
    GridData comboData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    fSchemeCombo.setLayoutData(comboData);
    String[] schemes = getColorSchemes();
    if (schemes.length == 0) {
        fSchemeCombo.setEnabled(false);
        schemes = new String[] { XQDTUIMessages.SyntaxColoringPage_NoSchemeItem };
    }
    fSchemeCombo.setItems(schemes);
    fSchemeCombo.setText("Choose one color scheme...");
    fSchemeCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            fStylesViewer.setSelection(StructuredSelection.EMPTY);
            activate(null);

            String schemeName = fSchemeCombo.getItem(fSchemeCombo.getSelectionIndex());
            Map<String, String> schemeStyles = XQDTColorSchemeRegistry.getColorSchemes().get(schemeName);

            List<String> stylesToChange = new ArrayList<String>(fStylePreferenceKeys);
            for (String key : schemeStyles.keySet()) {
                String style = schemeStyles.get(key);
                getOverlayStore().setValue(key, style);
                stylesToChange.remove(key);
            }
            for (String key : stylesToChange) {
                getOverlayStore().setValue(key, XQDTEditorUIPreferenceInitializer.DEFAULT_TEXT_STYLE);
            }

            applyStyles();
            fText.redraw();
        }
    });

    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, XQDTUIMessages.SyntaxColoringPage_0);
    fStylesViewer = createStylesViewer(styleEditor);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalIndent = 0;
    Iterator<String> 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;
    createLabel(editingComposite, ""); //$NON-NLS-1$
    Button enabler = createCheckbox(editingComposite, XQDTUIMessages.SyntaxColoringPage_2);
    enabler.setEnabled(false);
    enabler.setSelection(true);
    Composite editControls = createComposite(editingComposite, 2);
    ((GridLayout) editControls.getLayout()).marginLeft = 20;

    fColorLabel = createLabel(editControls, XQDTUIMessages.SyntaxColoringPage_1);
    ((GridData) fColorLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    fColorLabel.setEnabled(false);

    fColorSelector = new ColorSelector(editControls);
    Button fForegroundColor = fColorSelector.getButton();
    GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fForegroundColor.setLayoutData(gd);
    fColorSelector.setEnabled(false);

    fBold = createCheckbox(editControls, XQDTUIMessages.SyntaxColoringPage_3);
    fBold.setEnabled(false);
    ((GridData) fBold.getLayoutData()).horizontalSpan = 2;
    fItalic = createCheckbox(editControls, XQDTUIMessages.SyntaxColoringPage_4);
    fItalic.setEnabled(false);
    ((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
    fStrike = createCheckbox(editControls, XQDTUIMessages.SyntaxColoringPage_5);
    fStrike.setEnabled(false);
    ((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
    fUnderline = createCheckbox(editControls, XQDTUIMessages.SyntaxColoringPage_6);
    fUnderline.setEnabled(false);
    ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
    fClearStyle = new Button(editingComposite, SWT.PUSH);
    fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default"
    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;
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:"
    SourceViewer viewer = new SourceViewer(sampleArea, null,
            SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    fText = viewer.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);
    fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    fText.addKeyListener(getTextKeyListener());
    fText.addSelectionListener(getTextSelectionListener());
    fText.addMouseListener(getTextMouseListener());
    fText.addTraverseListener(getTraverseListener());
    setAccessible(fText, SSEUIMessages.Sample_text__UI_);
    fDocument = StructuredModelManager.getModelManager()
            .createStructuredDocumentFor(IXQDTSSECoreConstants.XQUERY_CONTENT_TYPE_ID);
    fDocument.set(getExampleText());
    viewer.setDocument(fDocument);

    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    // PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_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;
                }
            }
        }
    });

    fColorSelector.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 = XQDTColorHelper.unpackStylePreferences(prefString);
                if (stylePrefs != null) {
                    String oldValue = stylePrefs[0];
                    // open color dialog to get new color
                    String newValue = XQDTColorHelper.toRGBString(fColorSelector.getColorValue());

                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = XQDTColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        fText.redraw();
                    }
                }
            }
        }
    });

    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 = XQDTColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[2];
                String newValue = String.valueOf(fBold.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[2] = newValue;
                    String newPrefString = XQDTColorHelper.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 = XQDTColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[3];
                String newValue = String.valueOf(fItalic.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[3] = newValue;
                    String newPrefString = XQDTColorHelper.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 = XQDTColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[4];
                String newValue = String.valueOf(fStrike.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[4] = newValue;
                    String newPrefString = XQDTColorHelper.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 = XQDTColorHelper.unpackStylePreferences(prefString);
            if (stylePrefs != null) {
                String oldValue = stylePrefs[5];
                String newValue = String.valueOf(fUnderline.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[5] = newValue;
                    String newPrefString = XQDTColorHelper.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;
}

From source file:org.eclipse.wst.xsl.jaxp.debug.ui.internal.views.ResultView.java

License:Open Source License

private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {
        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXSL();

        @Override/*from   ww w.j a  v a  2 s .  c o  m*/
        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        @Override
        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    ((StructuredTextViewer) viewer).getTextWidget()
            .setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    viewer.configure(sourceViewerConfiguration);
    viewer.setEditable(false);
    return viewer;
}

From source file:org.eclipse.wst.xsl.ui.internal.preferences.XSLSyntaxColoringPage.java

License:Open Source License

@Override
protected Control createContents(final Composite parent) {
    initializeDialogUnits(parent);/*from w  w  w .  j av a  2s  . com*/

    defaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    defaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Composite pageComponent = createComposite(parent, 2);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent,
            IHelpContextIds.XML_PREFWEBX_STYLES_HELPID);

    Link link = new Link(pageComponent, SWT.WRAP);
    link.setText(Messages.XSLSyntaxColoringPage);
    link.addSelectionListener(new SelectionAdapter() {
        @Override
        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);
    linkData.widthHint = 150; // only expand further if anyone else requires
    // 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, XMLUIMessages.SyntaxColoringPage_0);
    stylesViewer = createStylesViewer(styleEditor);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalIndent = 0;
    Iterator iterator = styleToDescriptionMap.values().iterator();
    while (iterator.hasNext()) {
        gridData.widthHint = Math.max(gridData.widthHint,
                convertWidthInCharsToPixels(iterator.next().toString().length()));
    }
    gridData.heightHint = convertHeightInCharsToPixels(5);
    stylesViewer.getControl().setLayoutData(gridData);

    Composite editingComposite = createComposite(top, 1);
    ((GridLayout) styleEditor.getLayout()).marginLeft = 5;
    createLabel(editingComposite, ""); //$NON-NLS-1$
    Button enabler = createCheckbox(editingComposite, XMLUIMessages.SyntaxColoringPage_2);
    enabler.setEnabled(false);
    enabler.setSelection(true);
    Composite editControls = createComposite(editingComposite, 2);
    ((GridLayout) editControls.getLayout()).marginLeft = 20;

    foregroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_);
    ((GridData) foregroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    foregroundLabel.setEnabled(false);

    foregroundColorEditor = new ColorSelector(editControls);
    Button fForegroundColor = foregroundColorEditor.getButton();
    GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fForegroundColor.setLayoutData(gd);
    foregroundColorEditor.setEnabled(false);

    backgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_);
    ((GridData) backgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
    backgroundLabel.setEnabled(false);

    backgroundColorEditor = new ColorSelector(editControls);
    Button fBackgroundColor = backgroundColorEditor.getButton();
    gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    fBackgroundColor.setLayoutData(gd);
    backgroundColorEditor.setEnabled(false);

    bold = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_3);
    bold.setEnabled(false);
    ((GridData) bold.getLayoutData()).horizontalSpan = 2;
    italic = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_4);
    italic.setEnabled(false);
    ((GridData) italic.getLayoutData()).horizontalSpan = 2;
    strike = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_5);
    strike.setEnabled(false);
    ((GridData) strike.getLayoutData()).horizontalSpan = 2;
    underline = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_6);
    underline.setEnabled(false);
    ((GridData) underline.getLayoutData()).horizontalSpan = 2;
    clearStyle = new Button(editingComposite, SWT.PUSH);
    clearStyle.setText(SSEUIMessages.Restore_Default_UI_); // = "Restore Default"
    clearStyle.setLayoutData(new GridData(SWT.BEGINNING));
    ((GridData) clearStyle.getLayoutData()).horizontalIndent = 20;
    clearStyle.setEnabled(false);

    Composite sampleArea = createComposite(editor, 1);

    ((GridLayout) sampleArea.getLayout()).marginLeft = 5;
    ((GridLayout) sampleArea.getLayout()).marginTop = 5;
    createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); // = "&Sample text:"
    SourceViewer viewer = new SourceViewer(sampleArea, null,
            SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
    styledText = viewer.getTextWidget();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = convertWidthInCharsToPixels(20);
    gridData3.heightHint = convertHeightInCharsToPixels(5);
    gridData3.horizontalSpan = 2;
    styledText.setLayoutData(gridData3);
    styledText.setEditable(false);
    styledText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    styledText.addKeyListener(getTextKeyListener());
    styledText.addSelectionListener(getTextSelectionListener());
    styledText.addMouseListener(getTextMouseListener());
    styledText.addTraverseListener(getTraverseListener());
    setAccessible(styledText, SSEUIMessages.Sample_text__UI_);

    try {
        File file = XSLUIPlugin.makeFileFor(XSLSyntaxColoringPage.XSLFILES_DIR,
                XSLSyntaxColoringPage.SYNTAXCOLORING_XSL);
        document = StructuredModelManager.getModelManager().createStructuredDocumentFor(file.getAbsolutePath(),
                new FileInputStream(file), null);
    } catch (Exception ex) {
        XSLUIPlugin.log(ex);
    }

    viewer.setDocument(document);

    top.setWeights(new int[] { 1, 1 });
    editor.setWeights(new int[] { 1, 1 });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent,
            IHelpContextIds.XML_PREFWEBX_STYLES_HELPID);

    stylesViewer.setInput(getStylePreferenceKeys());

    applyStyles();

    stylesViewer.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;
            }
        }
    });

    foregroundColorEditor.addListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) stylesViewer.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(foregroundColorEditor.getColorValue());

                    if (!newValue.equals(oldValue)) {
                        stylePrefs[0] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        styledText.redraw();
                    }
                }
            }
        }
    });

    backgroundColorEditor.addListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
                Object o = ((IStructuredSelection) stylesViewer.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(backgroundColorEditor.getColorValue());

                    if (!newValue.equals(oldValue)) {
                        stylePrefs[1] = newValue;
                        String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                        getOverlayStore().setValue(namedStyle, newPrefString);
                        applyStyles();
                        styledText.redraw();
                        activate(namedStyle);
                    }
                }
            }
        }
    });

    bold.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) stylesViewer.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(bold.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[2] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    styledText.redraw();
                }
            }
        }
    });

    italic.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) stylesViewer.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(italic.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[3] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    styledText.redraw();
                }
            }
        }
    });

    strike.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) stylesViewer.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(strike.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[4] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    styledText.redraw();
                }
            }
        }
    });

    underline.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            // get current (newly old) style
            Object o = ((IStructuredSelection) stylesViewer.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(underline.getSelection());
                if (!newValue.equals(oldValue)) {
                    stylePrefs[5] = newValue;
                    String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
                    getOverlayStore().setValue(namedStyle, newPrefString);
                    applyStyles();
                    styledText.redraw();
                }
            }
        }
    });

    clearStyle.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (stylesViewer.getSelection().isEmpty())
                return;
            String namedStyle = ((IStructuredSelection) stylesViewer.getSelection()).getFirstElement()
                    .toString();
            getOverlayStore().setToDefault(namedStyle);
            applyStyles();
            styledText.redraw();
            activate(namedStyle);
        }
    });

    return pageComponent;
}