001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.ubt.report.view.chart;
006:
007: import com.sun.portal.ubt.report.data.DataMiner;
008: import com.sun.portal.ubt.report.data.UBTActions;
009: import com.sun.portal.ubt.report.data.PortletModes;
010: import com.sun.portal.ubt.report.data.file.raw.PortletMiner;
011: import com.sun.portal.ubt.report.data.file.aggregate.PortletRenderMinerAggregator;
012: import com.sun.portal.ubt.report.data.file.aggregate.PortletActionsMinerAggregator;
013: import com.sun.portal.ubt.report.view.chart.UBTChartI;
014: import com.sun.portal.ubt.report.view.chart.UBTChartUtil;
015: import com.sun.portal.ubt.report.view.chart.UBTChartRenderer;
016: import com.sun.portal.ubt.report.view.IllegalMinerException;
017: import com.sun.portal.ubt.report.util.UBTReportResourceBundle;
018:
019: import java.util.Vector;
020: import java.util.TreeMap;
021: import java.util.Arrays;
022: import java.util.Iterator;
023: import java.util.Locale;
024:
025: import org.jfree.chart.JFreeChart;
026: import org.jfree.chart.ChartFactory;
027: import org.jfree.chart.plot.PlotOrientation;
028: import org.jfree.data.category.CategoryDataset;
029: import org.jfree.data.category.DefaultIntervalCategoryDataset;
030:
031: /**
032: *
033: */
034: public class PortletChart implements UBTChartI {
035: DataMiner miner;
036: public static final String XAxisLabel = "Portlets";
037: public static final String YAxisLabel = "Modes";
038: public static final String PORTLET_POPULARITY = "PortletPopularity";
039: private UBTReportResourceBundle reportsResource;
040:
041: public PortletChart(DataMiner miner, Locale locale)
042: throws IllegalMinerException {
043: if (!(miner instanceof PortletMiner
044: || miner instanceof PortletRenderMinerAggregator || miner instanceof PortletActionsMinerAggregator))
045: throw new IllegalMinerException();
046: this .miner = miner;
047: reportsResource = new UBTReportResourceBundle(locale);
048: }
049:
050: private JFreeChart createChart() {
051: CategoryDataset dataset = createDataSet();
052: JFreeChart chart = ChartFactory.createStackedBarChart(
053: reportsResource.getReportProperty(PORTLET_POPULARITY),
054: reportsResource.getReportProperty(XAxisLabel), // X-Axis label
055: reportsResource.getReportProperty(YAxisLabel), // Y-Axis label
056: dataset, // Dataset
057: PlotOrientation.VERTICAL,// Orientation
058: true, false, false // Show legend
059: );
060: UBTChartUtil.customizeChart(chart);
061: return chart;
062: }
063:
064: private CategoryDataset createDataSet() {
065: //map(portlet, map(mode, map(windowstate, count)))
066: TreeMap data = (TreeMap) miner.getData();
067: String[] portlets; //portlets
068: String[] modes; //modes
069: Number[][] startValues;
070: Object[] objcArray = (Object[]) (data).keySet().toArray();
071: portlets = new String[objcArray.length];
072: copy(objcArray, portlets);
073: modes = new String[PortletModes.getSupportedModes().size()];
074: copy(PortletModes.getSupportedModes().toArray(), modes);
075: startValues = new Number[modes.length][portlets.length];
076: for (int i = 0; i < startValues.length; i++) {
077: Arrays.fill(startValues[i], new Integer(0));
078: }
079: for (int i = 0; i < portlets.length; i++) {
080: TreeMap portletMap = (TreeMap) data.get(portlets[i]);
081: for (int k = 0; k < modes.length; k++) {
082: if (portletMap.containsKey(modes[k])) {
083: TreeMap modeMap = (TreeMap) portletMap
084: .get(modes[k]);
085: Iterator values = modeMap.values().iterator();
086: while (values.hasNext()) {
087: startValues[k][i] = new Integer(
088: ((Integer) startValues[k][i])
089: .intValue()
090: + ((Integer) values.next())
091: .intValue());
092: }
093: }
094: }
095: }
096: return new DefaultIntervalCategoryDataset(modes, portlets,
097: startValues, startValues);
098: }
099:
100: private void copy(Object[] objArray, String[] series) {
101: for (int i = 0; i < objArray.length; i++) {
102: series[i] = (String) objArray[i];
103: }
104: }
105:
106: public Vector getChart() {
107: Vector charts = new Vector(1);
108: charts.add(0, new UBTChartRenderer(createChart()));
109: return charts;
110: }
111: }
|