--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.utils.ui.gfx;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.swt.graphics.ImageData;\r
+import org.eclipse.swt.graphics.PaletteData;\r
+\r
+/**\r
+ * Colored rectangle with black borders.\r
+ * \r
+ * @author toni.kalajainen\r
+ */\r
+public class ColorImageDescriptor extends ImageDescriptor {\r
+ static final PaletteData PALETTEDATA = new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff);\r
+\r
+ int width;\r
+ int height;\r
+ int c;\r
+ boolean selected;\r
+ \r
+ public ColorImageDescriptor(int red, int green, int blue, int width, int height, boolean selected)\r
+ {\r
+ c = (red<<16) | (green<<8) | (blue);\r
+ this.width = width;\r
+ this.height = height;\r
+ this.selected = selected;\r
+ }\r
+\r
+ @Override\r
+ public ImageData getImageData() {\r
+ ImageData id = new ImageData(width, height, 24, PALETTEDATA);\r
+ int cx = width / 2;\r
+ int cy = height / 2;\r
+ int dst = height * width / 23;\r
+ for (int x=0; x<width; x++) {\r
+ for (int y=0; y<height; y++) {\r
+ int color = c;\r
+ boolean border = x==0||x==width-1||y==0||y==height-1;\r
+ if ( border ) color = 0;\r
+ if (selected) {\r
+ int dist = (x-cx)*(x-cx)+(y-cy)*(y-cy);\r
+ if ( dist < dst ) color = 0xcccccc; \r
+ }\r
+ id.setPixel(x, y, color);\r
+ }\r
+ }\r
+ \r
+ return id;\r
+ }\r
+ \r
+ @Override\r
+ public int hashCode() {\r
+ return c + 7*width + 13*height + (selected?234234:4235);\r
+ }\r
+ \r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if ( obj instanceof ColorImageDescriptor == false ) return false;\r
+ ColorImageDescriptor other = (ColorImageDescriptor) obj;\r
+ if ( other.width!=width ) return false;\r
+ if ( other.height!=height ) return false;\r
+ if ( other.c!=c ) return false;\r
+ if ( other.selected!=selected ) return false;\r
+ return true;\r
+ }\r
+ \r
+}\r