|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007 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 |
|
| 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.IColorFactory; |
| 20 |
|
| 21 |
/** |
| 22 |
* ColorSelectionFactory is the abstract superclass of factories that compare |
| 23 |
* two colors. |
| 24 |
* |
| 25 |
* @since 3.3 |
| 26 |
* |
| 27 |
*/ |
| 28 |
public abstract class KelvinColorFactory implements IColorFactory, |
| 29 |
IExecutableExtension { |
| 30 |
|
| 31 |
protected static final RGB white = new RGB(255, 255, 255); |
| 32 |
|
| 33 |
String baseColorName; |
| 34 |
|
| 35 |
/** |
| 36 |
* This executable extension requires parameters to be explicitly declared |
| 37 |
* via the second method described in the <code>IExecutableExtension</code> |
| 38 |
* documentation. This class expects that there will be one parameter, |
| 39 |
* <code>base</code>, that describes the base color to produce all other colours from. |
| 40 |
* This value may either be an RGB triple or an SWT constant. |
| 41 |
* |
| 42 |
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, |
| 43 |
* java.lang.String, java.lang.Object) |
| 44 |
*/ |
| 45 |
public void setInitializationData(IConfigurationElement config, |
| 46 |
String propertyName, Object data) { |
| 47 |
|
| 48 |
if (data instanceof Hashtable) { |
| 49 |
Hashtable table = (Hashtable) data; |
| 50 |
baseColorName = (String) table.get("base"); //$NON-NLS-1$ |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* Return the number of RGB values in test that are |
| 56 |
* equal to or between lower and upper. |
| 57 |
*/ |
| 58 |
protected int valuesInRange(RGB test, int lower, int upper) { |
| 59 |
int hits = 0; |
| 60 |
if(test.red >= lower && test.red <= upper) hits++; |
| 61 |
if(test.blue >= lower && test.blue <= upper) hits++; |
| 62 |
if(test.green >= lower && test.green <= upper) hits++; |
| 63 |
|
| 64 |
return hits; |
| 65 |
} |
| 66 |
|
| 67 |
/* |
| 68 |
* Return an RGB value that is a blend of prop/100 of color1 and |
| 69 |
* 100-prop of color2. |
| 70 |
*/ |
| 71 |
protected RGB blend(int prop1, RGB color1, RGB color2) { |
| 72 |
int prop2 = 100 - prop1; |
| 73 |
return new RGB( |
| 74 |
(color1.red * prop1 / 100) + (color2.red * prop2 / 100), |
| 75 |
(color1.green * prop1 / 100) + (color2.green * prop2 / 100), |
| 76 |
(color1.blue * prop1 / 100) + (color2.blue * prop2 / 100) |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
} |