List of usage examples for org.jfree.chart.block Block setBounds
public void setBounds(Rectangle2D bounds);
From source file:com.hmsinc.epicenter.webapp.chart.SNColumnArrangement.java
/** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters.//from www . jav a 2s . co m * * @param container * the container whose items are being arranged. * @param g2 * the graphics device. * @param constraint * the size constraint. * * @return The size of the container after arrangement of the contents. */ @SuppressWarnings("unchecked") public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { List<Block> blocks = container.getBlocks(); // calculate max width of entries double maxWidth = 0.0; double maxHeight = 0.0; for (Block block : blocks) { Size2D size = block.arrange(g2, RectangleConstraint.NONE); maxWidth = Math.max(maxWidth, size.width + this.horizontalGap); maxHeight = Math.max(maxHeight, size.height + this.verticalGap); } // calculate number of columns double width = 0.0; if (constraint.getWidthConstraintType() == LengthConstraintType.FIXED) { width = constraint.getWidth(); } else if (constraint.getWidthConstraintType() == LengthConstraintType.RANGE) { Range range = constraint.getWidthRange(); width = range.getUpperBound(); } else { throw new RuntimeException("Not implemented."); } int columns = (int) (Math.floor(width / maxWidth)); if (columns > 0) { columns--; } // for all columns int colx = -1; int coly = 0; for (Block block : blocks) { Size2D size = block.arrange(g2, RectangleConstraint.NONE); if (colx < columns) { colx++; } else { colx = 0; coly++; } double x = colx * maxWidth; double y = coly * maxHeight; block.setBounds(new Rectangle2D.Double(x, y, size.width, size.height)); } // calculate size of bounding double bWidth = (coly == 0) ? (colx + 1) * maxWidth : (columns + 1) * maxWidth; double bHeight = (coly + 1) * maxHeight; return new Size2D(bWidth, bHeight); }