001: /*
002: * Copyright 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. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: */
014: package org.pentaho.plugin.jfreechart;
015:
016: import java.awt.Font;
017: import java.util.List;
018: import java.text.NumberFormat;
019: import java.text.DecimalFormat;
020:
021: import org.dom4j.Node;
022: import org.jfree.chart.axis.ValueAxis;
023: import org.pentaho.commons.connection.IPentahoResultSet;
024: import org.pentaho.core.session.IPentahoSession;
025:
026: public class BarLineChartDefinition extends
027: CategoryDatasetChartDefinition {
028:
029: private static final String SERIES_NODE_NAME = "series"; //$NON-NLS-1$
030:
031: private static final String BAR_SERIES_NODE_NAME = "bar-series"; //$NON-NLS-1$
032:
033: private static final String LINE_SERIES_NODE_NAME = "line-series"; //$NON-NLS-1$
034:
035: // private static final String CATEGORY_NODE_NAME = "category-column"; //$NON-NLS-1$
036:
037: private static final String LINES_RANGE_TITLE_NODE_NAME = "lines-range-title"; //$NON-NLS-1$
038:
039: private static final String LINES_RANGE_TITLE_FONT_NODE_NAME = "lines-range-title-font"; //$NON-NLS-1$
040:
041: private static final String LINES_RANGE_TICK_FORMAT_NODE_NAME = "lines-range-tick-format"; //$NON-NLS-1$
042:
043: private static final String LINES_RANGE_TICK_FONT_NODE_NAME = "lines-range-tick-font"; //$NON-NLS-1$
044:
045: private static final String LINES_RANGE_MINIMUM_NODE_NAME = "lines-range-minimum"; //$NON-NLS-1$
046:
047: private static final String LINES_RANGE_MAXIMUM_NODE_NAME = "lines-range-maximum"; //$NON-NLS-1$
048:
049: private String[] barColumns;
050:
051: private String[] lineColumns;
052:
053: //not used
054: //private String categoryColumn;
055:
056: private Node chartAttributes;
057:
058: private String linesRangeTitle = null;
059:
060: private Font linesRangeTitleFont = null;
061:
062: private NumberFormat linesRangeTickFormat = null;
063:
064: private Font linesRangeTickFont = null;
065:
066: private double linesRangeMinimum = ValueAxis.DEFAULT_LOWER_BOUND;
067:
068: private double linesRangeMaximum = ValueAxis.DEFAULT_UPPER_BOUND;
069:
070: private static final long serialVersionUID = 1955883428823312855L;
071:
072: public BarLineChartDefinition(IPentahoResultSet data,
073: boolean byRow, Node chartAttributes, IPentahoSession session) {
074: super (data, byRow, chartAttributes, session);
075:
076: //setting standard category chart definition attriutes
077: setChartAttributes(chartAttributes);
078:
079: //Setting bar-line-chart attributes
080: //setCategoryColumn(chartAttributes.selectSingleNode(CATEGORY_NODE_NAME));
081: setBarSeries(chartAttributes
082: .selectSingleNode(BAR_SERIES_NODE_NAME));
083: setLineSeries(chartAttributes
084: .selectSingleNode(LINE_SERIES_NODE_NAME));
085: setLinesRangeTitle(chartAttributes
086: .selectSingleNode(LINES_RANGE_TITLE_NODE_NAME));
087: setLinesRangeTitleFont(chartAttributes
088: .selectSingleNode(LINES_RANGE_TITLE_FONT_NODE_NAME));
089: setLinesRangeTickFormat(chartAttributes
090: .selectSingleNode(LINES_RANGE_TICK_FORMAT_NODE_NAME));
091: setLinesRangeTickFont(chartAttributes
092: .selectSingleNode(LINES_RANGE_TICK_FONT_NODE_NAME));
093: setLinesRangeMinimum(chartAttributes
094: .selectSingleNode(LINES_RANGE_MINIMUM_NODE_NAME));
095: setLinesRangeMaximum(chartAttributes
096: .selectSingleNode(LINES_RANGE_MAXIMUM_NODE_NAME));
097: }
098:
099: public String[] getBarColumns() {
100: return barColumns;
101: }
102:
103: public void setBarColumns(String[] barColumns) {
104: this .barColumns = barColumns;
105: }
106:
107: // public String getCategoryColumn() {
108: // return categoryColumn;
109: // }
110: //
111: // public void setCategoryColumn(Node categoryNode) {
112: // if (categoryNode != null) {
113: // this.categoryColumn = categoryNode.getText();
114: // }
115: // }
116:
117: public String[] getLineColumns() {
118: return lineColumns;
119: }
120:
121: public void setLineColumns(String[] lineColumns) {
122: this .lineColumns = lineColumns;
123: }
124:
125: public void setBarSeries(Node barSeriesNode) {
126: if (barSeriesNode != null) {
127: List barNodes = barSeriesNode.selectNodes(SERIES_NODE_NAME);
128: String[] bars = new String[barNodes.size()];
129: for (int i = 0; i < barNodes.size(); i++) {
130: Node barNode = (Node) barNodes.get(i);
131: bars[i] = barNode.getText();
132: }
133: setBarColumns(bars);
134: }
135: }
136:
137: public void setLineSeries(Node lineSeriesNode) {
138: if (lineSeriesNode != null) {
139: List lineNodes = lineSeriesNode
140: .selectNodes(SERIES_NODE_NAME);
141: String[] lines = new String[lineNodes.size()];
142: for (int i = 0; i < lineNodes.size(); i++) {
143: Node lineNode = (Node) lineNodes.get(i);
144: lines[i] = lineNode.getText();
145: }
146: setLineColumns(lines);
147: }
148: }
149:
150: public Node getChartAttributes() {
151: return chartAttributes;
152: }
153:
154: public void setChartAttributes(Node chartAttributes) {
155: this .chartAttributes = chartAttributes;
156: }
157:
158: public String getLinesRangeTitle() {
159: return linesRangeTitle;
160: }
161:
162: public void setLinesRangeTitle(Node titleNode) {
163: if (titleNode != null) {
164: setLinesRangeTitle(titleNode.getText());
165: }
166: }
167:
168: public void setLinesRangeTitle(String linesRangeTitle) {
169: this .linesRangeTitle = linesRangeTitle;
170: }
171:
172: public Font getLinesRangeTitleFont() {
173: return linesRangeTitleFont;
174: }
175:
176: public void setLinesRangeTitleFont(Node titleFontNode) {
177: Font font = JFreeChartEngine.getFont(titleFontNode);
178: if (font != null) {
179: setLinesRangeTitleFont(font);
180: }
181: }
182:
183: public void setLinesRangeTitleFont(Font linesRangeTitleFont) {
184: this .linesRangeTitleFont = linesRangeTitleFont;
185: }
186:
187: public NumberFormat getLinesRangeTickFormat() {
188: return linesRangeTickFormat;
189: }
190:
191: public void setLinesRangeTickFormat(
192: NumberFormat linesRangeTickFormat) {
193: this .linesRangeTickFormat = linesRangeTickFormat;
194: }
195:
196: public void setLinesRangeTickFormat(Node tickFormatFontNode) {
197: if (tickFormatFontNode != null) {
198: NumberFormat format = new DecimalFormat(tickFormatFontNode
199: .getText());
200: if (format != null) {
201: setLinesRangeTickFormat(format);
202: }
203: }
204: }
205:
206: /**
207: * Return the java.awt.Font to be used to display the range axis tick labels
208: *
209: * @return Font The Font for the range axis tick labels
210: */
211: public Font getLinesRangeTickFont() {
212: return linesRangeTickFont;
213: }
214:
215: public void setLinesRangeTickFont(Font linesRangeTickFont) {
216: this .linesRangeTickFont = linesRangeTickFont;
217: }
218:
219: public void setLinesRangeTickFont(Node linesRangeTickFontNode) {
220: Font font = JFreeChartEngine.getFont(linesRangeTickFontNode);
221: if (font != null) {
222: setLinesRangeTickFont(font);
223: }
224: }
225:
226: /**
227: * Return the range axis' minimum value
228: *
229: * @return double Range axis' minimum value
230: */
231: public double getLinesRangeMinimum() {
232: return linesRangeMinimum;
233: }
234:
235: public void setLinesRangeMinimum(Node linesRangeMinimumNode) {
236: if (linesRangeMinimumNode != null) {
237: setLinesRangeMinimum(Double
238: .parseDouble(linesRangeMinimumNode.getText()));
239: }
240:
241: }
242:
243: /**
244: * @param double rangeMinimum
245: * Set the minimum value of the range axis.
246: */
247: public void setLinesRangeMinimum(double linesRangeMinimum) {
248: this .linesRangeMinimum = linesRangeMinimum;
249: }
250:
251: /**
252: * Return the range axis' maximum value
253: *
254: * @return double Range axis' maximum value
255: */
256: public double getLinesRangeMaximum() {
257: return linesRangeMaximum;
258: }
259:
260: public void setLinesRangeMaximum(Node linesRangeMaximumNode) {
261: if (linesRangeMaximumNode != null) {
262: setLinesRangeMaximum(Double
263: .parseDouble(linesRangeMaximumNode.getText()));
264: }
265:
266: }
267:
268: /**
269: * @param double rangeMinimum
270: * Set the minimum value of the range axis.
271: */
272: public void setLinesRangeMaximum(double linesRangeMaximum) {
273: this .linesRangeMaximum = linesRangeMaximum;
274: }
275:
276: public void setNoDataMessage(String msg) {
277: noDataMessage = msg;
278: }
279:
280: }
|