|
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.ColorUtil; |
| 20 |
import org.eclipse.ui.themes.IColorFactory; |
| 21 |
|
| 22 |
/** |
| 23 |
* LightColorFactory returns tab begin and end colours based on taking |
| 24 |
* a system color as input, analyzing it, and lightening it appropriately. |
| 25 |
* |
| 26 |
* @since 3.3 |
| 27 |
* |
| 28 |
*/ |
| 29 |
public class LightColorFactory implements IColorFactory, |
| 30 |
IExecutableExtension { |
| 31 |
|
| 32 |
protected static final RGB white = new RGB(255, 255, 255); |
| 33 |
|
| 34 |
String baseColorName; |
| 35 |
String definitionId; |
| 36 |
|
| 37 |
/** |
| 38 |
* This executable extension requires parameters to be explicitly declared |
| 39 |
* via the second method described in the <code>IExecutableExtension</code> |
| 40 |
* documentation. The following parameters are parsed: |
| 41 |
* <code>base</code>, describes the base color to produce all other colours from. |
| 42 |
* This value may either be an RGB triple or an SWT constant. |
| 43 |
* <code>definitionId</code>, describes the id of color we are looking for, one of |
| 44 |
* "org.eclipse.ui.workbench.ACTIVE_TAB_BG_START" |
| 45 |
* "org.eclipse.ui.workbench.ACTIVE_TAB_BG_END" |
| 46 |
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, |
| 47 |
* java.lang.String, java.lang.Object) |
| 48 |
*/ |
| 49 |
public void setInitializationData(IConfigurationElement config, |
| 50 |
String propertyName, Object data) { |
| 51 |
|
| 52 |
if (data instanceof Hashtable) { |
| 53 |
Hashtable table = (Hashtable) data; |
| 54 |
baseColorName = (String) table.get("base"); //$NON-NLS-1$ |
| 55 |
definitionId = (String) table.get("definitionId"); //$NON-NLS-1$ |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
/* |
| 60 |
* Return the number of RGB values in test that are |
| 61 |
* equal to or between lower and upper. |
| 62 |
*/ |
| 63 |
protected int valuesInRange(RGB test, int lower, int upper) { |
| 64 |
int hits = 0; |
| 65 |
if(test.red >= lower && test.red <= upper) hits++; |
| 66 |
if(test.blue >= lower && test.blue <= upper) hits++; |
| 67 |
if(test.green >= lower && test.green <= upper) hits++; |
| 68 |
|
| 69 |
return hits; |
| 70 |
} |
| 71 |
|
| 72 |
/* |
| 73 |
* Return the RGB value for the bottom tab color |
| 74 |
* based on a blend of white and sample color |
| 75 |
*/ |
| 76 |
private RGB getLightenedColor(RGB sample) { |
| 77 |
//Group 1 |
| 78 |
if(valuesInRange(sample, 180, 255) >= 2) |
| 79 |
return sample; |
| 80 |
|
| 81 |
//Group 2 |
| 82 |
if(valuesInRange(sample, 100, 179) >= 2) |
| 83 |
return ColorUtil.blend(white, sample, 30); |
| 84 |
|
| 85 |
//Group 3 |
| 86 |
if(valuesInRange(sample, 0, 99) >= 2) |
| 87 |
return ColorUtil.blend(white, sample, 60); |
| 88 |
|
| 89 |
//Group 4 |
| 90 |
return ColorUtil.blend(white, sample, 30); |
| 91 |
} |
| 92 |
|
| 93 |
/* |
| 94 |
* Return the Start (top of tab) color as an RGB |
| 95 |
*/ |
| 96 |
private RGB createStartColor() { |
| 97 |
return ColorUtil.blend(white, createEndColor(), 75); |
| 98 |
} |
| 99 |
|
| 100 |
/* |
| 101 |
* Return the End (top of tab) color as an RGB |
| 102 |
*/ |
| 103 |
private RGB createEndColor() { |
| 104 |
return getLightenedColor( |
| 105 |
ColorUtil.getColorValue(baseColorName)); |
| 106 |
} |
| 107 |
|
| 108 |
/* |
| 109 |
* (non-Javadoc) |
| 110 |
* |
| 111 |
* @see org.eclipse.ui.themes.IColorFactory#createColor() |
| 112 |
*/ |
| 113 |
public RGB createColor() { |
| 114 |
//should have base, otherwise error in the xml |
| 115 |
if (baseColorName == null || definitionId == null) |
| 116 |
return white; |
| 117 |
|
| 118 |
if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START")) //$NON-NLS-1$ |
| 119 |
return createStartColor(); |
| 120 |
if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END")) //$NON-NLS-1$ |
| 121 |
return createEndColor(); |
| 122 |
|
| 123 |
//should be one of start or end, otherwise error in the xml |
| 124 |
return white; |
| 125 |
} |
| 126 |
} |