Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 180415 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/themes/ColorSelectionFactory.java (-98 lines)
Removed 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
 * ColorSelectionFactory is the abstract superclass of factories that compare
24
 * two colors.
25
 * 
26
 * @since 3.3
27
 * 
28
 */
29
public abstract class ColorSelectionFactory implements IColorFactory,
30
		IExecutableExtension {
31
32
	String color1;
33
	String color2;
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 two parameters,
39
	 * <code>color1</code> and <code>color2</code>, that describe the two
40
	 * colors to be compared. These values may either be RGB triples or SWT
41
	 * constants.
42
	 * 
43
	 * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
44
	 *      java.lang.String, java.lang.Object)
45
	 */
46
	public void setInitializationData(IConfigurationElement config,
47
			String propertyName, Object data) {
48
49
		if (data instanceof Hashtable) {
50
			Hashtable table = (Hashtable) data;
51
			color1 = (String) table.get("color1"); //$NON-NLS-1$
52
			color2 = (String) table.get("color2"); //$NON-NLS-1$            
53
		}
54
	}
55
56
	/**
57
	 * Return the difference of the two
58
	 * 
59
	 * @param rgb1
60
	 * @param rgb2
61
	 * @return int if the difference is positive rgb1 is darker, if negative
62
	 *         rgb2 is darker.
63
	 */
64
	protected int difference(RGB rgb1, RGB rgb2) {
65
66
		return (rgb1.blue - rgb2.blue) + (rgb1.red - rgb2.red)
67
				+ (rgb1.green - rgb2.green);
68
	}
69
70
	/*
71
	 * (non-Javadoc)
72
	 * 
73
	 * @see org.eclipse.ui.themes.IColorFactory#createColor()
74
	 */
75
	public RGB createColor() {
76
		if (color1 == null && color2 == null) {
77
			return new RGB(0, 0, 0);
78
		} else if (color1 != null && color2 == null) {
79
			return ColorUtil.getColorValue(color1);
80
		} else if (color1 == null && color2 != null) {
81
			return ColorUtil.getColorValue(color2);
82
		} else {
83
			RGB rgb1 = ColorUtil.getColorValue(color1);
84
			RGB rgb2 = ColorUtil.getColorValue(color2);
85
			return compare(rgb1, rgb2);
86
		}
87
	}
88
89
	/**
90
	 * Compare the two {@link RGB} instances and return one of them.
91
	 * 
92
	 * @param rgb1
93
	 * @param rgb2
94
	 * @return {@link RGB}
95
	 */
96
	abstract RGB compare(RGB rgb1, RGB rgb2);
97
98
}
(-)Eclipse UI/org/eclipse/ui/internal/themes/LightColorSelectionFactory.java (-35 lines)
Removed 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 org.eclipse.swt.graphics.RGB;
15
16
/**
17
 * LightColorSelectionFactory is a factory that returns the lighter of two
18
 * {@link RGB} instances.
19
 * 
20
 * @since 3.3
21
 * 
22
 */
23
24
public class LightColorSelectionFactory extends ColorSelectionFactory {
25
26
	/* (non-Javadoc)
27
	 * @see org.eclipse.ui.internal.themes.ColorSelectionFactory#compare(org.eclipse.swt.graphics.RGB, org.eclipse.swt.graphics.RGB)
28
	 */
29
	RGB compare(RGB rgb1, RGB rgb2) {
30
		if (difference(rgb1, rgb2) > 0)
31
			return rgb1;
32
		return rgb2;
33
	}
34
35
}
(-)Eclipse UI/org/eclipse/ui/internal/themes/DarkColorSelectionFactory.java (-38 lines)
Removed 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 org.eclipse.swt.graphics.RGB;
15
16
/**
17
 * DarkColorSelectionFactory is a factory that returns the darker of two
18
 * {@link RGB} instances.
19
 * 
20
 * @since 3.3
21
 * 
22
 */
23
24
public class DarkColorSelectionFactory extends ColorSelectionFactory {
25
26
	/*
27
	 * (non-Javadoc)
28
	 * 
29
	 * @see org.eclipse.ui.internal.themes.ColorSelectionFactory#compare(org.eclipse.swt.graphics.RGB,
30
	 *      org.eclipse.swt.graphics.RGB)
31
	 */
32
	RGB compare(RGB rgb1, RGB rgb2) {
33
		if (difference(rgb1, rgb2) > 0)
34
			return rgb2;
35
		return rgb1;
36
	}
37
38
}
(-)Eclipse (+126 lines)
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
}
(-)plugin.xml (-17 / +12 lines)
Lines 1189-1195 Link Here
1189
      <colorDefinition
1189
      <colorDefinition
1190
            label="%Color.activeTabText"
1190
            label="%Color.activeTabText"
1191
            categoryId="org.eclipse.ui.presentation.default"
1191
            categoryId="org.eclipse.ui.presentation.default"
1192
            value="COLOR_TITLE_FOREGROUND"
1192
            value="COLOR_WIDGET_FOREGROUND"
1193
            id="org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR">
1193
            id="org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR">
1194
         <description>
1194
         <description>
1195
            %Color.activeTabTextDesc
1195
            %Color.activeTabTextDesc
Lines 1202-1209 Link Here
1202
      <colorDefinition
1202
      <colorDefinition
1203
            categoryId="org.eclipse.ui.presentation.default"
1203
            categoryId="org.eclipse.ui.presentation.default"
1204
            id="org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"
1204
            id="org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"
1205
            label="%Color.activeTabBGEnd"
1205
            label="%Color.activeTabBGEnd">
1206
            >
1207
         <description>
1206
         <description>
1208
            %Color.activeTabBGEndDesc
1207
            %Color.activeTabBGEndDesc
1209
         </description>
1208
         </description>
Lines 1212-1226 Link Here
1212
               value="COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT">
1211
               value="COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT">
1213
         </colorValue>
1212
         </colorValue>
1214
         <colorFactory
1213
         <colorFactory
1215
               class="org.eclipse.ui.internal.themes.DarkColorSelectionFactory"
1214
               class="org.eclipse.ui.internal.themes.LightColorFactory"
1216
               plugin="org.eclipse.ui">
1215
               plugin="org.eclipse.ui">
1217
          <parameter
1216
          <parameter
1218
                  name="color1"
1217
                  name="base" value="COLOR_TITLE_BACKGROUND">
1219
                  value="COLOR_TITLE_BACKGROUND_GRADIENT">
1220
          </parameter>
1218
          </parameter>
1221
          <parameter
1219
          <parameter
1222
                  name="color2"
1220
                  name="definitionId" value="org.eclipse.ui.workbench.ACTIVE_TAB_BG_END">
1223
                  value="COLOR_TITLE_BACKGROUND">
1224
          </parameter>
1221
          </parameter>
1225
         </colorFactory>
1222
         </colorFactory>
1226
      </colorDefinition>
1223
      </colorDefinition>
Lines 1236-1251 Link Here
1236
               value="COLOR_TITLE_INACTIVE_BACKGROUND">
1233
               value="COLOR_TITLE_INACTIVE_BACKGROUND">
1237
         </colorValue>
1234
         </colorValue>
1238
         <colorFactory
1235
         <colorFactory
1239
               class="org.eclipse.ui.internal.themes.LightColorSelectionFactory"
1236
               class="org.eclipse.ui.internal.themes.LightColorFactory"
1240
               plugin="org.eclipse.ui">
1237
               plugin="org.eclipse.ui">
1241
            <parameter
1238
          <parameter
1242
                  name="color1"
1239
                  name="base" value="COLOR_TITLE_BACKGROUND">
1243
                  value="COLOR_TITLE_BACKGROUND_GRADIENT">
1240
          </parameter>
1244
            </parameter>
1241
          <parameter
1245
            <parameter
1242
                  name="definitionId" value="org.eclipse.ui.workbench.ACTIVE_TAB_BG_START">
1246
                  name="color2"
1243
          </parameter>
1247
                  value="COLOR_TITLE_BACKGROUND">
1248
            </parameter>
1249
         </colorFactory>
1244
         </colorFactory>
1250
      </colorDefinition>
1245
      </colorDefinition>
1251
<!-- Active (Nofocus) Tab Colors -->
1246
<!-- Active (Nofocus) Tab Colors -->

Return to bug 180415