KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > LegendItemCollection


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, 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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -------------------------
27  * LegendItemCollection.java
28  * -------------------------
29  * (C) Copyright 2002-2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: LegendItemCollection.java,v 1.4 2005/05/19 14:02:37 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 07-Feb-2002 : Version 1 (DG);
39  * 24-Sep-2002 : Added get(int) and getItemCount() methods (DG);
40  * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
41  * 18-Apr-2005 : Added equals() method and implemented Cloneable and
42  * Serializable (DG);
43  *
44  */

45
46 package org.jfree.chart;
47
48 import java.io.Serializable JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51
52 /**
53  * A collection of legend items.
54  */

55 public class LegendItemCollection implements Cloneable JavaDoc, Serializable JavaDoc {
56
57     /** For serialization. */
58     private static final long serialVersionUID = 1365215565589815953L;
59     
60     /** Storage for the legend items. */
61     private List JavaDoc items;
62
63     /**
64      * Constructs a new legend item collection, initially empty.
65      */

66     public LegendItemCollection() {
67         this.items = new java.util.ArrayList JavaDoc();
68     }
69
70     /**
71      * Adds a legend item to the collection.
72      *
73      * @param item the item to add.
74      */

75     public void add(LegendItem item) {
76         this.items.add(item);
77     }
78
79     /**
80      * Adds the legend items from another collection to this collection.
81      *
82      * @param collection the other collection.
83      */

84     public void addAll(LegendItemCollection collection) {
85         this.items.addAll(collection.items);
86     }
87
88     /**
89      * Returns a legend item from the collection.
90      *
91      * @param index the legend item index (zero-based).
92      *
93      * @return The legend item.
94      */

95     public LegendItem get(int index) {
96         return (LegendItem) this.items.get(index);
97     }
98
99     /**
100      * Returns the number of legend items in the collection.
101      *
102      * @return The item count.
103      */

104     public int getItemCount() {
105         return this.items.size();
106     }
107
108     /**
109      * Returns an iterator that provides access to all the legend items.
110      *
111      * @return An iterator.
112      */

113     public Iterator JavaDoc iterator() {
114         return this.items.iterator();
115     }
116     
117     /**
118      * Tests this collection for equality with an arbitrary object.
119      *
120      * @param obj the object (<code>null</code> permitted).
121      *
122      * @return A boolean.
123      */

124     public boolean equals(Object JavaDoc obj) {
125         if (obj == this) {
126             return true;
127         }
128         if (!(obj instanceof LegendItemCollection)) {
129             return false;
130         }
131         LegendItemCollection that = (LegendItemCollection) obj;
132         if (!this.items.equals(that.items)) {
133             return false;
134         }
135         return true;
136     }
137
138     /**
139      * Returns a clone of the collection.
140      *
141      * @return A clone.
142      *
143      * @throws CloneNotSupportedException if an item in the collection is not
144      * cloneable.
145      */

146     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
147         return super.clone();
148     }
149     
150 }
151
Popular Tags