Search in sources :

Example 1 with ISemanticHighlightingExtension2

use of org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2 in project webtools.sourceediting by eclipse.

the class SemanticHighlightingManager method handleHighlightingPropertyChange.

/**
 * Handles property change events for individual semantic highlightings.
 * @param event
 */
private void handleHighlightingPropertyChange(PropertyChangeEvent event) {
    String property = event.getProperty();
    if (property == null)
        return;
    boolean refreshRequired = false;
    for (int i = 0; i < fHighlightings.length; i++) {
        ISemanticHighlighting highlighting = fHighlightings[i];
        if (fHighlightingStyleStringKeys[i] != null) {
            if (property.equals(fHighlightingStyleStringKeys[i])) {
                adaptToStyleChange(fHighlightingStyles[i], event);
                fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
                refreshRequired = true;
                continue;
            }
        }
        if (property.equals(highlighting.getBoldPreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, SWT.BOLD);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getColorPreferenceKey())) {
            adaptToTextForegroundChange(fHighlightingStyles[i], event);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getEnabledPreferenceKey())) {
            adaptToEnablementChange(fHighlightingStyles[i], event);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getItalicPreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, SWT.ITALIC);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getStrikethroughPreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, TextAttribute.STRIKETHROUGH);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getUnderlinePreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, TextAttribute.UNDERLINE);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (highlighting instanceof ISemanticHighlightingExtension2 && property.equals(((ISemanticHighlightingExtension2) highlighting).getBackgroundColorPreferenceKey())) {
            adaptToTextBackgroundChange(fHighlightingStyles[i], event);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
    }
    if (refreshRequired && fReconciler != null)
        fReconciler.refresh();
}
Also used : ISemanticHighlightingExtension2(org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2) ISemanticHighlighting(org.eclipse.wst.sse.ui.ISemanticHighlighting)

Example 2 with ISemanticHighlightingExtension2

use of org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2 in project webtools.sourceediting by eclipse.

the class SemanticHighlightingManager method createHighlightingStyle.

/**
 * Creates a highlighting style based on the preferences defined in the semantic highlighting
 * @param highlighting the semantic highlighting
 * @return a highlighting style based on the preferences of the semantic highlighting
 */
private HighlightingStyle createHighlightingStyle(ISemanticHighlighting highlighting, String styleKey) {
    IPreferenceStore store = highlighting.getPreferenceStore();
    HighlightingStyle highlightingStyle = null;
    if (store != null) {
        TextAttribute attribute = null;
        // A style string is used instead of separate attribute keys
        if (styleKey != null) {
            attribute = createTextAttribute(store.getString(styleKey));
        } else {
            int style = getBoolean(store, highlighting.getBoldPreferenceKey()) ? SWT.BOLD : SWT.NORMAL;
            if (getBoolean(store, highlighting.getItalicPreferenceKey()))
                style |= SWT.ITALIC;
            if (getBoolean(store, highlighting.getStrikethroughPreferenceKey()))
                style |= TextAttribute.STRIKETHROUGH;
            if (getBoolean(store, highlighting.getUnderlinePreferenceKey()))
                style |= TextAttribute.UNDERLINE;
            String rgbString = getString(store, highlighting.getColorPreferenceKey());
            Color color = null;
            Color bgColor = null;
            if (rgbString != null)
                color = EditorUtility.getColor(ColorHelper.toRGB(rgbString));
            if (highlighting instanceof ISemanticHighlightingExtension2) {
                rgbString = getString(store, ((ISemanticHighlightingExtension2) highlighting).getBackgroundColorPreferenceKey());
                if (rgbString != null) {
                    bgColor = EditorUtility.getColor(ColorHelper.toRGB(rgbString));
                }
            }
            attribute = new TextAttribute(color, bgColor, style);
        }
        store.addPropertyChangeListener(fHighlightingChangeListener);
        boolean isEnabled = getBoolean(store, highlighting.getEnabledPreferenceKey());
        highlightingStyle = new HighlightingStyle(attribute, isEnabled);
    }
    return highlightingStyle;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) ISemanticHighlightingExtension2(org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ISemanticHighlightingExtension2 (org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 TextAttribute (org.eclipse.jface.text.TextAttribute)1 Color (org.eclipse.swt.graphics.Color)1 ISemanticHighlighting (org.eclipse.wst.sse.ui.ISemanticHighlighting)1