List of usage examples for org.jfree.chart.block LengthConstraintType RANGE
LengthConstraintType RANGE
To view the source code for org.jfree.chart.block LengthConstraintType RANGE.
Click Source Link
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.// w ww. j a va 2 s. 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); }
From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java
/** * paint a legend/* ww w.jav a 2s.com*/ * * @param legend * the legend * @param graphics * the graphics * @param bounds * the bounds */ private static final void __paintLegend(final LegendTitle legend, final Graphics2D graphics, final Rectangle2D bounds) { final Rectangle2D titleArea; final BlockParams p; final double ww, hh; final RectangleConstraint constraint; final Size2D size; p = new BlockParams(); p.setGenerateEntities(false); ww = bounds.getWidth(); if (ww <= 0.0d) { return; } hh = bounds.getHeight(); if (hh <= 0.0d) { return; } constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE); size = legend.arrange(graphics, constraint); titleArea = _JFCLineChart2D.__createAlignedRectangle2D(size, bounds, legend.getHorizontalAlignment(), VerticalAlignment.TOP); legend.setMargin(_JFCLineChart2D.LEGEND_MARGIN); legend.setPadding(_JFCLineChart2D.CHART_INSETS); legend.draw(graphics, titleArea, p); }