Commit 61c63d90 authored by Eric Tobias's avatar Eric Tobias

Added Gauge to be built via a bootstrapper

parent 9a321df4
......@@ -24,6 +24,7 @@ FONT_SIZE_NODE=fontSize
GLOBAL_STATE_LISTENER_NODE=globalStateListener
HANDLE_NODE=handle
HANDLES_NODE=handles
HEIGHT_NODE=height
IMAGE_NODE=image
INFORMATION=information
INITIAL_ROTATION_NODE=initialRotation
......@@ -46,15 +47,22 @@ OBJECT_NODE=object
OBJECTS_NODE=objects
RADIUS_NODE=radius
ROTATE_WITH_HANDLE_NODE=rotateWithHandle
SCALE_NODE=scale
SECTION_NODE=section
SECTIONS_NODE=sections
SHAPE_NODE=shape
SPACE=\
SPIN_ON_CORONA_CENTRE_NODE=spinOnCoronaCentre
START_NODE=start
STEP_SIZE_NODE=stepSize
STOP_NODE=stop
TEXT_NODE=text
TITLE_NODE=title
TRIGGER_CONDITION_NODE=triggerCondition
TYPE_NODE=type
UNIT_NODE=unit
UPPER_BOUND_NODE=upperBound
UPPER_STOP_ANGLE_NODE=upperStopAngle
VARIABLE_NODE=variable
WIDGET_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.builder
WIDTH_NODE=width
......@@ -54,6 +54,7 @@ public class Externalization extends NLS {
public static String GLOBAL_STATE_LISTENER_NODE;
public static String HANDLE_NODE;
public static String HANDLES_NODE;
public static String HEIGHT_NODE;
public static String IMAGE_NODE;
public static String INFORMATION;
public static String INITIAL_ROTATION_NODE;
......@@ -76,18 +77,25 @@ public class Externalization extends NLS {
public static String OBJECTS_NODE;
public static String RADIUS_NODE;
public static String ROTATE_WITH_HANDLE_NODE;
public static String SCALE_NODE;
public static String SECTION_NODE;
public static String SECTIONS_NODE;
public static String SHAPE_NODE;
public static String SPACE;
public static String SPIN_ON_CORONA_CENTRE_NODE;
public static String START_NODE;
public static String STEP_SIZE_NODE;
public static String STOP_NODE;
public static String TEXT_NODE;
public static String TITLE_NODE;
public static String TRIGGER_CONDITION_NODE;
public static String TYPE_NODE;
public static String UNIT_NODE;
public static String UPPER_BOUND_NODE;
public static String UPPER_STOP_ANGLE_NODE;
public static String VARIABLE_NODE;
public static String WIDGET_BUILDER_NAMESPACE;
public static String WIDTH_NODE;
static {
// initialize resource bundle
......
......@@ -31,10 +31,11 @@ import eu.hansolo.steelseries.tools.FrameType;
import eu.hansolo.steelseries.tools.Section;
/**
* @author nmack
* @author nmack [nico.mack@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @date 27 Apr 2015
*
* @since 2.2
* @version 2.2.2
*/
public class Gauge extends Corona implements InformationReceiver<Double> {
AbstractRadial gauge;
......@@ -60,6 +61,7 @@ public class Gauge extends Corona implements InformationReceiver<Double> {
gauge.setTitle(builder.title);
gauge.setUnitString(builder.unit);
gauge.setLedVisible(false);
gauge.setLcdVisible(false);
if (sections != null) {
gauge.setSectionsVisible(true);
......
......@@ -119,6 +119,8 @@ public abstract class CoronaBuilder<B extends CoronaBuilder<B>> {
Element initialTranslationNode = rootElement.getChild(Externalization.INITIAL_TRANSLATION_NODE);
if (null != initialTranslationNode) {
initialTranslation = new Point(initialTranslationNode);
} else {
initialTranslation = new Point();
}
Element rotateWithHandleNode = rootElement.getChild(Externalization.ROTATE_WITH_HANDLE_NODE);
......
......@@ -16,20 +16,27 @@
*/
package lu.list.itis.dkd.tui.widget.corona.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.Gauge;
import org.jdom2.Element;
import java.awt.Color;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import eu.hansolo.steelseries.tools.Section;
/**
* @author nmack
* @author nmack [nico.mack@list.lu]
* @author Eric Tobias [eric.tobias@list.lu]
* @date 28 Apr 2015
*
* <br>
* $Log: GaugeBuilder.java,v $
* @since 2.2
* @version 2.2.2
*/
public class GaugeBuilder extends CoronaBuilder<GaugeBuilder> {
public double width;
......@@ -39,19 +46,83 @@ public class GaugeBuilder extends CoronaBuilder<GaugeBuilder> {
public double scale;
public String title;
public String unit;
public List<Section> sections;
public List<Section> sections = new ArrayList<>();
/**
* Constructor initializing only the position.
*
* @param centre
* The position the corona should be built at.
*/
public GaugeBuilder(Point centre) {
super(centre);
// TODO Auto-generated constructor stub
}
/**
* Constructor initializing all fields from a provided element node.
*
* @param rootElement
* The element containing, as child elements, all necessary information to populate an
* instance of this builder.
* @throws BuildException
* Thrown when not all provided information could be interpreted or some information was
* missing.
*/
public GaugeBuilder(Element rootElement) throws BuildException {
super(rootElement);
try {
width = Double.parseDouble(rootElement.getChildText(Externalization.WIDTH_NODE));
height = Double.parseDouble(rootElement.getChildText(Externalization.HEIGHT_NODE));
lowerBound = Double.parseDouble(rootElement.getChildText(Externalization.LOWER_BOUND_NODE));
upperBound = Double.parseDouble(rootElement.getChildText(Externalization.UPPER_BOUND_NODE));
scale = Double.parseDouble(rootElement.getChildText(Externalization.SCALE_NODE));
} catch (NumberFormatException nfe) {
throw new BuildException("The provided values for width, height, both bounds, and the scale need to be double (large floating point) values!", nfe); //$NON-NLS-1$
}
title = rootElement.getChildText(Externalization.TITLE_NODE);
unit = rootElement.getChildText(Externalization.UNIT_NODE);
buildSections(rootElement.getChild(Externalization.SECTIONS_NODE));
}
/**
* Method used to extract information on sections from the bootstrapping XML and build sections
* accordingly to be used in the {@link Gauge}.
*
* @param sectionsNode
* The node containing, as child elements, information on sections.
* @throws BuildException
*/
private void buildSections(@Nullable Element sectionsNode) throws BuildException {
if (null == sectionsNode) {
return;
}
for (Element section : sectionsNode.getChildren(Externalization.SECTION_NODE)) {
try {
double start = Double.parseDouble(section.getChildText(Externalization.START_NODE));
double stop = Double.parseDouble(section.getChildText(Externalization.STOP_NODE));
Field field = Class.forName(Externalization.JAVA_AWT_COLOR_NAMESPACE).getField(section.getChildText(Externalization.COLOUR_NODE).toLowerCase());
Color colour = (Color) field.get(null);
sections.add(new Section(start, stop, colour));
} catch (ReflectiveOperationException roe) {
throw new BuildException("An error occured while trying to resolve the colour! The colour needs to mirror the java.awt.Color fields!", roe); //$NON-NLS-1$
} catch (NullPointerException npe) {
throw new BuildException("The XML needs to define a colour node for the section!", npe); //$NON-NLS-1$
} catch (NumberFormatException nfe) {
throw new BuildException("The provided values for start and stop on the section node need to be double (large floating point) values!", nfe); //$NON-NLS-1$
}
}
}
@Override
public Gauge build() throws BuildException {
// TODO Auto-generated method stub
return new Gauge(this);
}
......@@ -59,15 +130,15 @@ public class GaugeBuilder extends CoronaBuilder<GaugeBuilder> {
/**
* Method used to set the dimensions of the gauge
*
* @param width
* @param _width
* The width of the gauge
* @param upperBound
* @param _height
* The height of the gauge
* @return An instance of the builder for chain-calling.
*/
public GaugeBuilder withDimensions(double width, double height) {
this.width = width;
this.height = height;
public GaugeBuilder withDimensions(double _width, double _height) {
this.width = _width;
this.height = _height;
return this;
}
......@@ -93,14 +164,11 @@ public class GaugeBuilder extends CoronaBuilder<GaugeBuilder> {
/**
* Method used to set the upper and lower bound of the dial
*
* @param lowerBound
* The lower bound of the dial
* @param upperBound
* The upper bound of the dial
* @param scale
*
*
* @return An instance of the builder for chain-calling.
*/
public GaugeBuilder withScale(double scale) {
this.scale = scale;
......
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