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