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