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