001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)BasicCategoryDatasetBasedCharts.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.extchart.jfchart;
030:
031: import org.openesb.tools.extchart.exception.ChartException;
032: import org.openesb.tools.extchart.jfchart.data.DataAccess;
033: import org.openesb.tools.extchart.property.ChartConstants;
034: import org.openesb.tools.extchart.property.ChartDefaults;
035: import org.openesb.tools.extchart.property.JFChartConstants;
036: import org.openesb.tools.extchart.property.bar.BarProperties;
037: import org.openesb.tools.extchart.property.bar.XYProperties;
038: import org.openesb.tools.extpropertysheet.IExtPropertyGroup;
039: import org.openesb.tools.extpropertysheet.IExtPropertyGroupsBean;
040: import com.sun.web.ui.component.Property;
041: import java.text.DecimalFormat;
042: import java.util.HashMap;
043: import java.util.Map;
044: import java.util.Properties;
045: import java.util.logging.Logger;
046: import org.jfree.chart.ChartFactory;
047: import org.jfree.chart.JFreeChart;
048: import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
049: import org.jfree.chart.plot.PlotOrientation;
050: import org.jfree.chart.urls.StandardCategoryURLGenerator;
051: import org.jfree.data.category.CategoryDataset;
052:
053: /**
054: *
055: * @author rdwivedi
056: */
057: public class BasicCategoryDatasetBasedCharts extends Chart {
058: private IExtPropertyGroupsBean propGrps = null;
059: private DataAccess mDA = null;
060: private static Logger mLogger = Logger
061: .getLogger(BasicCategoryDatasetBasedCharts.class.getName());
062:
063: private static String AREA_CHART = "areaChart";
064: private static String BAR_CHART = "barChart";
065: private static String LINE_CHART = "lineChart";
066: private static String MULTIPLE_PIE_CHART = "multiplePieChart";
067: private static String WATERFALL_CHART = "waterfallChart";
068:
069: public static Map getAllAllowedCharts() {
070: HashMap map = new HashMap();
071: map.put(AREA_CHART, "Area Chart");
072: map.put(BAR_CHART, "Bar Chart");
073: map.put(LINE_CHART, "Line Chart");
074: map.put(MULTIPLE_PIE_CHART, "Multiple Pie Chart");
075: map.put(WATERFALL_CHART, "Waterfall Chart");
076:
077: return map;
078: }
079:
080: /** Creates a new instance of BasicCategoryDatasetBasedCharts */
081: public BasicCategoryDatasetBasedCharts(IExtPropertyGroupsBean pg,
082: DataAccess da) {
083: propGrps = pg;
084: mDA = da;
085: }
086:
087: public ChartDefaults getChartDefaults() {
088: IExtPropertyGroup p = propGrps
089: .getGroupByName(JFChartConstants.CHART_COMMON_PROPERTIES);
090: return (ChartDefaults) p;
091: }
092:
093: private IExtPropertyGroupsBean getChartPropertiesGroup() {
094: return propGrps;
095: }
096:
097: private IExtPropertyGroup getSpecificProperties() {
098: return getChartPropertiesGroup().getGroupByName(
099: JFChartConstants.CHART_SPECIFIC_PROPERTIES);
100: }
101:
102: private IExtPropertyGroup getBARSpecificProperties() {
103: return getChartPropertiesGroup().getGroupByName(
104: JFChartConstants.CHART_BAR_PROPERTIES);
105: }
106:
107: public JFreeChart createChart() throws ChartException {
108: CategoryDataset dataset = null;
109: JFreeChart chart = null;
110: dataset = (CategoryDataset) mDA.getDataSet();
111: chart = generateChart(dataset);
112:
113: return chart;
114: }
115:
116: private JFreeChart generateChart(CategoryDataset ds) {
117: JFreeChart chart = null;
118: ChartDefaults p = getChartDefaults();
119: String type = (String) p.getProperty(
120: JFChartConstants.CHART_TYPE).getValue();
121: if (type.equals(BAR_CHART)) {
122: chart = createBarChart(ds);
123: } else if (type.equals(LINE_CHART)) {
124: chart = createLineChart(ds);
125: } else if (type.equals(AREA_CHART)) {
126: chart = createAreaChart(ds);
127: } else if (type.equals(WATERFALL_CHART)) {
128: chart = createWaterfallChart(ds);
129: }
130:
131: chart.setBackgroundPaint(this .getChartDefaults()
132: .getBackgroundColor());
133: super .setTitle(chart);
134: super .setLegend(chart);
135: super .setBorder(chart);
136: String realNoFormat = this .getChartDefaults()
137: .getRealNumberFormat();
138: mLogger.info("The real number format is " + realNoFormat);
139: DecimalFormat formatter = new DecimalFormat(realNoFormat);
140: String formtat = "[{0}, {1}] = {2}";
141: StandardCategoryToolTipGenerator itl = new StandardCategoryToolTipGenerator(
142: formtat, formatter);
143: //StandardCategoryItemLabelGenerator itl = new StandardCategoryItemLabelGenerator(realNoFormat, formatter);
144:
145: chart.getCategoryPlot().getRenderer().setToolTipGenerator(itl);
146: StandardCategoryURLGenerator urlG = new StandardCategoryURLGenerator();
147: chart.getCategoryPlot().getRenderer().setBaseItemURLGenerator(
148: urlG);
149: chart.getPlot().setNoDataMessage("No Data Found.");
150:
151: return chart;
152: }
153:
154: private JFreeChart createWaterfallChart(CategoryDataset ds) {
155: XYProperties props = (XYProperties) this
156: .getSpecificProperties();
157: ChartDefaults def = this .getChartDefaults();
158: boolean includeLegend = def.isIncludeLegend();
159: boolean is3D = def.is3D();
160: String title = def.getTitle();
161: boolean bUseTooltips = true;
162: boolean bDrilldownEnabled = false;
163: JFreeChart chart = null;
164: PlotOrientation plotOrientation = null;
165: if (props.getOrientation() == XYProperties.HORIZONTAL) {
166: plotOrientation = PlotOrientation.HORIZONTAL;
167: } else {
168: plotOrientation = PlotOrientation.VERTICAL;
169: }
170: //3d not ...
171: chart = ChartFactory.createWaterfallChart(title,
172: props.getDomainLabel(), // domain axis label
173: props.getRangeLabel(), ds, plotOrientation,
174: includeLegend, bUseTooltips, bDrilldownEnabled);
175:
176: return chart;
177:
178: }
179:
180: private JFreeChart createLineChart(CategoryDataset ds) {
181: XYProperties def = (XYProperties) this .getSpecificProperties();
182: ChartDefaults props = this .getChartDefaults();
183: boolean includeLegend = props.isIncludeLegend();
184: boolean is3D = props.is3D();
185: String title = props.getTitle();
186: boolean bUseTooltips = true;
187: boolean bDrilldownEnabled = false;
188: JFreeChart chart = null;
189: PlotOrientation plotOrientation = null;
190: if (def.getOrientation() == XYProperties.HORIZONTAL) {
191: plotOrientation = PlotOrientation.HORIZONTAL;
192: } else {
193: plotOrientation = PlotOrientation.VERTICAL;
194: }
195: if (is3D) {
196: chart = ChartFactory.createLineChart3D(
197: props.getTitle(),
198: def.getDomainLabel(), // domain axis label
199: def.getRangeLabel(), ds, plotOrientation,
200: includeLegend, bUseTooltips, bDrilldownEnabled);
201: } else {
202: chart = ChartFactory.createLineChart(title,
203: def.getDomainLabel(), // domain axis label
204: def.getRangeLabel(), ds, plotOrientation,
205: includeLegend, bUseTooltips, bDrilldownEnabled);
206: }
207:
208: return chart;
209:
210: }
211:
212: private JFreeChart createAreaChart(CategoryDataset ds) {
213: XYProperties def = (XYProperties) this .getSpecificProperties();
214: ChartDefaults props = this .getChartDefaults();
215: boolean includeLegend = props.isIncludeLegend();
216: boolean is3D = props.is3D();
217: String title = props.getTitle();
218: boolean bUseTooltips = true;
219: boolean bDrilldownEnabled = false;
220: JFreeChart chart = null;
221: PlotOrientation plotOrientation = null;
222: if (def.getOrientation() == XYProperties.HORIZONTAL) {
223: plotOrientation = PlotOrientation.HORIZONTAL;
224: } else {
225: plotOrientation = PlotOrientation.VERTICAL;
226: }
227: //3d not supported ....
228: chart = ChartFactory.createAreaChart(props.getTitle(),
229: def.getDomainLabel(), // domain axis label
230: def.getRangeLabel(), ds, plotOrientation,
231: includeLegend, bUseTooltips, bDrilldownEnabled);
232:
233: return chart;
234:
235: }
236:
237: // Bar Chart
238:
239: private JFreeChart createBarChart(CategoryDataset mDataSet) {
240:
241: XYProperties xy = (XYProperties) this .getSpecificProperties();
242: BarProperties def = (BarProperties) this
243: .getBARSpecificProperties();
244: ChartDefaults props = this .getChartDefaults();
245: PlotOrientation plotOrientation = null;
246:
247: if (xy.getOrientation() == XYProperties.HORIZONTAL) {
248: plotOrientation = PlotOrientation.HORIZONTAL;
249: } else {
250: plotOrientation = PlotOrientation.VERTICAL;
251: }
252:
253: //boolean bCategorySeriesMutuallyExclusive = isMutuallyExclusiveCategorySeries(mDataSet);
254: boolean bUseTooltips = true;
255: boolean bDrilldownEnabled = true;
256: //boolean bDrilldownEnabled = barProp.isDrilldownEnabled();
257:
258: if (props.is3D()) {
259: if (def.isStacked() /*||*//*mSummaryDataset ||*//* bCategorySeriesMutuallyExclusive*/) {
260: return ChartFactory.createStackedBarChart3D(props
261: .getTitle(), // chart title
262: xy.getDomainLabel(), // domain axis label
263: xy.getRangeLabel(), // range axis label
264: mDataSet, // data
265: plotOrientation, props.isIncludeLegend(), // include legend
266: bUseTooltips, bDrilldownEnabled);
267: } else {
268: return ChartFactory.createBarChart3D(props.getTitle(), // chart title
269: xy.getDomainLabel(), // domain axis label
270: xy.getRangeLabel(), // range axis label
271: mDataSet, // data
272: plotOrientation, props.isIncludeLegend(), // include legend
273: bUseTooltips, bDrilldownEnabled);
274: }
275: } else {
276: if (def.isStacked() /*|| /*mSummaryDataset ||bCategorySeriesMutuallyExclusive*/) {
277: return ChartFactory.createStackedBarChart(props
278: .getTitle(), // chart title
279: xy.getDomainLabel(), // domain axis label
280: xy.getRangeLabel(), // range axis label
281: mDataSet, // data
282: plotOrientation, props.isIncludeLegend(), // include legend
283: bUseTooltips, bDrilldownEnabled);
284: } else {
285: return ChartFactory.createBarChart(props.getTitle(), // chart title
286: xy.getDomainLabel(), // domain axis label
287: xy.getRangeLabel(), // range axis label
288: mDataSet, // data
289: plotOrientation, props.isIncludeLegend(), // include legend
290: bUseTooltips, bDrilldownEnabled);
291: }
292: }
293: }
294:
295: }
|