KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > util > ColorUtil


1 /*
2  * Created on Jan 7, 2005
3  */

4 package com.nightlabs.rcp.util;
5
6 import org.eclipse.swt.graphics.Color;
7 import org.eclipse.swt.graphics.Device;
8 import org.eclipse.swt.graphics.RGB;
9 import org.eclipse.swt.widgets.Display;
10
11 /**
12  * @author Marco Schulze - marco at nightlabs dot de
13  */

14 public class ColorUtil extends com.nightlabs.util.ColorUtil
15 {
16
17     protected ColorUtil()
18     {
19     }
20
21     public static String JavaDoc rgbToString(RGB rgb)
22     {
23         return "RGBA{"
24                 + rgb.red + ','
25                 + rgb.green + ','
26                 + rgb.blue + ",255}"; // SWT RGB doesn't know alpha. We set it to 255 even though we could leave it out.
27
}
28
29     public static RGB stringToRGB(String JavaDoc color)
30     {
31         RGBA rgba = parseRGBA(color);
32         return new RGB(rgba.r, rgba.g, rgba.b);
33     }
34
35     public static String JavaDoc swtColorToString(Color color)
36     {
37         return "RGBA{"
38         + color.getRed() + ','
39         + color.getGreen() + ','
40         + color.getBlue() + ",255}"; // SWT Color doesn't know alpha. We set it to 255 even though we could leave it out.
41
}
42
43     /**
44      * <b>Important:</b> You must dispose the returned color when you don't need it
45      * anymore!
46      */

47     public static Color stringToSWTColor(String JavaDoc color)
48     {
49         RGBA rgba = parseRGBA(color);
50         return new Color(Display.getDefault(), rgba.r, rgba.g, rgba.b);
51     }
52
53     /**
54      * <b>Important:</b> You must dispose the returned color when you don't need it
55      * anymore!
56      */

57     public static Color stringToSWTColor(Device device, String JavaDoc color)
58     {
59         RGBA rgba = parseRGBA(color);
60         if (device == null)
61             device = Display.getDefault();
62         return new Color(device, rgba.r, rgba.g, rgba.b);
63     }
64 }
65
Popular Tags