01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.themes;
11:
12: import java.util.Hashtable;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IConfigurationElement;
16: import org.eclipse.core.runtime.IExecutableExtension;
17: import org.eclipse.swt.graphics.RGB;
18:
19: /**
20: * A resuable <code>IColorFactory</code> that may be used to blend two colors.
21: * The colors to blend are specified as per method number two in
22: * {@link org.eclipse.core.runtime.IExecutableExtension}.
23: * <p>
24: * Example usage:
25: * <br/>
26: * <code>
27: * <colorDefinition
28: * label="Red/Blue Blend"
29: * id="example.redblueblend">
30: * <colorFactory
31: * plugin="org.eclipse.ui"
32: * class="org.eclipse.ui.themes.RGBBlendColorFactory">
33: * <parameter name="color1" value="255,0,0" />
34: * <parameter name="color2" value="COLOR_BLUE" />
35: * </colorFactory>
36: * </colorDefinition>
37: * </code>
38: * </p>
39: *
40: * <p>
41: * The color values may be specified as RGB triples or as SWT constants.
42: * </p>
43: *
44: * @see org.eclipse.swt.SWT
45: * @since 3.0
46: */
47: public class RGBBlendColorFactory implements IColorFactory,
48: IExecutableExtension {
49:
50: private String color1, color2;
51:
52: /* (non-Javadoc)
53: * @see org.eclipse.ui.themes.IColorFactory#createColor()
54: */
55: public RGB createColor() {
56: if (color1 == null && color2 == null) {
57: return new RGB(0, 0, 0);
58: } else if (color1 != null && color2 == null) {
59: return ColorUtil.getColorValue(color1);
60: } else if (color1 == null && color2 != null) {
61: return ColorUtil.getColorValue(color2);
62: } else {
63: RGB rgb1 = ColorUtil.getColorValue(color1);
64: RGB rgb2 = ColorUtil.getColorValue(color2);
65: return ColorUtil.blend(rgb1, rgb2);
66: }
67: }
68:
69: /**
70: * This executable extension requires parameters to be explicitly declared
71: * via the second method described in the <code>IExecutableExtension</code>
72: * documentation. This class expects that there will be two parameters,
73: * <code>color1</code> and <code>color2</code>, that describe the two colors
74: * to be blended. These values may either be RGB triples or SWT constants.
75: *
76: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
77: */
78: public void setInitializationData(IConfigurationElement config,
79: String propertyName, Object data) throws CoreException {
80:
81: if (data instanceof Hashtable) {
82: Hashtable table = (Hashtable) data;
83: color1 = (String) table.get("color1"); //$NON-NLS-1$
84: color2 = (String) table.get("color2"); //$NON-NLS-1$
85: }
86: }
87: }
|