Commit 6a2d3b84 authored by Nico Mack's avatar Nico Mack

Created dedicated Leader Corona.

parent edb136d8
ABOVE_ELEMENT=above
BACKGROUND_NODE=background
BELOW_ELEMENT=below
BLINK_ON_OUT_OF_RANGE_NODE=blinkOnOutOfRange
CAPPED_DISPLAY_NODE=cappedDisplay
COLOUR_SCALE_NODE=colourScale
DECIMALS_ATTRIBUTE=decimals
FACE_IS_TOUCHABLE_NODE=faceIsTouchable
FOREGROUND_NODE=foreground
ITEMS_VARIABLE_NODE=itemsVariable
HTML_TEMPLATE_NODE=htmlTemplate
LABEL_NODE=label
LABEL_ANGLE_NODE=labelAngle
LABEL_TRANSLATION_NODE=labelTranslation
LANDING_LINE_LENGTH_NODE=landingLineLength
LEADER_COLOUR_NODE=leaderColour
LEADER_LINE_LENGTH_NODE=leaderLineLength
LEADER_STROKE_WIDTH_NODE=leaderStrokeWidth
LOWER_BOUND_RADIUS_NODE=lowerBoundRadius
LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable
LOWER_STOP_ANGLE_NODE=lowerStopAngle
......@@ -25,6 +31,7 @@ POSITIONS_NODE=positions
RANGE_SEPARATOR_ATTRIBUTE=rangeSeparator
REFERENCE_NODE=reference
RELATIVE_NODE=relative
ROTATION_NODE=rotation
SCALES_NODE=scales
SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable
SELECTED_RADIUS_NODE=selectedRadius
......@@ -32,6 +39,7 @@ STEP_SIZE_NODE=stepSize
STRETCH_TO_FIT_NODE=stretchToFit
TRACK_ROTATION_CONTINUOUSLY_NODE=trackRotationContinuously
TRACK_TRANSLATION_CONTINUOUSLY_NODE=trackTranslationContinuously
TRANSLATION_NODE=translation
UPPER_BOUND_RADIUS_NODE=upperBoundRadius
UPPER_BOUND_VARIABLE_NODE=upperBoundVariable
UPPER_STOP_ANGLE_NODE=upperStopAngle
......
......@@ -27,12 +27,14 @@ public class CpsNamespace extends NLS {
private static final String BUNDLE_NAME = "CpsNamespace"; //$NON-NLS-1$
public static String ABOVE_ELEMENT;
public static String BACKGROUND_NODE;
public static String BELOW_ELEMENT;
public static String BLINK_ON_OUT_OF_RANGE_NODE;
public static String CAPPED_DISPLAY_NODE;
public static String COLOUR_SCALE_NODE;
public static String FACE_IS_TOUCHABLE_NODE;
public static String FOREGROUND_NODE;
public static String DECIMALS_ATTRIBUTE;
......@@ -44,6 +46,12 @@ public class CpsNamespace extends NLS {
public static String LABEL_ANGLE_NODE;
public static String LABEL_TRANSLATION_NODE;
public static String LANDING_LINE_LENGTH_NODE;
public static String LEADER_COLOUR_NODE;
public static String LEADER_LINE_LENGTH_NODE;
public static String LEADER_STROKE_WIDTH_NODE;
public static String LOWER_BOUND_RADIUS_NODE;
public static String LOWER_BOUND_VARIABLE_NODE;
public static String LOWER_STOP_ANGLE_NODE;
......@@ -61,6 +69,7 @@ public class CpsNamespace extends NLS {
public static String RANGE_SEPARATOR_ATTRIBUTE;
public static String REFERENCE_NODE;
public static String RELATIVE_NODE;
public static String ROTATION_NODE;
public static String SCALES_NODE;
......@@ -72,6 +81,7 @@ public class CpsNamespace extends NLS {
public static String TRACK_ROTATION_CONTINUOUSLY_NODE;
public static String TRACK_TRANSLATION_CONTINUOUSLY_NODE;
public static String TRANSLATION_NODE;
public static String UPPER_BOUND_RADIUS_NODE;
public static String UPPER_BOUND_VARIABLE_NODE;
......
......@@ -3,7 +3,6 @@ package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.Leader;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.VariableFormat;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseArcGraphBuilder;
......@@ -38,7 +37,6 @@ import java.awt.geom.Rectangle2D;
// ***************************************************************************
public class ArcGraph extends ValueCorona {
// protected String title;
protected double innerRadius;
protected double outerRadius;
protected int startAngle;
......@@ -52,7 +50,6 @@ public class ArcGraph extends ValueCorona {
protected ColorPair strokeColour;
protected ColorPair labelColour;
protected ColorPair textColour;
protected ColorPair leaderColour;
protected ColorPair faceColour;
protected ColorPair bezelColour;
......@@ -62,9 +59,6 @@ public class ArcGraph extends ValueCorona {
protected Stroke borderStroke;
protected int strokeWidth;
protected int leaderLineLength;
protected int landingLineLength;
protected VariableFormat variableFormat;
protected int rampingTime;
......@@ -75,7 +69,6 @@ public class ArcGraph extends ValueCorona {
private Area face;
private String label;
private LineMetrics labelMetrics;
private Leader leader;
protected Timeline blinkingTimeline;
protected Timeline balisticTimeline;
......@@ -109,15 +102,12 @@ public class ArcGraph extends ValueCorona {
this.strokeColour = builder.strokeColour;
this.labelColour = builder.labelColour;
this.textColour = builder.textColour;
this.leaderColour = builder.leaderColour;
this.faceColour = builder.faceColour;
this.bezelColour = builder.bezelColour;
this.labelShape = builder.labelShape;
this.labelFormat = builder.labelFormat;
this.textFont = builder.textFont;
this.strokeWidth = builder.strokeWidth;
this.leaderLineLength = builder.leaderLineLength;
this.landingLineLength = builder.landingLineLength;
this.rampingTime = builder.rampingTime;
this.buildFromProperties();
......@@ -148,15 +138,12 @@ public class ArcGraph extends ValueCorona {
this.strokeColour = original.strokeColour;
this.labelColour = original.labelColour;
this.textColour = original.textColour;
this.leaderColour = original.leaderColour;
this.faceColour = original.faceColour;
this.bezelColour = original.bezelColour;
this.labelShape = original.labelShape;
this.labelFormat = original.labelFormat;
this.textFont = original.textFont;
this.strokeWidth = original.strokeWidth;
this.leaderLineLength = original.leaderLineLength;
this.landingLineLength = original.landingLineLength;
this.rampingTime = original.rampingTime;
this.buildFromProperties();
......@@ -210,12 +197,6 @@ public class ArcGraph extends ValueCorona {
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
if (leaderLineLength > 0) {
leader = new Leader(innerRadius, leaderLineLength, landingLineLength);
leader.setLabelShape(labelShape);
leader.setFont(textFont);
}
this.setInformation((relative) ? this.reference : this.variable.getValue());
}
......@@ -286,8 +267,6 @@ public class ArcGraph extends ValueCorona {
faceColour.setSwitched(selectIt);
if (bezelColour != null)
bezelColour.setSwitched(selectIt);
if (leaderColour != null)
leaderColour.setSwitched(selectIt);
}
}
......@@ -318,12 +297,6 @@ public class ArcGraph extends ValueCorona {
extend = arcSpan * normalizedValue;
}
if (leader != null) {
float leaderAngle = (float) -Math.toRadians(start + extend);
leader.updateLeader(leaderAngle);
}
if (blinkOnOutOfRange && reachedEndOfScale()) {
this.startBlinking();
} else {
......@@ -384,36 +357,22 @@ public class ArcGraph extends ValueCorona {
// Depending on whether we specified a leader or not, we're either
// painting the leader or the stationary graph label, but never both.
if ((leaderColour != null) && (this.leader != null)) {
// Paint the leader...
this.leader.setStrokeColour(leaderColour.getColor());
if (labelColour != null)
this.leader.setFillColour(labelColour.getColor());
if (textColour != null)
this.leader.setLabelColour(textColour.getColor());
this.leader.paint(localCanvas);
} else {
// Paint the stationary graph label
if ((labelShape != null) || (label.length() > 0)) {
Point labelOffset = this.getOffsetFromCenter();
translation.translate(labelOffset.x, labelOffset.y);
localCanvas.setTransform(translation);
}
if (labelShape != null) {
localCanvas.setPaint(labelColour.getColor());
localCanvas.fill(labelShape);
}
if ((labelShape != null) || (label.length() > 0)) {
Point labelOffset = this.getOffsetFromCenter();
translation.translate(labelOffset.x, labelOffset.y);
localCanvas.setTransform(translation);
}
if (textColour != null) {
localCanvas.setPaint(textColour.getColor());
localCanvas.setFont(textFont);
localCanvas.drawString(label, 5, (labelMetrics.getAscent() / 2));
}
if (labelShape != null) {
localCanvas.setPaint(labelColour.getColor());
localCanvas.fill(labelShape);
}
if (textColour != null) {
localCanvas.setPaint(textColour.getColor());
localCanvas.setFont(textFont);
localCanvas.drawString(label, 5, (labelMetrics.getAscent() / 2));
}
localCanvas.dispose();
}
......@@ -438,15 +397,8 @@ public class ArcGraph extends ValueCorona {
}
if (textFont != null) {
// StringBuilder labelBuilder = new StringBuilder(this.title).append(" "); //$NON-NLS-1$
// labelBuilder.append(this.variable.toString(this.cappedDisplay, true));
this.label = this.variableFormat.format(this.variable);
this.labelMetrics = textFont.getLineMetrics(this.label, new FontRenderContext(null, true, true));
if (leader != null) {
leader.setLabel(label);
}
}
}
}
......
......@@ -2,7 +2,6 @@ package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.utility.AngleUtils;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.Leader;
import lu.list.itis.dkd.tui.utility.ValueRange;
import lu.list.itis.dkd.tui.utility.VariableFormat;
import lu.list.itis.dkd.tui.widget.corona.builder.ArcRangeGraphBuilder;
......@@ -35,7 +34,6 @@ import java.awt.geom.Rectangle2D;
// ***************************************************************************
public class ArcRangeGraph extends ValueRangeCorona {
private String title;
private double innerRadius;
private double outerRadius;
private double startAngle;
......@@ -49,7 +47,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
private ColorPair strokeColour;
private ColorPair labelColour;
private ColorPair textColour;
private ColorPair leaderColour;
private ColorPair faceColour;
private ColorPair bezelColour;
......@@ -59,21 +56,13 @@ public class ArcRangeGraph extends ValueRangeCorona {
private int strokeWidth;
private String labelFormat;
private int leaderLineLength;
private int landingLineLength;
private Area outerArea;
private Area innerArea;
private Area positiveArc;
private Area negativeArc;
private Area face;
private Leader lowerLeader;
private Leader upperLeader;
private VariableFormat variableFormat;
private String lowerValueLabel;
private String upperValueLabel;
protected Timeline blinkingTimeline;
protected Timeline balisticTimeline;
......@@ -81,8 +70,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
private double shownUpperValue;
private double referenceAngle;
private double lowerAngle;
private double upperAngle;
// ***************************************************************************
......@@ -97,9 +84,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
public ArcRangeGraph(ArcRangeGraphBuilder<?> builder) {
super(builder);
this.title = builder.title;
this.startAngle = builder.startAngle;
this.arcSpan = builder.arcSpan;
this.relative = builder.relative;
......@@ -113,14 +97,11 @@ public class ArcRangeGraph extends ValueRangeCorona {
this.strokeColour = builder.strokeColour;
this.labelColour = builder.labelColour;
this.textColour = builder.textColour;
this.leaderColour = builder.leaderColour;
this.faceColour = builder.faceColour;
this.bezelColour = builder.bezelColour;
this.labelShape = builder.labelShape;
this.textFont = builder.textFont;
this.strokeWidth = builder.strokeWidth;
this.landingLineLength = builder.landingLineLength;
this.leaderLineLength = builder.leaderLineLength;
this.labelFormat = builder.labelFormat;
this.buildFromProperties();
......@@ -151,14 +132,11 @@ public class ArcRangeGraph extends ValueRangeCorona {
this.strokeColour = original.strokeColour;
this.labelColour = original.labelColour;
this.textColour = original.textColour;
this.leaderColour = original.leaderColour;
this.faceColour = original.faceColour;
this.bezelColour = original.bezelColour;
this.labelShape = original.labelShape;
this.textFont = original.textFont;
this.strokeWidth = original.strokeWidth;
this.landingLineLength = original.landingLineLength;
this.leaderLineLength = original.leaderLineLength;
this.labelFormat = original.labelFormat;
this.buildFromProperties();
......@@ -213,14 +191,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
range = (relative) ? new ValueRange<>(this.reference, this.reference)
: new ValueRange<>(this.lowerBoundVariable.getValue(), this.upperBoundVariable.getValue());
lowerLeader = new Leader(innerRadius, leaderLineLength, landingLineLength);
lowerLeader.setLabelShape(labelShape);
lowerLeader.setFont(textFont);
upperLeader = new Leader(innerRadius, leaderLineLength, landingLineLength);
upperLeader.setLabelShape(labelShape);
upperLeader.setFont(textFont);
this.setInformation(range);
}
......@@ -246,19 +216,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
// ---------------------------------------------------------------------------
private void updateLeader() {
float lowerLeaderAngle = (float) -Math.toRadians(lowerAngle);
float upperLeaderAngle = (float) -Math.toRadians(upperAngle);
this.lowerLeader.updateLeader(lowerLeaderAngle);
this.lowerLeader.setLabel(lowerValueLabel);
this.upperLeader.updateLeader(upperLeaderAngle);
this.upperLeader.setLabel(upperValueLabel);
}
// ---------------------------------------------------------------------------
private synchronized void updateArcFromValues() {
if ((lowerBoundVariable == null) || (upperBoundVariable == null)) {
......@@ -273,8 +230,8 @@ public class ArcRangeGraph extends ValueRangeCorona {
double diameter = 2 * outerRadius;
this.lowerAngle = startAngle + (arcSpan * normalizedLowerValue);
this.upperAngle = startAngle + (arcSpan * normalizedUpperValue);
// this.lowerAngle = startAngle + (arcSpan * normalizedLowerValue);
// this.upperAngle = startAngle + (arcSpan * normalizedUpperValue);
if (relative) {
double normalizedReference = (reference - this.lowerBoundVariable.getMinValue()) / valueRange;
......@@ -321,8 +278,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
outerArea.subtract(innerArea);
}
this.updateLeader();
if (blinkOnOutOfRange && ((shownUpperValue == this.upperBoundVariable.getMaxValue()) || (relative && (shownLowerValue == this.lowerBoundVariable.getMinValue()))))
this.startBlinking();
else
......@@ -350,8 +305,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
labelColour.setSwitched(selectIt);
if (textColour != null)
textColour.setSwitched(selectIt);
if (leaderColour != null)
leaderColour.setSwitched(selectIt);
if (faceColour != null)
faceColour.setSwitched(selectIt);
if (bezelColour != null)
......@@ -425,25 +378,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
if (this.opacity < 1.0f)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(1.0f));
if (leaderColour != null) {
if (this.lowerLeader != null) {
this.lowerLeader.setStrokeColour(leaderColour.getColor());
if (labelColour != null)
this.lowerLeader.setFillColour(labelColour.getColor());
if (textColour != null)
this.lowerLeader.setLabelColour(textColour.getColor());
this.lowerLeader.paint(localCanvas);
}
if (this.upperLeader != null) {
this.upperLeader.setStrokeColour(leaderColour.getColor());
if (labelColour != null)
this.upperLeader.setFillColour(labelColour.getColor());
if (textColour != null)
this.upperLeader.setLabelColour(textColour.getColor());
this.upperLeader.paint(localCanvas);
}
}
localCanvas.dispose();
}
......@@ -459,9 +393,6 @@ public class ArcRangeGraph extends ValueRangeCorona {
double lowerBound = this.lowerBoundVariable.getValue();
double upperBound = this.upperBoundVariable.getValue();
this.lowerValueLabel = this.variableFormat.format(this.lowerBoundVariable);
this.upperValueLabel = this.variableFormat.format(this.upperBoundVariable);
if ((lowerBound == shownLowerValue) && (upperBound == shownUpperValue)) {
return;
}
......
This diff is collapsed.
......@@ -110,15 +110,15 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value
/** Optional fields */
strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context);
leaderLineLength = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LEADER_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
landingLineLength = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LANDING_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
leaderLineLength = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.LEADER_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
landingLineLength = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.LANDING_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
rampingTime = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.RAMPING_TIME_NODE, BootstrappingUtils.OPTIONAL, 500, context);
fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
labelColour = buildColorPair(rootElement.getChild(Externalization.LABEL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
leaderColour = buildColorPair(rootElement.getChild(Externalization.LEADER_COLOUR_NODE), BootstrappingUtils.OPTIONAL, context);
leaderColour = buildColorPair(rootElement.getChild(CpsNamespace.LEADER_COLOUR_NODE), BootstrappingUtils.OPTIONAL, context);
faceColour = buildColorPair(rootElement.getChild(Externalization.FACE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
bezelColour = buildColorPair(rootElement.getChild(Externalization.BEZEL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
......
......@@ -45,12 +45,9 @@ public abstract class BaseArcRangeGraphBuilder<B extends BaseArcRangeGraphBuilde
public ColorPair strokeColour;
public ColorPair labelColour;
public ColorPair textColour;
public ColorPair leaderColour;
public ColorPair faceColour;
public ColorPair bezelColour;
public int strokeWidth;
public int landingLineLength;
public int leaderLineLength;
public Shape labelShape;
public Font textFont;
public String labelFormat;
......@@ -69,20 +66,26 @@ public abstract class BaseArcRangeGraphBuilder<B extends BaseArcRangeGraphBuilde
super(centre);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseArcRangeGraphBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
/** Mandatory fields */
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseArcRangeGraphBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
......@@ -108,15 +111,12 @@ public abstract class BaseArcRangeGraphBuilder<B extends BaseArcRangeGraphBuilde
/** Optional fields */
strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context);
leaderLineLength = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LEADER_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
landingLineLength = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LANDING_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
rampingTime = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.RAMPING_TIME_NODE, BootstrappingUtils.OPTIONAL, 500, context);
fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
labelColour = buildColorPair(rootElement.getChild(Externalization.LABEL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
leaderColour = buildColorPair(rootElement.getChild(Externalization.LEADER_COLOUR_NODE), BootstrappingUtils.OPTIONAL, context);
faceColour = buildColorPair(rootElement.getChild(Externalization.FACE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
bezelColour = buildColorPair(rootElement.getChild(Externalization.BEZEL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.widget.corona.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.bootstrapping.ShapeBootstrapper;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.corona.Leader;
import org.jdom2.Element;
import java.awt.Color;
import java.awt.Font;
import java.awt.Shape;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 1.6
* @version 1.0.0
*/
public abstract class BaseLeaderBuilder<B extends BaseLeaderBuilder<B>> extends BaseValueCoronaBuilder<B> {
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public double startAngle;
public double arcSpan;
public double reference;
public double innerRadius;
public boolean relative;
public int rampingTime;
public double leaderLineLength;
public double landingLineLength;
public ColorPair leaderColour;
public int leaderStrokeWidth;
public ColorPair textColour;
public ColorPair fillColour;
public ColorPair strokeColour;
public int strokeWidth;
public Font labelFont;
public Shape labelShape;
public String labelFormat;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
protected BaseLeaderBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseLeaderBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
innerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.INNER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context);
startAngle = BootstrappingUtils.getContentAsRadians(rootElement, Externalization.START_ANGLE_NODE, BootstrappingUtils.MANDATORY, null, context);
arcSpan = BootstrappingUtils.getContentAsRadians(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context);
relative = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.RELATIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
reference = BootstrappingUtils.getContentAsDouble(rootElement, CpsNamespace.REFERENCE_NODE, BootstrappingUtils.OPTIONAL, 0d, context);
rampingTime = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.RAMPING_TIME_NODE, BootstrappingUtils.OPTIONAL, 500, context);
leaderColour = buildColorPair(rootElement.getChild(CpsNamespace.LEADER_COLOUR_NODE), BootstrappingUtils.OPTIONAL, context);
leaderStrokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.LEADER_STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 1, context);
leaderLineLength = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.LEADER_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
landingLineLength = BootstrappingUtils.getContentAsInteger(rootElement, CpsNamespace.LANDING_LINE_LENGTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
labelFont = BootstrappingUtils.getContentAsFont(rootElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, null, context);
labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback);
labelFormat = BootstrappingUtils.getContentAsString(rootElement, Externalization.LABEL_FORMAT_NODE, BootstrappingUtils.OPTIONAL, null, context);
fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
}
// ---------------------------------------------------------------------------
private ColorPair buildColorPair(Element rootElement, boolean optional, BootstrapContext context) throws BuildException {
ColorPair color = null;
if (rootElement == null)
return null;
if (!relative) {
Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, optional, null, context);
Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, optional, null, context);
color = new ColorPair(selectedColour, deselectedColour);
} else {
Color aboveColour = BootstrappingUtils.getContentAsColour(rootElement, CpsNamespace.ABOVE_ELEMENT, optional, null, context);
Color belowColour = BootstrappingUtils.getContentAsColour(rootElement, CpsNamespace.BELOW_ELEMENT, optional, null, context);
color = new ColorPair(belowColour, aboveColour);
}
return color;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract Leader build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,