Frames | No Frames |
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 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: * LegendItemCollection.java 29: * ------------------------- 30: * (C) Copyright 2002-2005, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: LegendItemCollection.java,v 1.4.2.1 2005/10/25 16:50:20 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 07-Feb-2002 : Version 1 (DG); 40: * 24-Sep-2002 : Added get(int) and getItemCount() methods (DG); 41: * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); 42: * 18-Apr-2005 : Added equals() method and implemented Cloneable and 43: * Serializable (DG); 44: * 45: */ 46: 47: package org.jfree.chart; 48: 49: import java.io.Serializable; 50: import java.util.Iterator; 51: import java.util.List; 52: 53: /** 54: * A collection of legend items. 55: */ 56: public class LegendItemCollection implements Cloneable, Serializable { 57: 58: /** For serialization. */ 59: private static final long serialVersionUID = 1365215565589815953L; 60: 61: /** Storage for the legend items. */ 62: private List items; 63: 64: /** 65: * Constructs a new legend item collection, initially empty. 66: */ 67: public LegendItemCollection() { 68: this.items = new java.util.ArrayList(); 69: } 70: 71: /** 72: * Adds a legend item to the collection. 73: * 74: * @param item the item to add. 75: */ 76: public void add(LegendItem item) { 77: this.items.add(item); 78: } 79: 80: /** 81: * Adds the legend items from another collection to this collection. 82: * 83: * @param collection the other collection. 84: */ 85: public void addAll(LegendItemCollection collection) { 86: this.items.addAll(collection.items); 87: } 88: 89: /** 90: * Returns a legend item from the collection. 91: * 92: * @param index the legend item index (zero-based). 93: * 94: * @return The legend item. 95: */ 96: public LegendItem get(int index) { 97: return (LegendItem) this.items.get(index); 98: } 99: 100: /** 101: * Returns the number of legend items in the collection. 102: * 103: * @return The item count. 104: */ 105: public int getItemCount() { 106: return this.items.size(); 107: } 108: 109: /** 110: * Returns an iterator that provides access to all the legend items. 111: * 112: * @return An iterator. 113: */ 114: public Iterator iterator() { 115: return this.items.iterator(); 116: } 117: 118: /** 119: * Tests this collection for equality with an arbitrary object. 120: * 121: * @param obj the object (<code>null</code> permitted). 122: * 123: * @return A boolean. 124: */ 125: public boolean equals(Object obj) { 126: if (obj == this) { 127: return true; 128: } 129: if (!(obj instanceof LegendItemCollection)) { 130: return false; 131: } 132: LegendItemCollection that = (LegendItemCollection) obj; 133: if (!this.items.equals(that.items)) { 134: return false; 135: } 136: return true; 137: } 138: 139: /** 140: * Returns a clone of the collection. 141: * 142: * @return A clone. 143: * 144: * @throws CloneNotSupportedException if an item in the collection is not 145: * cloneable. 146: */ 147: public Object clone() throws CloneNotSupportedException { 148: return super.clone(); 149: } 150: 151: }