|
Lines 14-22
Link Here
|
| 14 |
import java.util.Iterator; |
14 |
import java.util.Iterator; |
| 15 |
import java.util.Map; |
15 |
import java.util.Map; |
| 16 |
|
16 |
|
|
|
17 |
import org.eclipse.jface.resource.ColorRegistry; |
| 18 |
import org.eclipse.jface.resource.FontRegistry; |
| 19 |
import org.eclipse.jface.resource.JFaceResources; |
| 17 |
import org.eclipse.jface.util.IPropertyChangeListener; |
20 |
import org.eclipse.jface.util.IPropertyChangeListener; |
| 18 |
import org.eclipse.jface.util.ListenerList; |
21 |
import org.eclipse.jface.util.ListenerList; |
| 19 |
import org.eclipse.jface.util.PropertyChangeEvent; |
22 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
|
23 |
import org.eclipse.swt.graphics.FontData; |
| 24 |
import org.eclipse.swt.graphics.RGB; |
| 20 |
import org.eclipse.ui.PlatformUI; |
25 |
import org.eclipse.ui.PlatformUI; |
| 21 |
import org.eclipse.ui.internal.IPreferenceConstants; |
26 |
import org.eclipse.ui.internal.IPreferenceConstants; |
| 22 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
27 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
|
Lines 34-44
Link Here
|
| 34 |
private IThemeRegistry themeRegistry; |
39 |
private IThemeRegistry themeRegistry; |
| 35 |
private static WorkbenchThemeManager instance; |
40 |
private static WorkbenchThemeManager instance; |
| 36 |
|
41 |
|
|
|
42 |
private ColorRegistry defaultThemeColorRegistry; |
| 43 |
private FontRegistry defaultThemeFontRegistry; |
| 44 |
|
| 37 |
/* |
45 |
/* |
| 38 |
* Call dispose when we close |
46 |
* Call dispose when we close |
| 39 |
*/ |
47 |
*/ |
| 40 |
private WorkbenchThemeManager () { |
48 |
private WorkbenchThemeManager () { |
| 41 |
//no-op |
49 |
defaultThemeColorRegistry = new ColorRegistry(PlatformUI.getWorkbench().getDisplay()); |
|
|
50 |
|
| 51 |
defaultThemeFontRegistry = new FontRegistry(PlatformUI.getWorkbench().getDisplay()); |
| 52 |
|
| 53 |
//copy the font values from preferences. |
| 54 |
FontRegistry jfaceFonts = JFaceResources.getFontRegistry(); |
| 55 |
for (Iterator i = jfaceFonts.getKeySet().iterator(); i.hasNext(); ) { |
| 56 |
String key = (String) i.next(); |
| 57 |
defaultThemeFontRegistry.put(key, jfaceFonts.getFontData(key)); |
| 58 |
} |
| 42 |
} |
59 |
} |
| 43 |
|
60 |
|
| 44 |
/** |
61 |
/** |
|
Lines 93-99
Link Here
|
| 93 |
private IPropertyChangeListener currentThemeListener = new IPropertyChangeListener() { |
110 |
private IPropertyChangeListener currentThemeListener = new IPropertyChangeListener() { |
| 94 |
|
111 |
|
| 95 |
public void propertyChange(PropertyChangeEvent event) { |
112 |
public void propertyChange(PropertyChangeEvent event) { |
| 96 |
firePropertyChange(event); |
113 |
firePropertyChange(event); |
|
|
114 |
if (event.getSource() instanceof FontRegistry) { |
| 115 |
JFaceResources.getFontRegistry().put(event.getProperty(), (FontData[]) event.getNewValue()); |
| 116 |
} |
| 117 |
else if (event.getSource() instanceof ColorRegistry) { |
| 118 |
JFaceResources.getColorRegistry().put(event.getProperty(), (RGB) event.getNewValue()); |
| 119 |
} |
| 97 |
} |
120 |
} |
| 98 |
}; |
121 |
}; |
| 99 |
|
122 |
|
|
Lines 123-128
Link Here
|
| 123 |
|
146 |
|
| 124 |
WorkbenchPlugin.getDefault().getPreferenceStore().setValue(IPreferenceConstants.CURRENT_THEME_ID, id == null ? "" : id); //$NON-NLS-1$ |
147 |
WorkbenchPlugin.getDefault().getPreferenceStore().setValue(IPreferenceConstants.CURRENT_THEME_ID, id == null ? "" : id); //$NON-NLS-1$ |
| 125 |
WorkbenchPlugin.getDefault().savePluginPreferences(); |
148 |
WorkbenchPlugin.getDefault().savePluginPreferences(); |
|
|
149 |
|
| 150 |
//update the jface registries |
| 151 |
{ |
| 152 |
ColorRegistry jfaceColors = JFaceResources.getColorRegistry(); |
| 153 |
ColorRegistry themeColors = currentTheme.getColorRegistry(); |
| 154 |
for (Iterator i = themeColors.getKeySet().iterator(); i.hasNext(); ) { |
| 155 |
String key = (String) i.next(); |
| 156 |
jfaceColors.put(key, themeColors.getRGB(key)); |
| 157 |
} |
| 158 |
} |
| 159 |
{ |
| 160 |
FontRegistry jfaceFonts = JFaceResources.getFontRegistry(); |
| 161 |
FontRegistry themeFonts = currentTheme.getFontRegistry(); |
| 162 |
for (Iterator i = themeFonts.getKeySet().iterator(); i.hasNext(); ) { |
| 163 |
String key = (String) i.next(); |
| 164 |
jfaceFonts.put(key, themeFonts.getFontData(key)); |
| 165 |
} |
| 166 |
} |
| 126 |
} |
167 |
} |
| 127 |
} |
168 |
} |
| 128 |
|
169 |
|
|
Lines 167-170
Link Here
|
| 167 |
public void removePropertyChangeListener(IPropertyChangeListener listener) { |
208 |
public void removePropertyChangeListener(IPropertyChangeListener listener) { |
| 168 |
propertyChangeListeners.remove(listener); |
209 |
propertyChangeListeners.remove(listener); |
| 169 |
} |
210 |
} |
|
|
211 |
|
| 212 |
public ColorRegistry getDefaultThemeColorRegistry() { |
| 213 |
return defaultThemeColorRegistry; |
| 214 |
} |
| 215 |
|
| 216 |
public FontRegistry getDefaultThemeFontRegistry() { |
| 217 |
return defaultThemeFontRegistry; |
| 218 |
} |
| 170 |
} |
219 |
} |