Commit 50e50848 authored by Nico Mack's avatar Nico Mack

Added borderInset property to Indicator

parent 2a4e31f5
......@@ -48,6 +48,7 @@ public class Indicator extends ValueCorona {
protected Shape labelShape;
protected Font textFont;
protected int strokeWidth;
protected int insetBorder;
protected String labelFormat;
private boolean stretchToFit;
......@@ -56,7 +57,7 @@ public class Indicator extends ValueCorona {
private VariableFormat variableFormat;
private BasicStroke borderStroke;
private LineMetrics labelMetrics;
private int horizontalOffset;
private float horizontalOffset;
private String formatted;
......@@ -85,6 +86,7 @@ public class Indicator extends ValueCorona {
this.textColour = builder.textColour;
this.textFont = builder.textFont;
this.strokeWidth = builder.strokeWidth;
this.insetBorder = builder.insetBorder;
this.labelFormat = builder.labelFormat;
this.labelShape = builder.labelShape;
......@@ -126,7 +128,8 @@ public class Indicator extends ValueCorona {
if (this.textFont != null) {
GlyphVector glyphVector = textFont.createGlyphVector(new FontRenderContext(null, true, true), labelToFit);
requiredWidth = glyphVector.getLogicalBounds().getWidth();
this.horizontalOffset = -(int) (requiredWidth / 2);
this.horizontalOffset = -(float) (requiredWidth / 2);
requiredWidth += 2 * this.insetBorder;
}
String className = this.shape.getClass().getCanonicalName();
......@@ -258,7 +261,7 @@ public class Indicator extends ValueCorona {
if ((this.textColour != null) && (this.formatted != null)) {
localCanvas.setPaint(textColour.getColor());
localCanvas.setFont(textFont);
localCanvas.drawString(this.formatted, this.horizontalOffset, (labelMetrics.getAscent() / 2));
localCanvas.drawString(this.formatted, this.horizontalOffset, ((labelMetrics.getAscent() - labelMetrics.getDescent()) / 2));
}
localCanvas.dispose();
......
......@@ -49,6 +49,7 @@ public abstract class BaseIndicatorBuilder<B extends ValueCoronaBuilder<B>> exte
public Shape labelShape;
public Font textFont;
public int strokeWidth;
public int insetBorder;
public String labelFormat;
public boolean stretchToFit;
......@@ -107,6 +108,9 @@ public abstract class BaseIndicatorBuilder<B extends ValueCoronaBuilder<B>> exte
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
strokeWidth = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.STROKE_WIDTH_NODE, BootstrappingUtils.OPTIONAL, 0, context);
insetBorder = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INSET_BORDER_NODE, BootstrappingUtils.OPTIONAL, 0, context);
labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback);
stretchToFit = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.STRETCH_TO_FIT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE);
......
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