Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ----------------------------- 28: * LegendItemBlockContainer.java 29: * ----------------------------- 30: * (C) Copyright 2006, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: LegendItemBlockContainer.java,v 1.1.2.1 2006/07/20 16:21:59 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 20-Jul-2006 : Version 1 (DG); 40: * 41: */ 42: 43: package org.jfree.chart.title; 44: 45: import java.awt.Graphics2D; 46: import java.awt.Shape; 47: import java.awt.geom.Rectangle2D; 48: 49: import org.jfree.chart.block.Arrangement; 50: import org.jfree.chart.block.BlockContainer; 51: import org.jfree.chart.block.BlockResult; 52: import org.jfree.chart.block.EntityBlockParams; 53: import org.jfree.chart.block.EntityBlockResult; 54: import org.jfree.chart.entity.EntityCollection; 55: import org.jfree.chart.entity.LegendItemEntity; 56: import org.jfree.chart.entity.StandardEntityCollection; 57: 58: /** 59: * A container that holds all the pieces of a single legend item. 60: * 61: * @since 1.0.2 62: */ 63: public class LegendItemBlockContainer extends BlockContainer { 64: 65: /** The dataset index. */ 66: private int dataset; 67: 68: /** The series index. */ 69: private int series; 70: 71: /** 72: * Creates a new legend item block. 73: * 74: * @param arrangement 75: * @param dataset 76: * @param series 77: */ 78: public LegendItemBlockContainer(Arrangement arrangement, int dataset, 79: int series) { 80: super(arrangement); 81: this.dataset = dataset; 82: this.series = series; 83: } 84: 85: /** 86: * Returns the dataset index. 87: * 88: * @return The dataset index. 89: */ 90: public int getDatasetIndex() { 91: return this.dataset; 92: } 93: 94: /** 95: * Returns the series index. 96: * 97: * @return The series index. 98: */ 99: public int getSeriesIndex() { 100: return this.series; 101: } 102: 103: /** 104: * Draws the block within the specified area. 105: * 106: * @param g2 the graphics device. 107: * @param area the area. 108: * @param params passed on to blocks within the container 109: * (<code>null</code> permitted). 110: * 111: * @return An instance of {@link EntityBlockResult}, or <code>null</code>. 112: */ 113: public Object draw(Graphics2D g2, Rectangle2D area, Object params) { 114: // draw the block without collecting entities 115: super.draw(g2, area, null); 116: EntityBlockParams ebp = null; 117: BlockResult r = new BlockResult(); 118: if (params instanceof EntityBlockParams) { 119: ebp = (EntityBlockParams) params; 120: if (ebp.getGenerateEntities()) { 121: EntityCollection ec = new StandardEntityCollection(); 122: LegendItemEntity entity = new LegendItemEntity( 123: (Shape) area.clone()); 124: entity.setSeriesIndex(this.series); 125: ec.add(entity); 126: r.setEntityCollection(ec); 127: } 128: } 129: return r; 130: } 131: }