    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2005, 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     * PieSectionEntity.java
    029     * ---------------------
    030     * (C) Copyright 2002-2005, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   Richard Atkinson;
    034     *                   Christian W. Zuckschwerdt;
    035     *
    036     * $Id: PieSectionEntity.java,v 1.5.2.1 2005/10/25 20:41:59 mungady Exp $
    037     *
    038     * Changes:
    039     * --------
    040     * 23-May-2002 : Version 1 (DG);
    041     * 12-Jun-2002 : Added Javadoc comments (DG);
    042     * 26-Jun-2002 : Added method to generate AREA tag for image map
    043     *               generation (DG);
    044     * 05-Aug-2002 : Added new constructor to populate URLText
    045     *               Moved getImageMapAreaTag() to ChartEntity (superclass) (RA);
    046     * 03-Oct-2002 : Fixed errors reported by Checkstyle (DG);
    047     * 07-Mar-2003 : Added pie index attribute, since the PiePlot class can create
    048     *               multiple pie plots within one chart.  Also renamed 'category'
    049     *               --> 'sectionKey' and changed the class from Object -->
    050     *               Comparable (DG);
    051     * 30-Jul-2003 : Added PieDataset reference (CZ);
    052     * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG);
    053     *
    054     */
    055
    056    package org.jfree.chart.entity;
    057
    058    import java.awt.Shape;
    059    import java.io.Serializable;
    060
    061    import org.jfree.data.general.PieDataset;
    062
    063    /**
    064     * A chart entity that represents one section within a pie plot.
    065     */
    066    public class PieSectionEntity extends ChartEntity
    067                                  implements Serializable {
    068
    069        /** For serialization. */
    070        private static final long serialVersionUID = 9199892576531984162L;
    071
    072        /** The dataset. */
    073        private PieDataset dataset;
    074
    075        /** The pie index. */
    076        private int pieIndex;
    077
    078        /** The section index. */
    079        private int sectionIndex;
    080
    081        /** The section key. */
    082        private Comparable sectionKey;
    083
    084        /**
    085         * Creates a new pie section entity.
    086         *
    087         * @param area  the area.
    088         * @param dataset  the pie dataset.
    089         * @param pieIndex  the pie index (zero-based).
    090         * @param sectionIndex  the section index (zero-based).
    091         * @param sectionKey  the section key.
    092         * @param toolTipText  the tool tip text.
    093         * @param urlText  the URL text for HTML image maps.
    094         */
    095        public PieSectionEntity(Shape area,
    096                                PieDataset dataset,
    097                                int pieIndex, int sectionIndex,
    098                                Comparable sectionKey,
    099                                String toolTipText, String urlText) {
    100
    101            super(area, toolTipText, urlText);
    102            this.dataset = dataset;
    103            this.pieIndex = pieIndex;
    104            this.sectionIndex = sectionIndex;
    105            this.sectionKey = sectionKey;
    106
    107        }
    108
    109        /**
    110         * Returns the datset this entity refers to.
    111         *
    112         * @return The dataset.
    113         */
    114        public PieDataset getDataset() {
    115            return this.dataset;
    116        }
    117
    118        /**
    119         * Sets the datset this entity refers to.
    120         *
    121         * @param dataset  the dataset.
    122         */
    123        public void setDataset(PieDataset dataset) {
    124            this.dataset = dataset;
    125        }
    126
    127        /**
    128         * Returns the pie index.  For a regular pie chart, the section index is 0.
    129         * For a pie chart containing multiple pie plots, the pie index is the row
    130         * or column index from which the pie data is extracted.
    131         *
    132         * @return The pie index.
    133         */
    134        public int getPieIndex() {
    135            return this.pieIndex;
    136        }
    137
    138        /**
    139         * Sets the pie index.
    140         *
    141         * @param index  the new index value.
    142         */
    143        public void setPieIndex(int index) {
    144            this.pieIndex = index;
    145        }
    146
    147        /**
    148         * Returns the section index.
    149         *
    150         * @return The section index.
    151         */
    152        public int getSectionIndex() {
    153            return this.sectionIndex;
    154        }
    155
    156        /**
    157         * Sets the section index.
    158         *
    159         * @param index  the section index.
    160         */
    161        public void setSectionIndex(int index) {
    162            this.sectionIndex = index;
    163        }
    164
    165        /**
    166         * Returns the section key.
    167         *
    168         * @return The section key.
    169         */
    170        public Comparable getSectionKey() {
    171            return this.sectionKey;
    172        }
    173
    174        /**
    175         * Sets the section key.
    176         *
    177         * @param key  the section key.
    178         */
    179        public void setSectionKey(Comparable key) {
    180            this.sectionKey = key;
    181        }
    182
    183        /**
    184         * Returns a string representing the entity.
    185         *
    186         * @return A string representing the entity.
    187         */
    188        public String toString() {
    189            return "PieSection: " + this.pieIndex + ", " + this.sectionIndex + "("
    190                                  + this.sectionKey.toString() + ")";
    191        }
    192
    193    }