KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***********************************************************************************************
2  * File Info: $Id: DataSet.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.IDataSet;
44 import org.krysalis.jcharts.properties.ChartTypeProperties;
45 import org.krysalis.jcharts.test.HTMLGenerator;
46 import org.krysalis.jcharts.test.HTMLTestable;
47
48 import java.awt.*;
49
50
51 public class DataSet implements IDataSet, HTMLTestable
52 {
53     private ChartTypeProperties chartTypeProperties;
54
55     protected double[][] data;
56     protected String JavaDoc[] legendLabels;
57     protected Paint[] paints;
58
59
60     /******************************************************************************************
61      * Constructor
62      *
63      * @param data
64      * @param legendLabels will be NULL if no Legend.
65      * @param paints
66      * @param chartTypeProperties
67      *******************************************************************************************/

68     public DataSet( double[][] data, String JavaDoc[] legendLabels, Paint[] paints, ChartTypeProperties chartTypeProperties )
69     {
70         this.data = data;
71         this.legendLabels = legendLabels;
72         this.paints = paints;
73         this.chartTypeProperties = chartTypeProperties;
74     }
75
76
77     /******************************************************************************************
78      * Returns the legend label for the passed index. This index corresponds to the DataSet
79      * for which label you want.
80      *
81      * @param index
82      * @return String
83      *******************************************************************************************/

84     public final String JavaDoc getLegendLabel( int index )
85     {
86         if( this.legendLabels == null )
87         {
88             return null;
89         }
90         else
91         {
92             return this.legendLabels[ index ];
93         }
94     }
95
96
97     /*********************************************************************************************
98      * Returns the number of Legend Labels to display. This may not be the same as the number of
99      * Data Items, as in AxisCharts, or Data Sets, as in Pie Charts.
100      *
101      * @return int
102      **********************************************************************************************/

103     public int getNumberOfLegendLabels()
104     {
105         if( this.legendLabels == null )
106         {
107             return 0;
108         }
109         else
110         {
111             return this.legendLabels.length;
112         }
113     }
114
115
116     /******************************************************************************************
117      * Returns the legend label for the passed index. This index corresponds to the DataSet
118      * for which label you want.
119      *
120      * @param index
121      * @return Paint
122      *******************************************************************************************/

123     public Paint getPaint( int index )
124     {
125         return this.paints[ index ];
126     }
127
128
129     /******************************************************************************************
130      *
131      *
132      * @return ChartTypeProperties
133      *******************************************************************************************/

134     public ChartTypeProperties getChartTypeProperties()
135     {
136         return this.chartTypeProperties;
137     }
138
139
140     /******************************************************************************************
141      * Returns the number of elements in the data set. All data sets must be of the same length
142      * so just look at the first one.
143      *
144      * @return int
145      *******************************************************************************************/

146     public int getNumberOfDataItems()
147     {
148         return this.data[ 0 ].length;
149     }
150
151
152     /*********************************************************************************************
153      * Enables the testing routines to display the contents of this Object.
154      *
155      * @param htmlGenerator
156      **********************************************************************************************/

157     public void toHTML( HTMLGenerator htmlGenerator )
158     {
159         htmlGenerator.propertiesTableStart( this.getClass().getName() );
160         htmlGenerator.addTableRow( "data", HTMLGenerator.arrayToString( this.data ) );
161
162         if( this.legendLabels != null )
163         {
164             htmlGenerator.addTableRow( "legendLabels", HTMLGenerator.arrayToString( this.legendLabels ) );
165         }
166         htmlGenerator.addTableRow( "paints", HTMLGenerator.arrayToString( this.paints ) );
167         htmlGenerator.propertiesTableEnd();
168
169         htmlGenerator.chartTableRowStart();
170         this.chartTypeProperties.toHTML( htmlGenerator );
171         htmlGenerator.chartTableRowEnd();
172     }
173
174 }
175
Popular Tags