KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > demo > userGuide > UserGuideBase


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

34
35 package org.krysalis.jcharts.demo.userGuide;
36
37
38 import java.io.FileOutputStream JavaDoc;
39
40 import org.krysalis.jcharts.Chart;
41 import org.krysalis.jcharts.encoders.PNGEncoder;
42
43
44 /*************************************************************************************
45  *
46  * @author Nathaniel Auvil
47  * @version $Id: UserGuideBase.java,v 1.5 2003/09/03 02:40:13 nathaniel_auvil Exp $
48  ************************************************************************************/

49 public class UserGuideBase
50 {
51    private static String JavaDoc path= "./src/documentation/resources/images/userGuide/";
52     private static String JavaDoc subdir;
53
54
55     /*******************************************************************************************
56      *
57      *
58      ******************************************************************************************/

59     public static void main( String JavaDoc[] args ) throws Throwable JavaDoc
60     {
61         if( args.length > 2 )
62         {
63             System.out.println( "Usage - java UserGuideBase <whatToRun>" );
64             return;
65         }
66         else
67         {
68             if( args.length == 1 )
69             {
70                 String JavaDoc whatToRun = args[0];
71             System.out.println( "running user guide charts for section: " + whatToRun );
72
73                 if( whatToRun.equals( "all" ) )
74                 {
75                     UserGuideBase.subdir= "allCharts/";
76                     AllChartsGuide allCharts = new AllChartsGuide();
77                     allCharts.run();
78                 }
79
80                 if( whatToRun.equals( "legend" ) )
81                 {
82                     UserGuideBase.subdir= "legends/";
83                     LegendsGuide legends = new LegendsGuide();
84                     legends.run();
85                 }
86
87                 if( whatToRun.equals( "stock" ) )
88                 {
89                     UserGuideBase.subdir= "allCharts/";
90                     StockChartsGuide stockCharts = new StockChartsGuide();
91                     stockCharts.run();
92                 }
93
94                 if( whatToRun.equals( "pie" ) )
95                 {
96                     UserGuideBase.subdir= "pieCharts/";
97                     PieChartsGuide pieChart = new PieChartsGuide();
98                     pieChart.run();
99                 }
100
101                 if( whatToRun.equals( "pie3d" ) )
102                 {
103                     UserGuideBase.subdir= "pieChart3d/";
104                     PieChart3DGuide pieChart3D = new PieChart3DGuide();
105                     pieChart3D.run();
106                 }
107
108                 if( whatToRun.equals( "axis" ) )
109                 {
110                     UserGuideBase.subdir= "axisCharts/";
111                     AxisChartsGuide axisCharts = new AxisChartsGuide();
112                     axisCharts.run();
113                 }
114
115                 if( whatToRun.equals( "area" ) )
116                 {
117                     UserGuideBase.subdir= "areaCharts/";
118                     AreaChartsGuide areaCharts = new AreaChartsGuide();
119                     areaCharts.run();
120                 }
121
122                 if( whatToRun.equals( "bar" ) )
123                 {
124                     UserGuideBase.subdir= "barCharts/";
125                     BarChartsGuide barCharts = new BarChartsGuide();
126                     barCharts.run();
127                 }
128
129                 if( whatToRun.equals( "line" ) )
130                 {
131                     UserGuideBase.subdir= "lineCharts/";
132                     LineChartsGuide lineCharts = new LineChartsGuide();
133                     lineCharts.run();
134                 }
135
136                 if( whatToRun.equals( "point" ) )
137                 {
138                     UserGuideBase.subdir= "pointCharts/";
139                     PointChartsGuide pointCharts = new PointChartsGuide();
140                     pointCharts.run();
141                 }
142
143                 if( whatToRun.equals( "combo" ) )
144                 {
145                     UserGuideBase.subdir= "comboCharts/";
146                     ComboChartsGuide comboCharts = new ComboChartsGuide();
147                     comboCharts.run();
148                 }
149             }
150             else
151             {
152                 AllChartsGuide allCharts = new AllChartsGuide();
153                 allCharts.run();
154
155                 LegendsGuide legends = new LegendsGuide();
156                 legends.run();
157
158                 StockChartsGuide stockCharts = new StockChartsGuide();
159                 stockCharts.run();
160
161                 PieChartsGuide pieChart = new PieChartsGuide();
162                 pieChart.run();
163
164                 PieChart3DGuide pieChart3d = new PieChart3DGuide();
165                 pieChart3d.run();
166
167                 AxisChartsGuide axisCharts = new AxisChartsGuide();
168                 axisCharts.run();
169
170                 AreaChartsGuide areaCharts = new AreaChartsGuide();
171                 areaCharts.run();
172
173                 BarChartsGuide barCharts = new BarChartsGuide();
174                 barCharts.run();
175
176                 LineChartsGuide lineCharts = new LineChartsGuide();
177                 lineCharts.run();
178
179                 PointChartsGuide pointCharts = new PointChartsGuide();
180                 pointCharts.run();
181
182                 ComboChartsGuide comboCharts = new ComboChartsGuide();
183                 comboCharts.run();
184             }
185         }
186     }
187
188
189     /******************************************************************************************
190      * Utility method to write the image to file so I do not have to deal with file i/o
191      * every time I write a demo.
192      *
193      * @param chart everything that is renderable extends this class.
194      * @param fileName what to name the file
195      ******************************************************************************************/

196     void exportImage( Chart chart, String JavaDoc fileName )
197     {
198         String JavaDoc extension = ".png";
199         FileOutputStream JavaDoc fileOutputStream;
200
201         try
202         {
203             fileOutputStream = new FileOutputStream JavaDoc( UserGuideBase.path + UserGuideBase.subdir + fileName + extension );
204             PNGEncoder.encode( chart, fileOutputStream );
205             //JPEGEncoder13.encode( chart, 1.0f, fileOutputStream );
206
fileOutputStream.flush();
207             fileOutputStream.close();
208         }
209         catch( Throwable JavaDoc throwable )
210         {
211             throwable.printStackTrace();
212         }
213     }
214 }
Popular Tags