KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > chartData > PieChartDataSet


1 /***********************************************************************************************
2  * File Info: $Id: PieChartDataSet.java,v 1.1 2003/05/17 16:58:11 nathaniel_auvil Exp $
3  * Copyright (C) 2002
4  * Author: Nathaniel G. Auvil
5  * Contributor(s):
6  *
7  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
8  *
9  * Redistribution and use of this software and associated documentation ("Software"), with or
10  * without modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain copyright statements and notices.
13  * Redistributions must also contain a copy of this document.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
16  * conditions and the following disclaimer in the documentation and/or other materials
17  * provided with the distribution.
18  *
19  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
20  * products derived from this Software without prior written permission of Nathaniel G.
21  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
22  *
23  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
24  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
25  * registered trademark of Nathaniel G. Auvil.
26  *
27  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
28  *
29  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
30  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
36  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
37  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
38  ************************************************************************************************/

39
40 package org.krysalis.jcharts.chartData;
41
42
43 import org.krysalis.jcharts.chartData.interfaces.IPieChartDataSet;
44 import org.krysalis.jcharts.properties.PieChart2DProperties;
45
46 import java.awt.*;
47
48
49 /*******************************************************************************************
50  * Implementation of the IPieChartDataSet Interface for use with the PieChart2D Object.
51  *
52  *******************************************************************************************/

53 final public class PieChartDataSet extends DataSet implements IPieChartDataSet
54 {
55     private String JavaDoc chartTitle;
56
57
58     /******************************************************************************************
59      * Constructor
60      *
61      * @param chartTitle if the title is NULL, no title will be drawn
62      * @param data
63      * @param legendLabels
64      * @param paints
65      * @param pieChart2DProperties
66      * @throws ChartDataException if fails a limited validation check
67      *******************************************************************************************/

68     public PieChartDataSet( String JavaDoc chartTitle,
69                                     double[] data,
70                                     String JavaDoc[] legendLabels,
71                                     Paint[] paints,
72                                     PieChart2DProperties pieChart2DProperties ) throws ChartDataException
73     {
74         super( new double[][]{data}, legendLabels, paints, pieChart2DProperties );
75
76         this.chartTitle=chartTitle;
77
78         this.validateData( data, legendLabels, paints );
79     }
80
81
82     /*******************************************************************************************
83      * Perform some limited validation of the structure of the passed data. This is useful for
84      * development.
85      *
86      * @param data
87      * @param legendLabels
88      * @param paints
89      * @throws ChartDataException
90      *******************************************************************************************/

91     private void validateData( double[] data, String JavaDoc[] legendLabels, Paint[] paints ) throws ChartDataException
92     {
93         if( legendLabels != null && ( data.length != legendLabels.length ) )
94         {
95             throw new ChartDataException( "There is not an one to one mapping of 'legend labels' to 'data items'." );
96         }
97
98         if( data.length != paints.length )
99         {
100             throw new ChartDataException( "There is not an one to one mapping of 'Paint' Implementations to 'data items'." );
101         }
102     }
103
104
105     /******************************************************************************************
106      * Returns the chart title.
107      *
108      * @return String the chart title. If this returns NULL, no title will be displayed.
109      ******************************************************************************************/

110     public String JavaDoc getChartTitle()
111     {
112         return this.chartTitle;
113     }
114
115
116     /******************************************************************************************
117      * Returns the value in the data set at the specified position.
118      *
119      * @param index
120      * @return double
121      * @throws ArrayIndexOutOfBoundsException
122      *******************************************************************************************/

123     public double getValue( int index ) throws ArrayIndexOutOfBoundsException JavaDoc
124     {
125         return super.data[ 0 ][ index ];
126     }
127 }
128
Popular Tags