1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.color;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.GC;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.widgets.Display;
23 * @author Marko Luukkainen
26 public class ColorIconCreator {
29 * Creates square image with defined color<br>
30 * Images created this way must be disposed<br>
35 public static Image createImage(Color color, int size, int style) {
36 return createImage(color,size,size,style);
39 * Creates rectangle image with defined color<br>
40 * Images created this way must be disposed<br>
46 public static Image createImage(Color color, int width, int height, int style) {
47 Display display = Display.getCurrent();
48 Image image = new Image(display, width, height);
49 GC gc = new GC(image);
50 org.eclipse.swt.graphics.Color swtColor = new org.eclipse.swt.graphics.Color(display, color.getR(), color.getG(), color.getB());
51 gc.setBackground(swtColor);
52 gc.setForeground(swtColor);
53 gc.fillRectangle(0, 0, width, height);
54 if ((style & SWT.BORDER) > 0) {
55 gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
56 gc.drawRectangle(0, 0, width-1, height-1);