Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2013 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 |
|
12 |
package org.eclipse.ui.internal.themes; |
13 |
|
14 |
import java.util.Hashtable; |
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 |
import org.eclipse.ui.themes.ColorUtil; |
20 |
import org.eclipse.ui.themes.IColorFactory; |
21 |
|
22 |
/** |
23 |
* @since 4.2 |
24 |
* |
25 |
*/ |
26 |
public class RGBBrightnessColorFactory implements IColorFactory, IExecutableExtension { |
27 |
|
28 |
String color, scaleFactor; |
29 |
|
30 |
/* (non-Javadoc) |
31 |
* @see org.eclipse.ui.themes.IColorFactory#createColor() |
32 |
*/ |
33 |
public RGB createColor() { |
34 |
RGB finalRGB = new RGB(0, 0, 0); |
35 |
try { |
36 |
if (color != null && scaleFactor != null) { |
37 |
RGB rgb = ColorUtil.getColorValue(color); |
38 |
float scale = Float.parseFloat(scaleFactor); |
39 |
float[] hsb = rgb.getHSB(); |
40 |
hsb[2] *= scale; |
41 |
if (hsb[2] < 0) |
42 |
hsb[2] = 0; |
43 |
if (hsb[2] > 255) |
44 |
hsb[2] = 255; |
45 |
finalRGB = new RGB(hsb[0], hsb[1], hsb[2]); |
46 |
} |
47 |
} catch (NumberFormatException ex) { |
48 |
} |
49 |
|
50 |
return finalRGB; |
51 |
} |
52 |
|
53 |
/** |
54 |
* This executable extension requires parameters to be explicitly declared |
55 |
* via the second method described in the <code>IExecutableExtension</code> |
56 |
* documentation. This class expects that there will be two parameters, |
57 |
* <code>color</code> that describe the color to be blended (this values may |
58 |
* either be RGB triples or SWT constants) and <code>scaleFactor</code> |
59 |
* which is the brightness scale factor with 1.0 having the same brightness |
60 |
* as the original color. |
61 |
* |
62 |
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, |
63 |
* java.lang.String, java.lang.Object) |
64 |
*/ |
65 |
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) |
66 |
throws CoreException { |
67 |
if (data instanceof Hashtable) { |
68 |
Hashtable table = (Hashtable) data; |
69 |
color = (String) table.get("color"); //$NON-NLS-1$ |
70 |
scaleFactor = (String) table.get("scaleFactor"); //$NON-NLS-1$ |
71 |
} |
72 |
} |
73 |
|
74 |
} |