Commit b0fa3b10 authored by Nico Mack's avatar Nico Mack

Added Selectable Interface.

Added ColorNuance class.
parent ff3be322
......@@ -15,6 +15,7 @@ BLOBS_NODE=blobs
BORDER_THICKNESS_NODE=borderThickness
BORDER_WIDTH_NODE=borderWidth
BOUNDS_NODE=bounds
BRIGHTNESS_NODE=brightness
BUILDER_CLASS_POSTFIX=Builder
BUNDLES_NODE=bundles
BUNDLE_NODE=bundle
......@@ -71,6 +72,7 @@ HANDLE_NODE=handle
HANDLES_NODE=handles
HEIGHT_NODE=height
HTML_CONTENT_NODE=htmlContent
HUE_NODE=hue
IDENTIFIER_NODE=identifier
IMAGE_BASE64_ELEMENT=imageBase64
IMAGE_ELEMENT=image
......
......@@ -19,6 +19,7 @@ package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.CameraCoordinates;
import lu.list.itis.dkd.tui.utility.ColorFactory;
import lu.list.itis.dkd.tui.utility.ColorNuance;
import lu.list.itis.dkd.tui.utility.CoordinateState;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
......@@ -72,9 +73,6 @@ public class BootstrappingUtils {
private static ScriptEngine script = new ScriptEngineManager().getEngineByName("js"); //$NON-NLS-1$
// private static final Pattern INDEXED_PATTERN =
// Pattern.compile("\\$\\{([a-z0-9\\-_]+)(\\[\\$\\{([a-z0-9\\-_]+)\\}\\])?\\}",
// Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern BOOTSTRAP_VAR_PATTERN = Pattern.compile("(\\${1,2})\\{([a-z0-9\\-_]+)\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern ANGLE_PATTERN = Pattern.compile("([+-]?\\d+.?\\d*)\\s*(deg|rad)?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern DIMENSION_PATTERN = Pattern.compile("([+-]?\\d+.?\\d*)\\s*(px|mm)?", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
......@@ -796,6 +794,50 @@ public class BootstrappingUtils {
return value;
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param childName
* @param optional
* @param context
* @return
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public static ColorNuance getContentAsColourNuance(Element rootElement, String childName, boolean optional, BootstrapContext context) throws BuildException {
ColorNuance nuance = null;
Element nuanceNode = (childName != null) ? rootElement.getChild(childName) : rootElement;
if (nuanceNode != null) {
nuance = new ColorNuance();
int alpha = getContentAsInteger(rootElement, Externalization.ALPHA_NODE, BootstrappingUtils.OPTIONAL, 0, context);
int hue = getContentAsInteger(rootElement, Externalization.HUE_NODE, BootstrappingUtils.OPTIONAL, 0, context);
int saturation = getContentAsInteger(rootElement, Externalization.SATURATION_NODE, BootstrappingUtils.OPTIONAL, 0, context);
int brightness = getContentAsInteger(rootElement, Externalization.BRIGHTNESS_NODE, BootstrappingUtils.OPTIONAL, 0, context);
if (alpha != 0) {
nuance.setAlpha((double) alpha / TWO_POWER_EIGHT);
}
if (hue != 0) {
nuance.setHue((double) hue / TWO_POWER_EIGHT);
}
if (saturation != 0) {
nuance.setSaturation((double) saturation / TWO_POWER_EIGHT);
}
if (brightness != 0) {
nuance.setBrightness((double) brightness / TWO_POWER_EIGHT);
}
} else {
if (!optional) {
logAndThrowBuildException(new BuildException(StringUtils.build(MANDATORY_NODE_TEMPLATE, childName)), rootElement, childName);
}
}
return nuance;
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.event;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0
*/
public interface Selectable {
/**
* @param selectIt
*/
public void setSelected(boolean selectIt);
/**
* @return
*/
public boolean isSelected();
}
......@@ -16,8 +16,6 @@
*/
package lu.list.itis.dkd.tui.event;
import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
......@@ -29,7 +27,7 @@ import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
// ***************************************************************************
public class SelectionEvent {
private SelectableCorona source;
private Selectable source;
private boolean selected;
// ---------------------------------------------------------------------------
......@@ -43,7 +41,7 @@ public class SelectionEvent {
*/
// ---------------------------------------------------------------------------
public SelectionEvent(SelectableCorona source, boolean selectionState) {
public SelectionEvent(Selectable source, boolean selectionState) {
this.source = source;
this.selected = selectionState;
}
......@@ -60,7 +58,7 @@ public class SelectionEvent {
*/
// ---------------------------------------------------------------------------
public SelectableCorona getSource() {
public Selectable getSource() {
return source;
}
......
......@@ -33,6 +33,10 @@ public class ColorFactory {
private static final int SATURATION = 1;
private static final int BRIGHTNESS = 2;
public static final int SATURATION_FULL_SCALE = 255;
public static final int BRIGHTNESS_FULL_SCALE = 255;
public static final int HUE_FULL_SCALE = 255;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.utility;
import com.jgoodies.common.base.Preconditions;
import java.awt.Color;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class ColorNuance {
private double hue;
private double saturation;
private double brightness;
private double alpha;
// ***************************************************************************
// * Constants
// ***************************************************************************
private static final int HUE = 0;
private static final int SATURATION = 1;
private static final int BRIGHTNESS = 2;
private static final double LOWER_BOUND = -1;
private static final double UPPER_BOUND = 1;
private static final String OUT_OF_RANGE_TEMPLATE = "Specified value {} must be within range -1 <= x <= 1"; //$NON-NLS-1$
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public ColorNuance() {
this.hue = 0;
this.saturation = 0;
this.brightness = 0;
this.alpha = 0;
}
// ---------------------------------------------------------------------------
/**
* @param hue
* @param saturation
* @param brightness
* @param alpha
*/
// ---------------------------------------------------------------------------
public ColorNuance(double hue, double saturation, double brightness, double alpha) {
this.hue = hue;
this.saturation = saturation;
this.brightness = brightness;
this.alpha = alpha;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return <code>true</code> if this color style affects the hue of a colour, <code>false</code>
* otherwise.
*/
// ---------------------------------------------------------------------------
public boolean affectsHue() {
return this.hue != 0;
}
// ---------------------------------------------------------------------------
/**
* @return <code>true</code> if this color style affects the saturation of a colour,
* <code>false</code> otherwise.
*/
// ---------------------------------------------------------------------------
public boolean affectsSaturation() {
return this.saturation != 0;
}
// ---------------------------------------------------------------------------
/**
* @return <code>true</code> if this color style affects the brightness of a colour,
* <code>false</code> otherwise.
*/
// ---------------------------------------------------------------------------
public boolean affectsBrightness() {
return this.brightness != 0;
}
// ---------------------------------------------------------------------------
/**
* @return <code>true</code> if this color style affects the transparency of a colour,
* <code>false</code> otherwise.
*/
// ---------------------------------------------------------------------------
public boolean affectsAlpha() {
return this.brightness != 0;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for brightness.
*
* @return The value of brightness.
*/
// ---------------------------------------------------------------------------
public double getBrightness() {
return brightness;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for brightness.
*
* @param brightness
* The value to set brightness to.
*/
// ---------------------------------------------------------------------------
public void setBrightness(double brightness) {
Preconditions.checkArgument(brightness >= LOWER_BOUND && brightness <= UPPER_BOUND, StringUtils.build(OUT_OF_RANGE_TEMPLATE, brightness));
this.brightness = brightness;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for saturation.
*
* @return The value of saturation.
*/
// ---------------------------------------------------------------------------
public double getSaturation() {
return saturation;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for saturation.
*
* @param saturation
* The value to set saturation to.
*/
// ---------------------------------------------------------------------------
public void setSaturation(double saturation) {
Preconditions.checkArgument(saturation >= LOWER_BOUND && saturation <= UPPER_BOUND, StringUtils.build(OUT_OF_RANGE_TEMPLATE, saturation));
this.saturation = saturation;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for hue.
*
* @return The value of hue.
*/
// ---------------------------------------------------------------------------
public double getHue() {
return hue;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for hue.
*
* @param hue
* The value to set hue to.
*/
// ---------------------------------------------------------------------------
public void setHue(double hue) {
Preconditions.checkArgument(hue >= LOWER_BOUND && hue <= UPPER_BOUND, StringUtils.build(OUT_OF_RANGE_TEMPLATE, hue));
this.hue = hue;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for alpha.
*
* @return The value of alpha.
*/
// ---------------------------------------------------------------------------
public double getAlpha() {
return alpha;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for alpha.
*
* @param alpha
* The value to set alpha to.
*/
// ---------------------------------------------------------------------------
public void setAlpha(double alpha) {
this.alpha = alpha;
}
// ---------------------------------------------------------------------------
/**
* @param original
* @return
*/
// ---------------------------------------------------------------------------
public Color apply(Color original) {
float[] hsb = new float[3];
hsb = Color.RGBtoHSB(original.getRed(), original.getGreen(), original.getBlue(), hsb);
int newAlpha = original.getAlpha();
if (affectsHue()) {
hsb[HUE] *= 1 + this.hue;
hsb[HUE] = MathUtils.constrain(hsb[HUE], 0f, 1f);
}
if (affectsSaturation()) {
hsb[SATURATION] *= 1 + this.saturation;
hsb[SATURATION] = MathUtils.constrain(hsb[SATURATION], 0f, 1f);
}
if (affectsBrightness()) {
hsb[BRIGHTNESS] *= 1 + this.brightness;
hsb[BRIGHTNESS] = MathUtils.constrain(hsb[BRIGHTNESS], 0f, 1f);
}
if (affectsAlpha()) {
double normalizedAlpha = newAlpha;
normalizedAlpha *= 1 + this.alpha;
newAlpha = MathUtils.constrain((int) (normalizedAlpha), 0x00, 0xff);
}
int rgb = Color.HSBtoRGB(hsb[HUE], hsb[SATURATION], hsb[BRIGHTNESS]);
rgb |= ((newAlpha << 24) & 0xFF000000);
return new Color(rgb);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class
// ***************************************************************************
// ---------------------------------------------------------------------------
}
......@@ -50,6 +50,7 @@ public class Externalization extends NLS {
public static String BORDER_THICKNESS_NODE;
public static String BORDER_WIDTH_NODE;
public static String BOUNDS_NODE;
public static String BRIGHTNESS_NODE;
public static String BUILDER_CLASS_POSTFIX;
public static String BUNDLES_NODE;
public static String BUNDLE_NODE;
......@@ -106,6 +107,7 @@ public class Externalization extends NLS {
public static String HANDLES_NODE;
public static String HEIGHT_NODE;
public static String HTML_CONTENT_NODE;
public static String HUE_NODE;
public static String IDENTIFIER_NODE;
public static String IMAGE_BASE64_ELEMENT;
public static String IMAGE_ELEMENT;
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.utility;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class MathUtils {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
private MathUtils() {}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param value
* @param lowerBound
* @param upperBound
* @return
*/
// ---------------------------------------------------------------------------
public static float constrain(float value, float lowerBound, float upperBound) {
float constrained = Math.max(value, lowerBound);
constrained = Math.min(constrained, upperBound);
return constrained;
}
// ---------------------------------------------------------------------------
/**
* @param value
* @param lowerBound
* @param upperBound
* @return
*/
// ---------------------------------------------------------------------------
public static double constrain(double value, double lowerBound, double upperBound) {
double constrained = Math.max(value, lowerBound);
constrained = Math.min(constrained, upperBound);
return constrained;
}
// ---------------------------------------------------------------------------
/**
* @param value
* @param lowerBound
* @param upperBound
* @return
*/
// ---------------------------------------------------------------------------
public static int constrain(int value, int lowerBound, int upperBound) {
int constrained = Math.max(value, lowerBound);
constrained = Math.min(constrained, upperBound);
return constrained;
}
}
......@@ -17,6 +17,7 @@
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.event.Selectable;
import lu.list.itis.dkd.tui.event.SelectionEvent;
import lu.list.itis.dkd.tui.event.SelectionListener;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseSelectableCoronaBuilder;
......@@ -33,7 +34,7 @@ import java.util.List;
// * Class Definition and Members *
// ***************************************************************************
public abstract class SelectableCorona extends FadingCorona {
public abstract class SelectableCorona extends FadingCorona implements Selectable {
protected boolean isSelected;
protected int index;
protected String group;
......@@ -132,6 +133,7 @@ public abstract class SelectableCorona extends FadingCorona {
*/
// ---------------------------------------------------------------------------
@Override
public void setSelected(boolean selectIt) {
boolean selectionState = this.isSelected;
this.isSelected = selectIt;
......@@ -147,6 +149,7 @@ public abstract class SelectableCorona extends FadingCorona {
*/
// ---------------------------------------------------------------------------
@Override
public boolean isSelected() {
return this.isSelected;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment