aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2013-04-08 08:34:32 (EDT)
committerTom Schindl2013-04-08 08:38:06 (EDT)
commit0c0f11522c9ca06af544d6f1e671a8fb77b68b88 (patch)
treea08bd9d17ca7bee526b3b0b7cf6998d2e2ef99a0
parent10f22b23d4671eaadcf935f892263cd3594b544e (diff)
downloadorg.eclipse.nebula-0c0f11522c9ca06af544d6f1e671a8fb77b68b88.zip
org.eclipse.nebula-0c0f11522c9ca06af544d6f1e671a8fb77b68b88.tar.gz
org.eclipse.nebula-0c0f11522c9ca06af544d6f1e671a8fb77b68b88.tar.bz2
adding css support for pshelf
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.classpath7
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.project28
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/META-INF/MANIFEST.MF12
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/build.properties5
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/plugin.xml30
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/CSSShelfRenderer.java505
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/CSSEngineHelper.java66
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElement.java14
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElementProvider.java16
-rw-r--r--widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfPropertyHandler.java48
11 files changed, 738 insertions, 0 deletions
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.classpath b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.classpath
new file mode 100644
index 0000000..098194c
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.project b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.project
new file mode 100644
index 0000000..a9b0dbc
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.nebula.widgets.pshelf.css</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.settings/org.eclipse.jdt.core.prefs b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f42de36
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/META-INF/MANIFEST.MF b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..2046ef7
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Css
+Bundle-SymbolicName: org.eclipse.nebula.widgets.pshelf.css;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.eclipse.swt;bundle-version="3.8.0",
+ org.eclipse.nebula.widgets.pshelf;bundle-version="1.0.0",
+ org.eclipse.e4.ui.services;bundle-version="1.0.0",
+ org.eclipse.e4.ui.css.core;bundle-version="0.10.100",
+ org.eclipse.e4.ui.css.swt;bundle-version="0.11.0"
+Export-Package: org.eclipse.nebula.widgets.pshelf.css
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/build.properties b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/build.properties
new file mode 100644
index 0000000..e9863e2
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/plugin.xml b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/plugin.xml
new file mode 100644
index 0000000..f358bb6
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.e4.ui.css.core.elementProvider">
+ <provider
+ class="org.eclipse.nebula.widgets.pshelf.css.internal.PShelfElementProvider">
+ <widget
+ class="org.eclipse.nebula.widgets.pshelf.PShelf"></widget>
+ </provider>
+ </extension>
+ <extension
+ point="org.eclipse.e4.ui.css.core.propertyHandler">
+ <handler
+ adapter="org.eclipse.nebula.widgets.pshelf.css.internal.PShelfElement"
+ composite="true"
+ handler="org.eclipse.nebula.widgets.pshelf.css.internal.PShelfPropertyHandler">
+ <property-name
+ name="pshelf-basecolor-selected">
+ </property-name>
+ <property-name
+ name="pshelf-basecolor-unselected">
+ </property-name>
+ <property-name
+ name="pshelf-basecolor-hover">
+ </property-name>
+ </handler>
+ </extension>
+
+</plugin>
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/CSSShelfRenderer.java b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/CSSShelfRenderer.java
new file mode 100644
index 0000000..43cf242
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/CSSShelfRenderer.java
@@ -0,0 +1,505 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tom Schindl. 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: Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.pshelf.css;
+
+import org.eclipse.e4.ui.services.IStylingEngine;
+import org.eclipse.nebula.widgets.pshelf.AbstractRenderer;
+import org.eclipse.nebula.widgets.pshelf.PShelf;
+import org.eclipse.nebula.widgets.pshelf.PShelfItem;
+import org.eclipse.nebula.widgets.pshelf.css.internal.CSSEngineHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Renderer which consults the CSS stylesheet to retrieve colors
+ * <ul>
+ * <li>pshelf-basecolor-selected</li>
+ * <li>pshelf-basecolor-unselected</li>
+ * <li>pshelf-basecolor-hover</li>
+ * </ul>
+ *
+ * @author Tom Schindl
+ */
+public class CSSShelfRenderer extends AbstractRenderer {
+
+ private Color[] initialColors; // to dispose created colors
+
+ private int textMargin = 2;
+ private int margin = 4;
+ private PShelf parent;
+ private int spacing = 8;
+
+ private Font initialFont;
+ private Font initialOpenFont;
+
+ private Color gradient1;
+ private Color gradient2;
+
+ private Font font;
+ private Font selectedFont;
+
+ private Color selectedGradient1;
+ private Color selectedGradient2;
+
+ private Color hoverGradient1;
+ private Color hoverGradient2;
+
+ private Color lineColor;
+
+ private Color selectedForeground;
+ private Color hoverForeground;
+ private Color foreground;
+
+ private IStylingEngine engine;
+ private CSSEngineHelper csshelper;
+
+ public CSSShelfRenderer(IStylingEngine engine) {
+ this.engine = engine;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Point computeSize(GC gc, int wHint, int hHint, Object value) {
+ PShelfItem item = (PShelfItem) value;
+
+ int h = 0;
+
+ gc.setFont(font);
+
+ if (item.getImage() == null) {
+ h = gc.getFontMetrics().getHeight() + (2 * (textMargin));
+ } else {
+ h = Math.max(item.getImage().getBounds().height, gc.getFontMetrics().getHeight() + (2 * textMargin));
+ }
+
+ gc.setFont(selectedFont);
+
+ h = Math.max(h, gc.getFontMetrics().getHeight() + (2 * textMargin));
+
+ h += 2 * margin;
+
+ if (h % 2 != 0)
+ h++;
+
+ return new Point(wHint, h);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void paint(GC gc, Object value) {
+ PShelfItem item = (PShelfItem) value;
+
+ // Color back = parent.getBackground();
+ Color fore = parent.getForeground();
+
+ if (isSelected()) {
+ gc.setForeground(selectedGradient1);
+ gc.setBackground(selectedGradient2);
+ } else {
+ if (isHover()) {
+ gc.setForeground(hoverGradient1);
+ gc.setBackground(hoverGradient2);
+ } else {
+ gc.setForeground(gradient1);
+ gc.setBackground(gradient2);
+ }
+ }
+
+ gc.fillGradientRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height, true);
+
+ if ((parent.getStyle() & SWT.SIMPLE) != 0) {
+ if (!isSelected()) {
+ gc.setForeground(lineColor);
+ gc.drawLine(0, getBounds().y, getBounds().width - 1, getBounds().y);
+ }
+ } else {
+ if (parent.getItems()[0] != item) {
+ gc.setForeground(lineColor);
+ gc.drawLine(0, getBounds().y, getBounds().width - 1, getBounds().y);
+ }
+
+ if (isSelected()) {
+ gc.setForeground(lineColor);
+ gc.drawLine(0, getBounds().y + getBounds().height - 1, getBounds().width - 1, getBounds().y + getBounds().height - 1);
+ }
+ }
+
+ boolean imageLeft = true;
+
+ if ((parent.getStyle() & SWT.SIMPLE) != 0) {
+ imageLeft = !isSelected();
+ }
+
+ int x = 6;
+ if (item.getImage() != null && imageLeft) {
+ int y2 = (getBounds().height - item.getImage().getBounds().height) / 2;
+ if ((getBounds().height - item.getImage().getBounds().height) % 2 != 0)
+ y2++;
+
+ gc.drawImage(item.getImage(), x, getBounds().y + y2);
+
+ x += item.getImage().getBounds().width + spacing;
+ }
+
+ if (isSelected()) {
+ gc.setFont(selectedFont);
+ gc.setForeground(selectedForeground != null ? selectedForeground : fore);
+ } else if (isHover()) {
+ gc.setFont(font);
+ gc.setForeground(hoverForeground != null ? hoverForeground : fore);
+ } else {
+ gc.setFont(font);
+ gc.setForeground(foreground != null ? foreground : fore);
+ }
+
+ int y2 = (getBounds().height - gc.getFontMetrics().getHeight()) / 2;
+ if ((getBounds().height - gc.getFontMetrics().getHeight()) % 2 != 0)
+ y2++;
+
+ int textWidth = getBounds().width - 12;
+ if (item.getImage() != null) {
+ textWidth -= item.getImage().getBounds().width;
+ textWidth -= 6;
+ }
+
+ gc.drawString(getShortString(gc, item.getText(), textWidth), x, getBounds().y + y2, true);
+
+ if (item.getImage() != null && !imageLeft) {
+ int y3 = (getBounds().height - item.getImage().getBounds().height) / 2;
+ if ((getBounds().height - item.getImage().getBounds().height) % 2 != 0)
+ y3++;
+
+ gc.drawImage(item.getImage(), getBounds().width - 6 - item.getImage().getBounds().width, getBounds().y + y3);
+ }
+
+ if (isFocus()) {
+ gc.drawFocus(1, 1, getBounds().width - 2, getBounds().height - 1);
+ }
+ }
+
+ public void initialize(Control control) {
+ this.parent = (PShelf) control;
+ this.csshelper = new CSSEngineHelper(engine, control, this);
+
+ FontData fd = parent.getFont().getFontData()[0];
+ initialFont = new Font(parent.getDisplay(), fd.getName(), fd.getHeight(), SWT.BOLD);
+ // parent.setFont(initialFont);
+
+ Color tmp = csshelper.getBaseColorSelected();
+ Color baseColor;
+ Color color1 = createNewBlendedColor(tmp, parent.getDisplay().getSystemColor(SWT.COLOR_WHITE), 30);
+
+ baseColor = createNewBlendedColor(tmp, parent.getDisplay().getSystemColor(SWT.COLOR_WHITE), 80);
+ tmp.dispose();
+
+ Color color2 = createNewSaturatedColor(baseColor, .01f);
+
+ if ((parent.getStyle() & SWT.SIMPLE) != 0) {
+ gradient1 = color1;
+ gradient2 = color2;
+ } else {
+ selectedGradient1 = color1;
+ selectedGradient2 = color2;
+ }
+
+ baseColor.dispose();
+
+ tmp = csshelper.getBaseColorUnselected();
+ lineColor = createNewSaturatedColor(tmp, .02f);
+
+ color1 = createNewBlendedColor(tmp, parent.getDisplay().getSystemColor(SWT.COLOR_WHITE), 70);
+
+ baseColor = createNewBlendedColor(tmp, parent.getDisplay().getSystemColor(SWT.COLOR_BLACK), 80);
+
+ tmp.dispose();
+
+ color2 = createNewSaturatedColor(baseColor, .02f);
+
+ if ((parent.getStyle() & SWT.SIMPLE) != 0) {
+ selectedGradient1 = color1;
+ selectedGradient2 = color2;
+ } else {
+ gradient1 = color1;
+ gradient2 = color2;
+ }
+
+ baseColor.dispose();
+
+ // initialOpenFont = FontUtils.createFont(parent.getFont(),4,SWT.BOLD);
+ if ((parent.getStyle() & SWT.SIMPLE) != 0)
+ initialOpenFont = new Font(parent.getDisplay(), "Arial", 12, SWT.BOLD);
+ else
+ initialOpenFont = new Font(parent.getDisplay(), initialFont.getFontData());
+
+ font = initialFont;
+ selectedFont = initialOpenFont;
+
+ Color inverseColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
+ if ((parent.getStyle() & SWT.SIMPLE) != 0)
+ selectedForeground = inverseColor;
+ else
+ foreground = inverseColor;
+ // the other color left null, foreground color of the parent will be
+ // used for it
+
+ tmp = csshelper.getBaseColorHover();
+ baseColor = createNewReverseColor(tmp);
+ tmp.dispose();
+
+ hoverGradient1 = createNewBlendedColor(baseColor, parent.getDisplay().getSystemColor(SWT.COLOR_WHITE), 30);
+
+ Color baseColor2 = createNewBlendedColor(baseColor, parent.getDisplay().getSystemColor(SWT.COLOR_WHITE), 99);
+
+ hoverGradient2 = createNewSaturatedColor(baseColor2, .00f);
+
+ baseColor2.dispose();
+ baseColor.dispose();
+
+ initialColors = new Color[] { gradient1, gradient2, selectedGradient1, selectedGradient2, hoverGradient1, hoverGradient2, lineColor };
+ }
+
+ public void dispose() {
+ initialFont.dispose();
+ initialOpenFont.dispose();
+
+ for (int i = 0; i < initialColors.length; i++) {
+ initialColors[i].dispose();
+ }
+
+ super.dispose();
+ }
+
+ public void reinitialize() {
+ initialFont.dispose();
+ initialOpenFont.dispose();
+
+ for (int i = 0; i < initialColors.length; i++) {
+ initialColors[i].dispose();
+ }
+ initialize(parent);
+ parent.redraw();
+ }
+
+ public Color getLineColor() {
+ return lineColor;
+ }
+
+ public void setLineColor(Color lineColor) {
+ this.lineColor = lineColor;
+ }
+
+ public Font getFont() {
+ return font;
+ }
+
+ public void setFont(Font font) {
+ this.font = font;
+ }
+
+ public Color getGradient1() {
+ return gradient1;
+ }
+
+ public void setGradient1(Color gradient1) {
+ this.gradient1 = gradient1;
+ }
+
+ public Color getGradient2() {
+ return gradient2;
+ }
+
+ public void setGradient2(Color gradient2) {
+ this.gradient2 = gradient2;
+ }
+
+ public Color getHoverGradient1() {
+ return hoverGradient1;
+ }
+
+ public void setHoverGradient1(Color hoverGradient1) {
+ this.hoverGradient1 = hoverGradient1;
+ }
+
+ public Color getHoverGradient2() {
+ return hoverGradient2;
+ }
+
+ public void setHoverGradient2(Color hoverGradient2) {
+ this.hoverGradient2 = hoverGradient2;
+ }
+
+ public Font getSelectedFont() {
+ return selectedFont;
+ }
+
+ public void setSelectedFont(Font selectedFont) {
+ this.selectedFont = selectedFont;
+ }
+
+ public Color getSelectedForeground() {
+ return selectedForeground;
+ }
+
+ /**
+ * Sets text color for the selected item.
+ *
+ * @param selectedForeground
+ * Can be <code>null</code>, foreground color of the parent is
+ * used in that case.
+ */
+ public void setSelectedForeground(Color selectedForeground) {
+ this.selectedForeground = selectedForeground;
+ }
+
+ public Color getHoverForeground() {
+ return hoverForeground;
+ }
+
+ /**
+ * Sets text color for the hovered item.
+ *
+ * @param hoverForeground
+ * Can be <code>null</code>, foreground color of the parent is
+ * used in that case.
+ */
+ public void setHoverForeground(Color hoverForeground) {
+ this.hoverForeground = hoverForeground;
+ }
+
+ public Color getForeground() {
+ return foreground;
+ }
+
+ /**
+ * Sets text color for non-selected items.
+ *
+ * @param foreground
+ * Can be <code>null</code>, foreground color of the parent is
+ * used in that case.
+ */
+ public void setForeground(Color foreground) {
+ this.foreground = foreground;
+ }
+
+ public Color getSelectedGradient1() {
+ return selectedGradient1;
+ }
+
+ public void setSelectedGradient1(Color selectedGradient1) {
+ this.selectedGradient1 = selectedGradient1;
+ }
+
+ public Color getSelectedGradient2() {
+ return selectedGradient2;
+ }
+
+ public void setSelectedGradient2(Color selectedGradient2) {
+ this.selectedGradient2 = selectedGradient2;
+ }
+
+ private static String getShortString(GC gc, String t, int width) {
+
+ if (t == null) {
+ return null;
+ }
+
+ if (t.equals("")) {
+ return "";
+ }
+
+ if (width >= gc.stringExtent(t).x) {
+ return t;
+ }
+
+ int w = gc.stringExtent("...").x;
+ String text = t;
+ int l = text.length();
+ int pivot = l / 2;
+ int s = pivot;
+ int e = pivot + 1;
+ while (s >= 0 && e < l) {
+ String s1 = text.substring(0, s);
+ String s2 = text.substring(e, l);
+ int l1 = gc.stringExtent(s1).x;
+ int l2 = gc.stringExtent(s2).x;
+ if (l1 + w + l2 < width) {
+ text = s1 + "..." + s2;
+ break;
+ }
+ s--;
+ e++;
+ }
+
+ if (s == 0 || e == l) {
+ text = text.substring(0, 1) + "..." + text.substring(l - 1, l);
+ }
+
+ return text;
+ }
+
+ private static int blend(int v1, int v2, int ratio) {
+ return (ratio * v1 + (100 - ratio) * v2) / 100;
+ }
+
+ private static RGB blend(RGB c1, RGB c2, int ratio) {
+ int r = blend(c1.red, c2.red, ratio);
+ int g = blend(c1.green, c2.green, ratio);
+ int b = blend(c1.blue, c2.blue, ratio);
+ return new RGB(r, g, b);
+ }
+
+ private static Color createNewBlendedColor(Color c1, Color c2, int ratio) {
+ Color newColor = new Color(Display.getCurrent(), blend(c1.getRGB(), c2.getRGB(), ratio));
+
+ return newColor;
+ }
+
+ private static Color createNewReverseColor(Color c) {
+ Color newColor = new Color(Display.getCurrent(), 255 - c.getRed(), 255 - c.getGreen(), 255 - c.getBlue());
+ return newColor;
+ }
+
+ private static RGB saturate(RGB rgb, float saturation) {
+ float[] hsb = rgb.getHSB();
+
+ hsb[1] += saturation;
+ if (hsb[1] > 1.0f) {
+ hsb[1] = 1.0f;
+ }
+ if (hsb[1] < 0f) {
+ hsb[1] = 0f;
+ }
+
+ // hue is 0.0..360.0, saturation and brightness 0.0..1.0
+ hsb[0] += 360.0 * saturation;
+ if (hsb[0] > 360.0f) {
+ hsb[0] = 360.0f;
+ }
+
+ if (hsb[0] < 0f) {
+ hsb[0] = 0f;
+ }
+
+ return new RGB(hsb[0], hsb[1], hsb[2]);
+ }
+
+ private static Color createNewSaturatedColor(Color c, float saturation) {
+ RGB newRGB = saturate(c.getRGB(), saturation);
+ return new Color(Display.getCurrent(), newRGB);
+ }
+}
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/CSSEngineHelper.java b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/CSSEngineHelper.java
new file mode 100644
index 0000000..4bd6437
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/CSSEngineHelper.java
@@ -0,0 +1,66 @@
+package org.eclipse.nebula.widgets.pshelf.css.internal;
+
+import org.eclipse.e4.ui.services.IStylingEngine;
+import org.eclipse.nebula.widgets.pshelf.css.CSSShelfRenderer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Control;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSValue;
+import org.w3c.dom.css.RGBColor;
+
+public class CSSEngineHelper {
+ Control control;
+ IStylingEngine engine;
+ CSSStyleDeclaration style;
+ CSSShelfRenderer renderer;
+
+ public CSSEngineHelper(IStylingEngine engine, Control control, CSSShelfRenderer renderer) {
+ this.engine = engine;
+ this.control = control;
+ this.renderer = renderer;
+ initialize();
+ }
+
+ private void initialize() {
+ if (engine != null) {
+ style = engine.getStyle(control);
+ }
+ }
+
+ public Color getBaseColorSelected() {
+ if( style == null ) {
+ return control.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
+ }
+ return getColor(style.getPropertyCSSValue("pshelf-basecolor-selected"), control.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
+ }
+
+ public Color getBaseColorUnselected() {
+ if( style == null ) {
+ return control.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
+ }
+ return getColor(style.getPropertyCSSValue("pshelf-basecolor-unselected"), control.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
+ }
+
+ public Color getBaseColorHover() {
+ if( style == null ) {
+ return control.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
+ }
+ return getColor(style.getPropertyCSSValue("pshelf-basecolor-hover"), control.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
+ }
+
+ private Color getColor(CSSValue value, Color defaultValue) {
+ if( value instanceof RGBColor ) {
+ RGBColor rgbValue = (RGBColor) value;
+ RGB rgb = new RGB(
+ Integer.parseInt(rgbValue.getRed().getCssText()),
+ Integer.parseInt(rgbValue.getGreen().getCssText()),
+ Integer.parseInt(rgbValue.getBlue().getCssText()));
+ return new Color(control.getDisplay(), rgb);
+ }
+
+
+ return defaultValue;
+ }
+}
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElement.java b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElement.java
new file mode 100644
index 0000000..33229fe
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElement.java
@@ -0,0 +1,14 @@
+package org.eclipse.nebula.widgets.pshelf.css.internal;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.CompositeElement;
+import org.eclipse.nebula.widgets.pshelf.PShelf;
+
+@SuppressWarnings("restriction")
+public class PShelfElement extends CompositeElement {
+
+ public PShelfElement(PShelf composite, CSSEngine engine) {
+ super(composite, engine);
+ }
+
+}
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElementProvider.java b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElementProvider.java
new file mode 100644
index 0000000..d0fe6ce
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfElementProvider.java
@@ -0,0 +1,16 @@
+package org.eclipse.nebula.widgets.pshelf.css.internal;
+
+import org.eclipse.e4.ui.css.core.dom.IElementProvider;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.nebula.widgets.pshelf.PShelf;
+import org.w3c.dom.Element;
+
+@SuppressWarnings("restriction")
+public class PShelfElementProvider implements IElementProvider {
+
+ @Override
+ public Element getElement(Object element, CSSEngine engine) {
+ return new PShelfElement((PShelf) element, engine);
+ }
+
+}
diff --git a/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfPropertyHandler.java b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfPropertyHandler.java
new file mode 100644
index 0000000..1175c83
--- /dev/null
+++ b/widgets/pshelf/org.eclipse.nebula.widgets.pshelf.css/src/org/eclipse/nebula/widgets/pshelf/css/internal/PShelfPropertyHandler.java
@@ -0,0 +1,48 @@
+package org.eclipse.nebula.widgets.pshelf.css.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.nebula.widgets.pshelf.AbstractRenderer;
+import org.eclipse.nebula.widgets.pshelf.PShelf;
+import org.eclipse.nebula.widgets.pshelf.css.CSSShelfRenderer;
+import org.w3c.dom.css.CSSValue;
+
+@SuppressWarnings("restriction")
+public class PShelfPropertyHandler implements ICSSPropertyHandler {
+ private Map<PShelf, Boolean> scheduled = new HashMap<>();
+
+ @Override
+ public boolean applyCSSProperty(Object element, String property,
+ CSSValue value, String pseudo, CSSEngine engine) throws Exception {
+ final PShelf s = (PShelf)((PShelfElement)element).getNativeWidget();
+ final AbstractRenderer r = s.getRenderer();
+
+ if( r instanceof CSSShelfRenderer ) {
+ if( ! scheduled.containsKey(s) ) {
+ scheduled.put(s, Boolean.TRUE);
+ // Queue the changes
+ s.getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ if( ! s.isDisposed() && ! r.isDisposed() ) {
+ scheduled.remove(s);
+ ((CSSShelfRenderer) r).reinitialize();
+ }
+ }
+ });
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String retrieveCSSProperty(Object element, String property,
+ String pseudo, CSSEngine engine) throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+} \ No newline at end of file