diff --git a/eclipse.platform.ui/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/RGBVisibleContrastColorFactory.java b/eclipse.platform.ui/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/RGBVisibleContrastColorFactory.java
new file mode 100644
index 0000000..67b33c7
--- /dev/null
+++ b/eclipse.platform.ui/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/RGBVisibleContrastColorFactory.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 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.ui.internal.themes;
+
+import java.util.Hashtable;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.themes.ColorUtil;
+import org.eclipse.ui.themes.IColorFactory;
+
+/**
+ * A IColorFactory
that may be used to select a color with a higher
+ * contrast. The input colors are specified as per method number two in
+ * {@link org.eclipse.core.runtime.IExecutableExtension}.
+ *
+ * Example usage: + * + *
+ * <colorDefinition + * label="Declaration view background" + * id="org.eclipse.jdt.ui.DeclarationView.backgroundColor"> + * <colorFactory + * plugin="org.eclipse.ui" + * class="org.eclipse.ui.internal.themes.RGBContrastFactory"> + * <parameter name="foreground" value="0,0,0" /> + * <parameter name="background" value="COLOR_INFO_BACKGROUND" /> + * <parameter name="alternativeBackground" value="COLOR_LIST_BACKGROUND" /> + * </colorFactory> + * </colorDefinition> + *+ * + *
+ * Returns background if foreground is visibly distinct from
+ * background. Otherwise, returns alternativeBackground if
+ * that color has more difference in brightness to the foreground. If both
+ * colors are bad, returns background. The color values may be
+ * specified as RGB triples or as SWT constants.
+ *
+ * @see org.eclipse.swt.SWT
+ * @since 3.107.100
+ */
+// This class is used by org.eclipse.jdt.ui/plugin.xml to fix
+// https://bugs.eclipse.org/477487
+public class RGBVisibleContrastColorFactory implements IColorFactory, IExecutableExtension {
+ private String fg, bg, altBg;
+
+ @Override
+ public RGB createColor() {
+ RGB cfg, cbg, cbgAlt;
+
+ if (fg != null) {
+ cfg = ColorUtil.getColorValue(fg);
+ } else {
+ cfg = new RGB(0, 0, 0);
+ }
+ if (bg != null) {
+ cbg = ColorUtil.getColorValue(bg);
+ } else {
+ cbg = new RGB(255, 255, 255);
+ }
+ if (altBg != null) {
+ cbgAlt = ColorUtil.getColorValue(altBg);
+ } else {
+ cbgAlt = new RGB(255, 255, 255);
+ }
+
+ float bfg = cfg.getHSB()[2];
+ float bbg = cbg.getHSB()[2];
+ float bbgAlt = cbgAlt.getHSB()[2];
+
+ if (Math.abs(bbg - bfg) < 0.5f && Math.abs(bbgAlt - bfg) > Math.abs(bbg - bfg)) {
+ return cbgAlt;
+ }
+ return cbg;
+ }
+
+ /**
+ * This executable extension requires parameters to be explicitly declared
+ * via the second method described in the IExecutableExtension
+ * documentation. This class expects that there will be three parameters,
+ * foreground
, background
and
+ * alternativeBackground
. These values may either be RGB
+ * triples or SWT constants.
+ */
+ @Override
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
+ throws CoreException {
+ if (data instanceof Hashtable) {
+ @SuppressWarnings("unchecked")
+ Hashtable