/** * Fetches the latest legend items. */ protected void fetchLegendItems() { this.items.clear(); RectangleEdge p = getPosition(); if (RectangleEdge.isTopOrBottom(p)) { this.items.setArrangement(this.hLayout); } else { this.items.setArrangement(this.vLayout); } for (int s = 0; s < this.sources.length; s++) { LegendItemCollection legendItems = this.sources[s].getLegendItems(); if (legendItems != null) { for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem item = legendItems.get(i); Block block = createLegendItemBlock(item); this.items.add(block); } } } }
@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); }
@Override protected Block createLegendItemBlock(LegendItem item) { if (item instanceof FlankedShapeLegendItem) { return createFlankedShapeLegendItem((FlankedShapeLegendItem) item); } else { return createDefaultLegendItem(item); } }
private BlockContainer createTestContainer1() { Block b1 = new EmptyBlock(10, 11); Block b2 = new EmptyBlock(20, 22); Block b3 = new EmptyBlock(30, 33); BlockContainer result = new BlockContainer(new GridArrangement(1, 3)); result.add(b1); result.add(b2); result.add(b3); return result; }
/** * Applies the attributes of this theme to the specified title. * * @param title the title. */ protected void applyToTitle(Title title) { if (title instanceof TextTitle) { TextTitle tt = (TextTitle) title; tt.setFont(this.largeFont); tt.setPaint(this.subtitlePaint); } else if (title instanceof LegendTitle) { LegendTitle lt = (LegendTitle) title; if (lt.getBackgroundPaint() != null) { lt.setBackgroundPaint(this.legendBackgroundPaint); } lt.setItemFont(this.regularFont); lt.setItemPaint(this.legendItemPaint); if (lt.getWrapper() != null) { applyToBlockContainer(lt.getWrapper()); } } else if (title instanceof PaintScaleLegend) { PaintScaleLegend psl = (PaintScaleLegend) title; psl.setBackgroundPaint(this.legendBackgroundPaint); ValueAxis axis = psl.getAxis(); if (axis != null) { applyToValueAxis(axis); } } else if (title instanceof CompositeTitle) { CompositeTitle ct = (CompositeTitle) title; BlockContainer bc = ct.getContainer(); List blocks = bc.getBlocks(); Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); if (b instanceof Title) { applyToTitle((Title) b); } } } }
/** * Applies the attributes of this theme to the specified container. * * @param bc a block container (<code>null</code> not permitted). */ protected void applyToBlockContainer(BlockContainer bc) { Iterator iterator = bc.getBlocks().iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); applyToBlock(b); } }
/** * Applies the attributes of this theme to the specified block. * * @param b the block. */ protected void applyToBlock(Block b) { if (b instanceof Title) { applyToTitle((Title) b); } else if (b instanceof LabelBlock) { LabelBlock lb = (LabelBlock) b; lb.setFont(this.regularFont); lb.setPaint(this.legendItemPaint); } }
/** * Applies the attributes of this theme to the specified container. * * @param bc a block container ({@code null} not permitted). */ protected void applyToBlockContainer(BlockContainer bc) { Iterator iterator = bc.getBlocks().iterator(); while (iterator.hasNext()) { Block b = (Block) iterator.next(); applyToBlock(b); } }
/** * 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); }