1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.ui.gfx;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.swt.graphics.ImageData;
16 import org.eclipse.swt.graphics.PaletteData;
19 * Colored rectangle with black borders.
21 * @author toni.kalajainen
23 public class ColorImageDescriptor extends ImageDescriptor {
24 static final PaletteData PALETTEDATA = new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff);
31 public ColorImageDescriptor(int red, int green, int blue, int width, int height, boolean selected)
33 c = (red<<16) | (green<<8) | (blue);
36 this.selected = selected;
40 public ImageData getImageData() {
41 ImageData id = new ImageData(width, height, 24, PALETTEDATA);
44 int dst = height * width / 23;
45 for (int x=0; x<width; x++) {
46 for (int y=0; y<height; y++) {
48 boolean border = x==0||x==width-1||y==0||y==height-1;
49 if ( border ) color = 0;
51 int dist = (x-cx)*(x-cx)+(y-cy)*(y-cy);
52 if ( dist < dst ) color = 0xcccccc;
54 id.setPixel(x, y, color);
62 public int hashCode() {
63 return c + 7*width + 13*height + (selected?234234:4235);
67 public boolean equals(Object obj) {
68 if ( obj instanceof ColorImageDescriptor == false ) return false;
69 ColorImageDescriptor other = (ColorImageDescriptor) obj;
70 if ( other.width!=width ) return false;
71 if ( other.height!=height ) return false;
72 if ( other.c!=c ) return false;
73 if ( other.selected!=selected ) return false;