Commit adc0e622 authored by Nico Mack's avatar Nico Mack

Added centred property

parent caa63ec0
...@@ -20,6 +20,7 @@ import java.awt.Graphics2D; ...@@ -20,6 +20,7 @@ import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.LineMetrics; import java.awt.font.LineMetrics;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D; import java.awt.geom.Arc2D;
...@@ -61,6 +62,7 @@ public class ArcGraph extends ValueCorona { ...@@ -61,6 +62,7 @@ public class ArcGraph extends ValueCorona {
protected int labelGap; protected int labelGap;
protected int insetBorder; protected int insetBorder;
protected boolean stretchToFit; protected boolean stretchToFit;
protected boolean centered;
protected Font textFont; protected Font textFont;
protected Stroke borderStroke; protected Stroke borderStroke;
protected int strokeWidth; protected int strokeWidth;
...@@ -115,6 +117,7 @@ public class ArcGraph extends ValueCorona { ...@@ -115,6 +117,7 @@ public class ArcGraph extends ValueCorona {
this.labelGap = builder.labelGap; this.labelGap = builder.labelGap;
this.insetBorder = builder.insetBorder; this.insetBorder = builder.insetBorder;
this.stretchToFit = builder.stretchToFit; this.stretchToFit = builder.stretchToFit;
this.centered = builder.centered;
this.textFont = builder.textFont; this.textFont = builder.textFont;
this.strokeWidth = builder.strokeWidth; this.strokeWidth = builder.strokeWidth;
...@@ -154,6 +157,7 @@ public class ArcGraph extends ValueCorona { ...@@ -154,6 +157,7 @@ public class ArcGraph extends ValueCorona {
this.labelFormat = original.labelFormat; this.labelFormat = original.labelFormat;
this.insetBorder = original.insetBorder; this.insetBorder = original.insetBorder;
this.stretchToFit = original.stretchToFit; this.stretchToFit = original.stretchToFit;
this.centered = original.centered;
this.textFont = original.textFont; this.textFont = original.textFont;
this.strokeWidth = original.strokeWidth; this.strokeWidth = original.strokeWidth;
...@@ -192,16 +196,19 @@ public class ArcGraph extends ValueCorona { ...@@ -192,16 +196,19 @@ public class ArcGraph extends ValueCorona {
AffineTransform originTranslator = new AffineTransform(); AffineTransform originTranslator = new AffineTransform();
if (stretchToFit) { if (stretchToFit) {
// String fullScale = this.variableFormat.format(this.variable.get);
labelShape = ShapeUtils.stretchToFit(labelShape, label, textFont, false, 2 * insetBorder); 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);
} }
if (centered) {
Rectangle2D bounds = labelShape.getBounds2D(); Rectangle2D bounds = labelShape.getBounds2D();
if (bounds.getX() < 0) GlyphVector glyphVector = textFont.createGlyphVector(new FontRenderContext(null, true, true), label);
originTranslator.translate(-bounds.getX() - insetBorder, 0); double requiredWidth = glyphVector.getLogicalBounds().getWidth();
labelShape = originTranslator.createTransformedShape(labelShape); insetBorder = (int) (bounds.getWidth() - requiredWidth) / 2;
}
} }
} }
...@@ -405,7 +412,7 @@ public class ArcGraph extends ValueCorona { ...@@ -405,7 +412,7 @@ public class ArcGraph extends ValueCorona {
if (textColour != null) { if (textColour != null) {
localCanvas.setPaint(textColour.getColor()); localCanvas.setPaint(textColour.getColor());
localCanvas.setFont(textFont); localCanvas.setFont(textFont);
localCanvas.drawString(label, 5, (labelMetrics.getAscent() / 2)); localCanvas.drawString(label, insetBorder, (labelMetrics.getAscent() / 2));
} }
localCanvas.dispose(); localCanvas.dispose();
......
...@@ -58,6 +58,7 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value ...@@ -58,6 +58,7 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value
public String labelFormat; public String labelFormat;
public Font textFont; public Font textFont;
public boolean stretchToFit; public boolean stretchToFit;
public boolean centered;
// *************************************************************************** // ***************************************************************************
// * Constants * // * Constants *
...@@ -131,6 +132,7 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value ...@@ -131,6 +132,7 @@ public class BaseArcGraphBuilder<B extends BaseArcGraphBuilder<B>> extends Value
labelGap = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LABEL_GAP_NODE, BootstrappingUtils.OPTIONAL, 0, context); labelGap = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.LABEL_GAP_NODE, BootstrappingUtils.OPTIONAL, 0, context);
insetBorder = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INSET_BORDER_NODE, BootstrappingUtils.OPTIONAL, 0, context); insetBorder = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INSET_BORDER_NODE, BootstrappingUtils.OPTIONAL, 0, context);
stretchToFit = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.STRETCH_TO_FIT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context); stretchToFit = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.STRETCH_TO_FIT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
centered = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.CENTRED_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
title = BootstrappingUtils.getContentAsString(rootElement, Externalization.TITLE_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context); 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$ 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