PT #168196551: Dark theme support for live boot hints

This commit is contained in:
BoykoAlex
2019-09-05 21:37:33 -04:00
parent 44e9532ea3
commit 2f31f55318
2 changed files with 9 additions and 56 deletions

View File

@@ -13,28 +13,21 @@ package org.springframework.tooling.ls.eclipse.commons;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.progress.UIJob;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl.UpdateHighlights;
import org.springframework.tooling.ls.eclipse.commons.preferences.PreferenceConstants;
@SuppressWarnings("restriction")
public class LanguageServerCommonsActivator extends AbstractUIPlugin {
public static final String PLUGIN_ID = "org.springframework.tooling.ls.eclipse.commons";
@@ -43,20 +36,13 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
private static LanguageServerCommonsActivator instance;
private ColorRegistry colorRegistry;
private final IPropertyChangeListener PROPERTY_LISTENER = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
switch (event.getProperty()) {
case PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS:
RGB prefsColor = PreferenceConverter
.getColor(EditorsPlugin.getDefault().getPreferenceStore(), PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
// Convert color to without alpha with background
RGB derivedColor = convertRGBtoNonTransparent(prefsColor);
colorRegistry.put(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS, derivedColor);
// No break - need to update highlights for the new color to take effect
case PreferenceConstants.HIGHLIGHT_RANGE_COLOR_THEME:
// Fall through to update highlights
case PreferenceConstants.HIGHLIGHT_CODELENS_PREFS:
new UpdateHighlights(null, true);
break;
@@ -66,23 +52,6 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
};
private static int convertColorToNonTransparent(int color, int bg, double alpha) {
int x = (int) Math.round((color - (1 - alpha) * bg) / alpha);
x = Math.max(0, x);
x = Math.min(x, 0xFF);
return x;
}
private static RGB convertRGBtoNonTransparent(RGB rgb) {
double alpha = 0.25;
RGB bg = new RGB(0xFF, 0xFF, 0xFF); // white
return new RGB(
convertColorToNonTransparent(rgb.red, bg.red, alpha),
convertColorToNonTransparent(rgb.green, bg.green, alpha),
convertColorToNonTransparent(rgb.blue, bg.blue, alpha)
);
}
public LanguageServerCommonsActivator() {
}
@@ -92,29 +61,12 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
super.start(context);
getImageRegistry().put(BOOT_KEY, getImageDescriptor("icons/boot.png"));
UIJob uiJob = new UIJob("Setup color registry") {
{
setSystem(true);
}
@Override
public IStatus runInUIThread(IProgressMonitor arg0) {
colorRegistry = new ColorRegistry(PlatformUI.getWorkbench().getDisplay(), true);
RGB prefsColor = PreferenceConverter.getColor(EditorsPlugin.getDefault().getPreferenceStore(), PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
colorRegistry.put(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS, convertRGBtoNonTransparent(prefsColor));
getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
EditorsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
return Status.OK_STATUS;
}
};
uiJob.schedule();
getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER);
PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(PROPERTY_LISTENER);;
}
public Color getBootHighlightRangeColor() {
if (colorRegistry!=null) {
return colorRegistry.get(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_PREFS);
}
return null;
return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_THEME);
}
public final static ImageDescriptor getImageDescriptor(String path) {
@@ -132,8 +84,8 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
@Override
public void stop(BundleContext context) throws Exception {
EditorsPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(PROPERTY_LISTENER);
getPreferenceStore().removePropertyChangeListener(PROPERTY_LISTENER);
PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(PROPERTY_LISTENER);
super.stop(context);
}
@@ -148,4 +100,5 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin {
public static void logInfo(String message) {
instance.getLog().log(new Status(IStatus.INFO, instance.getBundle().getSymbolicName(), message));
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* Copyright (c) 2018, 2019 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,6 +14,6 @@ public class PreferenceConstants {
public static final String HIGHLIGHT_CODELENS_PREFS = "highlight.codelens";
public static final String HIGHLIGHT_RANGE_COLOR_PREFS = "STS4BootMarkerIndicationColor";
public static final String HIGHLIGHT_RANGE_COLOR_THEME = "org.springframework.tooling.ls.eclipse.commons.STS4BootMarkerIndicationColor";
}