if (label == null) {
return state;
}
RectangleInsets insets = getLabelInsets();
g2.setFont(getLabelFont());
g2.setPaint(getLabelPaint());
TextLayout layout = new TextLayout(label.getIterator(),
g2.getFontRenderContext());
Rectangle2D labelBounds = layout.getBounds();
if (edge == RectangleEdge.TOP) {
AffineTransform t = AffineTransform.getRotateInstance(
getLabelAngle(), labelBounds.getCenterX(),
labelBounds.getCenterY());
Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
labelBounds = rotatedLabelBounds.getBounds2D();
double labelx = this.labelLocation.labelLocationX(dataArea);
double labely = state.getCursor() - insets.getBottom()
- labelBounds.getHeight() / 2.0;
TextAnchor anchor = this.labelLocation.labelAnchorH();
TextUtilities.drawRotatedString(label, g2, (float) labelx,
(float) labely, anchor, getLabelAngle(), TextAnchor.CENTER);
state.cursorUp(insets.getTop() + labelBounds.getHeight()
+ insets.getBottom());
}
else if (edge == RectangleEdge.BOTTOM) {
AffineTransform t = AffineTransform.getRotateInstance(
getLabelAngle(), labelBounds.getCenterX(),
labelBounds.getCenterY());
Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
labelBounds = rotatedLabelBounds.getBounds2D();
double labelx = this.labelLocation.labelLocationX(dataArea);
double labely = state.getCursor()
+ insets.getTop() + labelBounds.getHeight() / 2.0;
TextAnchor anchor = this.labelLocation.labelAnchorH();
TextUtilities.drawRotatedString(label, g2, (float) labelx,
(float) labely, anchor, getLabelAngle(), TextAnchor.CENTER);
state.cursorDown(insets.getTop() + labelBounds.getHeight()
+ insets.getBottom());
}
else if (edge == RectangleEdge.LEFT) {
AffineTransform t = AffineTransform.getRotateInstance(
getLabelAngle() - Math.PI / 2.0, labelBounds.getCenterX(),
labelBounds.getCenterY());
Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
labelBounds = rotatedLabelBounds.getBounds2D();
double labelx = state.getCursor()
- insets.getRight() - labelBounds.getWidth() / 2.0;
double labely = this.labelLocation.labelLocationY(dataArea);
TextAnchor anchor = this.labelLocation.labelAnchorV();
TextUtilities.drawRotatedString(label, g2, (float) labelx,
(float) labely, anchor, getLabelAngle() - Math.PI / 2.0,
anchor);
state.cursorLeft(insets.getLeft() + labelBounds.getWidth()
+ insets.getRight());
}
else if (edge == RectangleEdge.RIGHT) {
AffineTransform t = AffineTransform.getRotateInstance(
getLabelAngle() + Math.PI / 2.0,
labelBounds.getCenterX(), labelBounds.getCenterY());
Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
labelBounds = rotatedLabelBounds.getBounds2D();
double labelx = state.getCursor()
+ insets.getLeft() + labelBounds.getWidth() / 2.0;
double labely = this.labelLocation.labelLocationY(dataArea);
TextAnchor anchor = this.labelLocation.labelAnchorV();
TextUtilities.drawRotatedString(label, g2, (float) labelx,
(float) labely, anchor, getLabelAngle() + Math.PI / 2.0,
anchor);
state.cursorRight(insets.getLeft() + labelBounds.getWidth()
+ insets.getRight());
}
return state;