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.file.raw.ChannelWiseActionsMiner;
010: import com.sun.portal.ubt.report.data.file.aggregate.ChannelWiseActionsMinerAggregator;
011: import com.sun.portal.ubt.report.view.IllegalMinerException;
012: import com.sun.portal.ubt.report.util.UBTReportResourceBundle;
013:
014: import java.util.Vector;
015: import java.util.TreeMap;
016: import java.util.Arrays;
017: import java.util.Locale;
018:
019: import org.jfree.chart.JFreeChart;
020: import org.jfree.chart.ChartFactory;
021: import org.jfree.chart.plot.PlotOrientation;
022: import org.jfree.data.category.CategoryDataset;
023: import org.jfree.data.category.DefaultIntervalCategoryDataset;
024:
025: /**
026: *
027: */
028: public class ContainerWiseActionsChart implements UBTChartI {
029: DataMiner miner;
030: public static final String XAxisLabel = "Container";
031: public static final String YAxisLabel = "Activities";
032: public static final String ACTIONS_ON_CONTAINERS = "ActionsOnContainer";
033: private UBTReportResourceBundle reportsResource;
034:
035: public ContainerWiseActionsChart(DataMiner miner, Locale locale)
036: throws IllegalMinerException {
037: if (!(miner instanceof ChannelWiseActionsMiner || miner instanceof ChannelWiseActionsMinerAggregator))
038: throw new IllegalMinerException();
039: this .miner = miner;
040: reportsResource = new UBTReportResourceBundle(locale);
041: }
042:
043: private JFreeChart createChart() {
044: CategoryDataset dataset = createDataSet();
045: JFreeChart chart = ChartFactory.createStackedBarChart(
046: reportsResource
047: .getReportProperty(ACTIONS_ON_CONTAINERS),
048: reportsResource.getReportProperty(XAxisLabel), // X-Axis label
049: reportsResource.getReportProperty(YAxisLabel), // Y-Axis label
050: dataset, // Dataset
051: PlotOrientation.VERTICAL,// Orientation
052: true, false, false // Show legend
053: );
054: UBTChartUtil.customizeChart(chart);
055: return chart;
056: }
057:
058: private CategoryDataset createDataSet() {
059: TreeMap data = (TreeMap) miner.getData();
060: String[] containers; //chaannels
061: String[] actions; //actions
062: Number[][] startValues;
063: Object[] objcArray = (Object[]) (data).keySet().toArray();
064: containers = new String[objcArray.length];
065: copy(objcArray, containers);
066: actions = new String[UBTActions.getProviderValidSet().size()];
067: copy(UBTActions.getProviderValidSet().toArray(), actions);
068: startValues = new Number[actions.length][containers.length];
069: for (int i = 0; i < startValues.length; i++) {
070: Arrays.fill(startValues[i], new Integer(0));
071: }
072: for (int i = 0; i < containers.length; i++) {
073: TreeMap containerMap = (TreeMap) data.get(containers[i]);
074: Object[] objArray = (Object[]) containerMap.keySet()
075: .toArray();
076: for (int l = 0; l < objArray.length; l++) {
077: TreeMap channelMap = (TreeMap) containerMap
078: .get(objArray[l]);
079: for (int k = 0; k < actions.length; k++) {
080: if (channelMap.containsKey(actions[k])) {
081: startValues[k][i] = new Integer(
082: ((Integer) startValues[k][i])
083: .intValue()
084: + ((Integer) channelMap
085: .get(actions[k]))
086: .intValue());
087: }
088: }
089: }
090: }
091: return new DefaultIntervalCategoryDataset(actions, containers,
092: startValues, startValues);
093: }
094:
095: private void copy(Object[] objArray, String[] series) {
096: for (int i = 0; i < objArray.length; i++) {
097: series[i] = (String) objArray[i];
098: }
099: }
100:
101: public Vector getChart() {
102: Vector charts = new Vector(1);
103: charts.add(0, new UBTChartRenderer(createChart()));
104: return charts;
105: }
106: }
|