下面列出了怎么用org.eclipse.ui.themes.ITheme的API类实例代码及写法,或者点击链接到github查看源代码。
public static FindBugsConsole showConsole() {
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
boolean exists = false;
if (console != null) {
IConsole[] existing = manager.getConsoles();
for (int i = 0; i < existing.length; i++) {
if (console == existing[i]) {
exists = true;
}
}
} else {
console = new FindBugsConsole("SpotBugs",
FindbugsPlugin.getDefault().getImageDescriptor(AbstractFindbugsView.PERSPECTIVE_IMG), true);
}
if (!exists) {
manager.addConsoles(new IConsole[] { console });
}
ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
theme.addPropertyChangeListener(console);
console.setConsoleFont();
manager.showConsoleView(console);
return console;
}
private void setFont(String fontId, FontData[] data)
{
String fdString = PreferenceConverter.getStoredRepresentation(data);
// Only set new values if they're different from existing!
Font existing = JFaceResources.getFont(fontId);
String existingString = ""; //$NON-NLS-1$
if (!existing.isDisposed())
{
existingString = PreferenceConverter.getStoredRepresentation(existing.getFontData());
}
if (!existingString.equals(fdString))
{
// put in registry...
JFaceResources.getFontRegistry().put(fontId, data);
// Save to prefs...
ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
String key = ThemeElementHelper.createPreferenceKey(currentTheme, fontId);
IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
store.setValue(key, fdString);
}
}
private void setFont(String fontId, FontData[] data) {
String fdString = PreferenceConverter.getStoredRepresentation(data);
Font existing = JFaceResources.getFont(fontId);
String existingString = "";
if (!(existing.isDisposed())) {
existingString = PreferenceConverter
.getStoredRepresentation(existing.getFontData());
}
if (existingString.equals(fdString)) {
return;
}
JFaceResources.getFontRegistry().put(fontId, data);
ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
String key = ThemeElementHelper.createPreferenceKey(currentTheme,fontId);
IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
store.setValue(key, fdString);
}
@Override
protected void dispose() {
if (!disposed) {
disposed = true;
ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
theme.removePropertyChangeListener(this);
super.dispose();
}
}
private void setConsoleFont() {
if (Display.getCurrent() == null) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setConsoleFont();
}
});
} else {
ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
Font font = theme.getFontRegistry().get(CONSOLE_FONT);
console.setFont(font);
}
}
public Color getBackground(Object element) {
ITheme current = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
if (((PreviewFile)element).ignored) {
return current.getColorRegistry().get(SVNDecoratorConfiguration.IGNORED_BACKGROUND_COLOR);
} else if (((PreviewFile)element).dirty) {
return current.getColorRegistry().get(SVNDecoratorConfiguration.OUTGOING_CHANGE_BACKGROUND_COLOR);
}
return null;
}
public Color getForeground(Object element) {
ITheme current = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
if (((PreviewFile)element).ignored) {
return current.getColorRegistry().get(SVNDecoratorConfiguration.IGNORED_FOREGROUND_COLOR);
} else if (((PreviewFile)element).dirty) {
return current.getColorRegistry().get(SVNDecoratorConfiguration.OUTGOING_CHANGE_FOREGROUND_COLOR);
}
return null;
}
public Font getFont(Object element) {
ITheme current = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
if (((PreviewFile)element).ignored) {
return current.getFontRegistry().get(SVNDecoratorConfiguration.IGNORED_FONT);
} else if (((PreviewFile)element).dirty) {
return current.getFontRegistry().get(SVNDecoratorConfiguration.OUTGOING_CHANGE_FONT);
}
return null;
}
/**
* This method will ensure that the fonts and colors used by the decorator
* are cached in the registries. This avoids having to syncExec when
* decorating since we ensure that the fonts and colors are pre-created.
*
* @param fonts fonts ids to cache
* @param colors color ids to cache
*/
private void ensureFontAndColorsCreated(final String[] fonts, final String[] colors) {
SVNUIPlugin.getStandardDisplay().syncExec(new Runnable() {
public void run() {
ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
for (int i = 0; i < colors.length; i++) {
theme.getColorRegistry().get(colors[i]);
}
for (int i = 0; i < fonts.length; i++) {
theme.getFontRegistry().get(fonts[i]);
}
}
});
}
private void computeColorsAndFonts(boolean isIgnored, boolean isDirty, IDecoration decoration) {
if (!SVNUIPlugin.getPlugin().getPreferenceStore().getBoolean(ISVNUIConstants.PREF_USE_FONT_DECORATORS)) return;
ITheme current = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
if(isIgnored) {
decoration.setBackgroundColor(current.getColorRegistry().get(SVNDecoratorConfiguration.IGNORED_BACKGROUND_COLOR));
decoration.setForegroundColor(current.getColorRegistry().get(SVNDecoratorConfiguration.IGNORED_FOREGROUND_COLOR));
decoration.setFont(current.getFontRegistry().get(SVNDecoratorConfiguration.IGNORED_FONT));
} else if(isDirty) {
decoration.setBackgroundColor(current.getColorRegistry().get(SVNDecoratorConfiguration.OUTGOING_CHANGE_BACKGROUND_COLOR));
decoration.setForegroundColor(current.getColorRegistry().get(SVNDecoratorConfiguration.OUTGOING_CHANGE_FOREGROUND_COLOR));
decoration.setFont(current.getFontRegistry().get(SVNDecoratorConfiguration.OUTGOING_CHANGE_FONT));
}
}
private Font getTextFont() {
final ITheme theme = getWorkbench().getThemeManager().getCurrentTheme();
return theme.getFontRegistry().get(TEXT_FONT_ID);
}