KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > demo > samples > Sample


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

35
36 package org.krysalis.jcharts.demo.samples;
37
38
39 import org.krysalis.jcharts.Chart;
40 import org.krysalis.jcharts.chartData.ChartDataException;
41 import org.krysalis.jcharts.encoders.PNGEncoder;
42
43 import java.io.FileOutputStream JavaDoc;
44
45
46 /*************************************************************************************
47  *
48  * @author Nathaniel Auvil
49  * @version $Id: Sample.java,v 1.2 2003/08/09 19:46:14 nathaniel_auvil Exp $
50  ************************************************************************************/

51 public abstract class Sample
52 {
53     private static String JavaDoc path;
54     private static final String JavaDoc dir= "/samples/";
55
56
57
58     protected abstract void render() throws ChartDataException;
59     protected abstract String JavaDoc getSubdir();
60
61
62    /*************************************************************************************
63      * path to the images directory under the documentation for forrest as in:
64      * /jcharts/krysalis-jcharts/src/documentation/resources/images
65      *
66      * @param args
67      * @throws ChartDataException
68      ************************************************************************************/

69     public static void main( String JavaDoc[] args ) throws ChartDataException
70     {
71       Sample.path= args[ 0 ];
72
73         new AreaChartSamples().render();
74       new Pie3DSamples().render();
75     }
76
77
78    /******************************************************************************************
79      *
80      * @param chart
81      * @param filename
82      *****************************************************************************************/

83     protected void encode( Chart chart, String JavaDoc filename )
84     {
85         FileOutputStream JavaDoc fileOutputStream;
86
87         try
88         {
89             fileOutputStream = new FileOutputStream JavaDoc( path + dir + this.getSubdir() + filename + ".png" );
90             PNGEncoder.encode( chart, fileOutputStream );
91             fileOutputStream.flush();
92             fileOutputStream.close();
93         }
94         catch( Throwable JavaDoc throwable )
95         {
96             throwable.printStackTrace();
97         }
98     }
99 }
100
Popular Tags