Bug 487856 - ImageProxy needs to support Palette
Change-Id: I3913e9df8855946677057065c3b5ff276c6153fe
diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/scm/SCMLabelProvider.java b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/scm/SCMLabelProvider.java
index 28f9ec2..c4417c5 100644
--- a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/scm/SCMLabelProvider.java
+++ b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/views/scm/SCMLabelProvider.java
@@ -48,6 +48,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
/**
@@ -244,15 +245,23 @@
initProxy(proxy);
}
final ImageProxy imageProxy = proxy.getImage();
- final ImageData imageData = new ImageData(imageProxy.getWidth(),
- imageProxy.getHeight(),
- imageProxy.getDepth(),
- new PaletteData(imageProxy.getRedMask(), imageProxy.getGreenMask(), imageProxy.getBlueMask()),
- imageProxy.getScanlinePad(),
- imageProxy.getData());
+ final ImageData imageData = new ImageData(imageProxy.getWidth(), imageProxy.getHeight(), imageProxy.getDepth(),
+ createPaletteData(imageProxy), imageProxy.getScanlinePad(), imageProxy.getData());
return imageData;
}
+ private PaletteData createPaletteData(final ImageProxy imageProxy) {
+ if (imageProxy.isDirect()) {
+ return new PaletteData(imageProxy.getRedMask(), imageProxy.getGreenMask(), imageProxy.getBlueMask());
+ }
+ final RGB[] colors = new RGB[imageProxy.getPaletteColors().length];
+ for (int i = 0; i < imageProxy.getPaletteColors().length; i++) {
+ final ImageProxy.RGB rgb = imageProxy.getPaletteColors()[i];
+ colors[i] = new RGB(rgb.getRed(), rgb.getGreen(), rgb.getBlue());
+ }
+ return new PaletteData(colors);
+ }
+
private void initProxy(OperationProxy proxy) {
final FileBasedChangePackage changePackage = getChangePackage(proxy);
final AbstractOperation operation = changePackage.get(proxy.getIndex());
diff --git a/bundles/org.eclipse.emf.emfstore.server.model/src/org/eclipse/emf/emfstore/internal/server/model/versioning/ImageProxy.java b/bundles/org.eclipse.emf.emfstore.server.model/src/org/eclipse/emf/emfstore/internal/server/model/versioning/ImageProxy.java
index 2f3fff6..2a0a767 100644
--- a/bundles/org.eclipse.emf.emfstore.server.model/src/org/eclipse/emf/emfstore/internal/server/model/versioning/ImageProxy.java
+++ b/bundles/org.eclipse.emf.emfstore.server.model/src/org/eclipse/emf/emfstore/internal/server/model/versioning/ImageProxy.java
@@ -12,13 +12,63 @@
package org.eclipse.emf.emfstore.internal.server.model.versioning;
/**
- * Proxy for an ImageData object in order to avoid depdendency to SWT.
+ * Proxy for an ImageData object in order to avoid dependency to SWT.
*
* @author emueller
*
*/
public final class ImageProxy {
+ /**
+ * Helper class for representing RGB values.
+ */
+ public static class RGB {
+ private final int red;
+ private final int green;
+ private final int blue;
+
+ /**
+ * Value constructor for a RGB value.
+ *
+ * @param red the red value
+ * @param green the green value
+ * @param blue the blue value
+ */
+ public RGB(int red, int green, int blue) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ }
+
+ /**
+ * Returns the red value.
+ *
+ * @return the red value
+ */
+ public int getRed() {
+ return red;
+ }
+
+ /**
+ * Returns the green value.
+ *
+ * @return the green value
+ */
+ public int getGreen() {
+ return green;
+ }
+
+ /**
+ * Returns the blue value.
+ *
+ * @return the blue value
+ */
+ public int getBlue() {
+ return blue;
+ }
+
+ }
+
private int width;
private int height;
private int depth;
@@ -27,6 +77,8 @@
private int redMask;
private int greenMask;
private int blueMask;
+ private boolean direct = true;
+ private RGB[] paletteColors;
private ImageProxy() {
@@ -198,4 +250,34 @@
return this;
}
+ /**
+ * Set palette colors, the palette direct flag is set to false.
+ *
+ * @param colors colors to set
+ * @return this {@link ImageProxy}
+ */
+ public ImageProxy setPaletteColors(RGB[] colors) {
+ paletteColors = colors;
+ direct = false;
+ return this;
+ }
+
+ /**
+ * Returns the palette colors.
+ *
+ * @return the palette colors
+ */
+ public RGB[] getPaletteColors() {
+ return paletteColors;
+ }
+
+ /**
+ * Whether this is a palette is direct.
+ *
+ * @return {@code true}, if this palette is direct, {@code false} otherwise.
+ */
+ public boolean isDirect() {
+ return direct;
+ }
+
}