]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorIconCreator.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / color / ColorIconCreator.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.utils.ui.color;\r
13 \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
18 \r
19 \r
20 \r
21 /**\r
22  * \r
23  * @author Marko Luukkainen\r
24  *\r
25  */\r
26 public class ColorIconCreator {\r
27 \r
28         /**\r
29          * Creates square image with defined color<br>\r
30          * Images created this way must be disposed<br>\r
31          * @param color\r
32          * @param size\r
33          * @return\r
34          */\r
35         public static Image createImage(Color color, int size, int style) {\r
36                 return createImage(color,size,size,style);\r
37         }\r
38         /**\r
39          * Creates rectangle image with defined color<br>\r
40          * Images created this way must be disposed<br>\r
41          * @param color\r
42          * @param width\r
43          * @param height\r
44          * @return\r
45          */\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
57         }\r
58         swtColor.dispose();\r
59         gc.dispose();\r
60                 return image;\r
61         }\r
62         \r
63 }\r