KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***********************************************************************************************
2  * File Info: $Id: AxisChartDataSet.java,v 1.1 2003/05/17 16:58:10 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.IAxisChartDataSet;
44 import org.krysalis.jcharts.properties.*;
45 import org.krysalis.jcharts.test.HTMLGenerator;
46 import org.krysalis.jcharts.test.HTMLTestable;
47 import org.krysalis.jcharts.types.ChartType;
48
49 import java.awt.*;
50
51
52 public final class AxisChartDataSet extends DataSet implements IAxisChartDataSet, HTMLTestable
53 {
54     private ChartType chartType;
55
56
57     /******************************************************************************************
58      * Constructor
59      *
60      * @param data the data sets to be displayed in the chart.
61      * @param legendLabels if this is: NULL there will be no Legend. Otherwise, there must be an
62      * one to one mapping of labels to data sets.
63      * @param paints paints to use for the data sets. There must be an one to one mapping of
64      * labels to data sets.
65      * @param chartType constant defining how this data should be rendered
66      * @param chartTypeProperties properties Object specific to the type of chart you are rendering.
67      * @throws ChartDataException if data is not in correct form.
68      *******************************************************************************************/

69     public AxisChartDataSet( double[][] data,
70                                      String JavaDoc[] legendLabels,
71                                      Paint[] paints,
72                                      ChartType chartType,
73                                      ChartTypeProperties chartTypeProperties ) throws ChartDataException
74     {
75         super( data, legendLabels, paints, chartTypeProperties );
76         this.chartType=chartType;
77     }
78
79
80     /************************************************************************************************
81      * Performs a limited validation of data. This is static and not called by the rendering engine
82      * so as to avoid the, albeit small, cost of validation checking during deployment; this is viewed
83      * more so as a development time test.
84      *
85      * @throws ChartDataException
86      *************************************************************************************************/

87     public void validate() throws ChartDataException, PropertyException
88     {
89         if( ( super.legendLabels != null ) && ( super.data.length != super.legendLabels.length ) )
90         {
91             throw new ChartDataException( "There is not an one to one mapping of 'legend labels' to 'data sets'." );
92         }
93
94         if( super.data.length != super.paints.length )
95         {
96             throw new ChartDataException( "There is not an one to one mapping of 'Paint' implementations to 'data sets'." );
97         }
98
99         ( (AxisChartTypeProperties) super.getChartTypeProperties() ).validate( this );
100     }
101
102
103     /******************************************************************************************
104      * Returns the value in the data set at the specified position.
105      *
106      * @param dataset
107      * @param index
108      * @return double
109      * @throws ArrayIndexOutOfBoundsException
110      *******************************************************************************************/

111     public final double getValue( int dataset, int index ) throws ArrayIndexOutOfBoundsException JavaDoc
112     {
113         return super.data[ dataset ][ index ];
114     }
115
116
117     /******************************************************************************************
118      * Returns the type constant that this data set should be plotted as.
119      *
120      * @return ChartType
121      * @see ChartType
122      *******************************************************************************************/

123     public final ChartType getChartType()
124     {
125         return this.chartType;
126     }
127
128
129     /******************************************************************************************
130      * Returns the number of IAxisChartDataSet Objects in this series
131      *
132      * @return int
133      ******************************************************************************************/

134     public final int getNumberOfDataSets()
135     {
136         return this.data.length;
137     }
138
139
140     /*********************************************************************************************
141      * Enables the testing routines to display the contents of this Object.
142      *
143      * @param htmlGenerator
144      **********************************************************************************************/

145     public void toHTML( HTMLGenerator htmlGenerator )
146     {
147         super.toHTML( htmlGenerator );
148
149 /*
150         //String name= this.getClass().getSuperclass().getName() + "->";
151
152         Field[] fields= this.getClass().getDeclaredFields();
153         for( int i=0; i< fields.length; i++ )
154         {
155             htmlGenerator.addTableRow( fields[ i ].getName(), fields[ i ].get( this ) );
156         }
157 */

158     }
159
160
161 }
162
Popular Tags