From 8a32aee577baa2ed0c37563c76d5c232ca9b8af1 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Thu, 10 Sep 2020 01:13:34 -0400 Subject: [PATCH] Allow modification of individual theme colors with sliders/scales Signed-off-by: Andrew Obuchowicz --- .../spectrum/preferences/PreferencesPage.java | 114 ++++++++++++++++-- .../SpectrumPreferencesControl.java | 43 +++++++ 2 files changed, 145 insertions(+), 12 deletions(-) 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 601ab09..444d34e 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,6 +4,7 @@ import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Composite; @@ -22,9 +23,11 @@ public class PreferencesPage extends PreferencePage implements IWorkbenchPrefere private Color prevAccentColor; private Color prevBaseColor; + private Color prevBackgroundColor; + private Color prevGlobalFilterColor; private IEventBroker eventBroker; private ColorManager colorManager; - private Color prevBackgroundColor; + private SpectrumPreferencesControl preferenceControl; @@ -39,12 +42,18 @@ public void init(IWorkbench workbench) { prevBackgroundColor = colorManager.getBackgroundColor(); prevBaseColor = colorManager.getBaseColor(); prevAccentColor = colorManager.getAccentColor(); + prevGlobalFilterColor = new ColorHSL(0f, 0f, 0f).getColor(); } @Override protected Control createContents(Composite parent) { preferenceControl = new SpectrumPreferencesControl(parent, SWT.NONE); + preferenceControl.getAllColorsButton().setSelection(true); + preferenceControl.getAllColorsButton().addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> refresh())); + preferenceControl.getAccentColorButton().addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> refresh())); + preferenceControl.getBaseColorButton().addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> refresh())); + preferenceControl.getBackgroundColorButton().addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> refresh())); addHSLCustomization(preferenceControl); @@ -68,29 +77,92 @@ 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); - 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(); + if (control.getAllColorsButton().getSelection()) { + ColorHSL newBackgroundColor = new ColorHSL(prevBackgroundColor).modifyProperty(ColorHSL.HSL_PROPERTY.HUE, ColorHSL.BOUND_BEHAVIOR.CYCLE, selectionValue); + ColorHSL newBaseColor = new ColorHSL(prevBaseColor).modifyProperty(ColorHSL.HSL_PROPERTY.HUE, ColorHSL.BOUND_BEHAVIOR.CYCLE, selectionValue); + ColorHSL newAccentColor = new ColorHSL(prevAccentColor).modifyProperty(ColorHSL.HSL_PROPERTY.HUE, ColorHSL.BOUND_BEHAVIOR.CYCLE, selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + colorManager.setBaseColor(newBaseColor.getColor()); + colorManager.setAccentColor(newAccentColor.getColor()); + } + + if (control.getAccentColorButton().getSelection()) { + ColorHSL newAccentColor = new ColorHSL(colorManager.getAccentColor()).setHue(selectionValue); + colorManager.setAccentColor(newAccentColor.getColor()); + } + + if (control.getBaseColorButton().getSelection()) { + ColorHSL newBaseColor = new ColorHSL(colorManager.getBaseColor()).setHue(selectionValue); + colorManager.setBaseColor(newBaseColor.getColor()); + } + + if (control.getBackgroundColorButton().getSelection()) { + ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setHue(selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + } + + colorManager.saveColors(); }); final Scale saturationScale = control.getSaturationScale(); saturationScale.addListener(SWT.Selection, event -> { float selectionValue = ((float) saturationScale.getSelection()) / 100; + + if (control.getAllColorsButton().getSelection()) { + ColorHSL newBackgroundColor = new ColorHSL(prevBackgroundColor).modifyProperty(ColorHSL.HSL_PROPERTY.SATURATION, ColorHSL.BOUND_BEHAVIOR.LIMIT, selectionValue); + ColorHSL newBaseColor = new ColorHSL(prevBaseColor).modifyProperty(ColorHSL.HSL_PROPERTY.SATURATION, ColorHSL.BOUND_BEHAVIOR.LIMIT, selectionValue); + ColorHSL newAccentColor = new ColorHSL(prevAccentColor).modifyProperty(ColorHSL.HSL_PROPERTY.SATURATION, ColorHSL.BOUND_BEHAVIOR.LIMIT, selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + colorManager.setBaseColor(newBaseColor.getColor()); + colorManager.setAccentColor(newAccentColor.getColor()); + } + + if (control.getAccentColorButton().getSelection()) { + ColorHSL newAccentColor = new ColorHSL(colorManager.getAccentColor()).setSaturation(selectionValue); + colorManager.setAccentColor(newAccentColor.getColor()); + } + + if (control.getBaseColorButton().getSelection()) { + ColorHSL newBaseColor = new ColorHSL(colorManager.getBaseColor()).setSaturation(selectionValue); + colorManager.setBaseColor(newBaseColor.getColor()); + } + + if (control.getBackgroundColorButton().getSelection()) { ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setSaturation(selectionValue); colorManager.setBackgroundColor(newBackgroundColor.getColor()); + } + colorManager.saveColors(); }); final Scale brightnessScale = control.getBrightnessScale(); brightnessScale.addListener(SWT.Selection, event -> { float selectionValue = ((float) brightnessScale.getSelection()) / 100; + + if (control.getAllColorsButton().getSelection()) { + ColorHSL newBackgroundColor = new ColorHSL(prevBackgroundColor).modifyProperty(ColorHSL.HSL_PROPERTY.LUMINANCE, ColorHSL.BOUND_BEHAVIOR.LIMIT, selectionValue); + ColorHSL newBaseColor = new ColorHSL(prevBaseColor).modifyProperty(ColorHSL.HSL_PROPERTY.LUMINANCE, ColorHSL.BOUND_BEHAVIOR.LIMIT, selectionValue); + ColorHSL newAccentColor = new ColorHSL(prevAccentColor).modifyProperty(ColorHSL.HSL_PROPERTY.LUMINANCE, ColorHSL.BOUND_BEHAVIOR.LIMIT, selectionValue); + colorManager.setBackgroundColor(newBackgroundColor.getColor()); + colorManager.setBaseColor(newBaseColor.getColor()); + colorManager.setAccentColor(newAccentColor.getColor()); + } + + if (control.getAccentColorButton().getSelection()) { + ColorHSL newAccentColor = new ColorHSL(colorManager.getAccentColor()).setLuminance(selectionValue); + colorManager.setAccentColor(newAccentColor.getColor()); + } + + if (control.getBaseColorButton().getSelection()) { + ColorHSL newBaseColor = new ColorHSL(colorManager.getBaseColor()).setLuminance(selectionValue); + colorManager.setBaseColor(newBaseColor.getColor()); + } + + if (control.getBackgroundColorButton().getSelection()) { ColorHSL newBackgroundColor = new ColorHSL(colorManager.getBackgroundColor()).setLuminance(selectionValue); colorManager.setBackgroundColor(newBackgroundColor.getColor()); + } + colorManager.saveColors(); }); } @@ -107,6 +179,7 @@ public boolean performOk() { @Override protected void performDefaults() { colorManager.resetColors(); + prevGlobalFilterColor = new ColorHSL(0f, 0f, 0f).getColor(); refresh(); super.performDefaults(); } @@ -140,11 +213,28 @@ private void refresh() { } private void refreshScales() { - preferenceControl.getHueScale().setSelection((int) new ColorHSL(colorManager.getBackgroundColor()).getHue()); + Color selectedColor = getSelectedColor(); + + preferenceControl.getHueScale().setSelection((int) new ColorHSL(selectedColor).getHue()); preferenceControl.getSaturationScale() - .setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getSaturation() * 100)); + .setSelection((int) (new ColorHSL(selectedColor).getSaturation() * 100)); preferenceControl.getBrightnessScale() - .setSelection((int) (new ColorHSL(colorManager.getBackgroundColor()).getLuminance() * 100)); + .setSelection((int) (new ColorHSL(selectedColor).getLuminance() * 100)); + } + + private Color getSelectedColor() { + Color selectedColor; + if (preferenceControl.getBackgroundColorButton().getSelection()) { + selectedColor = colorManager.getBackgroundColor(); + } else if (preferenceControl.getBaseColorButton().getSelection()) { + selectedColor = colorManager.getBaseColor(); + } + else if (preferenceControl.getAccentColorButton().getSelection()) { + selectedColor = colorManager.getAccentColor(); + } else { + selectedColor = prevGlobalFilterColor; + } + return selectedColor; } private void refreshCssText() { 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 index 92b47ad..9e64a03 100644 --- 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 @@ -4,6 +4,7 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -17,6 +18,7 @@ *

*