1 11 package org.eclipse.ui.internal.presentations.defaultpresentation; 12 13 import org.eclipse.jface.resource.JFaceResources; 14 import org.eclipse.swt.graphics.Color; 15 import org.eclipse.swt.graphics.Font; 16 import org.eclipse.swt.graphics.RGB; 17 import org.eclipse.ui.internal.IWorkbenchThemeConstants; 18 import org.eclipse.ui.internal.preferences.AbstractPropertyListener; 19 import org.eclipse.ui.internal.preferences.IPropertyMap; 20 import org.eclipse.ui.internal.preferences.PropertyUtil; 21 import org.eclipse.ui.internal.themes.LightColorFactory; 22 import org.eclipse.ui.presentations.StackPresentation; 23 24 27 public class DefaultThemeListener extends AbstractPropertyListener { 28 29 private DefaultTabFolder folder; 30 private IPropertyMap theme; 31 32 public DefaultThemeListener(DefaultTabFolder folder, IPropertyMap theme) { 33 this.folder = folder; 34 this.theme = theme; 35 } 36 37 private Color getColor(String id, Color defaultValue) { 38 Color value = (Color)theme.getValue(id, Color.class); 39 if (value == null) { 40 value = defaultValue; 41 } 42 43 return value; 44 } 45 46 private int getInt(String id, int defaultValue) { 47 Integer result = ((Integer )theme.getValue(id, Integer .class)); 48 49 if (result == null) { 50 return defaultValue; 51 } 52 53 return result.intValue(); 54 } 55 56 private boolean getBoolean(String id, boolean defaultValue) { 57 Boolean result = ((Boolean )theme.getValue(id, Boolean .class)); 58 59 if (result == null) { 60 return defaultValue; 61 } 62 63 return result.booleanValue(); 64 } 65 66 75 private boolean updateHighlightColor() { 76 if(! useHighlight()) 77 return false; 78 RGB newTabBegin = getColor(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START, null).getRGB(); 80 RGB newHighlight = LightColorFactory.createHighlightStartColor(newTabBegin); 81 JFaceResources.getColorRegistry().put(IWorkbenchThemeConstants.ACTIVE_TAB_HIGHLIGHT_START, newHighlight); 83 return true; 84 } 85 86 private boolean useHighlight() { 87 return PropertyUtil.get( 88 this.theme, 89 IWorkbenchThemeConstants.ACTIVE_TAB_HIGHLIGHT, 90 false); 91 } 92 93 public void update() { 94 Color[] activeFocusBackgroundColors = updateHighlightColor() 95 ? new Color[] { 96 getColor(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START, null), 97 getColor(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END, null), 98 JFaceResources.getColorRegistry().get(IWorkbenchThemeConstants.ACTIVE_TAB_HIGHLIGHT_START) 99 } 100 : new Color[] { 101 getColor(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START, null), 102 getColor(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END, null) 103 }; 104 105 folder.setColors(new DefaultTabFolderColors( 106 getColor(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR, null), 107 activeFocusBackgroundColors, 108 new int[] { 109 getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT, 0) }, 110 getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL, true)), 111 StackPresentation.AS_ACTIVE_FOCUS, true); 112 113 folder.setColors(new DefaultTabFolderColors( 114 getColor(IWorkbenchThemeConstants.ACTIVE_NOFOCUS_TAB_TEXT_COLOR, null), 115 new Color[] { 116 getColor(IWorkbenchThemeConstants.ACTIVE_NOFOCUS_TAB_BG_START, null), 117 getColor(IWorkbenchThemeConstants.ACTIVE_NOFOCUS_TAB_BG_END, null) 118 }, 119 new int[] { 120 getInt(IWorkbenchThemeConstants.ACTIVE_NOFOCUS_TAB_PERCENT, 0) }, 121 getBoolean(IWorkbenchThemeConstants.ACTIVE_NOFOCUS_TAB_VERTICAL, true)), 122 StackPresentation.AS_ACTIVE_FOCUS, false); 123 124 folder.setColors(new DefaultTabFolderColors( 125 getColor(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR, null), 126 new Color[] { 127 getColor(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START, null), 128 getColor(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END, null) }, 129 new int[] { 130 getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT, 0) }, 131 getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL, true)), 132 StackPresentation.AS_INACTIVE); 133 134 folder.setColors(new DefaultTabFolderColors( 135 getColor(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR, null), 136 new Color[] { 137 getColor(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START, null) }, 138 new int[0], 139 true), StackPresentation.AS_ACTIVE_NOFOCUS); 140 141 folder.setFont((Font)theme.getValue(IWorkbenchThemeConstants.TAB_TEXT_FONT, Font.class)); 142 } 143 144 } 145 | Popular Tags |