use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
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.");
}
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class FlowArrangement method arrangeFN.
/**
* Arranges the blocks in the container with a fixed width and no height
* constraint.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size.
*/
protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
List blocks = container.getBlocks();
double width = constraint.getWidth();
double x = 0.0;
double y = 0.0;
double maxHeight = 0.0;
List itemsInRow = new ArrayList();
for (int i = 0; i < blocks.size(); i++) {
Block block = (Block) blocks.get(i);
Size2D size = block.arrange(g2, RectangleConstraint.NONE);
if (x + size.width <= width) {
itemsInRow.add(block);
block.setBounds(new Rectangle2D.Double(x, y, size.width, size.height));
x = x + size.width + this.horizontalGap;
maxHeight = Math.max(maxHeight, size.height);
} else {
if (itemsInRow.isEmpty()) {
// place in this row (truncated) anyway
block.setBounds(new Rectangle2D.Double(x, y, Math.min(size.width, width - x), size.height));
x = 0.0;
y = y + size.height + this.verticalGap;
} else {
// start new row
itemsInRow.clear();
x = 0.0;
y = y + maxHeight + this.verticalGap;
maxHeight = size.height;
block.setBounds(new Rectangle2D.Double(x, y, Math.min(size.width, width), size.height));
x = size.width + this.horizontalGap;
itemsInRow.add(block);
}
}
}
return new Size2D(constraint.getWidth(), y + maxHeight);
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class GridArrangement method arrangeNR.
/**
* Arrange with a fixed height and no width constraint.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size of the arrangement.
*/
protected Size2D arrangeNR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
RectangleConstraint c1 = constraint.toUnconstrainedHeight();
Size2D size1 = arrange(container, g2, c1);
if (constraint.getHeightRange().contains(size1.getHeight())) {
return size1;
} else {
double h = constraint.getHeightRange().constrain(size1.getHeight());
RectangleConstraint c2 = constraint.toFixedHeight(h);
return arrange(container, g2, c2);
}
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class GridArrangement method arrangeRF.
/**
* Arrange with a fixed height and a width within a given range.
*
* @param container the container.
* @param constraint the constraint.
* @param g2 the graphics device.
*
* @return The size of the arrangement.
*/
protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) {
RectangleConstraint c1 = constraint.toUnconstrainedWidth();
Size2D size1 = arrange(container, g2, c1);
if (constraint.getWidthRange().contains(size1.getWidth())) {
return size1;
} else {
double w = constraint.getWidthRange().constrain(size1.getWidth());
RectangleConstraint c2 = constraint.toFixedWidth(w);
return arrange(container, g2, c2);
}
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class BorderArrangement method arrangeRR.
/**
* Performs an arrangement with range constraints on both the vertical
* and horizontal sides.
*
* @param container the container.
* @param widthRange the allowable range for the container width.
* @param heightRange the allowable range for the container height.
* @param g2 the graphics device.
*
* @return The container size.
*/
protected Size2D arrangeRR(BlockContainer container, Range widthRange, Range heightRange, Graphics2D g2) {
double[] w = new double[5];
double[] h = new double[5];
if (this.topBlock != null) {
RectangleConstraint c1 = new RectangleConstraint(widthRange, heightRange);
Size2D size = this.topBlock.arrange(g2, c1);
w[0] = size.width;
h[0] = size.height;
}
if (this.bottomBlock != null) {
Range heightRange2 = Range.shift(heightRange, -h[0], false);
RectangleConstraint c2 = new RectangleConstraint(widthRange, heightRange2);
Size2D size = this.bottomBlock.arrange(g2, c2);
w[1] = size.width;
h[1] = size.height;
}
Range heightRange3 = Range.shift(heightRange, -(h[0] + h[1]));
if (this.leftBlock != null) {
RectangleConstraint c3 = new RectangleConstraint(widthRange, heightRange3);
Size2D size = this.leftBlock.arrange(g2, c3);
w[2] = size.width;
h[2] = size.height;
}
Range widthRange2 = Range.shift(widthRange, -w[2], false);
if (this.rightBlock != null) {
RectangleConstraint c4 = new RectangleConstraint(widthRange2, heightRange3);
Size2D size = this.rightBlock.arrange(g2, c4);
w[3] = size.width;
h[3] = size.height;
}
h[2] = Math.max(h[2], h[3]);
h[3] = h[2];
Range widthRange3 = Range.shift(widthRange, -(w[2] + w[3]), false);
if (this.centerBlock != null) {
RectangleConstraint c5 = new RectangleConstraint(widthRange3, heightRange3);
// TODO: the width and height ranges should be reduced by the
// height required for the top and bottom, and the width required
// by the left and right
Size2D size = this.centerBlock.arrange(g2, c5);
w[4] = size.width;
h[4] = size.height;
}
double width = Math.max(w[0], Math.max(w[1], w[2] + w[4] + w[3]));
double height = h[0] + h[1] + Math.max(h[2], Math.max(h[3], h[4]));
if (this.topBlock != null) {
this.topBlock.setBounds(new Rectangle2D.Double(0.0, 0.0, width, h[0]));
}
if (this.bottomBlock != null) {
this.bottomBlock.setBounds(new Rectangle2D.Double(0.0, height - h[1], width, h[1]));
}
if (this.leftBlock != null) {
this.leftBlock.setBounds(new Rectangle2D.Double(0.0, h[0], w[2], h[2]));
}
if (this.rightBlock != null) {
this.rightBlock.setBounds(new Rectangle2D.Double(width - w[3], h[0], w[3], h[3]));
}
if (this.centerBlock != null) {
this.centerBlock.setBounds(new Rectangle2D.Double(w[2], h[0], width - w[2] - w[3], height - h[0] - h[1]));
}
return new Size2D(width, height);
}
Aggregations