001 /* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
006 *
007 * Project Info: http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022 * USA.
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025 * in the United States and other countries.]
026 *
027 * -----------------------------
028 * LegendItemBlockContainer.java
029 * -----------------------------
030 * (C) Copyright 2006, by Object Refinery Limited.
031 *
032 * Original Author: David Gilbert (for Object Refinery Limited);
033 * Contributor(s): -;
034 *
035 * $Id: LegendItemBlockContainer.java,v 1.1.2.2 2006/10/06 15:46:34 mungady Exp $
036 *
037 * Changes
038 * -------
039 * 20-Jul-2006 : Version 1 (DG);
040 * 06-Oct-2006 : Added tooltip and URL text fields (DG);
041 *
042 */
043
044 package org.jfree.chart.title;
045
046 import java.awt.Graphics2D;
047 import java.awt.Shape;
048 import java.awt.geom.Rectangle2D;
049
050 import org.jfree.chart.block.Arrangement;
051 import org.jfree.chart.block.BlockContainer;
052 import org.jfree.chart.block.BlockResult;
053 import org.jfree.chart.block.EntityBlockParams;
054 import org.jfree.chart.block.EntityBlockResult;
055 import org.jfree.chart.entity.EntityCollection;
056 import org.jfree.chart.entity.LegendItemEntity;
057 import org.jfree.chart.entity.StandardEntityCollection;
058
059 /**
060 * A container that holds all the pieces of a single legend item.
061 *
062 * @since 1.0.2
063 */
064 public class LegendItemBlockContainer extends BlockContainer {
065
066 /** The dataset index. */
067 private int dataset;
068
069 /** The series index. */
070 private int series;
071
072 /** The tool tip text (can be <code>null</code>). */
073 private String toolTipText;
074
075 /** The URL text (can be <code>null</code>). */
076 private String urlText;
077
078 /**
079 * Creates a new legend item block.
080 *
081 * @param arrangement
082 * @param dataset
083 * @param series
084 */
085 public LegendItemBlockContainer(Arrangement arrangement, int dataset,
086 int series) {
087 super(arrangement);
088 this.dataset = dataset;
089 this.series = series;
090 }
091
092 /**
093 * Returns the dataset index.
094 *
095 * @return The dataset index.
096 */
097 public int getDatasetIndex() {
098 return this.dataset;
099 }
100
101 /**
102 * Returns the series index.
103 *
104 * @return The series index.
105 */
106 public int getSeriesIndex() {
107 return this.series;
108 }
109
110 /**
111 * Returns the tool tip text.
112 *
113 * @return The tool tip text (possibly <code>null</code>).
114 *
115 * @since 1.0.3
116 */
117 public String getToolTipText() {
118 return this.toolTipText;
119 }
120
121 /**
122 * Sets the tool tip text.
123 *
124 * @param text the text (<code>null</code> permitted).
125 *
126 * @since 1.0.3
127 */
128 public void setToolTipText(String text) {
129 this.toolTipText = text;
130 }
131
132 /**
133 * Returns the URL text.
134 *
135 * @return The URL text (possibly <code>null</code>).
136 *
137 * @since 1.0.3
138 */
139 public String getURLText() {
140 return this.urlText;
141 }
142
143 /**
144 * Sets the URL text.
145 *
146 * @param text the text (<code>null</code> permitted).
147 *
148 * @since 1.0.3
149 */
150 public void setURLText(String text) {
151 this.urlText = text;
152 }
153
154 /**
155 * Draws the block within the specified area.
156 *
157 * @param g2 the graphics device.
158 * @param area the area.
159 * @param params passed on to blocks within the container
160 * (<code>null</code> permitted).
161 *
162 * @return An instance of {@link EntityBlockResult}, or <code>null</code>.
163 */
164 public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
165 // draw the block without collecting entities
166 super.draw(g2, area, null);
167 EntityBlockParams ebp = null;
168 BlockResult r = new BlockResult();
169 if (params instanceof EntityBlockParams) {
170 ebp = (EntityBlockParams) params;
171 if (ebp.getGenerateEntities()) {
172 EntityCollection ec = new StandardEntityCollection();
173 LegendItemEntity entity = new LegendItemEntity(
174 (Shape) area.clone());
175 entity.setSeriesIndex(this.series);
176 entity.setToolTipText(getToolTipText());
177 entity.setURLText(getURLText());
178 ec.add(entity);
179 r.setEntityCollection(ec);
180 }
181 }
182 return r;
183 }
184 }