Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);

Expand All @@ -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();
});
}
Expand All @@ -107,6 +179,7 @@ public boolean performOk() {
@Override
protected void performDefaults() {
colorManager.resetColors();
prevGlobalFilterColor = new ColorHSL(0f, 0f, 0f).getColor();
refresh();
super.performDefaults();
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,7 @@
* <p>
* <ul>
* <li>Has scales for the three settings; hue, saturation and brightness</li>
* <li>Has a 4 radio buttons to select which theme color to affect; all, accent, base or background</li>
* <li>Has a CSS scheme text widget</li>
* <li>Has links to open the Gitub repo page and the Github issues page</li>
* <ul>
Expand All @@ -29,6 +31,14 @@ public class SpectrumPreferencesControl extends Composite {
private Scale saturationScale;

private Scale brightnessScale;

private Button allColorsButton;

private Button accentColorButton;

private Button baseColorButton;

private Button backgroundColorButton;

private StyledText cssText;

Expand Down Expand Up @@ -63,6 +73,8 @@ private void createSettingsGroup() {
group.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
group.setText(Messages.SpectrumPreferencePage_CustomizationGroup);
group.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());

createSelectedColorButtons(group);

hueScale = createScaleLine(group, Messages.PreferencesPage_LabelHue, 0, 360);
saturationScale = createScaleLine(group, Messages.PreferencesPage_LabelSaturation, 0, 100);
Expand All @@ -71,6 +83,21 @@ private void createSettingsGroup() {
createCssExandable(group);
}

private void createSelectedColorButtons(Group group) {
allColorsButton = new Button(group, SWT.RADIO);
allColorsButton.setText("Global Colors");
allColorsButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
accentColorButton = new Button(group, SWT.RADIO);
accentColorButton.setText("Accent Color");
accentColorButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
baseColorButton = new Button(group, SWT.RADIO);
baseColorButton.setText("Base Color");
baseColorButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
backgroundColorButton = new Button(group, SWT.RADIO);
backgroundColorButton.setText("Background Color");
backgroundColorButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
}

private Scale createScaleLine(Composite parent, String labelText, int min, int max) {
Label label = new Label(parent, SWT.NONE);
label.setText(labelText);
Expand Down Expand Up @@ -138,4 +165,20 @@ public Link getIssuesLink() {
return issuesLink;
}

public Button getAllColorsButton() {
return allColorsButton;
}

public Button getAccentColorButton() {
return accentColorButton;
}

public Button getBaseColorButton() {
return baseColorButton;
}

public Button getBackgroundColorButton() {
return backgroundColorButton;
}

}