Commit d96684e5 authored by Nico Mack's avatar Nico Mack

Added stretchToFit and insetBorder properties to ArcGraph corona

parent 602b2a6d
......@@ -102,7 +102,8 @@ public class VectorBasedCallback implements BootstrapCallback {
for (BaseWidget widget : widgets) {
List<Variable<?>> connected;
if (widget.getClass().isAssignableFrom(VariableBased.class)) {
// if (widget.getClass().isAssignableFrom(VariableBased.class)) {
if (widget instanceof VariableBased) {
VariableBased display = (VariableBased) widget;
connected = display.connectWithSystemVariables(systemVariables);
......
......@@ -4,6 +4,7 @@ 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.Point;
import lu.list.itis.dkd.tui.utility.ShapeUtils;
import lu.list.itis.dkd.tui.utility.VariableFormat;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseArcGraphBuilder;
......@@ -56,6 +57,8 @@ public class ArcGraph extends ValueCorona {
protected Shape labelShape;
protected String labelFormat;
protected int labelGap;
protected int insetBorder;
protected boolean stretchToFit;
protected Font textFont;
protected Stroke borderStroke;
protected int strokeWidth;
......@@ -108,6 +111,9 @@ public class ArcGraph extends ValueCorona {
this.labelShape = builder.labelShape;
this.labelFormat = builder.labelFormat;
this.labelGap = builder.labelGap;
this.insetBorder = builder.insetBorder;
this.stretchToFit = builder.stretchToFit;
this.textFont = builder.textFont;
this.strokeWidth = builder.strokeWidth;
this.rampingTime = builder.rampingTime;
......@@ -144,6 +150,9 @@ public class ArcGraph extends ValueCorona {
this.bezelColour = original.bezelColour;
this.labelShape = original.labelShape;
this.labelFormat = original.labelFormat;
this.insetBorder = original.insetBorder;
this.stretchToFit = original.stretchToFit;
this.textFont = original.textFont;
this.strokeWidth = original.strokeWidth;
this.rampingTime = original.rampingTime;
......@@ -182,15 +191,6 @@ public class ArcGraph extends ValueCorona {
face.subtract(inner);
outer.subtract(inner);
if (this.labelShape != null) {
AffineTransform originTranslator = new AffineTransform();
Rectangle2D bounds = labelShape.getBounds2D();
if (bounds.getX() < 0)
originTranslator.translate(-bounds.getX(), 0);
labelShape = originTranslator.createTransformedShape(labelShape);
}
if ((this.labelFormat != null) && (!this.labelFormat.isEmpty())) {
this.variableFormat = new VariableFormat(this.labelFormat);
} else {
......@@ -200,6 +200,22 @@ public class ArcGraph extends ValueCorona {
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
this.setInformation((relative) ? this.reference : this.variable.getValue());
if (this.labelShape != null) {
AffineTransform originTranslator = new AffineTransform();
if (stretchToFit) {
// String fullScale = this.variableFormat.format(this.variable.get);
labelShape = ShapeUtils.stretchToFit(labelShape, label, textFont, false, 2 * insetBorder);
}
Rectangle2D bounds = labelShape.getBounds2D();
if (bounds.getX() < 0)
originTranslator.translate(-bounds.getX() - insetBorder, 0);
labelShape = originTranslator.createTransformedShape(labelShape);
}
}
// ---------------------------------------------------------------------------
......@@ -250,6 +266,8 @@ public class ArcGraph extends ValueCorona {
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......
......@@ -53,9 +53,11 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value
public int landingLineLength;
public int leaderLineLength;
public int labelGap;
public int insetBorder;
public Shape labelShape;
public String labelFormat;
public Font textFont;
public boolean stretchToFit;
// ***************************************************************************
// * Constants *
......@@ -127,6 +129,8 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value
labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback);
labelFormat = BootstrappingUtils.getContentAsString(rootElement, Externalization.LABEL_FORMAT_NODE, BootstrappingUtils.OPTIONAL, null);
labelGap = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LABEL_GAP_NODE, BootstrappingUtils.OPTIONAL, 0);
insetBorder = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INSET_BORDER_NODE, BootstrappingUtils.OPTIONAL, 0);
stretchToFit = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.STRETCH_TO_FIT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE);
title = BootstrappingUtils.getContentAsString(rootElement, Externalization.TITLE_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
String fontName = BootstrappingUtils.getContentAsString(rootElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, "Monospaced"); //$NON-NLS-1$
......
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