Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental rebased #133

Open
wants to merge 9 commits into
base: experimental
Choose a base branch
from
Open
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ package
/bin/
# Eclipse Core
/.settings/
/.metadata/
# JDT-specific (Eclipse Java Development Tools)
.classpath
/.metadata/
7 changes: 7 additions & 0 deletions com.aobuchow.themes.spectrum.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@
version="0.0.0"
unpack="false"/>

<plugin
id="com.aobuchow.themes.spectrum.preferences"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
7 changes: 7 additions & 0 deletions com.aobuchow.themes.spectrum.preferences/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
5 changes: 5 additions & 0 deletions com.aobuchow.themes.spectrum.preferences/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Maven
/target/
/bin/
# Eclipse Core
/.settings/
28 changes: 28 additions & 0 deletions com.aobuchow.themes.spectrum.preferences/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.aobuchow.themes.spectrum.preferences</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
19 changes: 19 additions & 0 deletions com.aobuchow.themes.spectrum.preferences/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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,
org.eclipse.swt,
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.ui.forms;bundle-version="3.9.100"
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"
5 changes: 5 additions & 0 deletions com.aobuchow.themes.spectrum.preferences/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
19 changes: 19 additions & 0 deletions com.aobuchow.themes.spectrum.preferences/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.preferencePages">
<page
class="com.aobuchow.themes.spectrum.preferences.PreferencesPage"
id="com.aobuchow.themes.spectrum.preferences.page"
name="Spectrum Theme">
</page>
</extension>
<extension
point="org.eclipse.ui.startup">
<startup
class="com.aobuchow.themes.spectrum.preferences.PluginStartup">
</startup>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.aobuchow.themes.spectrum.preferences;

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 ColorManager colorManager;

/**
* The constructor
*/
public Activator() {
}

@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
colorManager = new ColorManager();
}

@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
colorManager.dispose();
}

/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}

/**
* @return the colorManager
*/
public ColorManager getColorManager() {
return colorManager;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +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.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;

public final class BrowserUtils {

public static void openUrl(String category, String url) {
try {
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);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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(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;
}

newValue = newValue + amount;

switch (boundBehavior) {
case CYCLE:
if (newValue < min) {
newValue = max - Math.abs(newValue);
} else if (newValue > max) {
newValue = min + (newValue - max);
}
break;
case LIMIT:
newValue = setFloatBounds(newValue, min, max);
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;
}

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.
*/
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;
}

}
Loading