/** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { Size2D result = new Size2D(); fetchLegendItems(); if (this.items.isEmpty()) { return result; } BlockContainer container = this.wrapper; if (container == null) { container = this.items; } RectangleConstraint c = toContentConstraint(constraint); Size2D size = container.arrange(g2, c); result.height = calculateTotalHeight(size.height); result.width = calculateTotalWidth(size.width); return result; }
/** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { Size2D result = new Size2D(); fetchLegendItems(); if (this.items.isEmpty()) { return result; } BlockContainer container = this.wrapper; if (container == null) { container = this.items; } RectangleConstraint c = toContentConstraint(constraint); Size2D size = container.arrange(g2, c); result.height = calculateTotalHeight(size.height); result.width = calculateTotalWidth(size.width); return result; }
/** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint ({@code null} not permitted). * * @return The block size (in Java2D units, never {@code null}). */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { Size2D result = new Size2D(); fetchLegendItems(); if (this.items.isEmpty()) { return result; } BlockContainer container = this.wrapper; if (container == null) { container = this.items; } RectangleConstraint c = toContentConstraint(constraint); Size2D size = container.arrange(g2, c); result.height = calculateTotalHeight(size.height); result.width = calculateTotalWidth(size.width); return result; }
/** * This test is for a particular bug that arose just prior to the release * of JFreeChart 1.0.10. A BorderArrangement with LEFT, CENTRE and RIGHT * blocks that is too wide, by default, for the available space, wasn't * shrinking the centre block as expected. */ public void testBugX() { RectangleConstraint constraint = new RectangleConstraint( new Range(0.0, 200.0), new Range(0.0, 100.0)); BlockContainer container = new BlockContainer(new BorderArrangement()); BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT); container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT); container.add(new EmptyBlock(30.0, 6.0)); Size2D size = container.arrange(g2, constraint); assertEquals(60.0, size.width, EPSILON); assertEquals(6.0, size.height, EPSILON); container.clear(); container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT); container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT); container.add(new EmptyBlock(300.0, 6.0)); size = container.arrange(g2, constraint); assertEquals(200.0, size.width, EPSILON); assertEquals(6.0, size.height, EPSILON); }
@SuppressWarnings("unchecked") @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { List<Block> blocks = container.getBlocks(); double cellHeight = maxHeight(blocks, g2); double cellWidth = maxWidth(blocks, g2); int rows = Math.round(blocks.size() / 2.0f); for (int i = 0; i < blocks.size(); i++) { Block block = blocks.get(i); int col = (i<rows?0:1); int row = i-col*rows; block.setBounds(new Rectangle2D.Double( col*cellWidth, row*cellHeight, cellWidth, cellHeight)); } return new Size2D(blocks.size()==1?cellWidth:cellWidth*2, cellHeight*rows); }
private int computeLegendHeight(final JFreeChart chart, final int imageWidth) { if (chart.getSubtitleCount() == 0) { return 0; } BufferedImage image = new BufferedImage(imageWidth, IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); RectangleConstraint constraint = new RectangleConstraint( imageWidth, new Range(0.0, imageWidth), LengthConstraintType.RANGE, 0.0, null, LengthConstraintType.NONE ); int height = 0; for (int i = 0; i < chart.getSubtitleCount(); i++) { final Title subtitle = chart.getSubtitle(i); final Size2D arrange = subtitle.arrange(g2, constraint); height += arrange.getHeight(); } return height; }
/** * Test arrangement with no constraints. */ public void testNN() { BlockContainer c = createTestContainer1(); Size2D s = c.arrange(null, RectangleConstraint.NONE); assertEquals(90.0, s.width, EPSILON); assertEquals(33.0, s.height, EPSILON); }
/** * Test arrangement with no constraints. */ public void testFN() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = new RectangleConstraint( 100.0, null, LengthConstraintType.FIXED, 0.0, null, LengthConstraintType.NONE ); Size2D s = c.arrange(null, constraint); assertEquals(100.0, s.width, EPSILON); assertEquals(33.0, s.height, EPSILON); }
/** * Test arrangement with a fixed width and no height constraint. */ public void testFN() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = new RectangleConstraint(100.0, null, LengthConstraintType.FIXED, 0.0, null, LengthConstraintType.NONE); Size2D s = c.arrange(null, constraint); assertEquals(100.0, s.width, EPSILON); assertEquals(33.0, s.height, EPSILON); }
/** * Test arrangement with a fixed height and no width constraint. */ public void testNF() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = RectangleConstraint.NONE.toFixedHeight( 100.0); Size2D s = c.arrange(null, constraint); assertEquals(90.0, s.width, EPSILON); assertEquals(100.0, s.height, EPSILON); }
/** * Test arrangement with a range for the width and a fixed height. */ public void testRF() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = new RectangleConstraint(new Range(40.0, 60.0), 100.0); Size2D s = c.arrange(null, constraint); assertEquals(60.0, s.width, EPSILON); assertEquals(100.0, s.height, EPSILON); }
/** * Test arrangement with a range for the width and height. */ public void testRR() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = new RectangleConstraint(new Range(40.0, 60.0), new Range(50.0, 70.0)); Size2D s = c.arrange(null, constraint); assertEquals(60.0, s.width, EPSILON); assertEquals(50.0, s.height, EPSILON); }
/** * Test arrangement with a range for the width and no height constraint. */ public void testRN() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = RectangleConstraint.NONE.toRangeWidth( new Range(40.0, 60.0)); Size2D s = c.arrange(null, constraint); assertEquals(60.0, s.width, EPSILON); assertEquals(33.0, s.height, EPSILON); }
/** * Test arrangement with a range for the height and no width constraint. */ public void testNR() { BlockContainer c = createTestContainer1(); RectangleConstraint constraint = RectangleConstraint.NONE.toRangeHeight( new Range(40.0, 60.0)); Size2D s = c.arrange(null, constraint); assertEquals(90.0, s.width, EPSILON); assertEquals(40.0, s.height, EPSILON); }
/** * The arrangement should be able to handle null blocks in the layout. */ public void testNullBlock_FF() { BlockContainer c = new BlockContainer(new GridArrangement(1, 1)); c.add(null); Size2D s = c.arrange(null, new RectangleConstraint(20, 10)); assertEquals(20.0, s.getWidth(), EPSILON); assertEquals(10.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle null blocks in the layout. */ public void testNullBlock_FN() { BlockContainer c = new BlockContainer(new GridArrangement(1, 1)); c.add(null); Size2D s = c.arrange(null, RectangleConstraint.NONE.toFixedWidth(10)); assertEquals(10.0, s.getWidth(), EPSILON); assertEquals(0.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle null blocks in the layout. */ public void testNullBlock_FR() { BlockContainer c = new BlockContainer(new GridArrangement(1, 1)); c.add(null); Size2D s = c.arrange(null, new RectangleConstraint(30.0, new Range(5.0, 10.0))); assertEquals(30.0, s.getWidth(), EPSILON); assertEquals(5.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle null blocks in the layout. */ public void testNullBlock_NN() { BlockContainer c = new BlockContainer(new GridArrangement(1, 1)); c.add(null); Size2D s = c.arrange(null, RectangleConstraint.NONE); assertEquals(0.0, s.getWidth(), EPSILON); assertEquals(0.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle less blocks than grid spaces. */ public void testGridNotFull_FF() { Block b1 = new EmptyBlock(5, 5); BlockContainer c = new BlockContainer(new GridArrangement(2, 3)); c.add(b1); Size2D s = c.arrange(null, new RectangleConstraint(200, 100)); assertEquals(200.0, s.getWidth(), EPSILON); assertEquals(100.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle less blocks than grid spaces. */ public void testGridNotFull_FN() { Block b1 = new EmptyBlock(5, 5); BlockContainer c = new BlockContainer(new GridArrangement(2, 3)); c.add(b1); Size2D s = c.arrange(null, RectangleConstraint.NONE.toFixedWidth(30.0)); assertEquals(30.0, s.getWidth(), EPSILON); assertEquals(10.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle less blocks than grid spaces. */ public void testGridNotFull_FR() { Block b1 = new EmptyBlock(5, 5); BlockContainer c = new BlockContainer(new GridArrangement(2, 3)); c.add(b1); Size2D s = c.arrange(null, new RectangleConstraint(30.0, new Range(5.0, 10.0))); assertEquals(30.0, s.getWidth(), EPSILON); assertEquals(10.0, s.getHeight(), EPSILON); }
/** * The arrangement should be able to handle less blocks than grid spaces. */ public void testGridNotFull_NN() { Block b1 = new EmptyBlock(5, 5); BlockContainer c = new BlockContainer(new GridArrangement(2, 3)); c.add(b1); Size2D s = c.arrange(null, RectangleConstraint.NONE); assertEquals(15.0, s.getWidth(), EPSILON); assertEquals(10.0, s.getHeight(), EPSILON); }
private double maxWidth(List<Block> blocks, Graphics2D g2) { double max = 0.0; for(Block b : blocks) { max = Math.max(max, b.arrange(g2, RectangleConstraint.NONE).width); } return max; }