KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > themes > RGBBlendColorFactory


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.themes;
12
13 import java.util.Hashtable JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExecutableExtension;
18 import org.eclipse.swt.graphics.RGB;
19
20 /**
21  * A resuable <code>IColorFactory</code> that may be used to blend two colors.
22  * The colors to blend are specified as per method number two in
23  * {@link org.eclipse.core.runtime.IExecutableExtension}.
24  * <p>
25  * Example usage:
26  * <br/>
27  * <code>
28  * &lt;colorDefinition
29  * label="Red/Blue Blend"
30  * id="example.redblueblend"&gt;
31  * &lt;colorFactory
32  * plugin="org.eclipse.ui"
33  * class="org.eclipse.ui.themes.RGBBlendColorFactory"&gt;
34  * &lt;parameter name="color1" value="255,0,0" /&gt;
35  * &lt;parameter name="color2" value="COLOR_BLUE" /&gt;
36  * &lt;/colorFactory&gt;
37  * &lt;/colorDefinition&gt;
38  * </code>
39  * </p>
40  *
41  * <p>
42  * The color values may be specified as RGB triples or as SWT constants.
43  * </p>
44  *
45  * @see org.eclipse.swt.SWT
46  * @since 3.0
47  */

48 public class RGBBlendColorFactory implements IColorFactory,
49         IExecutableExtension {
50
51     private String JavaDoc color1, color2;
52
53     /* (non-Javadoc)
54      * @see org.eclipse.ui.themes.IColorFactory#createColor()
55      */

56     public RGB createColor() {
57         if (color1 == null && color2 == null) {
58             return new RGB(0, 0, 0);
59         } else if (color1 != null && color2 == null) {
60             return ColorUtil.getColorValue(color1);
61         } else if (color1 == null && color2 != null) {
62             return ColorUtil.getColorValue(color2);
63         } else {
64             RGB rgb1 = ColorUtil.getColorValue(color1);
65             RGB rgb2 = ColorUtil.getColorValue(color2);
66             return ColorUtil.blend(rgb1, rgb2);
67         }
68     }
69
70     /**
71      * This executable extension requires parameters to be explicitly declared
72      * via the second method described in the <code>IExecutableExtension</code>
73      * documentation. This class expects that there will be two parameters,
74      * <code>color1</code> and <code>color2</code>, that describe the two colors
75      * to be blended. These values may either be RGB triples or SWT constants.
76      *
77      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
78      */

79     public void setInitializationData(IConfigurationElement config,
80             String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
81
82         if (data instanceof Hashtable JavaDoc) {
83             Hashtable JavaDoc table = (Hashtable JavaDoc) data;
84             color1 = (String JavaDoc) table.get("color1"); //$NON-NLS-1$
85
color2 = (String JavaDoc) table.get("color2"); //$NON-NLS-1$
86
}
87     }
88 }
89
Popular Tags