Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2002-04-08 17:28:48 +0000
committerAndre Weinand2002-04-08 17:28:48 +0000
commitc745e4aaa4d2622efae89e205d6507020606396e (patch)
treef7bf2b9c69a2ac6eb8709270a59476d0bb203ea2 /bundles/org.eclipse.compare
parentd4060b25802794799be83dd5ae2d22f84bf659b5 (diff)
downloadeclipse.platform.team-c745e4aaa4d2622efae89e205d6507020606396e.tar.gz
eclipse.platform.team-c745e4aaa4d2622efae89e205d6507020606396e.tar.xz
eclipse.platform.team-c745e4aaa4d2622efae89e205d6507020606396e.zip
Fixed backgroundcolor issues
Diffstat (limited to 'bundles/org.eclipse.compare')
-rw-r--r--bundles/org.eclipse.compare/buildnotes_compare.html3
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java69
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java116
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java88
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java6
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html3
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java69
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java116
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java88
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java6
10 files changed, 536 insertions, 28 deletions
diff --git a/bundles/org.eclipse.compare/buildnotes_compare.html b/bundles/org.eclipse.compare/buildnotes_compare.html
index 8739886db..8bc22bb90 100644
--- a/bundles/org.eclipse.compare/buildnotes_compare.html
+++ b/bundles/org.eclipse.compare/buildnotes_compare.html
@@ -36,6 +36,9 @@ Problem reports fixed</h2>
<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=11536">#11536</a>: Option to turn off structured comparison<br>
<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=10682">#10682</a>: Need better UI for recovering deletions from local history<br>
<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=11446">#11446</a>: provide "add from local history" for compilation units<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=8615">#8615</a>: Styled Text widget does not respond to system color change<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9673">#9673</a>: editor background color - no effect on other viewers<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=11642">#11642</a>: Compare editors not using default background colors<br>
<h2>
Problem reports closed</h2>
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 1897291f5..40c3e6122 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -48,6 +48,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.texteditor.IUpdate;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.MergeSourceViewer;
@@ -267,6 +268,7 @@ public class TextMergeViewer extends ContentMergeViewer {
// SWT resources to be disposed
private Map fColors;
private Font fFont;
+ private Color fBackgroundColor;
private Cursor fBirdsEyeCursor;
@@ -562,7 +564,10 @@ public class TextMergeViewer extends ContentMergeViewer {
};
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
- updateFont(fPreferenceStore, parent);
+ Display display= parent.getDisplay();
+ updateFont(fPreferenceStore, display);
+ updateBackgroundColor(fPreferenceStore, display);
+
fLeftIsLocal= Utilities.getBoolean(configuration, "LEFT_IS_LOCAL", false); //$NON-NLS-1$
fSynchronizedScrolling= fPreferenceStore.getBoolean(ComparePreferencePage.SYNCHRONIZE_SCROLLING);
fShowMoreInfo= fPreferenceStore.getBoolean(ComparePreferencePage.SHOW_MORE_INFO);
@@ -591,7 +596,7 @@ public class TextMergeViewer extends ContentMergeViewer {
fBirdsEyeCursor= new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
}
- private void updateFont(IPreferenceStore ps, Control c) {
+ private void updateFont(IPreferenceStore ps, Display display) {
Font oldFont= fFont;
@@ -602,7 +607,7 @@ public class TextMergeViewer extends ContentMergeViewer {
else
fontData= PreferenceConverter.getDefaultFontData(ps, ComparePreferencePage.TEXT_FONT);
if (fontData != null) {
- fFont= new Font(c.getDisplay(), fontData);
+ fFont= new Font(display, fontData);
if (fAncestor != null)
fAncestor.setFont(fFont);
@@ -616,6 +621,48 @@ public class TextMergeViewer extends ContentMergeViewer {
}
}
+ private void updateBackgroundColor(IPreferenceStore ps, Display display) {
+
+ Color color= null;
+ if (ps.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT))
+ color= null;
+ else
+ color= createColor(ps, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, display);
+
+ if (fAncestor != null)
+ fAncestor.setBackgroundColor(color);
+ if (fLeft != null)
+ fLeft.setBackgroundColor(color);
+ if (fRight != null)
+ fRight.setBackgroundColor(color);
+
+ if (fBackgroundColor != null)
+ fBackgroundColor.dispose();
+ fBackgroundColor= color;
+ }
+
+ /**
+ * Creates a color from the information stored in the given preference store.
+ * Returns <code>null</code> if there is no such information available.
+ */
+ private static 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;
+ }
+
/**
* Configures the passed text viewer.
* This method is called after the three text viewers have been created for the
@@ -700,7 +747,10 @@ public class TextMergeViewer extends ContentMergeViewer {
fFont.dispose();
fFont= null;
}
-
+ if (fBackgroundColor != null) {
+ fBackgroundColor.dispose();
+ fBackgroundColor= null;
+ }
if (fBirdsEyeCursor != null) {
fBirdsEyeCursor.dispose();
fBirdsEyeCursor= null;
@@ -1007,6 +1057,8 @@ public class TextMergeViewer extends ContentMergeViewer {
if (fFont != null)
te.setFont(fFont);
+ if (fBackgroundColor != null)
+ te.setBackground(fBackgroundColor);
configureTextViewer(part);
@@ -2380,7 +2432,7 @@ public class TextMergeViewer extends ContentMergeViewer {
} else if (key.equals(ComparePreferencePage.TEXT_FONT)) {
if (fPreferenceStore != null) {
- updateFont(fPreferenceStore, fComposite);
+ updateFont(fPreferenceStore, fComposite.getDisplay());
invalidateLines();
}
@@ -2401,6 +2453,13 @@ public class TextMergeViewer extends ContentMergeViewer {
clearStatus();
}
+ } else if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)
+ || key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
+
+ if (fPreferenceStore != null) {
+ updateBackgroundColor(fPreferenceStore, fComposite.getDisplay());
+ }
+
} else
super.propertyChange(event);
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java
new file mode 100644
index 000000000..d3aea03f8
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java
@@ -0,0 +1,116 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.resource.JFaceResources;
+
+/**
+ * A "button" of a certain color determined by the color picker.
+ */
+public class ColorEditor {
+
+ private Point fExtent;
+ private Image fImage;
+ private RGB fColorValue;
+ private Color fColor;
+ private Button fButton;
+
+ public ColorEditor(Composite parent) {
+
+ fButton= new Button(parent, SWT.PUSH);
+ fExtent= computeImageSize(parent);
+ fImage= new Image(parent.getDisplay(), fExtent.x, fExtent.y);
+
+ GC gc= new GC(fImage);
+ gc.setBackground(fButton.getBackground());
+ gc.fillRectangle(0, 0, fExtent.x, fExtent.y);
+ gc.dispose();
+
+ fButton.setImage(fImage);
+ fButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ ColorDialog colorDialog= new ColorDialog(fButton.getShell());
+ colorDialog.setRGB(fColorValue);
+ RGB newColor = colorDialog.open();
+ if (newColor != null) {
+ fColorValue= newColor;
+ updateColorImage();
+ }
+ }
+ });
+
+ fButton.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent event) {
+ if (fImage != null) {
+ fImage.dispose();
+ fImage= null;
+ }
+ if (fColor != null) {
+ fColor.dispose();
+ fColor= null;
+ }
+ }
+ });
+ }
+
+ public RGB getColorValue() {
+ return fColorValue;
+ }
+
+ public void setColorValue(RGB rgb) {
+ fColorValue= rgb;
+ updateColorImage();
+ }
+
+ public Button getButton() {
+ return fButton;
+ }
+
+ protected void updateColorImage() {
+
+ Display display= fButton.getDisplay();
+
+ GC gc= new GC(fImage);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
+ gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4);
+
+ if (fColor != null)
+ fColor.dispose();
+
+ fColor= new Color(display, fColorValue);
+ gc.setBackground(fColor);
+ gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
+ gc.dispose();
+
+ fButton.setImage(fImage);
+ }
+
+ protected Point computeImageSize(Control window) {
+ GC gc= new GC(window);
+ Font f= JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
+ gc.setFont(f);
+ int height= gc.getFontMetrics().getHeight();
+ gc.dispose();
+ Point p= new Point(height * 3 - 6, height);
+ return p;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
index 45f40301d..fff0dfc00 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
@@ -12,6 +12,8 @@ import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.jface.preference.*;
import org.eclipse.jface.util.*;
@@ -19,6 +21,7 @@ import org.eclipse.jface.util.*;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.texteditor.WorkbenchChainedTextFontFieldEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.compare.*;
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
@@ -57,12 +60,16 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
public static final String TEXT_FONT= PREFIX + "TextFont"; //$NON-NLS-1$
private WorkbenchChainedTextFontFieldEditor fFontEditor;
- private TextMergeViewer fTextMergeViewer;
+ private TextMergeViewer fPreviewViewer;
private IPropertyChangeListener fPreferenceChangeListener;
private CompareConfiguration fCompareConfiguration;
private OverlayPreferenceStore fOverlayStore;
private Map fCheckBoxes= new HashMap();
private SelectionListener fCheckBoxListener;
+ private Button fBackgroundDefaultRadioButton;
+ private Button fBackgroundCustomRadioButton;
+ private Button fBackgroundColorButton;
+ private ColorEditor fBackgroundColorEditor;
public final OverlayPreferenceStore.OverlayKey[] fKeys= new OverlayPreferenceStore.OverlayKey[] {
@@ -71,10 +78,13 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SHOW_PSEUDO_CONFLICTS),
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, INITIALLY_SHOW_ANCESTOR_PANE),
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SHOW_MORE_INFO),
- new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, TEXT_FONT)
+ new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, TEXT_FONT),
+
+ new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND),
+ new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
};
-
+
public static void initDefaults(IPreferenceStore store) {
store.setDefault(OPEN_STRUCTURE_COMPARE, true);
store.setDefault(SYNCHRONIZE_SCROLLING, true);
@@ -82,6 +92,11 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
store.setDefault(INITIALLY_SHOW_ANCESTOR_PANE, false);
store.setDefault(SHOW_MORE_INFO, false);
+ Display display= Display.getDefault();
+ Color color= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
+ PreferenceConverter.setDefault(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, color.getRGB());
+ store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true);
+
WorkbenchChainedTextFontFieldEditor.startPropagate(store, TEXT_FONT);
}
@@ -207,11 +222,59 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
}
private Control createTextComparePage(Composite parent) {
+
Composite composite= new Composite(parent, SWT.NULL);
GridLayout layout= new GridLayout();
layout.numColumns= 1;
composite.setLayout(layout);
-
+
+
+ // background color
+ Composite backgroundComposite= new Composite(composite, SWT.NULL);
+ layout= new GridLayout();
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ layout.numColumns= 2;
+ backgroundComposite.setLayout(new RowLayout());
+
+ Label label= new Label(backgroundComposite, SWT.NULL);
+ label.setText("Bac&kground Color:");
+
+ SelectionListener backgroundSelectionListener= new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean custom= fBackgroundCustomRadioButton.getSelection();
+ fBackgroundColorButton.setEnabled(custom);
+ fOverlayStore.setValue(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, !custom);
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ };
+
+ fBackgroundDefaultRadioButton= new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
+ fBackgroundDefaultRadioButton.setText("S&ystem Default");
+ fBackgroundDefaultRadioButton.addSelectionListener(backgroundSelectionListener);
+
+ fBackgroundCustomRadioButton= new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
+ fBackgroundCustomRadioButton.setText("C&ustom");
+ fBackgroundCustomRadioButton.addSelectionListener(backgroundSelectionListener);
+
+ fBackgroundColorEditor= new ColorEditor(backgroundComposite);
+
+ fBackgroundColorButton= fBackgroundColorEditor.getButton();
+ fBackgroundColorButton.addSelectionListener(
+ new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+ public void widgetSelected(SelectionEvent e) {
+ PreferenceConverter.setValue(fOverlayStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, fBackgroundColorEditor.getColorValue());
+ }
+ }
+ );
+
+
+ // background color end
+
+
addCheckBox(composite, "ComparePreferencePage.synchronizeScrolling.label", SYNCHRONIZE_SCROLLING, 0); //$NON-NLS-1$
addCheckBox(composite, "ComparePreferencePage.initiallyShowAncestorPane.label", INITIALLY_SHOW_ANCESTOR_PANE, 0); //$NON-NLS-1$
@@ -246,9 +309,9 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
fCompareConfiguration.setRightLabel(Utilities.getString("ComparePreferencePage.right.label")); //$NON-NLS-1$
fCompareConfiguration.setRightEditable(false);
- fTextMergeViewer= new TextMergeViewer(parent, SWT.BORDER, fCompareConfiguration);
-
- fTextMergeViewer.setInput(
+ fPreviewViewer= new TextMergeViewer(parent, SWT.BORDER, fCompareConfiguration);
+
+ fPreviewViewer.setInput(
new DiffNode(Differencer.CONFLICTING,
new FakeInput("previewAncestor.txt"), //$NON-NLS-1$
new FakeInput("previewLeft.txt"), //$NON-NLS-1$
@@ -256,9 +319,9 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
)
);
- return fTextMergeViewer.getControl();
+ return fPreviewViewer.getControl();
}
-
+
private void initializeFields() {
Iterator e= fCheckBoxes.keySet().iterator();
@@ -267,6 +330,13 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
String key= (String) fCheckBoxes.get(b);
b.setSelection(fOverlayStore.getBoolean(key));
}
+
+ RGB rgb= PreferenceConverter.getColor(fOverlayStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
+ fBackgroundColorEditor.setColorValue(rgb);
+ boolean default_= fOverlayStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
+ fBackgroundDefaultRadioButton.setSelection(default_);
+ fBackgroundCustomRadioButton.setSelection(!default_);
+ fBackgroundColorButton.setEnabled(!default_);
}
// overlay stuff
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
index 116d8785e..307a1d139 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
@@ -94,6 +94,12 @@ public class MergeSourceViewer extends SourceViewer
te.setFont(font);
}
+ public void setBackgroundColor(Color color) {
+ StyledText te= getTextWidget();
+ if (te != null)
+ te.setBackground(color);
+ }
+
public void setEnabled(boolean enabled) {
if (enabled != fEnabled) {
fEnabled= enabled;
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
index 8739886db..8bc22bb90 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/buildnotes_compare.html
@@ -36,6 +36,9 @@ Problem reports fixed</h2>
<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=11536">#11536</a>: Option to turn off structured comparison<br>
<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=10682">#10682</a>: Need better UI for recovering deletions from local history<br>
<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=11446">#11446</a>: provide "add from local history" for compilation units<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=8615">#8615</a>: Styled Text widget does not respond to system color change<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9673">#9673</a>: editor background color - no effect on other viewers<br>
+<a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=11642">#11642</a>: Compare editors not using default background colors<br>
<h2>
Problem reports closed</h2>
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 1897291f5..40c3e6122 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -48,6 +48,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.texteditor.IUpdate;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.compare.*;
import org.eclipse.compare.internal.MergeSourceViewer;
@@ -267,6 +268,7 @@ public class TextMergeViewer extends ContentMergeViewer {
// SWT resources to be disposed
private Map fColors;
private Font fFont;
+ private Color fBackgroundColor;
private Cursor fBirdsEyeCursor;
@@ -562,7 +564,10 @@ public class TextMergeViewer extends ContentMergeViewer {
};
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
- updateFont(fPreferenceStore, parent);
+ Display display= parent.getDisplay();
+ updateFont(fPreferenceStore, display);
+ updateBackgroundColor(fPreferenceStore, display);
+
fLeftIsLocal= Utilities.getBoolean(configuration, "LEFT_IS_LOCAL", false); //$NON-NLS-1$
fSynchronizedScrolling= fPreferenceStore.getBoolean(ComparePreferencePage.SYNCHRONIZE_SCROLLING);
fShowMoreInfo= fPreferenceStore.getBoolean(ComparePreferencePage.SHOW_MORE_INFO);
@@ -591,7 +596,7 @@ public class TextMergeViewer extends ContentMergeViewer {
fBirdsEyeCursor= new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
}
- private void updateFont(IPreferenceStore ps, Control c) {
+ private void updateFont(IPreferenceStore ps, Display display) {
Font oldFont= fFont;
@@ -602,7 +607,7 @@ public class TextMergeViewer extends ContentMergeViewer {
else
fontData= PreferenceConverter.getDefaultFontData(ps, ComparePreferencePage.TEXT_FONT);
if (fontData != null) {
- fFont= new Font(c.getDisplay(), fontData);
+ fFont= new Font(display, fontData);
if (fAncestor != null)
fAncestor.setFont(fFont);
@@ -616,6 +621,48 @@ public class TextMergeViewer extends ContentMergeViewer {
}
}
+ private void updateBackgroundColor(IPreferenceStore ps, Display display) {
+
+ Color color= null;
+ if (ps.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT))
+ color= null;
+ else
+ color= createColor(ps, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, display);
+
+ if (fAncestor != null)
+ fAncestor.setBackgroundColor(color);
+ if (fLeft != null)
+ fLeft.setBackgroundColor(color);
+ if (fRight != null)
+ fRight.setBackgroundColor(color);
+
+ if (fBackgroundColor != null)
+ fBackgroundColor.dispose();
+ fBackgroundColor= color;
+ }
+
+ /**
+ * Creates a color from the information stored in the given preference store.
+ * Returns <code>null</code> if there is no such information available.
+ */
+ private static 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;
+ }
+
/**
* Configures the passed text viewer.
* This method is called after the three text viewers have been created for the
@@ -700,7 +747,10 @@ public class TextMergeViewer extends ContentMergeViewer {
fFont.dispose();
fFont= null;
}
-
+ if (fBackgroundColor != null) {
+ fBackgroundColor.dispose();
+ fBackgroundColor= null;
+ }
if (fBirdsEyeCursor != null) {
fBirdsEyeCursor.dispose();
fBirdsEyeCursor= null;
@@ -1007,6 +1057,8 @@ public class TextMergeViewer extends ContentMergeViewer {
if (fFont != null)
te.setFont(fFont);
+ if (fBackgroundColor != null)
+ te.setBackground(fBackgroundColor);
configureTextViewer(part);
@@ -2380,7 +2432,7 @@ public class TextMergeViewer extends ContentMergeViewer {
} else if (key.equals(ComparePreferencePage.TEXT_FONT)) {
if (fPreferenceStore != null) {
- updateFont(fPreferenceStore, fComposite);
+ updateFont(fPreferenceStore, fComposite.getDisplay());
invalidateLines();
}
@@ -2401,6 +2453,13 @@ public class TextMergeViewer extends ContentMergeViewer {
clearStatus();
}
+ } else if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)
+ || key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
+
+ if (fPreferenceStore != null) {
+ updateBackgroundColor(fPreferenceStore, fComposite.getDisplay());
+ }
+
} else
super.propertyChange(event);
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java
new file mode 100644
index 000000000..d3aea03f8
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ColorEditor.java
@@ -0,0 +1,116 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.compare.internal;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.resource.JFaceResources;
+
+/**
+ * A "button" of a certain color determined by the color picker.
+ */
+public class ColorEditor {
+
+ private Point fExtent;
+ private Image fImage;
+ private RGB fColorValue;
+ private Color fColor;
+ private Button fButton;
+
+ public ColorEditor(Composite parent) {
+
+ fButton= new Button(parent, SWT.PUSH);
+ fExtent= computeImageSize(parent);
+ fImage= new Image(parent.getDisplay(), fExtent.x, fExtent.y);
+
+ GC gc= new GC(fImage);
+ gc.setBackground(fButton.getBackground());
+ gc.fillRectangle(0, 0, fExtent.x, fExtent.y);
+ gc.dispose();
+
+ fButton.setImage(fImage);
+ fButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ ColorDialog colorDialog= new ColorDialog(fButton.getShell());
+ colorDialog.setRGB(fColorValue);
+ RGB newColor = colorDialog.open();
+ if (newColor != null) {
+ fColorValue= newColor;
+ updateColorImage();
+ }
+ }
+ });
+
+ fButton.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent event) {
+ if (fImage != null) {
+ fImage.dispose();
+ fImage= null;
+ }
+ if (fColor != null) {
+ fColor.dispose();
+ fColor= null;
+ }
+ }
+ });
+ }
+
+ public RGB getColorValue() {
+ return fColorValue;
+ }
+
+ public void setColorValue(RGB rgb) {
+ fColorValue= rgb;
+ updateColorImage();
+ }
+
+ public Button getButton() {
+ return fButton;
+ }
+
+ protected void updateColorImage() {
+
+ Display display= fButton.getDisplay();
+
+ GC gc= new GC(fImage);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
+ gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4);
+
+ if (fColor != null)
+ fColor.dispose();
+
+ fColor= new Color(display, fColorValue);
+ gc.setBackground(fColor);
+ gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
+ gc.dispose();
+
+ fButton.setImage(fImage);
+ }
+
+ protected Point computeImageSize(Control window) {
+ GC gc= new GC(window);
+ Font f= JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
+ gc.setFont(f);
+ int height= gc.getFontMetrics().getHeight();
+ gc.dispose();
+ Point p= new Point(height * 3 - 6, height);
+ return p;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
index 45f40301d..fff0dfc00 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
@@ -12,6 +12,8 @@ import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.jface.preference.*;
import org.eclipse.jface.util.*;
@@ -19,6 +21,7 @@ import org.eclipse.jface.util.*;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.texteditor.WorkbenchChainedTextFontFieldEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.compare.*;
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
@@ -57,12 +60,16 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
public static final String TEXT_FONT= PREFIX + "TextFont"; //$NON-NLS-1$
private WorkbenchChainedTextFontFieldEditor fFontEditor;
- private TextMergeViewer fTextMergeViewer;
+ private TextMergeViewer fPreviewViewer;
private IPropertyChangeListener fPreferenceChangeListener;
private CompareConfiguration fCompareConfiguration;
private OverlayPreferenceStore fOverlayStore;
private Map fCheckBoxes= new HashMap();
private SelectionListener fCheckBoxListener;
+ private Button fBackgroundDefaultRadioButton;
+ private Button fBackgroundCustomRadioButton;
+ private Button fBackgroundColorButton;
+ private ColorEditor fBackgroundColorEditor;
public final OverlayPreferenceStore.OverlayKey[] fKeys= new OverlayPreferenceStore.OverlayKey[] {
@@ -71,10 +78,13 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SHOW_PSEUDO_CONFLICTS),
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, INITIALLY_SHOW_ANCESTOR_PANE),
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SHOW_MORE_INFO),
- new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, TEXT_FONT)
+ new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, TEXT_FONT),
+
+ new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND),
+ new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
};
-
+
public static void initDefaults(IPreferenceStore store) {
store.setDefault(OPEN_STRUCTURE_COMPARE, true);
store.setDefault(SYNCHRONIZE_SCROLLING, true);
@@ -82,6 +92,11 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
store.setDefault(INITIALLY_SHOW_ANCESTOR_PANE, false);
store.setDefault(SHOW_MORE_INFO, false);
+ Display display= Display.getDefault();
+ Color color= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
+ PreferenceConverter.setDefault(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, color.getRGB());
+ store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true);
+
WorkbenchChainedTextFontFieldEditor.startPropagate(store, TEXT_FONT);
}
@@ -207,11 +222,59 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
}
private Control createTextComparePage(Composite parent) {
+
Composite composite= new Composite(parent, SWT.NULL);
GridLayout layout= new GridLayout();
layout.numColumns= 1;
composite.setLayout(layout);
-
+
+
+ // background color
+ Composite backgroundComposite= new Composite(composite, SWT.NULL);
+ layout= new GridLayout();
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ layout.numColumns= 2;
+ backgroundComposite.setLayout(new RowLayout());
+
+ Label label= new Label(backgroundComposite, SWT.NULL);
+ label.setText("Bac&kground Color:");
+
+ SelectionListener backgroundSelectionListener= new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean custom= fBackgroundCustomRadioButton.getSelection();
+ fBackgroundColorButton.setEnabled(custom);
+ fOverlayStore.setValue(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, !custom);
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {}
+ };
+
+ fBackgroundDefaultRadioButton= new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
+ fBackgroundDefaultRadioButton.setText("S&ystem Default");
+ fBackgroundDefaultRadioButton.addSelectionListener(backgroundSelectionListener);
+
+ fBackgroundCustomRadioButton= new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
+ fBackgroundCustomRadioButton.setText("C&ustom");
+ fBackgroundCustomRadioButton.addSelectionListener(backgroundSelectionListener);
+
+ fBackgroundColorEditor= new ColorEditor(backgroundComposite);
+
+ fBackgroundColorButton= fBackgroundColorEditor.getButton();
+ fBackgroundColorButton.addSelectionListener(
+ new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+ public void widgetSelected(SelectionEvent e) {
+ PreferenceConverter.setValue(fOverlayStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, fBackgroundColorEditor.getColorValue());
+ }
+ }
+ );
+
+
+ // background color end
+
+
addCheckBox(composite, "ComparePreferencePage.synchronizeScrolling.label", SYNCHRONIZE_SCROLLING, 0); //$NON-NLS-1$
addCheckBox(composite, "ComparePreferencePage.initiallyShowAncestorPane.label", INITIALLY_SHOW_ANCESTOR_PANE, 0); //$NON-NLS-1$
@@ -246,9 +309,9 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
fCompareConfiguration.setRightLabel(Utilities.getString("ComparePreferencePage.right.label")); //$NON-NLS-1$
fCompareConfiguration.setRightEditable(false);
- fTextMergeViewer= new TextMergeViewer(parent, SWT.BORDER, fCompareConfiguration);
-
- fTextMergeViewer.setInput(
+ fPreviewViewer= new TextMergeViewer(parent, SWT.BORDER, fCompareConfiguration);
+
+ fPreviewViewer.setInput(
new DiffNode(Differencer.CONFLICTING,
new FakeInput("previewAncestor.txt"), //$NON-NLS-1$
new FakeInput("previewLeft.txt"), //$NON-NLS-1$
@@ -256,9 +319,9 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
)
);
- return fTextMergeViewer.getControl();
+ return fPreviewViewer.getControl();
}
-
+
private void initializeFields() {
Iterator e= fCheckBoxes.keySet().iterator();
@@ -267,6 +330,13 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
String key= (String) fCheckBoxes.get(b);
b.setSelection(fOverlayStore.getBoolean(key));
}
+
+ RGB rgb= PreferenceConverter.getColor(fOverlayStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
+ fBackgroundColorEditor.setColorValue(rgb);
+ boolean default_= fOverlayStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
+ fBackgroundDefaultRadioButton.setSelection(default_);
+ fBackgroundCustomRadioButton.setSelection(!default_);
+ fBackgroundColorButton.setEnabled(!default_);
}
// overlay stuff
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
index 116d8785e..307a1d139 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
@@ -94,6 +94,12 @@ public class MergeSourceViewer extends SourceViewer
te.setFont(font);
}
+ public void setBackgroundColor(Color color) {
+ StyledText te= getTextWidget();
+ if (te != null)
+ te.setBackground(color);
+ }
+
public void setEnabled(boolean enabled) {
if (enabled != fEnabled) {
fEnabled= enabled;

Back to the top