[195135] [ui] background color in syntax highlighting preview
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPSyntaxColoringPage.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPSyntaxColoringPage.java
index 0cfacfd..8ea7515 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPSyntaxColoringPage.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPSyntaxColoringPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,9 +20,9 @@
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -81,6 +81,7 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey;
+import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage;
import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper;
import org.eclipse.wst.sse.ui.internal.util.EditorUtility;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
@@ -94,7 +95,7 @@
* and CDT pages far more than our original color page while retaining the
* extra "click-to-find" functionality.
*/
-public final class JSPSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage {
+public final class JSPSyntaxColoringPage extends AbstractSyntaxColoringPage implements IWorkbenchPreferencePage {
private Button fBold;
private Label fForegroundLabel;
@@ -114,6 +115,7 @@
private Map fStyleToDescriptionMap;
private StyledText fText;
private Button fUnderline;
+ private ISourceViewer fPreviewViewer;
// activate controls based on the given local color type
@@ -321,8 +323,8 @@
((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();
+ 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);
@@ -337,7 +339,8 @@
setAccessible(fText, SSEUIMessages.Sample_text__UI_);
fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForJSP.ContentTypeID_JSP);
fDocument.set(getExampleText());
- viewer.setDocument(fDocument);
+ initializeSourcePreviewColors(fPreviewViewer);
+ fPreviewViewer.setDocument(fDocument);
top.setWeights(new int[]{1, 1});
editor.setWeights(new int[]{1, 1});
@@ -511,6 +514,13 @@
return pageComponent;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage#getSourcePreviewViewer()
+ */
+ protected ISourceViewer getSourcePreviewViewer() {
+ return fPreviewViewer;
+ }
+
private Label createLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.WRAP);
label.setText(text);
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/preferences/ui/CSSSyntaxColoringPage.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/preferences/ui/CSSSyntaxColoringPage.java
index f6d4d0a..3afc688 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/preferences/ui/CSSSyntaxColoringPage.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/preferences/ui/CSSSyntaxColoringPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,9 +20,9 @@
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -80,6 +80,7 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey;
+import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage;
import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper;
import org.eclipse.wst.sse.ui.internal.util.EditorUtility;
@@ -90,7 +91,7 @@
* and CDT pages far more than our original color page while retaining the
* extra "click-to-find" functionality.
*/
-public final class CSSSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage {
+public final class CSSSyntaxColoringPage extends AbstractSyntaxColoringPage implements IWorkbenchPreferencePage {
private Button fBold;
private Label fForegroundLabel;
@@ -110,6 +111,7 @@
private Map fStyleToDescriptionMap;
private StyledText fText;
private Button fUnderline;
+ private ISourceViewer fPreviewViewer;
// activate controls based on the given local color type
private void activate(String namedStyle) {
@@ -315,8 +317,8 @@
((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();
+ 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);
@@ -331,7 +333,8 @@
setAccessible(fText, SSEUIMessages.Sample_text__UI_);
fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForCSS.ContentTypeID_CSS);
fDocument.set(getExampleText());
- viewer.setDocument(fDocument);
+ initializeSourcePreviewColors(fPreviewViewer);
+ fPreviewViewer.setDocument(fDocument);
top.setWeights(new int[]{1, 1});
editor.setWeights(new int[]{1, 1});
@@ -505,6 +508,13 @@
return pageComponent;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage#getSourcePreviewViewer()
+ */
+ protected ISourceViewer getSourcePreviewViewer() {
+ return fPreviewViewer;
+ }
+
private Label createLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.WRAP);
label.setText(text);
diff --git a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/preferences/DTDSyntaxColoringPage.java b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/preferences/DTDSyntaxColoringPage.java
index 80d9f10..6af8698 100644
--- a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/preferences/DTDSyntaxColoringPage.java
+++ b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/preferences/DTDSyntaxColoringPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,9 +20,9 @@
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -80,6 +80,7 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey;
+import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage;
import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper;
import org.eclipse.wst.sse.ui.internal.util.EditorUtility;
@@ -90,7 +91,7 @@
* and CDT pages far more than our original color page while retaining the
* extra "click-to-find" functionality.
*/
-public final class DTDSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage {
+public final class DTDSyntaxColoringPage extends AbstractSyntaxColoringPage implements IWorkbenchPreferencePage {
private Button fBold;
private Label fForegroundLabel;
@@ -110,6 +111,7 @@
private Map fStyleToDescriptionMap;
private StyledText fText;
private Button fUnderline;
+ private ISourceViewer fPreviewViewer;
// activate controls based on the given local color type
private void activate(String namedStyle) {
@@ -317,8 +319,8 @@
((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();
+ 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);
@@ -333,7 +335,8 @@
setAccessible(fText, SSEUIMessages.Sample_text__UI_);
fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForDTD.ContentTypeID_DTD);
fDocument.set(getExampleText());
- viewer.setDocument(fDocument);
+ initializeSourcePreviewColors(fPreviewViewer);
+ fPreviewViewer.setDocument(fDocument);
top.setWeights(new int[]{1, 1});
editor.setWeights(new int[]{1, 1});
@@ -507,6 +510,13 @@
return pageComponent;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage#getSourcePreviewViewer()
+ */
+ protected ISourceViewer getSourcePreviewViewer() {
+ return fPreviewViewer;
+ }
+
private Label createLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.WRAP);
label.setText(text);
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLSyntaxColoringPage.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLSyntaxColoringPage.java
index 8e3fc8e..eb532d7 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLSyntaxColoringPage.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLSyntaxColoringPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,9 +20,9 @@
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -78,6 +78,7 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey;
+import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage;
import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper;
import org.eclipse.wst.sse.ui.internal.util.EditorUtility;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
@@ -91,7 +92,7 @@
* and CDT pages far more than our original color page while retaining the
* extra "click-to-find" functionality.
*/
-public final class HTMLSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage {
+public final class HTMLSyntaxColoringPage extends AbstractSyntaxColoringPage implements IWorkbenchPreferencePage {
private Button fBold;
private Label fForegroundLabel;
@@ -111,6 +112,7 @@
private Map fStyleToDescriptionMap;
private StyledText fText;
private Button fUnderline;
+ private ISourceViewer fPreviewViewer;
// activate controls based on the given local color type
private void activate(String namedStyle) {
@@ -317,8 +319,8 @@
((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();
+ 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);
@@ -333,7 +335,8 @@
setAccessible(fText, SSEUIMessages.Sample_text__UI_);
fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForHTML.ContentTypeID_HTML);
fDocument.set(getExampleText());
- viewer.setDocument(fDocument);
+ initializeSourcePreviewColors(fPreviewViewer);
+ fPreviewViewer.setDocument(fDocument);
top.setWeights(new int[]{1, 1});
editor.setWeights(new int[]{1, 1});
@@ -507,6 +510,13 @@
return pageComponent;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage#getSourcePreviewViewer()
+ */
+ protected ISourceViewer getSourcePreviewViewer() {
+ return fPreviewViewer;
+ }
+
private Label createLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.WRAP);
label.setText(text);
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/preferences/ui/AbstractSyntaxColoringPage.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/preferences/ui/AbstractSyntaxColoringPage.java
new file mode 100644
index 0000000..ea18219
--- /dev/null
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/preferences/ui/AbstractSyntaxColoringPage.java
@@ -0,0 +1,170 @@
+/******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.wst.sse.ui.internal.preferences.ui;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+public abstract class AbstractSyntaxColoringPage extends PreferencePage {
+
+ private Color fForegroundColor;
+ private Color fBackgroundColor;
+ private Color fSelectionForegroundColor;
+ private Color fSelectionBackgroundColor;
+
+ final private IPropertyChangeListener fListener = new IPropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent event) {
+ final String property = event.getProperty();
+ if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT.equals(property)) {
+ initializeSourcePreviewColors(getSourcePreviewViewer());
+ }
+ }
+ };
+
+ public AbstractSyntaxColoringPage() {
+ final IPreferenceStore store = EditorsUI.getPreferenceStore();
+ if (store != null) {
+ store.addPropertyChangeListener(fListener);
+ }
+ }
+
+ /**
+ * Initializes the colors of the source preview window based on the values in the Editors' UI preference store
+ *
+ * @param viewer the {@link ISourceViewer} used as the source preview
+ */
+ protected void initializeSourcePreviewColors(ISourceViewer viewer) {
+ final IPreferenceStore store = EditorsUI.getPreferenceStore();
+ if (store != null && viewer != null) {
+
+ final StyledText styledText = viewer.getTextWidget();
+
+ // ----------- foreground color --------------------
+ Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
+ styledText.setForeground(color);
+
+ if (fForegroundColor != null)
+ fForegroundColor.dispose();
+
+ fForegroundColor = color;
+
+ // ---------- background color ----------------------
+ color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
+ styledText.setBackground(color);
+
+ if (fBackgroundColor != null)
+ fBackgroundColor.dispose();
+
+ fBackgroundColor = color;
+
+ // ----------- selection foreground color --------------------
+ color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, styledText.getDisplay());
+ styledText.setSelectionForeground(color);
+
+ if (fSelectionForegroundColor != null)
+ fSelectionForegroundColor.dispose();
+
+ fSelectionForegroundColor = color;
+
+ // ---------- selection background color ----------------------
+ color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, styledText.getDisplay());
+ styledText.setSelectionBackground(color);
+
+ if (fSelectionBackgroundColor != null)
+ fSelectionBackgroundColor.dispose();
+
+ fSelectionBackgroundColor = color;
+ }
+ }
+
+ /**
+ * Provides the {@link ISourceViewer} that is acting as the source preview
+ * @return
+ */
+ protected ISourceViewer getSourcePreviewViewer() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+ */
+ public void dispose() {
+ if (fForegroundColor != null) {
+ fForegroundColor.dispose();
+ fForegroundColor = null;
+ }
+ if (fBackgroundColor != null) {
+ fBackgroundColor.dispose();
+ fBackgroundColor = null;
+ }
+ if (fSelectionForegroundColor != null) {
+ fSelectionForegroundColor.dispose();
+ fSelectionForegroundColor = null;
+ }
+ if (fSelectionBackgroundColor != null) {
+ fSelectionBackgroundColor.dispose();
+ fSelectionBackgroundColor = null;
+ }
+ if (fListener != null) {
+ final IPreferenceStore store = EditorsUI.getPreferenceStore();
+ if (store != null) {
+ store.removePropertyChangeListener(fListener);
+ }
+ }
+ super.dispose();
+ }
+
+ /**
+ * Creates a color from the information stored in the given preference
+ * store. Returns <code>null</code> if there is no such information
+ * available.
+ *
+ * @param store
+ * the store to read from
+ * @param key
+ * the key used for the lookup in the preference store
+ * @param display
+ * the display used create the color
+ * @return the created color according to the specification in the
+ * preference store
+ * @since 2.0
+ */
+ private Color createColor(IPreferenceStore store, String key, Display display) {
+
+ RGB rgb = null;
+
+ if (store.contains(key)) {
+
+ if (store.isDefault(key))
+ rgb = PreferenceConverter.getDefaultColor(store, key);
+ else
+ rgb = PreferenceConverter.getColor(store, key);
+
+ if (rgb != null)
+ return new Color(display, rgb);
+ }
+
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java
index 45293f0..a0548bc 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,9 +20,9 @@
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -74,6 +74,7 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore;
import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey;
+import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage;
import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper;
import org.eclipse.wst.sse.ui.internal.util.EditorUtility;
import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
@@ -90,7 +91,7 @@
* and CDT pages far more than our original color page while retaining the
* extra "click-to-find" functionality.
*/
-public final class XMLSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage {
+public final class XMLSyntaxColoringPage extends AbstractSyntaxColoringPage implements IWorkbenchPreferencePage {
private Button fBold;
private Label fForegroundLabel;
@@ -111,6 +112,8 @@
private StyledText fText;
private Button fUnderline;
+ private ISourceViewer fPreviewViewer;
+
// activate controls based on the given local color type
private void activate(String namedStyle) {
Color foreground = fDefaultForeground;
@@ -315,8 +318,8 @@
((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();
+ 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);
@@ -331,7 +334,8 @@
setAccessible(fText, SSEUIMessages.Sample_text__UI_);
fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML);
fDocument.set(getExampleText());
- viewer.setDocument(fDocument);
+ initializeSourcePreviewColors(fPreviewViewer);
+ fPreviewViewer.setDocument(fDocument);
top.setWeights(new int[]{1, 1});
editor.setWeights(new int[]{1, 1});
@@ -514,6 +518,13 @@
return label;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSyntaxColoringPage#getSourcePreview()
+ */
+ protected ISourceViewer getSourcePreviewViewer() {
+ return fPreviewViewer;
+ }
+
// protected Label createDescriptionLabel(Composite parent) {
// return null;
// }