aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2013-10-21 18:49:17 (EDT)
committerRobin Stocker2013-10-22 15:56:36 (EDT)
commit68c6962a44c8ab7f595d9660dbf73a205004ae87 (patch)
tree645b03ea40f0debbd547dec0c22d33945e98aba8
parent69fa5ef99e4c20aa47314f505d6385c1afa2b303 (diff)
downloadeclipse.platform.ui-68c6962a44c8ab7f595d9660dbf73a205004ae87.zip
eclipse.platform.ui-68c6962a44c8ab7f595d9660dbf73a205004ae87.tar.gz
eclipse.platform.ui-68c6962a44c8ab7f595d9660dbf73a205004ae87.tar.bz2
Bug 420035 - [CSS] Support SWT color constants in gradientsrefs/changes/17/17617/2
Similar to single colors, this change makes using SWT color constants in gradient definitions possible, e.g.: background-color: COLOR-WIDGET-BACKGROUND #E2E2E2 100%; Change-Id: I55121b7b47342d9b7f0683ecef157c95a0b5b198 Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java20
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java6
2 files changed, 17 insertions, 9 deletions
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java
index 9308acc..868af2f 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/CSSSWTColorHelper.java
@@ -9,6 +9,7 @@
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
* IBM Corporation
* Kai Toedter - added radial gradient support
+ * Robin Stocker - Bug 420035 - [CSS] Support SWT color constants in gradients
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.helpers;
@@ -48,16 +49,21 @@ public class CSSSWTColorHelper {
return null;
}
Color color = display.getSystemColor(SWT.COLOR_BLACK);
- RGB rgb = getRGB((CSSPrimitiveValue) value);
- if (rgb == null) {
- String name = ((CSSPrimitiveValue) value).getStringValue();
+ RGB rgb = getRGB((CSSPrimitiveValue) value, display);
+ if (rgb != null) color = new Color(display, rgb.red, rgb.green, rgb.blue);
+ return color;
+ }
+
+ private static RGB getRGB(CSSPrimitiveValue value, Display display) {
+ RGB rgb = getRGB(value);
+ if (rgb == null && display != null) {
+ String name = value.getStringValue();
if (name.contains("-")) {
name = name.replace('-', '_');
rgb = process(display, name);
}
}
- if (rgb != null) color = new Color(display, rgb.red, rgb.green, rgb.blue);
- return color;
+ return rgb;
}
/**
@@ -163,7 +169,7 @@ public class CSSSWTColorHelper {
return new Integer(percent);
}
- public static Gradient getGradient(CSSValueList list) {
+ public static Gradient getGradient(CSSValueList list, Display display) {
Gradient gradient = new Gradient();
for (int i = 0; i < list.getLength(); i++) {
CSSValue value = list.item(i);
@@ -187,7 +193,7 @@ public class CSSSWTColorHelper {
case CSSPrimitiveValue.CSS_IDENT:
case CSSPrimitiveValue.CSS_STRING:
case CSSPrimitiveValue.CSS_RGBCOLOR:
- RGB rgb = getRGB((CSSPrimitiveValue) value);
+ RGB rgb = getRGB((CSSPrimitiveValue) value, display);
if (rgb != null) {
gradient.addRGB(rgb, (CSSPrimitiveValue) value);
} else {
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java
index 790c0cc..a4df613 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/converters/CSSValueSWTGradientConverterImpl.java
@@ -11,8 +11,9 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.converters;
-import java.util.List;
+import org.eclipse.swt.widgets.Display;
+import java.util.List;
import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
import org.eclipse.e4.ui.css.core.dom.properties.converters.AbstractCSSValueConverter;
import org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter;
@@ -41,7 +42,8 @@ public class CSSValueSWTGradientConverterImpl extends AbstractCSSValueConverter
public Object convert(CSSValue value, CSSEngine engine, Object context) throws Exception {
if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
- Gradient grad = CSSSWTColorHelper.getGradient((CSSValueList) value);
+ Display display = (context instanceof Display) ? (Display) context : null;
+ Gradient grad = CSSSWTColorHelper.getGradient((CSSValueList) value, display);
List values = grad.getValues();
for (int i = 0; i < values.size(); i++) {
//Ensure all the colors are already converted and in the registry