Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-12-20 22:54:35 +0000
committerThomas Wolf2019-12-30 11:19:21 +0000
commit5d4c228ec0fc2924113fcae24519fb1b9c1094ce (patch)
treee5a2c242f6b77196ec4933f7e6709b9ca5b7e229
parent1d9720c8d026ac8c066a0c92f09e1821ded543ee (diff)
downloadeclipse.platform.text-5d4c228ec0fc2924113fcae24519fb1b9c1094ce.tar.gz
eclipse.platform.text-5d4c228ec0fc2924113fcae24519fb1b9c1094ce.tar.xz
eclipse.platform.text-5d4c228ec0fc2924113fcae24519fb1b9c1094ce.zip
Bug 558529 - Use configured colors for revision "by age"I20200102-1800I20200101-1800I20191231-1800
Use the new configurable JFace colors for the newest and oldest revision as end stops of the gradient. Just in case none should be defined keep using the hard-coded stops. Change-Id: Ia67e748f72aabe79a024ac829229fa6a5614a5eb Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jface.text/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java55
2 files changed, 53 insertions, 4 deletions
diff --git a/org.eclipse.jface.text/META-INF/MANIFEST.MF b/org.eclipse.jface.text/META-INF/MANIFEST.MF
index d211451fbfd..b02e336e74d 100644
--- a/org.eclipse.jface.text/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text/META-INF/MANIFEST.MF
@@ -36,7 +36,7 @@ Require-Bundle:
org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.text;bundle-version="[3.8.0,4.0.0)";visibility:=reexport,
org.eclipse.swt;bundle-version="[3.110.100,4.0.0)",
- org.eclipse.jface;bundle-version="[3.15.0,4.0.0)"
+ org.eclipse.jface;bundle-version="[3.19.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.ibm.icu.text
Automatic-Module-Name: org.eclipse.jface.text
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java
index 58723425de4..ceab558ab1d 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/RevisionPainter.java
@@ -46,7 +46,10 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.internal.text.html.BrowserInformationControl;
import org.eclipse.jface.internal.text.html.HTMLPrinter;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
import org.eclipse.jface.text.BadLocationException;
@@ -148,6 +151,11 @@ public final class RevisionPainter {
*/
private final Map<Revision, RGB> fFocusColors= new HashMap<>();
+ /** Cached gradient start and stop values. */
+ private RGB fGradientStart;
+
+ private RGB fGradientStop;
+
/**
* Sets the revision information, which is needed to compute the relative age of a revision.
*
@@ -157,7 +165,8 @@ public final class RevisionPainter {
fRevisions= null;
fColors.clear();
fFocusColors.clear();
-
+ fGradientStart= null;
+ fGradientStop= null;
if (info == null)
return;
List<Long> revisions= new ArrayList<>();
@@ -168,6 +177,11 @@ public final class RevisionPainter {
fRevisions= revisions;
}
+ private RGB getRGB(String key, RGB defaultValue) {
+ RGB rgb= JFaceResources.getColorRegistry().getRGB(key);
+ return rgb != null ? rgb : defaultValue;
+ }
+
private RGB adaptColor(Revision revision, boolean focus) {
RGB rgb;
float scale;
@@ -176,8 +190,14 @@ public final class RevisionPainter {
if (index == -1 || fRevisions.isEmpty()) {
rgb= getBackground().getRGB();
} else {
- // gradient from intense red for most recent to faint yellow for oldest
- RGB[] gradient= Colors.palette(BY_DATE_START_COLOR, BY_DATE_END_COLOR, fRevisions.size());
+ if (fGradientStart == null) {
+ fGradientStart= getRGB(JFacePreferences.REVISION_NEWEST_COLOR, BY_DATE_START_COLOR);
+ }
+ if (fGradientStop == null) {
+ fGradientStop= getRGB(JFacePreferences.REVISION_OLDEST_COLOR, BY_DATE_END_COLOR);
+ }
+ // gradient from most recent to oldest
+ RGB[] gradient= Colors.palette(fGradientStart, fGradientStop, fRevisions.size());
rgb= gradient[gradient.length - index - 1];
}
scale= 0.99f;
@@ -590,6 +610,26 @@ public final class RevisionPainter {
*/
private int fLastWidth= -1;
+ /** The JFace preference store, or {@code null} if there is none. */
+ private IPreferenceStore fPreferences;
+
+ /** Listens on {@link #fPreferences} to update the ruler when colors change. */
+ private final IPropertyChangeListener fColorListener= event -> {
+ String property= event.getProperty();
+ if (property == null) {
+ return;
+ }
+ switch (property) {
+ case JFacePreferences.REVISION_NEWEST_COLOR:
+ case JFacePreferences.REVISION_OLDEST_COLOR:
+ fLastWidth= -1; // Recalculate colors
+ postRedraw();
+ break;
+ default:
+ break;
+ }
+ };
+
/**
* Creates a new revision painter for a vertical ruler column.
*
@@ -656,6 +696,15 @@ public final class RevisionPainter {
*/
public void setParentRuler(CompositeRuler parentRuler) {
fParentRuler= parentRuler;
+ if (parentRuler != null) {
+ fPreferences= JFacePreferences.getPreferenceStore();
+ if (fPreferences != null) {
+ fPreferences.addPropertyChangeListener(fColorListener);
+ }
+ } else if (fPreferences != null) {
+ fPreferences.removePropertyChangeListener(fColorListener);
+ fPreferences= null;
+ }
}
/**

Back to the top