KickJava   Java API By Example, From Geeks To Geeks.

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


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 //Original copyright
34
/***********************************************************************************************
35  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
36  *
37  * Redistribution and use of this software and associated documentation ("Software"), with or
38  * without modification, are permitted provided that the following conditions are met:
39  *
40  * 1. Redistributions of source code must retain copyright statements and notices.
41  * Redistributions must also contain a copy of this document.
42  *
43  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
44  * conditions and the following disclaimer in the documentation and/or other materials
45  * provided with the distribution.
46  *
47  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
48  * products derived from this Software without prior written permission of Nathaniel G.
49  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
50  *
51  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
52  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
53  * registered trademark of Nathaniel G. Auvil.
54  *
55  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
56  *
57  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
58  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
59  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
60  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
61  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
64  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
65  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
66  ************************************************************************************************/

67 package com.icesoft.icefaces.samples.showcase.components.charts;
68
69 import com.icesoft.faces.component.outputchart.OutputChart;
70 import com.icesoft.faces.context.effects.Effect;
71 import com.icesoft.faces.context.effects.Highlight;
72 import com.icesoft.faces.context.effects.Pulsate;
73 import org.krysalis.jcharts.axisChart.AxisChart;
74 import org.krysalis.jcharts.chartData.AxisChartDataSet;
75 import org.krysalis.jcharts.chartData.DataSeries;
76 import org.krysalis.jcharts.properties.AxisProperties;
77 import org.krysalis.jcharts.properties.BarChartProperties;
78 import org.krysalis.jcharts.properties.ChartProperties;
79 import org.krysalis.jcharts.properties.LegendProperties;
80 import org.krysalis.jcharts.properties.LineChartProperties;
81 import org.krysalis.jcharts.properties.PointChartProperties;
82 import org.krysalis.jcharts.test.TestDataGenerator;
83 import org.krysalis.jcharts.types.ChartType;
84
85 import javax.faces.event.ActionEvent;
86 import java.awt.*;
87
88 /**
89  * CombinedChartBean class. this class holds the backing information for the
90  * combined chart component of the showcase.
91  */

92 public class CombinedChartBean {
93
94     //flag to determine if initialized
95
private boolean initialzed = false;
96
97     //the text value returned after clicking on the chart
98
private String JavaDoc clickedValue;
99
100     //highlight effect when text is changed
101
private Effect effectOutputText = new Highlight("#ffff99");;
102
103     //local variable for the axis chart component of the combined chart
104
private static AxisChart axisChart;
105
106     public CombinedChartBean() {
107     }
108
109     private void buildAxisChart() {
110         try {
111             String JavaDoc[] xAxisLabels =
112                     {"1998", "1999", "2000", "2001", "2002", "2003", "2004"};
113             String JavaDoc xAxisTitle = "Years";
114             String JavaDoc yAxisTitle = "Problems";
115             String JavaDoc title = "Company Software";
116             DataSeries dataSeries =
117                     new DataSeries(xAxisLabels, xAxisTitle, yAxisTitle, title);
118
119             double[][] data = TestDataGenerator.getRandomNumbers(3, 7, 0, 5000);
120             String JavaDoc[] legendLabels = {"Bugs", "Security Holes", "Backdoors"};
121             Paint[] paints = new Color[]{
122                                 new Color(0xCAE1EF),
123                                 new Color(0xF78208),
124                                 new Color(0x0D4274) };
125
126             BarChartProperties barChartProperties = new BarChartProperties();
127             AxisChartDataSet axisChartDataSet =
128                     new AxisChartDataSet(data,
129                                          legendLabels,
130                                          paints,
131                                          ChartType.BAR,
132                                          barChartProperties);
133             dataSeries.addIAxisPlotDataSet(axisChartDataSet);
134
135
136             data = TestDataGenerator.getRandomNumbers(2, 7, 1000, 5000);
137             legendLabels = new String JavaDoc[]{"Patches", "New Patch Bugs"};
138             paints = new Paint[]{ new Color(0x0D4274),
139                                 new Color(0xF78208)};
140
141             Stroke[] strokes = {LineChartProperties.DEFAULT_LINE_STROKE,
142                                 LineChartProperties.DEFAULT_LINE_STROKE};
143             Shape[] shapes = {PointChartProperties.SHAPE_CIRCLE,
144                               PointChartProperties.SHAPE_TRIANGLE};
145             LineChartProperties lineChartProperties =
146                     new LineChartProperties(strokes, shapes);
147             axisChartDataSet = new AxisChartDataSet(data, legendLabels, paints,
148                                                     ChartType.LINE,
149                                                     lineChartProperties);
150             dataSeries.addIAxisPlotDataSet(axisChartDataSet);
151
152
153             ChartProperties chartProperties = new ChartProperties();
154             AxisProperties axisProperties = new AxisProperties();
155             LegendProperties legendProperties = new LegendProperties();
156
157             axisChart = new AxisChart(dataSeries, chartProperties,
158                                       axisProperties,
159                                       legendProperties, 500, 500);
160
161         } catch (Exception JavaDoc e) {
162             e.printStackTrace();
163         }
164     }
165
166
167     /**
168      * Method to tell the page to render or not based on the initialized flag
169      *
170      * @param component chart component which will be rendered.
171      * @return boolean true if OutputChart should be re-rendered; otherwise,
172      * false.
173      */

174     public boolean renderOnSubmit(OutputChart component) {
175         if (axisChart == null || component.getChart() == null)
176             buildAxisChart();
177         component.setChart(axisChart);
178
179         return !initialzed && (initialzed = true);
180
181     }
182
183
184     /**
185      * Method to change the output text to the valuse selected by the user when
186      * they click on the chart
187      *
188      * @param event JSF action event
189      */

190     public void action(ActionEvent event) {
191         if (event.getSource() instanceof OutputChart) {
192             OutputChart chart = (OutputChart) event.getSource();
193             clickedValue = "";
194             if (chart.getClickedImageMapArea().getXAxisLabel() != null) {
195                 setClickedValue(chart.getClickedImageMapArea().getXAxisLabel() +
196                                 " : " +
197                                 chart.getClickedImageMapArea().getValue());
198                 effectOutputText.setFired(false);
199             }
200         }
201     }
202
203
204     public String JavaDoc getClickedValue() {
205         return clickedValue;
206     }
207
208     public void setClickedValue(String JavaDoc clickedValue) {
209         this.clickedValue = clickedValue;
210     }
211
212
213     public Effect getEffectOutputText() {
214         return effectOutputText;
215     }
216
217     public void setEffectOutputText(Effect effectOutputText) {
218         this.effectOutputText = effectOutputText;
219     }
220 }
221
Popular Tags