001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.jfreereport.legacy;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018: import org.jfree.data.xy.XYSeries;
019: import org.jfree.data.xy.XYSeriesCollection;
020: import org.jfree.report.event.ReportEvent;
021: import org.jfree.report.function.AbstractFunction;
022: import org.jfree.report.function.Expression;
023: import org.jfree.report.function.FunctionUtilities;
024:
025: import java.util.ArrayList;
026: import java.util.Arrays;
027: import java.util.HashMap;
028: import java.util.logging.Level;
029: import java.util.logging.Logger;
030:
031: @Deprecated
032: public class XYDataSetCollectorFunction extends AbstractFunction {
033: @NotNull
034: private static final Logger LOG = Logger
035: .getLogger(XYDataSetCollectorFunction.class.getName());
036:
037: @NotNull
038: private ArrayList<String> seriesNames;
039: @Nullable
040: private String domainColumn;
041: @Nullable
042: private XYSeriesCollection xyDataset;
043: @Nullable
044: private String resetGroup;
045: @NotNull
046: private HashMap<String, XYSeries> series;
047:
048: public XYDataSetCollectorFunction() {
049: this .seriesNames = new ArrayList<String>();
050: series = new HashMap<String, XYSeries>();
051:
052: xyDataset = new XYSeriesCollection();
053: }
054:
055: public void setSeriesName(final int index, @NotNull
056: final String field) {
057: if (seriesNames.size() == index) {
058: seriesNames.add(field);
059: } else {
060: seriesNames.set(index, field);
061: }
062: }
063:
064: @NotNull
065: public String getSeriesName(final int index) {
066: return seriesNames.get(index);
067: }
068:
069: public int getSeriesNameCount() {
070: return seriesNames.size();
071: }
072:
073: @NotNull
074: public String[] getSeriesName() {
075: return seriesNames.toArray(new String[seriesNames.size()]);
076: }
077:
078: public void setSeriesName(@NotNull
079: final String[] fields) {
080: this .seriesNames.clear();
081: this .seriesNames.addAll(Arrays.asList(fields));
082: }
083:
084: @Nullable
085: public String getDomainColumn() {
086: return domainColumn;
087: }
088:
089: public void setDomainColumn(@Nullable
090: String domainColumn) {
091: this .domainColumn = domainColumn;
092: }
093:
094: @Nullable
095: public String getResetGroup() {
096: return resetGroup;
097: }
098:
099: public void setResetGroup(@Nullable
100: String resetGroup) {
101: this .resetGroup = resetGroup;
102: }
103:
104: @Nullable
105: public Object getValue() {
106: return xyDataset;
107: }
108:
109: public void reportInitialized(@NotNull
110: ReportEvent event) {
111: }
112:
113: public void groupStarted(@NotNull
114: ReportEvent event) {
115: if (FunctionUtilities.isDefinedGroup(getResetGroup(), event)) {
116: // reset ...
117: if (FunctionUtilities.isDefinedPrepareRunLevel(this , event)) {
118: if (LOG.isLoggable(Level.FINE))
119: LOG.log(Level.FINE,
120: "XYDataSetCollectorFunction.groupStarted ");//NON-NLS
121: XYSeriesCollection xyDataset = new XYSeriesCollection();
122: for (int i = 0; i < getSeriesName().length; i++) {
123: String s = getSeriesName()[i];
124: XYSeries series = new XYSeries(s, true, true);
125: xyDataset.addSeries(series);
126: this .series.put(s, series);
127:
128: }
129: this .xyDataset = xyDataset;
130: //results.add(categoryDataset);
131: } else {
132: if (FunctionUtilities.isLayoutLevel(event)) {
133: // Activate the current group, which was filled in the prepare run.
134: //currentIndex += 1;
135: //categoryDataset = results.get(currentIndex);
136: }
137: }
138: } else {
139: // reset ...
140: if (FunctionUtilities.isDefinedPrepareRunLevel(this , event)) {
141: if (LOG.isLoggable(Level.FINE))
142: LOG.log(Level.FINE,
143: "XYDataSetCollectorFunction.groupStarted ");//NON-NLS
144: XYSeriesCollection xyDataset = new XYSeriesCollection();
145: for (int i = 0; i < getSeriesName().length; i++) {
146: String s = getSeriesName()[i];
147: XYSeries series = new XYSeries(s, true, true);
148: xyDataset.addSeries(series);
149: this .series.put(s, series);
150: }
151: this .xyDataset = xyDataset;
152: //results.add(categoryDataset);
153: }
154: }
155: }
156:
157: public void itemsAdvanced(@NotNull
158: final ReportEvent event) {
159: if (FunctionUtilities.isDefinedPrepareRunLevel(this , event)) {
160: final Object domainValue = getDataRow().get(
161: getDomainColumn());
162: if (domainValue == null) {
163: return;
164: }
165: if (!(domainValue instanceof Number)) {
166: return;
167: }
168:
169: final Number x = (Number) domainValue;
170:
171: for (String sn : seriesNames) {
172: final Object o = getDataRow().get(sn);
173: if (o instanceof Number) {
174: Number y = (Number) o;
175: (series.get(sn)).add(x, y);
176: }
177: }
178: }
179:
180: }
181:
182: @NotNull
183: public Expression getInstance() {
184: final XYDataSetCollectorFunction fn = (XYDataSetCollectorFunction) super
185: .getInstance();
186: fn.xyDataset = null;
187: fn.series = new HashMap<String, XYSeries>();
188: return fn;
189: }
190:
191: }
|