1 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.swt.widgets.Display; 20 import org.eclipse.ui.themes.ColorUtil; 21 import org.eclipse.ui.themes.IColorFactory; 22 23 30 public class LightColorFactory implements IColorFactory, 31 IExecutableExtension { 32 33 protected static final RGB white = ColorUtil.getColorValue("COLOR_WHITE"); protected static final RGB black = ColorUtil.getColorValue("COLOR_BLACK"); 36 String baseColorName; 37 String definitionId; 38 39 43 44 public static RGB createHighlightStartColor(RGB tabStartColor) { 45 return ColorUtil.blend(white, tabStartColor); 46 } 47 48 60 public void setInitializationData(IConfigurationElement config, 61 String propertyName, Object data) { 62 63 if (data instanceof Hashtable ) { 64 Hashtable table = (Hashtable ) data; 65 baseColorName = (String ) table.get("base"); definitionId = (String ) table.get("definitionId"); } 68 } 69 70 74 protected int valuesInRange(RGB test, int lower, int upper) { 75 int hits = 0; 76 if(test.red >= lower && test.red <= upper) hits++; 77 if(test.blue >= lower && test.blue <= upper) hits++; 78 if(test.green >= lower && test.green <= upper) hits++; 79 80 return hits; 81 } 82 83 87 private RGB getLightenedColor(RGB sample) { 88 if(valuesInRange(sample, 180, 255) >= 2) 90 return sample; 91 92 if(valuesInRange(sample, 100, 179) >= 2) 94 return ColorUtil.blend(white, sample, 40); 95 96 if(valuesInRange(sample, 0, 99) >= 2) 98 return ColorUtil.blend(white, sample, 60); 99 100 return ColorUtil.blend(white, sample, 30); 102 } 103 104 107 private RGB getActiveFocusStartColor() { 108 if (Display.getCurrent().getDepth() < 15) 109 return getActiveFocusEndColor(); 110 111 RGB startColor = ColorUtil.blend(white, getActiveFocusEndColor(), 75); 112 return startColor; 113 } 114 115 118 private RGB getActiveFocusEndColor() { 119 if (Display.getCurrent().getDepth() < 15) 120 return ColorUtil.getColorValue(baseColorName); 121 122 return getLightenedColor( 123 ColorUtil.getColorValue(baseColorName)); 124 } 125 126 129 private RGB getActiveFocusTextColor() { 130 if (Display.getCurrent().getDepth() < 15) 131 return ColorUtil.getColorValue(baseColorName); 133 return ColorUtil.getColorValue("COLOR_BLACK"); } 135 138 private RGB getActiveNofocusStartColor() { 139 RGB base = ColorUtil.getColorValue(baseColorName); 140 if (Display.getCurrent().getDepth() < 15) 141 return base; 142 143 return ColorUtil.blend(white, base, 40); 144 } 145 146 151 public RGB createColor() { 152 if (baseColorName == null || definitionId == null) 154 return white; 155 156 if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START")) return getActiveFocusStartColor(); 158 if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END")) return getActiveFocusEndColor(); 160 if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")) return getActiveFocusTextColor(); 162 if (definitionId.equals("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START")) return getActiveNofocusStartColor(); 164 165 return white; 167 } 168 } 169 | Popular Tags |