From 950ea1b5bc248b900d2bd7e81c4b15a50c91a3ce Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Thu, 2 Jul 2020 23:23:32 -0400 Subject: [PATCH 1/9] Fix LSP4E & Generic editor occurrence highlight color Also change the default selection colors to yellow background, black foreground Fix #109 Signed-off-by: Andrew Obuchowicz --- com.aobuchow.themes.spectrum/css/preference_styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.aobuchow.themes.spectrum/css/preference_styles.css b/com.aobuchow.themes.spectrum/css/preference_styles.css index 63d1df9..a074c51 100644 --- a/com.aobuchow.themes.spectrum/css/preference_styles.css +++ b/com.aobuchow.themes.spectrum/css/preference_styles.css @@ -20,7 +20,7 @@ IEclipsePreferences#org-eclipse-ui-editors:com-aobuchow-themes-spectrum-editors 'AbstractTextEditor.Color.Foreground.SystemDefault=false' 'hyperlinkColor.SystemDefault=false' 'hyperlinkColor=40,235,195' - 'asOccurencesIndicationColor=72,72,72' + 'asOccurencesIndicationColor=255,72,72' 'breakpointIndicationColor=51,119,193' 'currentIPColor=90,90,90' 'infoIndicationColor=86,194,170' From 10a90947dc846c432a49f78f5f4b5d842a1ab0a1 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Fri, 10 Jul 2020 02:16:17 -0400 Subject: [PATCH 2/9] Add preference page, remove some CSS color definitions Also move some CTabFolder related CSS from default_overrides.css to tabstyle.css Fix #52 Signed-off-by: Andrew Obuchowicz --- .../feature.xml | 7 +++ .../.gitignore | 7 +++ .../.project | 28 +++++++++ .../META-INF/MANIFEST.MF | 12 ++++ .../build.properties | 5 ++ .../plugin.xml | 13 ++++ .../spectrum/preferences/Activator.java | 53 ++++++++++++++++ .../spectrum/preferences/BrowserUtils.java | 46 ++++++++++++++ .../spectrum/preferences/ColorManager.java | 25 ++++++++ .../spectrum/preferences/ColorUtils.java | 13 ++++ .../themes/spectrum/preferences/Messages.java | 18 ++++++ .../spectrum/preferences/PreferencesPage.java | 63 +++++++++++++++++++ .../spectrum/preferences/messages.properties | 4 ++ .../META-INF/MANIFEST.MF | 2 +- .../css/color_definitions.css | 63 +------------------ .../css/default_overrides.css | 26 -------- com.aobuchow.themes.spectrum/css/tabstyle.css | 18 ++++++ com.aobuchow.themes.spectrum/plugin.xml | 44 +++++++++++++ pom.xml | 1 + 19 files changed, 360 insertions(+), 88 deletions(-) create mode 100644 com.aobuchow.themes.spectrum.preferences/.gitignore create mode 100644 com.aobuchow.themes.spectrum.preferences/.project create mode 100644 com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF create mode 100644 com.aobuchow.themes.spectrum.preferences/build.properties create mode 100644 com.aobuchow.themes.spectrum.preferences/plugin.xml create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties diff --git a/com.aobuchow.themes.spectrum.feature/feature.xml b/com.aobuchow.themes.spectrum.feature/feature.xml index b40e8a1..889f224 100644 --- a/com.aobuchow.themes.spectrum.feature/feature.xml +++ b/com.aobuchow.themes.spectrum.feature/feature.xml @@ -26,4 +26,11 @@ version="0.0.0" unpack="false"/> + + diff --git a/com.aobuchow.themes.spectrum.preferences/.gitignore b/com.aobuchow.themes.spectrum.preferences/.gitignore new file mode 100644 index 0000000..7484207 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/.gitignore @@ -0,0 +1,7 @@ +# Maven +/target/ +/bin/ +# Eclipse Core +/.settings/ +# JDT-specific (Eclipse Java Development Tools) +.classpath diff --git a/com.aobuchow.themes.spectrum.preferences/.project b/com.aobuchow.themes.spectrum.preferences/.project new file mode 100644 index 0000000..01b9f5b --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/.project @@ -0,0 +1,28 @@ + + + com.aobuchow.themes.spectrum.preferences + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a5d7d6a --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Spectrum Preferences +Bundle-SymbolicName: com.aobuchow.themes.spectrum.preferences;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: com.aobuchow.themes.spectrum.preferences.Activator +Bundle-Vendor: aobuchow +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Automatic-Module-Name: com.aobuchow.themes.spectrum.preferences +Bundle-ActivationPolicy: lazy diff --git a/com.aobuchow.themes.spectrum.preferences/build.properties b/com.aobuchow.themes.spectrum.preferences/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/com.aobuchow.themes.spectrum.preferences/plugin.xml b/com.aobuchow.themes.spectrum.preferences/plugin.xml new file mode 100644 index 0000000..6442588 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java new file mode 100644 index 0000000..f01be39 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java @@ -0,0 +1,53 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "com.aobuchow.themes.spectrum.preferences"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + private ColorRegistry colorRegistry; + + /** + * The constructor + */ + public Activator() { + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + public ColorRegistry getColorRegistry() { + return colorRegistry; + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java new file mode 100644 index 0000000..fd25b5d --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java @@ -0,0 +1,46 @@ +package com.aobuchow.themes.spectrum.preferences; + +import java.net.URL; + +import org.eclipse.core.runtime.Status; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.browser.IWebBrowser; + +public interface BrowserUtils { + + public static IWebBrowser newBrowser() { + IWebBrowser browser = null; + try { + browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("spectrum.browser"); //$NON-NLS-1$ + } catch (PartInitException e) { + // Internal browser shouldn't cause an exception + Activator.getDefault().getLog().log(new Status(org.eclipse.jface.dialogs.IMessageProvider.ERROR, BrowserUtils.class, e.getMessage())); + } + + try { + browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser(); + } catch (PartInitException e) { + Activator.getDefault().getLog().log(new Status(org.eclipse.jface.dialogs.IMessageProvider.INFORMATION, BrowserUtils.class, e.getMessage())); + } + + return browser; + } + + public static Link createLinkURL(Group parent, String text, URL url, IWebBrowser webBrowser) { + Link link = new Link(parent, SWT.BORDER | SWT.BOLD); + link.setText(text); + link.addListener(SWT.Selection, event -> { + try { + webBrowser.openURL(url); + } catch (PartInitException e) { + Activator.getDefault().getLog().log(new Status(org.eclipse.jface.dialogs.IMessageProvider.ERROR, BrowserUtils.class, e.getMessage())); + } + }); + return link; + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java new file mode 100644 index 0000000..7df9838 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -0,0 +1,25 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.swt.graphics.Color; + +public class ColorManager { + + public static String getCurrentColorSchemeCSS() { + ColorRegistry colorRegistry = Activator.getDefault().getColorRegistry(); + Color accentColor = colorRegistry.get("com.aobuchow.themes.spectrum.ACCENT_COLOR"); //$NON-NLS-1$ + Color baseColor = colorRegistry.get("com.aobuchow.themes.spectrum.BASE_COLOR"); //$NON-NLS-1$ + Color backgroundColor = colorRegistry.get("com.aobuchow.themes.spectrum.BACKGROUND_COLOR"); //$NON-NLS-1$ + + String accentColorHex = ColorUtils.colorToHex(accentColor); + String baseColorHex = ColorUtils.colorToHex(baseColor); + String backgroundColorHex = ColorUtils.colorToHex(backgroundColor); + String currentColorScheme = "ColorScheme {\n" + //$NON-NLS-1$ + " --background-color: " + backgroundColorHex + ";\n" + //$NON-NLS-1$ //$NON-NLS-2$ + " --base-color: " + baseColorHex + ";\n" + //$NON-NLS-1$ //$NON-NLS-2$ + " --accent-color: " + accentColorHex + ";\n" + //$NON-NLS-1$ //$NON-NLS-2$ + "}"; //$NON-NLS-1$ + return currentColorScheme; + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java new file mode 100644 index 0000000..2b175ee --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java @@ -0,0 +1,13 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.swt.graphics.Color; + +public class ColorUtils { + + private static final String rgbToHex = "#%02X%02X%02X"; + + public static String colorToHex(Color color) { + return String.format(rgbToHex, color.getRed(), color.getGreen(), color.getBlue()); + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java new file mode 100644 index 0000000..51a8646 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java @@ -0,0 +1,18 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "com.aobuchow.themes.spectrum.preferences.messages"; //$NON-NLS-1$ + public static String SpectrumPreferencePage_BugReportLink; + public static String SpectrumPreferencePage_CommunityGroup; + public static String SpectrumPreferencePage_CustomizationGroup; + public static String SpectrumPreferencePage_RepositoryLink; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java new file mode 100644 index 0000000..a357775 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java @@ -0,0 +1,63 @@ +package com.aobuchow.themes.spectrum.preferences; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.browser.IWebBrowser; + +public class PreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { + + private IWebBrowser browser; + private URL issuesURL; + private URL repoURL; + + @Override + public void init(IWorkbench workbench) { + browser = BrowserUtils.newBrowser(); + try { + issuesURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme/issues"); //$NON-NLS-1$ + repoURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme"); //$NON-NLS-1$ + } catch (MalformedURLException e) { + Activator.getDefault().getLog().log(new Status(ERROR, getClass(), e.getMessage())); + } + } + + @Override + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(1, true); + layout.marginWidth = 0; + layout.marginHeight = 0; + composite.setLayout(layout); + + Group customizeGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + customizeGroup.setText(Messages.SpectrumPreferencePage_CustomizationGroup); + customizeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + customizeGroup.setLayout(layout); + Text colorScheme = new Text(customizeGroup, SWT.LEAD | SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); + colorScheme.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + String currentColorScheme = ColorManager.getCurrentColorSchemeCSS(); + colorScheme.setText(currentColorScheme); + + Group communityGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); + communityGroup.setText(Messages.SpectrumPreferencePage_CommunityGroup); + communityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + communityGroup.setLayout(layout); + BrowserUtils.createLinkURL(communityGroup, Messages.SpectrumPreferencePage_RepositoryLink, repoURL, browser); + BrowserUtils.createLinkURL(communityGroup, Messages.SpectrumPreferencePage_BugReportLink, issuesURL, browser); + + return composite; + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties new file mode 100644 index 0000000..0944b2e --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties @@ -0,0 +1,4 @@ +SpectrumPreferencePage_BugReportLink=Report a bug or feature request: open GitHub Issues. +SpectrumPreferencePage_CommunityGroup=Get involved: +SpectrumPreferencePage_CustomizationGroup=Customization: +SpectrumPreferencePage_RepositoryLink=Spectrum Theme is open-source: checkout the repository. diff --git a/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF b/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF index 9c64736..8159abb 100644 --- a/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF +++ b/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF @@ -6,5 +6,5 @@ Bundle-Version: 1.0.0.qualifier Bundle-Vendor: aobuchow Automatic-Module-Name: Spectrum_Theme Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: org.eclipse.e4.ui.css.swt.theme;bundle-version="0.12.700", +Require-Bundle: org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.12.700, 0.14.000)", org.eclipse.ui diff --git a/com.aobuchow.themes.spectrum/css/color_definitions.css b/com.aobuchow.themes.spectrum/css/color_definitions.css index e37e6b9..ac30c11 100644 --- a/com.aobuchow.themes.spectrum/css/color_definitions.css +++ b/com.aobuchow.themes.spectrum/css/color_definitions.css @@ -11,62 +11,9 @@ *******************************************************************************/ ThemesExtension { - color-definition: '#org-eclipse-ui-workbench-INACTIVE_TAB_UNSELECTED_TEXT_COLOR', - '#org-eclipse-ui-workbench-INACTIVE_TAB_SELECTED_TEXT_COLOR', - '#org-eclipse-ui-workbench-ACTIVE_TAB_UNSELECTED_TEXT_COLOR', + color-definition: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR', - '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_SELECTED_TEXT_COLOR', - '#org-eclipse-ui-workbench-LINK_COLOR', - '#com-aobuchow-themes-spectrum-ACCENT_COLOR', - '#com-aobuchow-themes-spectrum-BASE_COLOR', - '#com-aobuchow-themes-spectrum-TAB_HOVER_COLOR', - '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; -} - -ColorDefinition#com-aobuchow-themes-spectrum-ACCENT_COLOR { - color: #d70000; - category: '#com-aobuchow-themes-spectrum-themeCategory'; - label: 'Accent Color'; - description: 'The accent color used in Spectrum theme.'; -} - -ColorDefinition#com-aobuchow-themes-spectrum-BASE_COLOR { - color: #2f2f2f; - category: '#com-aobuchow-themes-spectrum-themeCategory'; - label: 'Base Color'; - description: 'The base color used in Spectrum theme.'; -} - -ColorDefinition#com-aobuchow-themes-spectrum-TAB_HOVER_COLOR { - color: #161616; - category: '#com-aobuchow-themes-spectrum-themeCategory'; - label: 'Tab Hover Color'; - description: 'The color used when an hovering on a tab in Spectrum theme.'; -} - -ColorDefinition#com-aobuchow-themes-spectrum-BACKGROUND_COLOR { - color: #17171b; - category: '#com-aobuchow-themes-spectrum-themeCategory'; - label: 'Background Color'; - description: 'The background color used in Spectrum theme.'; -} - -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_UNSELECTED_TEXT_COLOR { - color: #bbbbbb; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_TAB_UNSELECTED_TEXT_COLOR'); -} - -ColorDefinition#org-eclipse-ui-workbench-INACTIVE_TAB_SELECTED_TEXT_COLOR { - color: #ffffff; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=INACTIVE_TAB_SELECTED_TEXT_COLOR'); -} - -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_UNSELECTED_TEXT_COLOR { - color: white; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_UNSELECTED_TEXT_COLOR'); + '#org-eclipse-ui-workbench-LINK_COLOR'; } ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR { @@ -75,12 +22,6 @@ ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR { label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_SELECTED_TEXT_COLOR'); } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_SELECTED_TEXT_COLOR { - color: #cccccc; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_NOFOCUS_TAB_SELECTED_TEXT_COLOR'); -} - ColorDefinition#org-eclipse-ui-workbench-LINK_COLOR { color: #28ebc3; category: '#org-eclipse-ui-presentation-default'; diff --git a/com.aobuchow.themes.spectrum/css/default_overrides.css b/com.aobuchow.themes.spectrum/css/default_overrides.css index cb06d5e..4d76a25 100644 --- a/com.aobuchow.themes.spectrum/css/default_overrides.css +++ b/com.aobuchow.themes.spectrum/css/default_overrides.css @@ -15,32 +15,6 @@ font-weight: bold; } -/* ###################### CTabFolder ########################## */ - -CTabItem, -CTabItem CLabel { - /* background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; HACK for background of CTabFolder inner Toolbars */ - color: '#org-eclipse-ui-workbench-INACTIVE_TAB_UNSELECTED_TEXT_COLOR'; -} -CTabItem:selected, -CTabItem:selected CLabel { - color: '#org-eclipse-ui-workbench-INACTIVE_TAB_SELECTED_TEXT_COLOR'; -} - -.MPartStack.active > CTabItem, -.MPartStack.active > CTabItem CLabel { - /* background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; HACK for background of CTabFolder inner Toolbars */ - color: '#org-eclipse-ui-workbench-ACTIVE_TAB_UNSELECTED_TEXT_COLOR'; -} -.MPartStack.active > CTabItem:selected, -.MPartStack.active > CTabItem:selected CLabel { - color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR'; -} - -.MPartStack.active.noFocus > CTabItem:selected { - color: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_SELECTED_TEXT_COLOR'; -} - /* ###################### Tree, Table ########################## */ Tree, diff --git a/com.aobuchow.themes.spectrum/css/tabstyle.css b/com.aobuchow.themes.spectrum/css/tabstyle.css index 0cc584c..26c0c3b 100644 --- a/com.aobuchow.themes.spectrum/css/tabstyle.css +++ b/com.aobuchow.themes.spectrum/css/tabstyle.css @@ -90,3 +90,21 @@ CTabItem CLabel { background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR'; /* HACK for background of CTabFolder inner Toolbars */ color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR'; } + +/* ###################### Below used to be in default overrides ########################## */ + +/* TODO: Maybe inactive tabs should have a darker color? */ +CTabItem:selected, +CTabItem:selected CLabel { + color: white; +} + +.MPartStack.active > CTabItem, +.MPartStack.active > CTabItem CLabel { + /* background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; HACK for background of CTabFolder inner Toolbars */ + color: white; +} + +.MPartStack.active.noFocus > CTabItem:selected { + color: white; +} diff --git a/com.aobuchow.themes.spectrum/plugin.xml b/com.aobuchow.themes.spectrum/plugin.xml index 138d6c4..172d622 100644 --- a/com.aobuchow.themes.spectrum/plugin.xml +++ b/com.aobuchow.themes.spectrum/plugin.xml @@ -23,6 +23,50 @@ id="com.aobuchow.themes.spectrum.themeCategory" label="Spectrum"> + + + + + The accent color used in Spectrum theme. + + + + + The base color used in Spectrum theme. + + + + + The background color used in Spectrum theme. + + + + + The color used when an hovering on a tab in Spectrum theme. + + diff --git a/pom.xml b/pom.xml index f4b77f5..86d1ff5 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ com.aobuchow.themes.spectrum + com.aobuchow.themes.spectrum.preferences com.aobuchow.themes.spectrum.feature releng-updatesite From 06d97d47d9caa0097513f0e12be1123f197f5379 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Tue, 14 Jul 2020 17:35:12 -0400 Subject: [PATCH 3/9] Use StyledText to render colorscheme colors Signed-off-by: Andrew Obuchowicz --- .../META-INF/MANIFEST.MF | 5 ++- .../spectrum/preferences/ColorManager.java | 36 +++++++++++++++++++ .../spectrum/preferences/ColorUtils.java | 10 ++++-- .../spectrum/preferences/PreferencesPage.java | 29 ++++++++++++--- 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF index a5d7d6a..cc2fbfc 100644 --- a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF +++ b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF @@ -6,7 +6,10 @@ Bundle-Version: 1.0.0.qualifier Bundle-Activator: com.aobuchow.themes.spectrum.preferences.Activator Bundle-Vendor: aobuchow Require-Bundle: org.eclipse.ui, - org.eclipse.core.runtime + org.eclipse.core.runtime, + org.eclipse.swt, + org.eclipse.e4.core.services Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Automatic-Module-Name: com.aobuchow.themes.spectrum.preferences Bundle-ActivationPolicy: lazy +Import-Package: org.osgi.service.event;version="1.4.0" diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java index 7df9838..502ffa9 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -1,6 +1,9 @@ package com.aobuchow.themes.spectrum.preferences; import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Color; public class ColorManager { @@ -21,5 +24,38 @@ public static String getCurrentColorSchemeCSS() { "}"; //$NON-NLS-1$ return currentColorScheme; } + + public static void setStyledTextColoring(StyledText colorScheme, ColorRegistry colorRegistry) { + Color accentColor = colorRegistry.get("com.aobuchow.themes.spectrum.ACCENT_COLOR"); //$NON-NLS-1$ + Color baseColor = colorRegistry.get("com.aobuchow.themes.spectrum.BASE_COLOR"); //$NON-NLS-1$ + Color backgroundColor = colorRegistry.get("com.aobuchow.themes.spectrum.BACKGROUND_COLOR"); //$NON-NLS-1$ + Color white = new Color(colorScheme.getDisplay(), 255, 255, 255); + Color black = new Color(colorScheme.getDisplay(), 0, 0, 0); + String text = colorScheme.getText(); + + StyleRange bgStyle = new StyleRange(); + bgStyle.start = text.indexOf("--background-color:") + "--background-color:".length() + 1; + bgStyle.length = 7; + bgStyle.fontStyle = SWT.BOLD; + bgStyle.background = backgroundColor; + bgStyle.foreground = ColorUtils.useReadableForegroundColor(backgroundColor, white, black); + colorScheme.setStyleRange(bgStyle); + + StyleRange baseStyle = new StyleRange(); + baseStyle.start = text.indexOf("--base-color:") + "--base-color:".length() + 1; + baseStyle.length = 7; + baseStyle.fontStyle = SWT.BOLD; + baseStyle.background = baseColor; + baseStyle.foreground = ColorUtils.useReadableForegroundColor(baseColor, white, black); + colorScheme.setStyleRange(baseStyle); + + StyleRange accentStyle = new StyleRange(); + accentStyle.start = text.indexOf("--accent-color:") + "--accent-color:".length() + 1; + accentStyle.length = 7; + accentStyle.fontStyle = SWT.BOLD; + accentStyle.foreground = ColorUtils.useReadableForegroundColor(accentColor, white, black); + accentStyle.background = accentColor; + colorScheme.setStyleRange(accentStyle); + } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java index 2b175ee..38fc0ae 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java @@ -4,10 +4,16 @@ public class ColorUtils { - private static final String rgbToHex = "#%02X%02X%02X"; + private static final String RGB_TO_HEX = "#%02X%02X%02X"; public static String colorToHex(Color color) { - return String.format(rgbToHex, color.getRed(), color.getGreen(), color.getBlue()); + return String.format(RGB_TO_HEX, color.getRed(), color.getGreen(), color.getBlue()); + } + + public static Color useReadableForegroundColor(Color backgroundColor, Color white, Color black) { + double luminance = 0.2126 * backgroundColor.getRed() + 0.7152 * backgroundColor.getGreen() + + 0.0722 * backgroundColor.getBlue(); + return luminance > 128 ? black : white; } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java index a357775..23a8e47 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java @@ -4,17 +4,22 @@ import java.net.URL; import org.eclipse.core.runtime.Status; +import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.browser.IWebBrowser; +import org.eclipse.ui.internal.themes.WorkbenchThemeManager; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; public class PreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { @@ -22,9 +27,22 @@ public class PreferencesPage extends PreferencePage implements IWorkbenchPrefere private URL issuesURL; private URL repoURL; + private EventHandler themeRegistryRestyledHandler = new EventHandler() { + @Override + public void handleEvent(Event event) { + String currentColorScheme = ColorManager.getCurrentColorSchemeCSS(); + colorScheme.setText(currentColorScheme); + ColorManager.setStyledTextColoring(colorScheme, Activator.getDefault().getColorRegistry()); + } + }; + private StyledText colorScheme; + @Override public void init(IWorkbench workbench) { browser = BrowserUtils.newBrowser(); + IEventBroker eventBroker = workbench.getService(IEventBroker.class); + eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_RESTYLED, themeRegistryRestyledHandler); + eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_MODIFIED, themeRegistryRestyledHandler); try { issuesURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme/issues"); //$NON-NLS-1$ repoURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme"); //$NON-NLS-1$ @@ -40,15 +58,18 @@ protected Control createContents(Composite parent) { layout.marginWidth = 0; layout.marginHeight = 0; composite.setLayout(layout); - + Group customizeGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); customizeGroup.setText(Messages.SpectrumPreferencePage_CustomizationGroup); customizeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); customizeGroup.setLayout(layout); - Text colorScheme = new Text(customizeGroup, SWT.LEAD | SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); + + colorScheme = new StyledText(customizeGroup, SWT.LEAD | SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); + ColorRegistry colorRegistry = Activator.getDefault().getColorRegistry(); colorScheme.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); String currentColorScheme = ColorManager.getCurrentColorSchemeCSS(); colorScheme.setText(currentColorScheme); + ColorManager.setStyledTextColoring(colorScheme, colorRegistry); Group communityGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); communityGroup.setText(Messages.SpectrumPreferencePage_CommunityGroup); @@ -59,5 +80,5 @@ protected Control createContents(Composite parent) { return composite; } - + } From 1198ed4991b7e5984d1cff74cb9085f3e8840097 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Wed, 15 Jul 2020 23:05:32 -0400 Subject: [PATCH 4/9] Dynamically set the git uncommitted changes color Add ColorHSL class Signed-off-by: Andrew Obuchowicz --- .gitignore | 4 +- .../.classpath | 7 + .../.gitignore | 2 - .../META-INF/MANIFEST.MF | 5 +- .../plugin.xml | 6 + .../spectrum/preferences/Activator.java | 20 ++- .../themes/spectrum/preferences/ColorHSL.java | 147 ++++++++++++++++++ .../spectrum/preferences/ColorManager.java | 116 +++++++++++--- .../spectrum/preferences/ColorUtils.java | 21 ++- .../spectrum/preferences/PluginStartup.java | 29 ++++ .../spectrum/preferences/PreferencesPage.java | 34 ++-- .../META-INF/MANIFEST.MF | 2 +- 12 files changed, 348 insertions(+), 45 deletions(-) create mode 100644 com.aobuchow.themes.spectrum.preferences/.classpath create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java diff --git a/.gitignore b/.gitignore index 5476be3..1432c0e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,4 @@ package /bin/ # Eclipse Core /.settings/ -/.metadata/ -# JDT-specific (Eclipse Java Development Tools) -.classpath \ No newline at end of file +/.metadata/ \ No newline at end of file diff --git a/com.aobuchow.themes.spectrum.preferences/.classpath b/com.aobuchow.themes.spectrum.preferences/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/com.aobuchow.themes.spectrum.preferences/.gitignore b/com.aobuchow.themes.spectrum.preferences/.gitignore index 7484207..956c0d7 100644 --- a/com.aobuchow.themes.spectrum.preferences/.gitignore +++ b/com.aobuchow.themes.spectrum.preferences/.gitignore @@ -3,5 +3,3 @@ /bin/ # Eclipse Core /.settings/ -# JDT-specific (Eclipse Java Development Tools) -.classpath diff --git a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF index cc2fbfc..016d6d8 100644 --- a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF +++ b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF @@ -8,7 +8,10 @@ Bundle-Vendor: aobuchow Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.swt, - org.eclipse.e4.core.services + org.eclipse.e4.core.services, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.contexts, + org.eclipse.e4.ui.css.swt.theme Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Automatic-Module-Name: com.aobuchow.themes.spectrum.preferences Bundle-ActivationPolicy: lazy diff --git a/com.aobuchow.themes.spectrum.preferences/plugin.xml b/com.aobuchow.themes.spectrum.preferences/plugin.xml index 6442588..972ecf5 100644 --- a/com.aobuchow.themes.spectrum.preferences/plugin.xml +++ b/com.aobuchow.themes.spectrum.preferences/plugin.xml @@ -9,5 +9,11 @@ name="Spectrum Theme"> + + + + diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java index f01be39..1803516 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java @@ -1,9 +1,15 @@ package com.aobuchow.themes.spectrum.preferences; +import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.swt.graphics.Color; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.themes.WorkbenchThemeManager; +import org.eclipse.ui.internal.util.PrefUtil; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; /** * The activator class controls the plug-in life cycle @@ -16,8 +22,8 @@ public class Activator extends AbstractUIPlugin { // The shared instance private static Activator plugin; - private ColorRegistry colorRegistry; - + private ColorManager colorManager; + /** * The constructor */ @@ -28,13 +34,14 @@ public Activator() { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); + colorManager = new ColorManager(); } @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); + colorManager.dispose(); } /** @@ -46,8 +53,11 @@ public static Activator getDefault() { return plugin; } - public ColorRegistry getColorRegistry() { - return colorRegistry; + /** + * @return the colorManager + */ + public ColorManager getColorManager() { + return colorManager; } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java new file mode 100644 index 0000000..0127847 --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java @@ -0,0 +1,147 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.PlatformUI; + +public class ColorHSL { + private Color color; + private float hue; + private float saturation; + private float luminance; + + public ColorHSL(Color color) { + this.color = color; + this.hue = color.getRGB().getHSB()[0]; + this.saturation = color.getRGB().getHSB()[1]; + this.luminance = color.getRGB().getHSB()[2]; + } + + public ColorHSL(float hue, float saturation, float luminance) { + this(new Color(PlatformUI.getWorkbench().getDisplay(), new RGB(hue, saturation, luminance))); + } + + // TODO: Add test coverage + public ColorHSL modifyProperty(MODIFICATION modificationType, HSL_PROPERTY propertyToModify, + BOUND_BEHAVIOR boundBehavior, float amount) { + // Hue must be within the range [0, 360] + // Saturation must be within the range [0, 1] + // Luminance must be within the range [0, 1] + float newValue = -1; + float max = 1; + float min = 0; + + switch (propertyToModify) { + case HUE: + max = 360; + newValue = hue; + break; + case SATURATION: + newValue = saturation; + break; + case LUMINANCE: + newValue = luminance; + break; + } + + switch (modificationType) { + case INCREASE: + newValue = newValue + amount; + break; + case DECREASE: + newValue = newValue - amount; + break; + } + + switch (boundBehavior) { + case CYCLE: + if (newValue < min) { + newValue = max - Math.abs(newValue); + } else if (newValue > max) { + newValue = min + (newValue - max); + } + break; + case LIMIT: + newValue = Math.min(newValue, max); + newValue = Math.max(newValue, min); + break; + case REVERSE: + if (newValue < min) { + newValue = min + Math.abs(newValue); + } else if (newValue > max) { + newValue = max - (newValue - max); + } + + } + + switch (propertyToModify) { + case HUE: + return new ColorHSL(newValue, this.getSaturation(), this.getLuminance()); + case SATURATION: + return new ColorHSL(this.getHue(), newValue, this.getLuminance()); + case LUMINANCE: + return new ColorHSL(this.getHue(), this.getSaturation(), newValue); + } + + return null; + } + + public void dispose() { + color.dispose(); + } + + public Color getColor() { + return color; + } + + public float getHue() { + return hue; + } + + public float getSaturation() { + return saturation; + } + + public float getLuminance() { + return luminance; + } + + public float getPerceivedLuminance() { + return (299f * color.getRed() + 587f * color.getGreen() + 114f * color.getBlue()) / 1000; + } + + enum MODIFICATION { + INCREASE, DECREASE; + } + + /* + * How the modification amount to a property should behave when hitting an upper + * or lower bound. + */ + enum BOUND_BEHAVIOR { + /* + * Jump from one bound to another. Example: For a color with a luminance of + * 0.6f, increasing the luminance by 0.5f while using the CYCLE BOUND_BEHAVIOR + * will result in the color having a luminance of 0.1f. + */ + CYCLE, + + /* + * Negate any excess amount from the bound. Example: For a color with a + * luminance of 0.6f, increasing the luminance by 0.5f while using the REVERSE + * BOUND_BEHAVIOR will result in the color having a luminance of 0.9f. + */ + REVERSE, + + /* + * Set the amount to the nearest bound. Example: Fora color with a luminance of 0.6f, increasing the luminance by 0.5f while using the LIMIT + * BOUND_BEHAVIOR will result in the color having a luminance of 1f. + */ + LIMIT; + } + + enum HSL_PROPERTY { + HUE, SATURATION, LUMINANCE; + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java index 502ffa9..dc2c111 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -1,34 +1,76 @@ package com.aobuchow.themes.spectrum.preferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; +import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.internal.util.PrefUtil; +import org.osgi.service.prefs.BackingStoreException; + +import com.aobuchow.themes.spectrum.preferences.ColorHSL.BOUND_BEHAVIOR; +import com.aobuchow.themes.spectrum.preferences.ColorHSL.HSL_PROPERTY; +import com.aobuchow.themes.spectrum.preferences.ColorHSL.MODIFICATION; public class ColorManager { + private static final String BACKGROUND_COLOR_ID = "com.aobuchow.themes.spectrum.BACKGROUND_COLOR"; + private static final String BASE_COLOR_ID = "com.aobuchow.themes.spectrum.BASE_COLOR"; + private static final String ACCENT_COLOR_ID = "com.aobuchow.themes.spectrum.ACCENT_COLOR"; + private ColorRegistry colorRegistry; + private Color accentColor; + private Color baseColor; + private Color backgroundColor; + private IThemeEngine engine; + private final String THEME_ID = "spectrum.dark.theme.id"; + private Display display; - public static String getCurrentColorSchemeCSS() { - ColorRegistry colorRegistry = Activator.getDefault().getColorRegistry(); - Color accentColor = colorRegistry.get("com.aobuchow.themes.spectrum.ACCENT_COLOR"); //$NON-NLS-1$ - Color baseColor = colorRegistry.get("com.aobuchow.themes.spectrum.BASE_COLOR"); //$NON-NLS-1$ - Color backgroundColor = colorRegistry.get("com.aobuchow.themes.spectrum.BACKGROUND_COLOR"); //$NON-NLS-1$ - + public ColorManager() { + MApplication application = PlatformUI.getWorkbench().getService(MApplication.class); + IEclipseContext context = application.getContext(); + engine = context.get(IThemeEngine.class); + display = PlatformUI.getWorkbench().getDisplay(); + updateColors(); + } + + public void updateColors() { + this.colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); + accentColor = colorRegistry.get(ACCENT_COLOR_ID); + baseColor = colorRegistry.get(BASE_COLOR_ID); + backgroundColor = colorRegistry.get(BACKGROUND_COLOR_ID); + if (engine.getActiveTheme().getId().equals(THEME_ID)) { + updateGitColors(); + savePreferences(); + } + } + + private void savePreferences() { + try { + InstanceScope.INSTANCE.getNode(PlatformUI.PLUGIN_ID).flush(); + } catch (BackingStoreException e) { + e.printStackTrace(); + } + } + + public String getCurrentColorSchemeCSS() { String accentColorHex = ColorUtils.colorToHex(accentColor); - String baseColorHex = ColorUtils.colorToHex(baseColor); - String backgroundColorHex = ColorUtils.colorToHex(backgroundColor); - String currentColorScheme = "ColorScheme {\n" + //$NON-NLS-1$ - " --background-color: " + backgroundColorHex + ";\n" + //$NON-NLS-1$ //$NON-NLS-2$ - " --base-color: " + baseColorHex + ";\n" + //$NON-NLS-1$ //$NON-NLS-2$ - " --accent-color: " + accentColorHex + ";\n" + //$NON-NLS-1$ //$NON-NLS-2$ - "}"; //$NON-NLS-1$ + String baseColorHex = ColorUtils.colorToHex(baseColor); + String backgroundColorHex = ColorUtils.colorToHex(backgroundColor); + String currentColorScheme = "ColorScheme {\n" + + " --background-color: " + backgroundColorHex + ";\n" + + " --base-color: " + baseColorHex + ";\n" + + " --accent-color: " + accentColorHex + ";\n" + + "}"; return currentColorScheme; } - - public static void setStyledTextColoring(StyledText colorScheme, ColorRegistry colorRegistry) { - Color accentColor = colorRegistry.get("com.aobuchow.themes.spectrum.ACCENT_COLOR"); //$NON-NLS-1$ - Color baseColor = colorRegistry.get("com.aobuchow.themes.spectrum.BASE_COLOR"); //$NON-NLS-1$ - Color backgroundColor = colorRegistry.get("com.aobuchow.themes.spectrum.BACKGROUND_COLOR"); //$NON-NLS-1$ + + public void setStyledTextColoring(StyledText colorScheme) { Color white = new Color(colorScheme.getDisplay(), 255, 255, 255); Color black = new Color(colorScheme.getDisplay(), 0, 0, 0); String text = colorScheme.getText(); @@ -56,6 +98,44 @@ public static void setStyledTextColoring(StyledText colorScheme, ColorRegistry c accentStyle.foreground = ColorUtils.useReadableForegroundColor(accentColor, white, black); accentStyle.background = accentColor; colorScheme.setStyleRange(accentStyle); + + white.dispose(); + black.dispose(); + } + + public void dispose() { + accentColor.dispose(); + baseColor.dispose(); + backgroundColor.dispose(); + } + + private void updateGitColors() { + ColorHSL uncommittedChangeBackground = new ColorHSL(backgroundColor).modifyProperty(MODIFICATION.INCREASE, + HSL_PROPERTY.LUMINANCE, BOUND_BEHAVIOR.REVERSE, 0.1f); + uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(MODIFICATION.INCREASE, + HSL_PROPERTY.SATURATION, BOUND_BEHAVIOR.LIMIT, 0.1f); + uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(MODIFICATION.INCREASE, + HSL_PROPERTY.HUE, BOUND_BEHAVIOR.CYCLE, 5f); + + Color uncommittedChangeForeground; + if (uncommittedChangeBackground.getPerceivedLuminance() >= 127.5f) { + uncommittedChangeForeground = new Color(display, 0, 0, 0); + } else { + uncommittedChangeForeground = new Color(display, 255, 255, 255); + } + setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor", + uncommittedChangeBackground.getColor()); + setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", + uncommittedChangeForeground); + + uncommittedChangeBackground.dispose(); + uncommittedChangeForeground.dispose(); + } + + private void setColorPreference(String preferenceKey, Color color) { + // We can't use PlatformUI.getPreferenceStore() as it won't affect preferences for plugins such as EGit + PlatformUI.getWorkbench().getPreferenceStore().setValue(preferenceKey, + String.format("%d,%d,%d", color.getRed(), color.getGreen(), color.getBlue())); } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java index 38fc0ae..0175d7c 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java @@ -3,14 +3,29 @@ import org.eclipse.swt.graphics.Color; public class ColorUtils { - + private static final String RGB_TO_HEX = "#%02X%02X%02X"; - + public static String colorToHex(Color color) { - return String.format(RGB_TO_HEX, color.getRed(), color.getGreen(), color.getBlue()); + return String.format(RGB_TO_HEX, color.getRed(), color.getGreen(), color.getBlue()); + } + + public ColorHSL ColorToHSL(Color color) { + return null; + } + + public static int maxRGB(Color color) { + return Math.max(color.getRed(), Math.max(color.getGreen(), color.getBlue())); } + public static int minRGB(Color color) { + return Math.min(color.getRed(), Math.min(color.getGreen(), color.getBlue())); + } + + // TODO: Reimplement using ColorHSL.getPerceivableLuminance() + @Deprecated public static Color useReadableForegroundColor(Color backgroundColor, Color white, Color black) { + // TODO: This is probably wrong... double luminance = 0.2126 * backgroundColor.getRed() + 0.7152 * backgroundColor.getGreen() + 0.0722 * backgroundColor.getBlue(); return luminance > 128 ? black : white; diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java new file mode 100644 index 0000000..23c98da --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java @@ -0,0 +1,29 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.IStartup; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.themes.WorkbenchThemeManager; +import org.eclipse.ui.internal.util.PrefUtil; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +public class PluginStartup implements IStartup { + + @Override + public void earlyStartup() { + IEventBroker eventBroker = PlatformUI.getWorkbench().getService(IEventBroker.class); + eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_RESTYLED, themeRegistryRestyledHandler); + eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_MODIFIED, themeRegistryRestyledHandler); + Activator.getDefault().getColorManager().updateColors(); + + } + + private EventHandler themeRegistryRestyledHandler = event -> { + // TODO: Update git uncommitted changes font to use project explorer font? + Activator.getDefault().getColorManager().updateColors(); + }; + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java index 23a8e47..47bccb1 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java @@ -3,12 +3,17 @@ import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -16,25 +21,20 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.browser.IWebBrowser; +import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.themes.WorkbenchThemeManager; +import org.eclipse.ui.internal.util.PrefUtil; import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; +import org.osgi.service.prefs.BackingStoreException; public class PreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { private IWebBrowser browser; private URL issuesURL; private URL repoURL; - - private EventHandler themeRegistryRestyledHandler = new EventHandler() { - @Override - public void handleEvent(Event event) { - String currentColorScheme = ColorManager.getCurrentColorSchemeCSS(); - colorScheme.setText(currentColorScheme); - ColorManager.setStyledTextColoring(colorScheme, Activator.getDefault().getColorRegistry()); - } - }; private StyledText colorScheme; @Override @@ -43,6 +43,8 @@ public void init(IWorkbench workbench) { IEventBroker eventBroker = workbench.getService(IEventBroker.class); eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_RESTYLED, themeRegistryRestyledHandler); eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_MODIFIED, themeRegistryRestyledHandler); + setPreferenceStore(PlatformUI.getPreferenceStore()); + try { issuesURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme/issues"); //$NON-NLS-1$ repoURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme"); //$NON-NLS-1$ @@ -65,11 +67,10 @@ protected Control createContents(Composite parent) { customizeGroup.setLayout(layout); colorScheme = new StyledText(customizeGroup, SWT.LEAD | SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); - ColorRegistry colorRegistry = Activator.getDefault().getColorRegistry(); colorScheme.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - String currentColorScheme = ColorManager.getCurrentColorSchemeCSS(); + String currentColorScheme = Activator.getDefault().getColorManager().getCurrentColorSchemeCSS(); colorScheme.setText(currentColorScheme); - ColorManager.setStyledTextColoring(colorScheme, colorRegistry); + Activator.getDefault().getColorManager().setStyledTextColoring(colorScheme); Group communityGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); communityGroup.setText(Messages.SpectrumPreferencePage_CommunityGroup); @@ -81,4 +82,13 @@ protected Control createContents(Composite parent) { return composite; } + private EventHandler themeRegistryRestyledHandler = event -> { + // Update the relevant UI when the theme's colors are modified + if (!colorScheme.isDisposed()) { + String currentColorScheme = Activator.getDefault().getColorManager().getCurrentColorSchemeCSS(); + colorScheme.setText(currentColorScheme); + Activator.getDefault().getColorManager().setStyledTextColoring(colorScheme); + } + }; + } diff --git a/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF b/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF index 8159abb..21e4560 100644 --- a/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF +++ b/com.aobuchow.themes.spectrum/META-INF/MANIFEST.MF @@ -6,5 +6,5 @@ Bundle-Version: 1.0.0.qualifier Bundle-Vendor: aobuchow Automatic-Module-Name: Spectrum_Theme Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.12.700, 0.14.000)", +Require-Bundle: org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.12.700,0.14.000)", org.eclipse.ui From 7f7cf01c9a8775dbf657ed4d0f78a0a3c599f636 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Mon, 20 Jul 2020 23:11:49 -0400 Subject: [PATCH 5/9] Remove MODIFICATION_TYPE parameter from ColorHSL.modifyProperty() Signed-off-by: Andrew Obuchowicz --- .../spectrum/preferences/Activator.java | 8 --- .../themes/spectrum/preferences/ColorHSL.java | 23 +++------ .../spectrum/preferences/ColorManager.java | 50 +++++++------------ .../spectrum/preferences/ColorUtils.java | 17 ++----- .../spectrum/preferences/PluginStartup.java | 4 -- .../spectrum/preferences/PreferencesPage.java | 10 ---- 6 files changed, 29 insertions(+), 83 deletions(-) diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java index 1803516..32d60b9 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Activator.java @@ -1,15 +1,7 @@ package com.aobuchow.themes.spectrum.preferences; -import org.eclipse.e4.core.services.events.IEventBroker; -import org.eclipse.jface.resource.ColorRegistry; -import org.eclipse.swt.graphics.Color; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.internal.themes.WorkbenchThemeManager; -import org.eclipse.ui.internal.util.PrefUtil; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; -import org.osgi.service.event.Event; -import org.osgi.service.event.EventHandler; /** * The activator class controls the plug-in life cycle diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java index 0127847..d9afbce 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java @@ -22,8 +22,7 @@ public ColorHSL(float hue, float saturation, float luminance) { } // TODO: Add test coverage - public ColorHSL modifyProperty(MODIFICATION modificationType, HSL_PROPERTY propertyToModify, - BOUND_BEHAVIOR boundBehavior, float amount) { + public ColorHSL modifyProperty(HSL_PROPERTY propertyToModify, BOUND_BEHAVIOR boundBehavior, float amount) { // Hue must be within the range [0, 360] // Saturation must be within the range [0, 1] // Luminance must be within the range [0, 1] @@ -44,14 +43,7 @@ public ColorHSL modifyProperty(MODIFICATION modificationType, HSL_PROPERTY prope break; } - switch (modificationType) { - case INCREASE: - newValue = newValue + amount; - break; - case DECREASE: - newValue = newValue - amount; - break; - } + newValue = newValue + amount; switch (boundBehavior) { case CYCLE: @@ -85,7 +77,7 @@ public ColorHSL modifyProperty(MODIFICATION modificationType, HSL_PROPERTY prope return null; } - + public void dispose() { color.dispose(); } @@ -110,10 +102,6 @@ public float getPerceivedLuminance() { return (299f * color.getRed() + 587f * color.getGreen() + 114f * color.getBlue()) / 1000; } - enum MODIFICATION { - INCREASE, DECREASE; - } - /* * How the modification amount to a property should behave when hitting an upper * or lower bound. @@ -134,8 +122,9 @@ enum BOUND_BEHAVIOR { REVERSE, /* - * Set the amount to the nearest bound. Example: Fora color with a luminance of 0.6f, increasing the luminance by 0.5f while using the LIMIT - * BOUND_BEHAVIOR will result in the color having a luminance of 1f. + * Set the amount to the nearest bound. Example: Fora color with a luminance of + * 0.6f, increasing the luminance by 0.5f while using the LIMIT BOUND_BEHAVIOR + * will result in the color having a luminance of 1f. */ LIMIT; } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java index dc2c111..e946c34 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -11,13 +11,10 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.util.PrefUtil; import org.osgi.service.prefs.BackingStoreException; import com.aobuchow.themes.spectrum.preferences.ColorHSL.BOUND_BEHAVIOR; import com.aobuchow.themes.spectrum.preferences.ColorHSL.HSL_PROPERTY; -import com.aobuchow.themes.spectrum.preferences.ColorHSL.MODIFICATION; public class ColorManager { private static final String BACKGROUND_COLOR_ID = "com.aobuchow.themes.spectrum.BACKGROUND_COLOR"; @@ -62,17 +59,14 @@ public String getCurrentColorSchemeCSS() { String accentColorHex = ColorUtils.colorToHex(accentColor); String baseColorHex = ColorUtils.colorToHex(baseColor); String backgroundColorHex = ColorUtils.colorToHex(backgroundColor); - String currentColorScheme = "ColorScheme {\n" + - " --background-color: " + backgroundColorHex + ";\n" + - " --base-color: " + baseColorHex + ";\n" + - " --accent-color: " + accentColorHex + ";\n" + - "}"; + String currentColorScheme = "ColorScheme {\n" + " --background-color: " + backgroundColorHex + ";\n" + + " --base-color: " + baseColorHex + ";\n" + " --accent-color: " + accentColorHex + ";\n" + "}"; return currentColorScheme; } public void setStyledTextColoring(StyledText colorScheme) { - Color white = new Color(colorScheme.getDisplay(), 255, 255, 255); - Color black = new Color(colorScheme.getDisplay(), 0, 0, 0); + Color white = display.getSystemColor(SWT.COLOR_WHITE); + Color black = display.getSystemColor(SWT.COLOR_BLACK); String text = colorScheme.getText(); StyleRange bgStyle = new StyleRange(); @@ -98,11 +92,8 @@ public void setStyledTextColoring(StyledText colorScheme) { accentStyle.foreground = ColorUtils.useReadableForegroundColor(accentColor, white, black); accentStyle.background = accentColor; colorScheme.setStyleRange(accentStyle); - - white.dispose(); - black.dispose(); } - + public void dispose() { accentColor.dispose(); baseColor.dispose(); @@ -110,30 +101,27 @@ public void dispose() { } private void updateGitColors() { - ColorHSL uncommittedChangeBackground = new ColorHSL(backgroundColor).modifyProperty(MODIFICATION.INCREASE, - HSL_PROPERTY.LUMINANCE, BOUND_BEHAVIOR.REVERSE, 0.1f); - uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(MODIFICATION.INCREASE, - HSL_PROPERTY.SATURATION, BOUND_BEHAVIOR.LIMIT, 0.1f); - uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(MODIFICATION.INCREASE, - HSL_PROPERTY.HUE, BOUND_BEHAVIOR.CYCLE, 5f); - - Color uncommittedChangeForeground; - if (uncommittedChangeBackground.getPerceivedLuminance() >= 127.5f) { - uncommittedChangeForeground = new Color(display, 0, 0, 0); - } else { - uncommittedChangeForeground = new Color(display, 255, 255, 255); - } + ColorHSL uncommittedChangeBackground = new ColorHSL(backgroundColor).modifyProperty(HSL_PROPERTY.LUMINANCE, + BOUND_BEHAVIOR.REVERSE, 0.1f); + uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(HSL_PROPERTY.SATURATION, + BOUND_BEHAVIOR.LIMIT, 0.1f); + uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(HSL_PROPERTY.HUE, BOUND_BEHAVIOR.CYCLE, + 5f); + Color uncommittedChangeForeground = ColorUtils.useReadableForegroundColor( + uncommittedChangeBackground.getColor(), display.getSystemColor(SWT.COLOR_WHITE), + display.getSystemColor(SWT.COLOR_BLACK)); + setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor", uncommittedChangeBackground.getColor()); - setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", - uncommittedChangeForeground); - + setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", uncommittedChangeForeground); + uncommittedChangeBackground.dispose(); uncommittedChangeForeground.dispose(); } private void setColorPreference(String preferenceKey, Color color) { - // We can't use PlatformUI.getPreferenceStore() as it won't affect preferences for plugins such as EGit + // We can't use PlatformUI.getPreferenceStore() as it won't affect preferences + // for plugins such as EGit PlatformUI.getWorkbench().getPreferenceStore().setValue(preferenceKey, String.format("%d,%d,%d", color.getRed(), color.getGreen(), color.getBlue())); } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java index 0175d7c..ca4feb2 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorUtils.java @@ -2,18 +2,14 @@ import org.eclipse.swt.graphics.Color; -public class ColorUtils { +public interface ColorUtils { - private static final String RGB_TO_HEX = "#%02X%02X%02X"; + static final String RGB_TO_HEX = "#%02X%02X%02X"; public static String colorToHex(Color color) { return String.format(RGB_TO_HEX, color.getRed(), color.getGreen(), color.getBlue()); } - - public ColorHSL ColorToHSL(Color color) { - return null; - } - + public static int maxRGB(Color color) { return Math.max(color.getRed(), Math.max(color.getGreen(), color.getBlue())); } @@ -22,13 +18,8 @@ public static int minRGB(Color color) { return Math.min(color.getRed(), Math.min(color.getGreen(), color.getBlue())); } - // TODO: Reimplement using ColorHSL.getPerceivableLuminance() - @Deprecated public static Color useReadableForegroundColor(Color backgroundColor, Color white, Color black) { - // TODO: This is probably wrong... - double luminance = 0.2126 * backgroundColor.getRed() + 0.7152 * backgroundColor.getGreen() - + 0.0722 * backgroundColor.getBlue(); - return luminance > 128 ? black : white; + return new ColorHSL(backgroundColor).getPerceivedLuminance() >= 127.5f ? black : white; } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java index 23c98da..91f7bb2 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java @@ -1,13 +1,9 @@ package com.aobuchow.themes.spectrum.preferences; import org.eclipse.e4.core.services.events.IEventBroker; -import org.eclipse.jface.resource.ColorRegistry; -import org.eclipse.swt.graphics.Color; import org.eclipse.ui.IStartup; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.themes.WorkbenchThemeManager; -import org.eclipse.ui.internal.util.PrefUtil; -import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; public class PluginStartup implements IStartup { diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java index 47bccb1..39d99b6 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java @@ -3,17 +3,11 @@ import java.net.MalformedURLException; import java.net.URL; -import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.preferences.ConfigurationScope; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -23,12 +17,8 @@ import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.browser.IWebBrowser; -import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.themes.WorkbenchThemeManager; -import org.eclipse.ui.internal.util.PrefUtil; -import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; -import org.osgi.service.prefs.BackingStoreException; public class PreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { From ef314751a352a7e3f6ebfd51394065d4dbc4973e Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Mon, 20 Jul 2020 23:30:17 -0400 Subject: [PATCH 6/9] Get system colors on the UI thread Signed-off-by: Andrew Obuchowicz --- .../spectrum/preferences/ColorManager.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java index e946c34..ab595a2 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -65,6 +65,7 @@ public String getCurrentColorSchemeCSS() { } public void setStyledTextColoring(StyledText colorScheme) { + display.asyncExec(() -> { Color white = display.getSystemColor(SWT.COLOR_WHITE); Color black = display.getSystemColor(SWT.COLOR_BLACK); String text = colorScheme.getText(); @@ -92,6 +93,7 @@ public void setStyledTextColoring(StyledText colorScheme) { accentStyle.foreground = ColorUtils.useReadableForegroundColor(accentColor, white, black); accentStyle.background = accentColor; colorScheme.setStyleRange(accentStyle); + }); } public void dispose() { @@ -101,22 +103,21 @@ public void dispose() { } private void updateGitColors() { - ColorHSL uncommittedChangeBackground = new ColorHSL(backgroundColor).modifyProperty(HSL_PROPERTY.LUMINANCE, - BOUND_BEHAVIOR.REVERSE, 0.1f); - uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(HSL_PROPERTY.SATURATION, - BOUND_BEHAVIOR.LIMIT, 0.1f); - uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(HSL_PROPERTY.HUE, BOUND_BEHAVIOR.CYCLE, - 5f); - Color uncommittedChangeForeground = ColorUtils.useReadableForegroundColor( - uncommittedChangeBackground.getColor(), display.getSystemColor(SWT.COLOR_WHITE), - display.getSystemColor(SWT.COLOR_BLACK)); - - setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor", - uncommittedChangeBackground.getColor()); - setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", uncommittedChangeForeground); - - uncommittedChangeBackground.dispose(); - uncommittedChangeForeground.dispose(); + display.asyncExec(() -> { + ColorHSL uncommittedChangeBackground = new ColorHSL(backgroundColor).modifyProperty(HSL_PROPERTY.LUMINANCE, + BOUND_BEHAVIOR.REVERSE, 0.1f); + uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(HSL_PROPERTY.SATURATION, + BOUND_BEHAVIOR.LIMIT, 0.1f); + uncommittedChangeBackground = uncommittedChangeBackground.modifyProperty(HSL_PROPERTY.HUE, + BOUND_BEHAVIOR.CYCLE, 5f); + Color uncommittedChangeForeground = ColorUtils.useReadableForegroundColor( + uncommittedChangeBackground.getColor(), display.getSystemColor(SWT.COLOR_WHITE), + display.getSystemColor(SWT.COLOR_BLACK)); + setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", uncommittedChangeForeground); + setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor", + uncommittedChangeBackground.getColor()); + uncommittedChangeBackground.dispose(); + }); } private void setColorPreference(String preferenceKey, Color color) { From 4a8f2b308052637c2a7697dd65cab75aa46c4bd3 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Tue, 21 Jul 2020 23:37:53 -0400 Subject: [PATCH 7/9] Add preferences to modify HSL of the theme Signed-off-by: Andrew Obuchowicz --- .../themes/spectrum/preferences/ColorHSL.java | 24 +++- .../spectrum/preferences/ColorManager.java | 114 +++++++++++++----- .../themes/spectrum/preferences/Messages.java | 3 + .../spectrum/preferences/PluginStartup.java | 3 + .../spectrum/preferences/PreferencesPage.java | 113 ++++++++++++++++- .../spectrum/preferences/messages.properties | 3 + 6 files changed, 230 insertions(+), 30 deletions(-) diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java index d9afbce..5ef7743 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorHSL.java @@ -54,8 +54,7 @@ public ColorHSL modifyProperty(HSL_PROPERTY propertyToModify, BOUND_BEHAVIOR bou } break; case LIMIT: - newValue = Math.min(newValue, max); - newValue = Math.max(newValue, min); + newValue = setFloatBounds(newValue, min, max); break; case REVERSE: if (newValue < min) { @@ -102,6 +101,27 @@ public float getPerceivedLuminance() { return (299f * color.getRed() + 587f * color.getGreen() + 114f * color.getBlue()) / 1000; } + public ColorHSL setHue(float hue) { + hue = setFloatBounds(hue, 0, 360); + return new ColorHSL(hue, this.getSaturation(), this.getLuminance()); + } + + public ColorHSL setSaturation(float saturation) { + saturation = setFloatBounds(saturation, 0, 1); + return new ColorHSL(this.getHue(), saturation, this.getLuminance()); + } + + public ColorHSL setLuminance(float luminance) { + luminance = setFloatBounds(luminance, 0, 1); + return new ColorHSL(this.getHue(), this.getSaturation(), luminance); + } + + private static float setFloatBounds(float value, float min, float max) { + value = Math.min(value, max); + value = Math.max(value, min); + return value; + } + /* * How the modification amount to a property should behave when hitting an upper * or lower bound. diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java index ab595a2..f93a215 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -1,7 +1,11 @@ package com.aobuchow.themes.spectrum.preferences; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.jface.resource.ColorRegistry; @@ -11,6 +15,7 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.themes.WorkbenchThemeManager; import org.osgi.service.prefs.BackingStoreException; import com.aobuchow.themes.spectrum.preferences.ColorHSL.BOUND_BEHAVIOR; @@ -27,15 +32,19 @@ public class ColorManager { private IThemeEngine engine; private final String THEME_ID = "spectrum.dark.theme.id"; private Display display; + private IEventBroker eventBroker; public ColorManager() { MApplication application = PlatformUI.getWorkbench().getService(MApplication.class); IEclipseContext context = application.getContext(); engine = context.get(IThemeEngine.class); display = PlatformUI.getWorkbench().getDisplay(); + eventBroker = PlatformUI.getWorkbench().getService(IEventBroker.class); updateColors(); } + // Should only be called from PluginStartup theme registry listener, clients + // should use saveColors() instead public void updateColors() { this.colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); accentColor = colorRegistry.get(ACCENT_COLOR_ID); @@ -47,6 +56,18 @@ public void updateColors() { } } + public void saveColors() { + setColorPreference(BACKGROUND_COLOR_ID, backgroundColor); + colorRegistry.put(BACKGROUND_COLOR_ID, backgroundColor.getRGB()); + setColorPreference(BASE_COLOR_ID, baseColor); + colorRegistry.put(BASE_COLOR_ID, baseColor.getRGB()); + setColorPreference(ACCENT_COLOR_ID, accentColor); + colorRegistry.put(ACCENT_COLOR_ID, accentColor.getRGB()); + savePreferences(); + updateColors(); + eventBroker.send(WorkbenchThemeManager.Events.THEME_REGISTRY_MODIFIED, null); + } + private void savePreferences() { try { InstanceScope.INSTANCE.getNode(PlatformUI.PLUGIN_ID).flush(); @@ -66,33 +87,33 @@ public String getCurrentColorSchemeCSS() { public void setStyledTextColoring(StyledText colorScheme) { display.asyncExec(() -> { - Color white = display.getSystemColor(SWT.COLOR_WHITE); - Color black = display.getSystemColor(SWT.COLOR_BLACK); - String text = colorScheme.getText(); - - StyleRange bgStyle = new StyleRange(); - bgStyle.start = text.indexOf("--background-color:") + "--background-color:".length() + 1; - bgStyle.length = 7; - bgStyle.fontStyle = SWT.BOLD; - bgStyle.background = backgroundColor; - bgStyle.foreground = ColorUtils.useReadableForegroundColor(backgroundColor, white, black); - colorScheme.setStyleRange(bgStyle); - - StyleRange baseStyle = new StyleRange(); - baseStyle.start = text.indexOf("--base-color:") + "--base-color:".length() + 1; - baseStyle.length = 7; - baseStyle.fontStyle = SWT.BOLD; - baseStyle.background = baseColor; - baseStyle.foreground = ColorUtils.useReadableForegroundColor(baseColor, white, black); - colorScheme.setStyleRange(baseStyle); - - StyleRange accentStyle = new StyleRange(); - accentStyle.start = text.indexOf("--accent-color:") + "--accent-color:".length() + 1; - accentStyle.length = 7; - accentStyle.fontStyle = SWT.BOLD; - accentStyle.foreground = ColorUtils.useReadableForegroundColor(accentColor, white, black); - accentStyle.background = accentColor; - colorScheme.setStyleRange(accentStyle); + Color white = display.getSystemColor(SWT.COLOR_WHITE); + Color black = display.getSystemColor(SWT.COLOR_BLACK); + String text = colorScheme.getText(); + + StyleRange bgStyle = new StyleRange(); + bgStyle.start = text.indexOf("--background-color:") + "--background-color:".length() + 1; + bgStyle.length = 7; + bgStyle.fontStyle = SWT.BOLD; + bgStyle.background = backgroundColor; + bgStyle.foreground = ColorUtils.useReadableForegroundColor(backgroundColor, white, black); + colorScheme.setStyleRange(bgStyle); + + StyleRange baseStyle = new StyleRange(); + baseStyle.start = text.indexOf("--base-color:") + "--base-color:".length() + 1; + baseStyle.length = 7; + baseStyle.fontStyle = SWT.BOLD; + baseStyle.background = baseColor; + baseStyle.foreground = ColorUtils.useReadableForegroundColor(baseColor, white, black); + colorScheme.setStyleRange(baseStyle); + + StyleRange accentStyle = new StyleRange(); + accentStyle.start = text.indexOf("--accent-color:") + "--accent-color:".length() + 1; + accentStyle.length = 7; + accentStyle.fontStyle = SWT.BOLD; + accentStyle.foreground = ColorUtils.useReadableForegroundColor(accentColor, white, black); + accentStyle.background = accentColor; + colorScheme.setStyleRange(accentStyle); }); } @@ -127,4 +148,43 @@ private void setColorPreference(String preferenceKey, Color color) { String.format("%d,%d,%d", color.getRed(), color.getGreen(), color.getBlue())); } + public Color getAccentColor() { + return accentColor; + } + + public void setAccentColor(Color accentColor) { + this.accentColor = accentColor; + } + + public Color getBaseColor() { + return baseColor; + } + + public void setBaseColor(Color baseColor) { + this.baseColor = baseColor; + } + + public Color getBackgroundColor() { + return backgroundColor; + } + + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public List getThemeColors() { + List colors = new ArrayList<>(); + colors.add(accentColor); + colors.add(baseColor); + colors.add(backgroundColor); + return colors; + } + + public void resetColors() { + this.setBackgroundColor(new Color(display, 23, 23, 27)); + this.setBaseColor(new Color(display, 47, 47, 47)); + this.setAccentColor(new Color(display, 215, 0, 0)); + this.saveColors(); + } + } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java index 51a8646..bb5e8cd 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java @@ -4,6 +4,9 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "com.aobuchow.themes.spectrum.preferences.messages"; //$NON-NLS-1$ + public static String PreferencesPage_LabelHue; + public static String PreferencesPage_LabelLuminance; + public static String PreferencesPage_LabelSaturation; public static String SpectrumPreferencePage_BugReportLink; public static String SpectrumPreferencePage_CommunityGroup; public static String SpectrumPreferencePage_CustomizationGroup; diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java index 91f7bb2..1d63983 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PluginStartup.java @@ -17,6 +17,9 @@ public void earlyStartup() { } + // TODO: investigate why this listener is required here. Setting it in the + // ColorManager doesn't seem to + // respond to theme registry events. private EventHandler themeRegistryRestyledHandler = event -> { // TODO: Update git uncommitted changes font to use project explorer font? Activator.getDefault().getColorManager().updateColors(); diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java index 39d99b6..9658eaa 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java @@ -8,11 +8,15 @@ import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; @@ -20,21 +24,37 @@ import org.eclipse.ui.internal.themes.WorkbenchThemeManager; import org.osgi.service.event.EventHandler; +import com.aobuchow.themes.spectrum.preferences.ColorHSL.BOUND_BEHAVIOR; +import com.aobuchow.themes.spectrum.preferences.ColorHSL.HSL_PROPERTY; + public class PreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { private IWebBrowser browser; private URL issuesURL; private URL repoURL; private StyledText colorScheme; + private Color prevAccentColor; + private Color prevBaseColor; + private IEventBroker eventBroker; + private ColorManager colorManager; + private Color prevBackgroundColor; + private Scale hueScale; + private Scale saturationScale; + private Scale luminanceScale; @Override public void init(IWorkbench workbench) { + colorManager = Activator.getDefault().getColorManager(); browser = BrowserUtils.newBrowser(); - IEventBroker eventBroker = workbench.getService(IEventBroker.class); + eventBroker = workbench.getService(IEventBroker.class); eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_RESTYLED, themeRegistryRestyledHandler); eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_MODIFIED, themeRegistryRestyledHandler); setPreferenceStore(PlatformUI.getPreferenceStore()); + prevBackgroundColor = colorManager.getBackgroundColor(); + prevBaseColor = colorManager.getBaseColor(); + prevAccentColor = colorManager.getAccentColor(); + try { issuesURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme/issues"); //$NON-NLS-1$ repoURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme"); //$NON-NLS-1$ @@ -56,6 +76,8 @@ protected Control createContents(Composite parent) { customizeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); customizeGroup.setLayout(layout); + addHSLCustomization(customizeGroup); + colorScheme = new StyledText(customizeGroup, SWT.LEAD | SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); colorScheme.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); String currentColorScheme = Activator.getDefault().getColorManager().getCurrentColorSchemeCSS(); @@ -72,6 +94,76 @@ protected Control createContents(Composite parent) { return composite; } + private void addHSLCustomization(Group customizeGroup) { + Text hueLabel = new Text(customizeGroup, SWT.BOLD); + hueLabel.setText(Messages.PreferencesPage_LabelHue); + hueScale = newScale(customizeGroup, 0, 360, + (int) new ColorHSL(colorManager.getBackgroundColor()).getHue()); + hueScale.addListener(SWT.Selection, event -> { + int selectionValue = hueScale.getSelection(); + ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setHue(selectionValue); + ColorHSL newBaseColor = new ColorHSL(prevBaseColor).setHue(selectionValue) + .modifyProperty(HSL_PROPERTY.SATURATION, BOUND_BEHAVIOR.LIMIT, -0.1f); + ColorHSL newAccentColor = new ColorHSL(colorManager.getAccentColor()).setHue(selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + colorManager.setBaseColor(newBaseColor.getColor()); + colorManager.setAccentColor(newAccentColor.getColor()); + colorManager.saveColors(); + }); + + Text saturationLabel = new Text(customizeGroup, SWT.BOLD); + saturationLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true)); + saturationLabel.setText(Messages.PreferencesPage_LabelSaturation); + saturationScale = newScale(customizeGroup, 0, 100, + (int) (new ColorHSL(colorManager.getBackgroundColor()).getSaturation() * 100)); + saturationScale.addListener(SWT.Selection, event -> { + float selectionValue = ((float) saturationScale.getSelection()) / 100; + ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setSaturation(selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + colorManager.saveColors(); + }); + + Text luminanceLabel = new Text(customizeGroup, SWT.BOLD); + luminanceLabel.setText(Messages.PreferencesPage_LabelLuminance); + luminanceScale = newScale(customizeGroup, 0, 100, + (int) (new ColorHSL(colorManager.getBackgroundColor()).getLuminance() * 100)); + luminanceScale.addListener(SWT.Selection, event -> { + float selectionValue = ((float) luminanceScale.getSelection()) / 100; + ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setLuminance(selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + colorManager.saveColors(); + }); + } + + @Override + public boolean performOk() { + prevBackgroundColor = colorManager.getBackgroundColor(); + prevBaseColor = colorManager.getBaseColor(); + prevAccentColor = colorManager.getAccentColor(); + updateScales(); + return super.performOk(); + } + + @Override + protected void performDefaults() { + colorManager.resetColors(); + updateScales(); + super.performDefaults(); + } + + @Override + public boolean performCancel() { + colorManager.setBackgroundColor(prevBackgroundColor); + colorManager.setBaseColor(prevBaseColor); + colorManager.setAccentColor(prevAccentColor); + colorManager.saveColors(); + prevBackgroundColor = colorManager.getBackgroundColor(); + prevBaseColor = colorManager.getBaseColor(); + prevAccentColor = colorManager.getAccentColor(); + updateScales(); + return super.performCancel(); + } + private EventHandler themeRegistryRestyledHandler = event -> { // Update the relevant UI when the theme's colors are modified if (!colorScheme.isDisposed()) { @@ -81,4 +173,23 @@ protected Control createContents(Composite parent) { } }; + private void updateScales() { + hueScale.setSelection((int) new ColorHSL(colorManager.getBackgroundColor()).getHue()); + saturationScale.setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getSaturation() * 100)); + luminanceScale.setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getLuminance() * 100)); + } + + private static Scale newScale(Composite parent, int min, int max, int selection) { + Scale scale = new Scale(parent, SWT.BORDER); + scale.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + Rectangle clientArea = parent.getClientArea(); + scale.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height); + scale.setMaximum(max); + scale.setMinimum(min); + scale.setSelection(selection); + scale.setPageIncrement(5); + scale.setIncrement(5); + return scale; + } + } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties index 0944b2e..21179da 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties @@ -1,3 +1,6 @@ +PreferencesPage_LabelHue=Hue: +PreferencesPage_LabelLuminance=Brightness: +PreferencesPage_LabelSaturation=Saturation: SpectrumPreferencePage_BugReportLink=Report a bug or feature request: open GitHub Issues. SpectrumPreferencePage_CommunityGroup=Get involved: SpectrumPreferencePage_CustomizationGroup=Customization: From 55b56a65a56ba12dfea336e9d670f9d5ff61c140 Mon Sep 17 00:00:00 2001 From: Ingo Mohr Date: Tue, 11 Aug 2020 00:24:40 +0200 Subject: [PATCH 8/9] Update layout of preference page; make links open in their own browsers --- .../META-INF/MANIFEST.MF | 3 +- .../spectrum/preferences/BrowserUtils.java | 41 ++--- .../themes/spectrum/preferences/Messages.java | 3 + .../spectrum/preferences/PreferencesPage.java | 133 +++++++---------- .../SpectrumPreferencesControl.java | 141 ++++++++++++++++++ .../spectrum/preferences/messages.properties | 7 +- 6 files changed, 211 insertions(+), 117 deletions(-) create mode 100644 com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/SpectrumPreferencesControl.java diff --git a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF index 016d6d8..ca1cbe1 100644 --- a/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF +++ b/com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.e4.core.services, org.eclipse.e4.ui.model.workbench, org.eclipse.e4.core.contexts, - org.eclipse.e4.ui.css.swt.theme + org.eclipse.e4.ui.css.swt.theme, + org.eclipse.ui.forms;bundle-version="3.9.100" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Automatic-Module-Name: com.aobuchow.themes.spectrum.preferences Bundle-ActivationPolicy: lazy diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java index fd25b5d..5751bed 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/BrowserUtils.java @@ -1,46 +1,25 @@ package com.aobuchow.themes.spectrum.preferences; +import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Link; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.browser.IWebBrowser; -public interface BrowserUtils { +public final class BrowserUtils { - public static IWebBrowser newBrowser() { - IWebBrowser browser = null; + public static void openUrl(String category, String url) { try { - browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser("spectrum.browser"); //$NON-NLS-1$ - } catch (PartInitException e) { - // Internal browser shouldn't cause an exception - Activator.getDefault().getLog().log(new Status(org.eclipse.jface.dialogs.IMessageProvider.ERROR, BrowserUtils.class, e.getMessage())); + IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport() + .createBrowser("spectrum.browser." + category); + browser.openURL(new URL(url)); + } catch (PartInitException | MalformedURLException e) { + final Status status = new Status(IStatus.ERROR, BrowserUtils.class, "Cannot open URL '" + url + "'", e); + Activator.getDefault().getLog().log(status); } - - try { - browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser(); - } catch (PartInitException e) { - Activator.getDefault().getLog().log(new Status(org.eclipse.jface.dialogs.IMessageProvider.INFORMATION, BrowserUtils.class, e.getMessage())); - } - - return browser; - } - - public static Link createLinkURL(Group parent, String text, URL url, IWebBrowser webBrowser) { - Link link = new Link(parent, SWT.BORDER | SWT.BOLD); - link.setText(text); - link.addListener(SWT.Selection, event -> { - try { - webBrowser.openURL(url); - } catch (PartInitException e) { - Activator.getDefault().getLog().log(new Status(org.eclipse.jface.dialogs.IMessageProvider.ERROR, BrowserUtils.class, e.getMessage())); - } - }); - return link; } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java index bb5e8cd..502d545 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/Messages.java @@ -11,6 +11,9 @@ public class Messages extends NLS { public static String SpectrumPreferencePage_CommunityGroup; public static String SpectrumPreferencePage_CustomizationGroup; public static String SpectrumPreferencePage_RepositoryLink; + public static String SpectrumPreferencePage_GithubURL_Issues; + public static String SpectrumPreferencePage_GithubURL; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java index 9658eaa..601ab09 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/PreferencesPage.java @@ -1,26 +1,17 @@ package com.aobuchow.themes.spectrum.preferences; -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.runtime.Status; import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.browser.IWebBrowser; import org.eclipse.ui.internal.themes.WorkbenchThemeManager; import org.osgi.service.event.EventHandler; @@ -29,23 +20,17 @@ public class PreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { - private IWebBrowser browser; - private URL issuesURL; - private URL repoURL; - private StyledText colorScheme; private Color prevAccentColor; private Color prevBaseColor; private IEventBroker eventBroker; private ColorManager colorManager; private Color prevBackgroundColor; - private Scale hueScale; - private Scale saturationScale; - private Scale luminanceScale; + + private SpectrumPreferencesControl preferenceControl; @Override public void init(IWorkbench workbench) { colorManager = Activator.getDefault().getColorManager(); - browser = BrowserUtils.newBrowser(); eventBroker = workbench.getService(IEventBroker.class); eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_RESTYLED, themeRegistryRestyledHandler); eventBroker.subscribe(WorkbenchThemeManager.Events.THEME_REGISTRY_MODIFIED, themeRegistryRestyledHandler); @@ -54,51 +39,33 @@ public void init(IWorkbench workbench) { prevBackgroundColor = colorManager.getBackgroundColor(); prevBaseColor = colorManager.getBaseColor(); prevAccentColor = colorManager.getAccentColor(); - - try { - issuesURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme/issues"); //$NON-NLS-1$ - repoURL = new URL("https://github.com/AObuchow/Eclipse-Spectrum-Theme"); //$NON-NLS-1$ - } catch (MalformedURLException e) { - Activator.getDefault().getLog().log(new Status(ERROR, getClass(), e.getMessage())); - } } @Override protected Control createContents(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(1, true); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - Group customizeGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); - customizeGroup.setText(Messages.SpectrumPreferencePage_CustomizationGroup); - customizeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - customizeGroup.setLayout(layout); + preferenceControl = new SpectrumPreferencesControl(parent, SWT.NONE); + + addHSLCustomization(preferenceControl); + + preferenceControl.getRepoLink().addSelectionListener( + SelectionListener.widgetSelectedAdapter(e -> openURL("repo", Messages.SpectrumPreferencePage_GithubURL))); - addHSLCustomization(customizeGroup); + preferenceControl.getIssuesLink().addSelectionListener(SelectionListener + .widgetSelectedAdapter(e -> openURL("issues", Messages.SpectrumPreferencePage_GithubURL_Issues))); - colorScheme = new StyledText(customizeGroup, SWT.LEAD | SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); - colorScheme.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); String currentColorScheme = Activator.getDefault().getColorManager().getCurrentColorSchemeCSS(); - colorScheme.setText(currentColorScheme); - Activator.getDefault().getColorManager().setStyledTextColoring(colorScheme); + final StyledText cssText = preferenceControl.getCssText(); + cssText.setText(currentColorScheme); + Activator.getDefault().getColorManager().setStyledTextColoring(cssText); - Group communityGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); - communityGroup.setText(Messages.SpectrumPreferencePage_CommunityGroup); - communityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - communityGroup.setLayout(layout); - BrowserUtils.createLinkURL(communityGroup, Messages.SpectrumPreferencePage_RepositoryLink, repoURL, browser); - BrowserUtils.createLinkURL(communityGroup, Messages.SpectrumPreferencePage_BugReportLink, issuesURL, browser); + refresh(); - return composite; + return preferenceControl; } - private void addHSLCustomization(Group customizeGroup) { - Text hueLabel = new Text(customizeGroup, SWT.BOLD); - hueLabel.setText(Messages.PreferencesPage_LabelHue); - hueScale = newScale(customizeGroup, 0, 360, - (int) new ColorHSL(colorManager.getBackgroundColor()).getHue()); + private void addHSLCustomization(SpectrumPreferencesControl control) { + final Scale hueScale = control.getHueScale(); hueScale.addListener(SWT.Selection, event -> { int selectionValue = hueScale.getSelection(); ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setHue(selectionValue); @@ -111,11 +78,7 @@ private void addHSLCustomization(Group customizeGroup) { colorManager.saveColors(); }); - Text saturationLabel = new Text(customizeGroup, SWT.BOLD); - saturationLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true)); - saturationLabel.setText(Messages.PreferencesPage_LabelSaturation); - saturationScale = newScale(customizeGroup, 0, 100, - (int) (new ColorHSL(colorManager.getBackgroundColor()).getSaturation() * 100)); + final Scale saturationScale = control.getSaturationScale(); saturationScale.addListener(SWT.Selection, event -> { float selectionValue = ((float) saturationScale.getSelection()) / 100; ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setSaturation(selectionValue); @@ -123,12 +86,9 @@ private void addHSLCustomization(Group customizeGroup) { colorManager.saveColors(); }); - Text luminanceLabel = new Text(customizeGroup, SWT.BOLD); - luminanceLabel.setText(Messages.PreferencesPage_LabelLuminance); - luminanceScale = newScale(customizeGroup, 0, 100, - (int) (new ColorHSL(colorManager.getBackgroundColor()).getLuminance() * 100)); - luminanceScale.addListener(SWT.Selection, event -> { - float selectionValue = ((float) luminanceScale.getSelection()) / 100; + final Scale brightnessScale = control.getBrightnessScale(); + brightnessScale.addListener(SWT.Selection, event -> { + float selectionValue = ((float) brightnessScale.getSelection()) / 100; ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setLuminance(selectionValue); colorManager.setBackgroundColor(newBackgroundColor.getColor()); colorManager.saveColors(); @@ -140,14 +100,14 @@ public boolean performOk() { prevBackgroundColor = colorManager.getBackgroundColor(); prevBaseColor = colorManager.getBaseColor(); prevAccentColor = colorManager.getAccentColor(); - updateScales(); + refresh(); return super.performOk(); } @Override protected void performDefaults() { colorManager.resetColors(); - updateScales(); + refresh(); super.performDefaults(); } @@ -160,36 +120,43 @@ public boolean performCancel() { prevBackgroundColor = colorManager.getBackgroundColor(); prevBaseColor = colorManager.getBaseColor(); prevAccentColor = colorManager.getAccentColor(); - updateScales(); + refresh(); return super.performCancel(); } private EventHandler themeRegistryRestyledHandler = event -> { // Update the relevant UI when the theme's colors are modified - if (!colorScheme.isDisposed()) { + if (!getControl().isDisposed()) { String currentColorScheme = Activator.getDefault().getColorManager().getCurrentColorSchemeCSS(); - colorScheme.setText(currentColorScheme); - Activator.getDefault().getColorManager().setStyledTextColoring(colorScheme); + final StyledText cssText = preferenceControl.getCssText(); + cssText.setText(currentColorScheme); + Activator.getDefault().getColorManager().setStyledTextColoring(cssText); } }; - private void updateScales() { - hueScale.setSelection((int) new ColorHSL(colorManager.getBackgroundColor()).getHue()); - saturationScale.setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getSaturation() * 100)); - luminanceScale.setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getLuminance() * 100)); + private void refresh() { + refreshScales(); + refreshCssText(); + } + + private void refreshScales() { + preferenceControl.getHueScale().setSelection((int) new ColorHSL(colorManager.getBackgroundColor()).getHue()); + preferenceControl.getSaturationScale() + .setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getSaturation() * 100)); + preferenceControl.getBrightnessScale() + .setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getLuminance() * 100)); + } + + private void refreshCssText() { + String currentColorScheme = Activator.getDefault().getColorManager().getCurrentColorSchemeCSS(); + final StyledText cssText = preferenceControl.getCssText(); + if (!cssText.getText().equals(currentColorScheme)) { + cssText.setText(currentColorScheme); + } } - private static Scale newScale(Composite parent, int min, int max, int selection) { - Scale scale = new Scale(parent, SWT.BORDER); - scale.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - Rectangle clientArea = parent.getClientArea(); - scale.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height); - scale.setMaximum(max); - scale.setMinimum(min); - scale.setSelection(selection); - scale.setPageIncrement(5); - scale.setIncrement(5); - return scale; + private void openURL(String category, String url) { + BrowserUtils.openUrl(category, url); } } diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/SpectrumPreferencesControl.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/SpectrumPreferencesControl.java new file mode 100644 index 0000000..92b47ad --- /dev/null +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/SpectrumPreferencesControl.java @@ -0,0 +1,141 @@ +package com.aobuchow.themes.spectrum.preferences; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Scale; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * Control to be displayed on the preference page. + *

+ *

    + *
  • Has scales for the three settings; hue, saturation and brightness
  • + *
  • Has a CSS scheme text widget
  • + *
  • Has links to open the Gitub repo page and the Github issues page
  • + *
      + *

      + */ +public class SpectrumPreferencesControl extends Composite { + + private Scale hueScale; + + private Scale saturationScale; + + private Scale brightnessScale; + + private StyledText cssText; + + private Link repoLink; + + private Link issuesLink; + + private FormToolkit kit; + + public SpectrumPreferencesControl(Composite parent, int style) { + super(parent, style); + + kit = new FormToolkit(parent.getDisplay()); + + create(); + + addDisposeListener(e -> { + if (kit != null) { + kit.dispose(); + } + }); + } + + private void create() { + setLayout(GridLayoutFactory.fillDefaults().create()); + createSettingsGroup(); + createComunityGroup(); + } + + private void createSettingsGroup() { + Group group = new Group(this, SWT.SHADOW_ETCHED_IN); + group.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); + group.setText(Messages.SpectrumPreferencePage_CustomizationGroup); + group.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create()); + + hueScale = createScaleLine(group, Messages.PreferencesPage_LabelHue, 0, 360); + saturationScale = createScaleLine(group, Messages.PreferencesPage_LabelSaturation, 0, 100); + brightnessScale = createScaleLine(group, Messages.PreferencesPage_LabelLuminance, 0, 100); + + createCssExandable(group); + } + + private Scale createScaleLine(Composite parent, String labelText, int min, int max) { + Label label = new Label(parent, SWT.NONE); + label.setText(labelText); + label.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).create()); + + Scale scale = new Scale(parent, SWT.HORIZONTAL); + scale.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); + scale.setMinimum(min); + scale.setMaximum(max); + scale.setIncrement(5); + scale.setPageIncrement(5); + + return scale; + } + + private void createCssExandable(Composite parent) { + ExpandableComposite expandableComposite = kit.createExpandableComposite(parent, ExpandableComposite.TWISTIE); + expandableComposite.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).create()); + expandableComposite.setText("CSS"); + + cssText = new StyledText(expandableComposite, SWT.BORDER); + expandableComposite.setClient(cssText); + } + + private void createComunityGroup() { + Group group = new Group(this, SWT.SHADOW_ETCHED_IN); + group.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); + group.setText(Messages.SpectrumPreferencePage_CommunityGroup); + group.setLayout(GridLayoutFactory.swtDefaults().create()); + + repoLink = createLink(group, Messages.SpectrumPreferencePage_RepositoryLink, + Messages.SpectrumPreferencePage_GithubURL); + + issuesLink = createLink(group, Messages.SpectrumPreferencePage_BugReportLink, + Messages.SpectrumPreferencePage_GithubURL_Issues); + } + + private Link createLink(Composite parent, String text, String targetUrl) { + Link link = new Link(parent, SWT.NONE); + link.setText(text); + return link; + } + + public Scale getHueScale() { + return hueScale; + } + + public Scale getSaturationScale() { + return saturationScale; + } + + public Scale getBrightnessScale() { + return brightnessScale; + } + + public StyledText getCssText() { + return cssText; + } + + public Link getRepoLink() { + return repoLink; + } + + public Link getIssuesLink() { + return issuesLink; + } + +} diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties index 21179da..95f7895 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/messages.properties @@ -1,7 +1,10 @@ PreferencesPage_LabelHue=Hue: PreferencesPage_LabelLuminance=Brightness: PreferencesPage_LabelSaturation=Saturation: -SpectrumPreferencePage_BugReportLink=Report a bug or feature request: open GitHub Issues. +SpectrumPreferencePage_BugReportLink=Report a bug or feature request: Open GitHub Issues SpectrumPreferencePage_CommunityGroup=Get involved: SpectrumPreferencePage_CustomizationGroup=Customization: -SpectrumPreferencePage_RepositoryLink=Spectrum Theme is open-source: checkout the repository. +SpectrumPreferencePage_RepositoryLink=Spectrum Theme is open-source: Open GitHub repository +SpectrumPreferencePage_GithubURL_Issues=https://github.com/AObuchow/Eclipse-Spectrum-Theme/issues +SpectrumPreferencePage_GithubURL=https://github.com/AObuchow/Eclipse-Spectrum-Theme + From 6429260f1ae561c090ee6646ddab3a88d7f031f1 Mon Sep 17 00:00:00 2001 From: andrew obuchowicz Date: Sun, 6 Sep 2020 22:21:20 -0400 Subject: [PATCH 9/9] Allow light/dark font to be dynamically used based on user selected theme colors More CSS refactoring is required for certain edge cases such as tables Fix #46 Signed-off-by: andrew obuchowicz --- .../spectrum/preferences/ColorManager.java | 19 +++++++++++++- .../css/color_definitions.css | 7 ----- .../css/default_overrides.css | 26 +++++++++---------- com.aobuchow.themes.spectrum/css/tabstyle.css | 12 ++++----- com.aobuchow.themes.spectrum/plugin.xml | 18 +++++++++++++ 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java index f93a215..3d129a7 100644 --- a/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java +++ b/com.aobuchow.themes.spectrum.preferences/src/com/aobuchow/themes/spectrum/preferences/ColorManager.java @@ -52,6 +52,7 @@ public void updateColors() { backgroundColor = colorRegistry.get(BACKGROUND_COLOR_ID); if (engine.getActiveTheme().getId().equals(THEME_ID)) { updateGitColors(); + updateThemeFontColors(); savePreferences(); } } @@ -137,7 +138,23 @@ private void updateGitColors() { setColorPreference("org.eclipse.egit.ui.UncommittedChangeForegroundColor", uncommittedChangeForeground); setColorPreference("org.eclipse.egit.ui.UncommittedChangeBackgroundColor", uncommittedChangeBackground.getColor()); - uncommittedChangeBackground.dispose(); + }); + } + + private void updateThemeFontColors() { + display.asyncExec(() -> { + Color primaryFontColor = ColorUtils.useReadableForegroundColor( + backgroundColor, display.getSystemColor(SWT.COLOR_WHITE), + display.getSystemColor(SWT.COLOR_BLACK)); + Color activeFontColor = ColorUtils.useReadableForegroundColor( + accentColor, display.getSystemColor(SWT.COLOR_WHITE), + display.getSystemColor(SWT.COLOR_BLACK)); + Color inactiveFontColor = ColorUtils.useReadableForegroundColor( + baseColor, display.getSystemColor(SWT.COLOR_WHITE), + display.getSystemColor(SWT.COLOR_BLACK)); + setColorPreference("com.aobuchow.themes.spectrum.PRIMARY_FONT_COLOR", primaryFontColor); + setColorPreference("com.aobuchow.themes.spectrum.ACTIVE_FONT_COLOR", activeFontColor); + setColorPreference("com.aobuchow.themes.spectrum.INACTIVE_FONT_COLOR", inactiveFontColor); }); } diff --git a/com.aobuchow.themes.spectrum/css/color_definitions.css b/com.aobuchow.themes.spectrum/css/color_definitions.css index ac30c11..7f93742 100644 --- a/com.aobuchow.themes.spectrum/css/color_definitions.css +++ b/com.aobuchow.themes.spectrum/css/color_definitions.css @@ -12,16 +12,9 @@ ThemesExtension { color-definition: - '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR', '#org-eclipse-ui-workbench-LINK_COLOR'; } -ColorDefinition#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR { - color: white; - category: '#org-eclipse-ui-presentation-default'; - label: url('platform:/plugin/org.eclipse.ui.themes?message=ACTIVE_TAB_SELECTED_TEXT_COLOR'); -} - ColorDefinition#org-eclipse-ui-workbench-LINK_COLOR { color: #28ebc3; category: '#org-eclipse-ui-presentation-default'; diff --git a/com.aobuchow.themes.spectrum/css/default_overrides.css b/com.aobuchow.themes.spectrum/css/default_overrides.css index 4d76a25..926f352 100644 --- a/com.aobuchow.themes.spectrum/css/default_overrides.css +++ b/com.aobuchow.themes.spectrum/css/default_overrides.css @@ -19,8 +19,8 @@ Tree, Table { - color: white; - swt-header-color: white; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; + swt-header-color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; swt-header-background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR'; swt-selection-background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; swt-selection-foreground-color: black; @@ -41,11 +41,11 @@ Composite#org-eclipse-ui-navigator-ProjectExplorer * { .MPartStack.active Table { background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR'; - color: #ccc; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } .View { background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR'; - color: #f5f5f5; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } /* ###################### Hyperlink ########################## */ @@ -77,7 +77,7 @@ Composite#org-eclipse-ui-navigator-ProjectExplorer * { /* Color in between text editors */ .MPartSashContainer { background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; - color: #eeeeee; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } /* ###################### Form Editors ########################## */ @@ -176,7 +176,7 @@ Section { .MPart Section > Label { background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; - color: white; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } ExpandableComposite { @@ -204,7 +204,7 @@ Shell > Composite > Composite > Composite > Composite > Composite > List, Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][style~='SWT.SHADOW_ETCHED_OUT'][style~='SWT.RESIZE'][style~='SWT.MENU'][style~='SWT.FULL_SELECTION'][style~='SWT.DATE'] > Composite > List, Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][style~='SWT.SHADOW_ETCHED_OUT'][style~='SWT.RESIZE'][style~='SWT.MENU'][style~='SWT.FULL_SELECTION'][style~='SWT.DATE'] > Composite > * > List { background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; /* TODO: This should be SECONDARY_COLOR_DULL */ - color: white; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } #org-eclipse-ui-main-toolbar, @@ -213,7 +213,7 @@ Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][s background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR' '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR' 100%; handle-image: none; - color: #ebe8e4; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } /* ############################## Console View ############################## */ @@ -222,7 +222,7 @@ Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][s #org-eclipse-ui-console-ConsoleView .MPart StyledText, #org-eclipse-ui-console-ConsoleView .MPart PageBook Label { background-color: black; - color: white; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } /* ############################## Global Styles ############################## */ @@ -254,7 +254,7 @@ Shell[style~='SWT.RADIO'][style~='SWT.CASCADE'][style~='SWT.SHADOW_ETCHED_IN'][s .MPart DependenciesComposite > SashForm > Section > * { /* Section > DependenciesComposite$... */ background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; - color: #eeeeee; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } Shell, @@ -302,7 +302,7 @@ Composite > *, Composite > * > *, Group > StyledText { background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; - color: #eeeeee; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } Composite > StyledText, @@ -310,7 +310,7 @@ Shell [style~='SWT.DROP_DOWN'] > StyledText, /* for eg. folded code popup (but i SashForm > StyledText { /* Fix StyledText inside a SashForm */ background-color: '#com-aobuchow-themes-spectrum-BACKGROUND_COLOR'; - color: #eeeeee; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } .MPart Table, @@ -321,7 +321,7 @@ SashForm > StyledText { .MPart PageBook > Label, .MPart PageBook > SashForm { background-color: #161616; /* hard coded since color definitions dont seem to work here? */ - color: #ccc; + color: '#com-aobuchow-themes-spectrum-PRIMARY_FONT_COLOR'; } /* Toolbar should inherit the colors of its container to avoid drawing artifacts*/ diff --git a/com.aobuchow.themes.spectrum/css/tabstyle.css b/com.aobuchow.themes.spectrum/css/tabstyle.css index 26c0c3b..0364cbb 100644 --- a/com.aobuchow.themes.spectrum/css/tabstyle.css +++ b/com.aobuchow.themes.spectrum/css/tabstyle.css @@ -60,12 +60,12 @@ CTabFolder[style~='SWT.DOWN'][style~='SWT.BOTTOM'] { .MPartStack.active > CTabItem, .MPartStack.active > CTabItem CLabel { background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; /* HACK for background of CTabFolder inner Toolbars */ - color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR'; + color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR'; } .MPartStack.active > CTabItem:selected, .MPartStack.active > CTabItem:selected CLabel { - color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR'; + color: '#com-aobuchow-themes-spectrum-ACTIVE_FONT_COLOR'; } CTabFolder > Composite#ToolbarComposite { @@ -88,7 +88,7 @@ CTabFolder Scale { CTabItem, CTabItem CLabel { background-color: '#com-aobuchow-themes-spectrum-BASE_COLOR'; /* HACK for background of CTabFolder inner Toolbars */ - color: '#org-eclipse-ui-workbench-ACTIVE_TAB_SELECTED_TEXT_COLOR'; + color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR'; } /* ###################### Below used to be in default overrides ########################## */ @@ -96,15 +96,15 @@ CTabItem CLabel { /* TODO: Maybe inactive tabs should have a darker color? */ CTabItem:selected, CTabItem:selected CLabel { - color: white; + color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR'; } .MPartStack.active > CTabItem, .MPartStack.active > CTabItem CLabel { /* background-color: '#com-aobuchow-themes-spectrum-ACCENT_COLOR'; HACK for background of CTabFolder inner Toolbars */ - color: white; + color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR'; } .MPartStack.active.noFocus > CTabItem:selected { - color: white; + color: '#com-aobuchow-themes-spectrum-INACTIVE_FONT_COLOR'; } diff --git a/com.aobuchow.themes.spectrum/plugin.xml b/com.aobuchow.themes.spectrum/plugin.xml index 172d622..d515fb0 100644 --- a/com.aobuchow.themes.spectrum/plugin.xml +++ b/com.aobuchow.themes.spectrum/plugin.xml @@ -67,6 +67,24 @@ The color used when an hovering on a tab in Spectrum theme. + + + + + +