KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > icefaces > samples > showcase > components > charts > ChartFactory


1 /*
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * "The contents of this file are subject to the Mozilla Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11 * License for the specific language governing rights and limitations under
12 * the License.
13 *
14 * The Original Code is ICEfaces 1.5 open source software code, released
15 * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16 * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17 * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18 *
19 * Contributor(s): _____________________.
20 *
21 * Alternatively, the contents of this file may be used under the terms of
22 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23 * License), in which case the provisions of the LGPL License are
24 * applicable instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the LGPL License and not to
26 * allow others to use your version of this file under the MPL, indicate
27 * your decision by deleting the provisions above and replace them with
28 * the notice and other provisions required by the LGPL License. If you do
29 * not delete the provisions above, a recipient may use your version of
30 * this file under either the MPL or the LGPL License."
31 *
32 */

33
34 /*
35  * ChartFactory.java
36  *
37  * Created on January 24, 2007, 10:13 AM
38  *
39  * This class is the governing class for the chart component in the Component Showcase.
40  *It is used to set up the types of charts, create the charts, and manage the actions of the different charts.
41  *
42  */

43
44 package com.icesoft.icefaces.samples.showcase.components.charts;
45
46
47 import com.icesoft.faces.component.outputchart.OutputChart;
48 import com.icesoft.faces.context.effects.Effect;
49 import com.icesoft.faces.context.effects.Highlight;
50
51 import javax.faces.event.ActionEvent;
52 import javax.faces.event.ValueChangeEvent;
53 import javax.faces.model.SelectItem;
54
55 /**
56  * The chart factory is responsible for returning a Chart fo rthe given
57  * OutputChart type.
58  *
59  * @author dnorthcott
60  * @version 1.5
61  */

62 public class ChartFactory {
63
64     //List of charts that the user can seleect from the drop down menu
65
private static SelectItem[] chartList = new SelectItem[]{
66             new SelectItem(OutputChart.AREA_CHART_TYPE),
67             new SelectItem(OutputChart.AREA_STACKED_CHART_TYPE),
68             new SelectItem(OutputChart.BAR_CHART_TYPE),
69             new SelectItem(OutputChart.BAR_CLUSTERED_CHART_TYPE),
70             new SelectItem(OutputChart.BAR_STACKED_CHART_TYPE),
71             new SelectItem(OutputChart.LINE_CHART_TYPE),
72             new SelectItem(OutputChart.POINT_CHART_TYPE),
73             new SelectItem(OutputChart.PIE2D_CHART_TYPE),
74             new SelectItem(OutputChart.PIE3D_CHART_TYPE),};
75
76
77     //boolean to determine if the chart is a 2D pie chart
78
private boolean pie = false;
79
80     
81     
82     //boolean to determine if the chart is an axis chart
83
private boolean axis = true;
84
85     //boolean to determine if the chart is a 3D pie chart
86
public boolean pie3D = false;
87
88     //Flag to determine whether the type of chart was changed
89
private boolean chartChangedFlag = true;
90
91     //Temporary holding string when the type of chart has been changed
92
private String JavaDoc wasChanged;
93
94     public static final String JavaDoc DEFAULT_STRING =
95             "Click on the image map below to display a chart value: ";
96
97     //Highlight effect on the text when the image is clicked
98
private Highlight effectOutputText = new Highlight("#ffff99");
99
100     //sets the chart type to bar for default
101
private static String JavaDoc chart = OutputChart.BAR_CHART_TYPE;
102     
103     public static Chart chartObject = new Chart(chart);
104
105     //sets the string returned when the chart is clicked to the default value
106
private String JavaDoc clickedValue = DEFAULT_STRING;
107
108     /*
109      * Returns the list of charts to choose from
110      * @return list of possible charts.
111     */

112     public SelectItem[] getChartList() {
113         return chartList;
114     }
115
116     /*
117     * Sets the isAxis Boolean
118     *@param boolean isAxis
119     */

120     public boolean isAxis() {
121         return axis;
122     }
123
124     /*
125     * Returns whether the graph is a 3D PieChart
126     *@return boolean
127     */

128     public boolean isPie3D() {
129         return pie3D;
130     }
131
132     /*
133     * Sets the graph to a 3D pie
134     *@param boolean pie3D
135     */

136     public void setPie3D(boolean pie3D) {
137         this.pie3D = pie3D;
138     }
139
140     /*
141     * Returns whether the graph is a pie chart(2d)
142     *@return boolean
143     */

144     public boolean isPie() {
145         return pie;
146     }
147
148     /*
149     * Sets the graph to an axis type
150     *@param boolean axis
151     */

152     public void setAxis(boolean axis) {
153         this.axis = axis;
154     }
155
156     /*
157     * Sets the graph to a 2dPie type
158     *@param boolean pie
159     */

160     public void setPie(boolean pie) {
161         this.pie = pie;
162     }
163
164
165     /*
166     * Returns the chart String
167     *@return String chart
168     */

169     public String JavaDoc getChart() {
170
171         return chart;
172     }
173     
174     
175
176     /*
177     * Sets the chart String
178     * Determines what type of graph it is based on the parameter passed in
179     *@param String chart
180     */

181     public void setChart(String JavaDoc chart) {
182         
183         if (wasChanged != null) {
184             this.chart = wasChanged;
185             wasChanged = null;
186         } else {
187             this.chart = chart;
188         }
189         
190          chartObject.setType(chart);
191         
192         
193
194         if (!chart.equals(OutputChart.PIE3D_CHART_TYPE)) {
195             pie3D = false;
196            
197         }
198         if (chart.equals(OutputChart.PIE3D_CHART_TYPE) ||
199             chart.equals(OutputChart.PIE2D_CHART_TYPE)) {
200             axis = false;
201             
202             if (chart.equals(OutputChart.PIE3D_CHART_TYPE)) {
203                 pie3D = true;
204                
205        
206             }
207         } else {
208             axis = true;
209         }
210         
211     }
212
213     /*
214     * Determines whether or not the application should render based on status change
215     *@return boolean
216     */

217     public boolean allCharts(OutputChart component) {
218         
219         if (chartChangedFlag) {
220             chartChangedFlag = false;
221             return true;
222         } else {
223             return chartChangedFlag;
224         }
225     }
226
227
228     /*
229     * Determines whether the chart was changed
230     * Sets the default_string if the area type charts are selected
231     *@param ValueChangeEvent event
232     */

233     public void chartChanged(ValueChangeEvent event) {
234
235         chartChangedFlag = true;
236         wasChanged = (String JavaDoc) event.getNewValue();
237
238         if (event.getNewValue().equals(OutputChart.AREA_CHART_TYPE) ||
239             event.getNewValue().equals(OutputChart.AREA_STACKED_CHART_TYPE)) {
240             setClickedValue(
241                     "A client side image map is not supported for Area charts " +
242                     "(clicking on the chart will not display any values)");
243         } else {
244             setClickedValue(DEFAULT_STRING);
245         }
246     }
247
248
249     /*
250     * Returns the clickedValue
251     *@return String clickedValue
252     */

253     public String JavaDoc getClickedValue() {
254
255         return clickedValue;
256     }
257
258     public Chart getChartObject(){
259         return chartObject;
260     }
261     /*
262     * Returns the text effect
263     *@return Effect EffectOutputText
264     */

265     public Effect getEffectOutputText() {
266         return effectOutputText;
267     }
268
269     /*
270     * Sets the output text effect
271     *@param Effect effectOutputText
272     */

273     public void setEffectOutputText(Effect effectOutputText) {
274         this.effectOutputText = (Highlight) effectOutputText;
275     }
276
277     /*
278     * Sets the clicked value
279     *@param String clickedValue
280     */

281     public void setClickedValue(String JavaDoc clickedValue) {
282
283         this.clickedValue = clickedValue;
284     }
285
286     /*
287     * When the image map has been clicked this method returns the axis label plus the value
288     *@param ActionEvent event
289     */

290     public void imageClicked(ActionEvent event) {
291
292         if (event.getSource() instanceof OutputChart) {
293             OutputChart chart = (OutputChart) event.getSource();
294             if (chart.getClickedImageMapArea().getXAxisLabel() != null) {
295
296                 setClickedValue(DEFAULT_STRING +
297                                 chart.getClickedImageMapArea()
298                                         .getXAxisLabel() +
299                                 " : " + chart.getClickedImageMapArea()
300                                 .getValue());
301
302                 effectOutputText.setFired(false);
303             }
304
305         }
306
307     }
308     
309     public void pieAction(ActionEvent event)
310     {
311        
312         if (event.getSource() instanceof OutputChart) {
313             OutputChart chart = (OutputChart) event.getSource();
314             if (chart.getClickedImageMapArea().getLengendLabel() != null) {
315                 setClickedValue(DEFAULT_STRING + chart
316                         .getClickedImageMapArea().getLengendLabel()
317                                     + " : " +
318                                     chart.getClickedImageMapArea().getValue());
319                 PieChartBean.setSalesForYear(
320                         chart.getClickedImageMapArea().getLengendLabel());
321                 effectOutputText.setFired(false);
322
323
324             }
325         }
326     
327     }
328
329 }
330
Popular Tags