use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ShortTextTitle method arrange.
/**
* Performs a layout for this title, subject to the supplied constraint,
* and returns the dimensions required for the title (if the title
* cannot be displayed in the available space, this method will return
* zero width and height for the dimensions).
*
* @param g2 the graphics target.
* @param constraint the layout constraints.
*
* @return The dimensions for the title.
*/
@Override
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
RectangleConstraint cc = toContentConstraint(constraint);
LengthConstraintType w = cc.getWidthConstraintType();
LengthConstraintType h = cc.getHeightConstraintType();
Size2D contentSize = null;
if (w == LengthConstraintType.NONE) {
if (h == LengthConstraintType.NONE) {
contentSize = arrangeNN(g2);
} else if (h == LengthConstraintType.RANGE) {
throw new RuntimeException("Not yet implemented.");
} else if (h == LengthConstraintType.FIXED) {
throw new RuntimeException("Not yet implemented.");
}
} else if (w == LengthConstraintType.RANGE) {
if (h == LengthConstraintType.NONE) {
contentSize = arrangeRN(g2, cc.getWidthRange());
} else if (h == LengthConstraintType.RANGE) {
contentSize = arrangeRR(g2, cc.getWidthRange(), cc.getHeightRange());
} else if (h == LengthConstraintType.FIXED) {
throw new RuntimeException("Not yet implemented.");
}
} else if (w == LengthConstraintType.FIXED) {
if (h == LengthConstraintType.NONE) {
contentSize = arrangeFN(g2, cc.getWidth());
} else if (h == LengthConstraintType.RANGE) {
throw new RuntimeException("Not yet implemented.");
} else if (h == LengthConstraintType.FIXED) {
throw new RuntimeException("Not yet implemented.");
}
}
assert contentSize != null;
if (contentSize.width <= 0.0 || contentSize.height <= 0.0) {
return new Size2D(0.0, 0.0);
} else {
return new Size2D(calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
}
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ShortTextTitle 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.
*/
@Override
protected Size2D arrangeFN(Graphics2D g2, double w) {
g2.setFont(getFont());
FontMetrics fm = g2.getFontMetrics(getFont());
Rectangle2D bounds = TextUtils.getTextBounds(getText(), g2, fm);
if (bounds.getWidth() <= w) {
return new Size2D(w, bounds.getHeight());
} else {
return new Size2D(0.0, 0.0);
}
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class TextFragment method calculateDimensions.
/**
* Calculates the dimensions of the text fragment.
*
* @param g2 the graphics device.
*
* @return The width and height of the text.
*/
public Size2D calculateDimensions(Graphics2D g2) {
FontMetrics fm = g2.getFontMetrics(this.font);
Rectangle2D bounds = TextUtils.getTextBounds(this.text, g2, fm);
Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight());
return result;
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ImageTitle method drawHorizontal.
/**
* Draws the title on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param chartArea the area within which the title (and plot) should be
* drawn.
*
* @return The size of the area used by the title.
*/
protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) {
double startY;
double topSpace;
double bottomSpace;
double leftSpace;
double rightSpace;
double w = getWidth();
double h = getHeight();
RectangleInsets padding = getPadding();
topSpace = padding.calculateTopOutset(h);
bottomSpace = padding.calculateBottomOutset(h);
leftSpace = padding.calculateLeftOutset(w);
rightSpace = padding.calculateRightOutset(w);
if (getPosition() == RectangleEdge.TOP) {
startY = chartArea.getY() + topSpace;
} else {
startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h;
}
// what is our alignment?
double startX = 0.0;
switch(getHorizontalAlignment()) {
case CENTER:
startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
break;
case LEFT:
startX = chartArea.getX() + leftSpace;
break;
case RIGHT:
startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
break;
default:
throw new IllegalStateException("Unexpected horizontal alignment.");
}
g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ImageTitle method drawVertical.
/**
* Draws the title on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param chartArea the area within which the title (and plot) should be
* drawn.
*
* @return The size of the area used by the title.
*/
protected Size2D drawVertical(Graphics2D g2, Rectangle2D chartArea) {
double startX;
double topSpace = 0.0;
double bottomSpace = 0.0;
double leftSpace = 0.0;
double rightSpace = 0.0;
double w = getWidth();
double h = getHeight();
RectangleInsets padding = getPadding();
if (padding != null) {
topSpace = padding.calculateTopOutset(h);
bottomSpace = padding.calculateBottomOutset(h);
leftSpace = padding.calculateLeftOutset(w);
rightSpace = padding.calculateRightOutset(w);
}
if (getPosition() == RectangleEdge.LEFT) {
startX = chartArea.getX() + leftSpace;
} else {
startX = chartArea.getMaxX() - rightSpace - w;
}
// what is our alignment?
double startY = 0.0;
switch(getVerticalAlignment()) {
case CENTER:
startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
break;
case TOP:
startY = chartArea.getMinY() + topSpace;
break;
case BOTTOM:
startY = chartArea.getMaxY() - bottomSpace - h;
break;
default:
throw new IllegalStateException("Unexpected vertical alignment.");
}
g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
Aggregations