KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > title > LegendItemBlockContainer


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.2 2006/10/06 15:46:34 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 20-Jul-2006 : Version 1 (DG);
40  * 06-Oct-2006 : Added tooltip and URL text fields (DG);
41  *
42  */

43
44 package org.jfree.chart.title;
45
46 import java.awt.Graphics2D JavaDoc;
47 import java.awt.Shape JavaDoc;
48 import java.awt.geom.Rectangle2D JavaDoc;
49
50 import org.jfree.chart.block.Arrangement;
51 import org.jfree.chart.block.BlockContainer;
52 import org.jfree.chart.block.BlockResult;
53 import org.jfree.chart.block.EntityBlockParams;
54 import org.jfree.chart.block.EntityBlockResult;
55 import org.jfree.chart.entity.EntityCollection;
56 import org.jfree.chart.entity.LegendItemEntity;
57 import org.jfree.chart.entity.StandardEntityCollection;
58
59 /**
60  * A container that holds all the pieces of a single legend item.
61  *
62  * @since 1.0.2
63  */

64 public class LegendItemBlockContainer extends BlockContainer {
65
66     /** The dataset index. */
67     private int dataset;
68     
69     /** The series index. */
70     private int series;
71     
72     /** The tool tip text (can be <code>null</code>). */
73     private String JavaDoc toolTipText;
74     
75     /** The URL text (can be <code>null</code>). */
76     private String JavaDoc urlText;
77     
78     /**
79      * Creates a new legend item block.
80      *
81      * @param arrangement
82      * @param dataset
83      * @param series
84      */

85     public LegendItemBlockContainer(Arrangement arrangement, int dataset,
86             int series) {
87         super(arrangement);
88         this.dataset = dataset;
89         this.series = series;
90     }
91     
92     /**
93      * Returns the dataset index.
94      *
95      * @return The dataset index.
96      */

97     public int getDatasetIndex() {
98         return this.dataset;
99     }
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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc draw(Graphics2D JavaDoc g2, Rectangle2D JavaDoc area, Object JavaDoc 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 JavaDoc) 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 }
185
Popular Tags