use of org.jfree.text.G2TextMeasurer in project SIMVA-SoS by SESoS.
the class PiePlot method drawRightLabels.
/**
* Draws the right labels.
*
* @param keys the keys.
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param linkArea the link area.
* @param maxLabelWidth the maximum label width.
* @param state the state.
*/
protected void drawRightLabels(KeyedValues keys, Graphics2D g2, Rectangle2D plotArea, Rectangle2D linkArea, float maxLabelWidth, PiePlotState state) {
// draw the right labels...
this.labelDistributor.clear();
double lGap = plotArea.getWidth() * this.labelGap;
double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
for (int i = 0; i < keys.getItemCount(); i++) {
String label = this.labelGenerator.generateSectionLabel(this.dataset, keys.getKey(i));
if (label != null) {
TextBlock block = TextUtilities.createTextBlock(label, this.labelFont, this.labelPaint, maxLabelWidth, new G2TextMeasurer(g2));
TextBox labelBox = new TextBox(block);
labelBox.setBackgroundPaint(this.labelBackgroundPaint);
labelBox.setOutlinePaint(this.labelOutlinePaint);
labelBox.setOutlineStroke(this.labelOutlineStroke);
if (this.shadowGenerator == null) {
labelBox.setShadowPaint(this.labelShadowPaint);
} else {
labelBox.setShadowPaint(null);
}
labelBox.setInteriorGap(this.labelPadding);
double theta = Math.toRadians(keys.getValue(i).doubleValue());
double baseY = state.getPieCenterY() - Math.sin(theta) * verticalLinkRadius;
double hh = labelBox.getHeight(g2);
this.labelDistributor.addPieLabelRecord(new PieLabelRecord(keys.getKey(i), theta, baseY, labelBox, hh, lGap / 2.0 + lGap / 2.0 * Math.cos(theta), 1.0 - getLabelLinkDepth() + getExplodePercent(keys.getKey(i))));
}
}
double hh = plotArea.getHeight();
// hh * getInteriorGap();
double gap = 0.00;
this.labelDistributor.distributeLabels(plotArea.getMinY() + gap, hh - 2 * gap);
for (int i = 0; i < this.labelDistributor.getItemCount(); i++) {
drawRightLabel(g2, state, this.labelDistributor.getPieLabelRecord(i));
}
}
use of org.jfree.text.G2TextMeasurer in project SIMVA-SoS by SESoS.
the class Plot method drawNoDataMessage.
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
TextBlock block = TextUtilities.createTextBlock(this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint, 0.9f * (float) area.getWidth(), new G2TextMeasurer(g2));
block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER);
}
g2.setClip(savedClip);
}
use of org.jfree.text.G2TextMeasurer in project SIMVA-SoS by SESoS.
the class TextTitle method arrangeRR.
/**
* Returns the content size for the title. This will reflect the fact that
* a text title positioned on the left or right of a chart will be rotated
* 90 degrees.
*
* @param g2 the graphics device.
* @param widthRange the width range.
* @param heightRange the height range.
*
* @return The content size.
*/
protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) {
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
float maxWidth = (float) widthRange.getUpperBound();
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
if (this.expandToFitSpace) {
return new Size2D(maxWidth, contentSize.getHeight());
} else {
return contentSize;
}
} else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
float maxWidth = (float) heightRange.getUpperBound();
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
// transpose the dimensions, because the title is rotated
if (this.expandToFitSpace) {
return new Size2D(contentSize.getHeight(), maxWidth);
} else {
return new Size2D(contentSize.height, contentSize.width);
}
} else {
throw new RuntimeException("Unrecognised exception.");
}
}
use of org.jfree.text.G2TextMeasurer in project SIMVA-SoS by SESoS.
the class PiePlot method drawLeftLabels.
/**
* Draws the left labels.
*
* @param leftKeys a collection of keys and angles (to the middle of the
* section, in degrees) for the sections on the left side of the
* plot.
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param linkArea the link area.
* @param maxLabelWidth the maximum label width.
* @param state the state.
*/
protected void drawLeftLabels(KeyedValues leftKeys, Graphics2D g2, Rectangle2D plotArea, Rectangle2D linkArea, float maxLabelWidth, PiePlotState state) {
this.labelDistributor.clear();
double lGap = plotArea.getWidth() * this.labelGap;
double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0;
for (int i = 0; i < leftKeys.getItemCount(); i++) {
String label = this.labelGenerator.generateSectionLabel(this.dataset, leftKeys.getKey(i));
if (label != null) {
TextBlock block = TextUtilities.createTextBlock(label, this.labelFont, this.labelPaint, maxLabelWidth, new G2TextMeasurer(g2));
TextBox labelBox = new TextBox(block);
labelBox.setBackgroundPaint(this.labelBackgroundPaint);
labelBox.setOutlinePaint(this.labelOutlinePaint);
labelBox.setOutlineStroke(this.labelOutlineStroke);
if (this.shadowGenerator == null) {
labelBox.setShadowPaint(this.labelShadowPaint);
} else {
labelBox.setShadowPaint(null);
}
labelBox.setInteriorGap(this.labelPadding);
double theta = Math.toRadians(leftKeys.getValue(i).doubleValue());
double baseY = state.getPieCenterY() - Math.sin(theta) * verticalLinkRadius;
double hh = labelBox.getHeight(g2);
this.labelDistributor.addPieLabelRecord(new PieLabelRecord(leftKeys.getKey(i), theta, baseY, labelBox, hh, lGap / 2.0 + lGap / 2.0 * -Math.cos(theta), 1.0 - getLabelLinkDepth() + getExplodePercent(leftKeys.getKey(i))));
}
}
double hh = plotArea.getHeight();
double gap = hh * getInteriorGap();
this.labelDistributor.distributeLabels(plotArea.getMinY() + gap, hh - 2 * gap);
for (int i = 0; i < this.labelDistributor.getItemCount(); i++) {
drawLeftLabel(g2, state, this.labelDistributor.getPieLabelRecord(i));
}
}
use of org.jfree.text.G2TextMeasurer in project SIMVA-SoS by SESoS.
the class TextTitle method arrangeFN.
/**
* Arranges the content for this title assuming a fixed width and no bounds
* on the height, and returns the required size. This will reflect the
* fact that a text title positioned on the left or right of a chart will
* be rotated by 90 degrees.
*
* @param g2 the graphics target.
* @param w the width.
*
* @return The content size.
*
* @since 1.0.9
*/
protected Size2D arrangeFN(Graphics2D g2, double w) {
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
float maxWidth = (float) w;
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
if (this.expandToFitSpace) {
return new Size2D(maxWidth, contentSize.getHeight());
} else {
return contentSize;
}
} else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
float maxWidth = Float.MAX_VALUE;
g2.setFont(this.font);
this.content = TextUtilities.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
// transpose the dimensions, because the title is rotated
if (this.expandToFitSpace) {
return new Size2D(contentSize.getHeight(), maxWidth);
} else {
return new Size2D(contentSize.height, contentSize.width);
}
} else {
throw new RuntimeException("Unrecognised exception.");
}
}
Aggregations