0001: /*
0002: * Copyright 2006 Pentaho Corporation. All rights reserved.
0003: * This software was developed by Pentaho Corporation and is provided under the terms
0004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
0005: * this file except in compliance with the license. If you need a copy of the license,
0006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
0007: * BI Platform. The Initial Developer is Pentaho Corporation.
0008: *
0009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
0010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
0011: * the license for the specific language governing your rights and limitations.
0012: */
0013: /*
0014: * Copyright 2006 Pentaho Corporation. All rights reserved.
0015: * This software was developed by Pentaho Corporation and is provided under the terms
0016: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
0017: * this file except in compliance with the license. If you need a copy of the license,
0018: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
0019: * BI Platform. The Initial Developer is Pentaho Corporation.
0020: *
0021: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
0022: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
0023: * the license for the specific language governing your rights and limitations.
0024: *
0025: * Created Jun 19, 2006
0026: * @author rtroyer
0027: */
0028:
0029: package org.pentaho.plugin.jfreechart;
0030:
0031: import java.awt.Color;
0032: import java.awt.Font;
0033: import java.awt.Image;
0034: import java.awt.Paint;
0035: import java.text.DateFormat;
0036: import java.text.ParseException;
0037: import java.util.ArrayList;
0038: import java.util.Date;
0039: import java.util.Iterator;
0040: import java.util.List;
0041:
0042: import org.apache.commons.logging.Log;
0043: import org.apache.commons.logging.LogFactory;
0044: import org.dom4j.Node;
0045: import org.jfree.chart.axis.ValueAxis;
0046: import org.jfree.chart.plot.PlotOrientation;
0047: import org.jfree.chart.title.TextTitle;
0048: import org.jfree.data.time.Day;
0049: import org.jfree.data.time.Hour;
0050: import org.jfree.data.time.Millisecond;
0051: import org.jfree.data.time.Minute;
0052: import org.jfree.data.time.Month;
0053: import org.jfree.data.time.Quarter;
0054: import org.jfree.data.time.RegularTimePeriod;
0055: import org.jfree.data.time.Second;
0056: import org.jfree.data.time.TimeSeries;
0057: import org.jfree.data.time.TimeSeriesCollection;
0058: import org.jfree.data.time.TimeSeriesDataItem;
0059: import org.jfree.data.time.Week;
0060: import org.jfree.data.time.Year;
0061: import org.jfree.ui.RectangleEdge;
0062: import org.pentaho.commons.connection.IPentahoResultSet;
0063: import org.pentaho.core.session.IPentahoSession;
0064: import org.pentaho.messages.Messages;
0065:
0066: public class TimeSeriesCollectionChartDefinition extends
0067: TimeSeriesCollection implements XYChartDefinition {
0068:
0069: public static final String DATE_MINIMUM_NODE_NAME = "date-minimum"; //$NON-NLS-1$
0070:
0071: public static final String DATE_MAXIMUM_NODE_NAME = "date-maximum"; //$NON-NLS-1$
0072:
0073: private int chartType = JFreeChartEngine.UNDEFINED_CHART_TYPE;
0074:
0075: private String noDataMessage = null;
0076:
0077: // JFreeChart Customizations
0078: private String title = ""; //$NON-NLS-1$
0079:
0080: private RectangleEdge titlePosition = RectangleEdge.TOP;
0081:
0082: private Font titleFont = TextTitle.DEFAULT_FONT;
0083:
0084: private List subTitles = new ArrayList();
0085:
0086: private Paint chartBackgroundPaint = Color.WHITE;
0087:
0088: private Image chartBackgroundImage = null;
0089:
0090: private boolean borderVisible = false;
0091:
0092: private Paint borderPaint = Color.BLACK;
0093:
0094: private int width = 200;
0095:
0096: private int height = 200;
0097:
0098: private int dotWidth = 5;
0099:
0100: private int dotHeight = 5;
0101:
0102: // Plot Customizations
0103: private PlotOrientation orientation = PlotOrientation.VERTICAL;
0104:
0105: private Paint plotBackgroundPaint = Color.WHITE;
0106:
0107: private Image plotBackgroundImage = null;
0108:
0109: private boolean legendIncluded = true;
0110:
0111: private boolean threeD = false;
0112:
0113: private boolean stacked = false;
0114:
0115: private boolean domainVerticalTickLabels = false;
0116:
0117: private String domainPeriodType = "Millisecond"; //$NON-NLS-1$
0118:
0119: private Paint[] paintSequence = null;
0120:
0121: private String domainTitle = null;
0122:
0123: private Font domainTitleFont = TextTitle.DEFAULT_FONT;
0124:
0125: private String rangeTitle = null;
0126:
0127: private Font rangeTitleFont = TextTitle.DEFAULT_FONT;
0128:
0129: private double rangeMinimum = ValueAxis.DEFAULT_LOWER_BOUND;
0130:
0131: private double rangeMaximum = ValueAxis.DEFAULT_UPPER_BOUND;
0132:
0133: private Date dateMinimum = null;
0134:
0135: private Date dateMaximum = null;
0136:
0137: private Font legendFont = null;
0138:
0139: private boolean legendBorderVisible = true;
0140:
0141: private String lineStyle = ChartDefinition.LINE_STYLE_SOLID_STR;
0142:
0143: private float lineWidth = 1.0f;
0144:
0145: private boolean markersVisible = false;
0146:
0147: // in JFreeChart, the tokens stand for:
0148: // {0} - the series name
0149: // {1} - the preformatted x-value
0150: // {2} - the preformatted y-value
0151: private String tooltipContent = "{1}, {2}"; //$NON-NLS-1$
0152:
0153: private String tooltipYFormat = "0"; //$NON-NLS-1$
0154:
0155: private String tooltipXFormat = "0"; //$NON-NLS-1$
0156:
0157: // Other stuff
0158: private IPentahoSession session;
0159:
0160: private static final long serialVersionUID = 1717509132920946530L;
0161:
0162: public TimeSeriesCollectionChartDefinition(IPentahoSession session) {
0163: super ();
0164: this .session = session;
0165: }
0166:
0167: public TimeSeriesCollectionChartDefinition(int chartType,
0168: IPentahoResultSet data, boolean byRow,
0169: Node chartAttributes, IPentahoSession session) {
0170: this (session);
0171: this .chartType = chartType;
0172: setChartAttributes(chartAttributes);
0173: if (byRow) {
0174: setDataByRow(data);
0175: } else {
0176: setDataByColumn(data);
0177: }
0178: }
0179:
0180: public TimeSeriesCollectionChartDefinition(IPentahoResultSet data,
0181: boolean byRow, Node chartAttributes, IPentahoSession session) {
0182: this (JFreeChartEngine.UNDEFINED_CHART_TYPE, data, byRow,
0183: chartAttributes, session);
0184: }
0185:
0186: public Log getLogger() {
0187: return LogFactory
0188: .getLog(TimeSeriesCollectionChartDefinition.class);
0189: }
0190:
0191: private void setChartAttributes(Node chartAttributes) {
0192: if (chartAttributes == null) {
0193: return;
0194: }
0195: // get the chart type from the chart node -- this overrides the current
0196: // chart type
0197: setChartType(chartAttributes.selectSingleNode(TYPE_NODE_NAME));
0198:
0199: // set the chart background
0200: setChartBackground(chartAttributes
0201: .selectSingleNode(CHART_BACKGROUND_NODE_NAME));
0202:
0203: // set the plot background
0204: setPlotBackground(chartAttributes
0205: .selectSingleNode(PLOT_BACKGROUND_NODE_NAME));
0206:
0207: // set the orientation
0208: setOrientation(chartAttributes
0209: .selectSingleNode(ORIENTATION_NODE_NAME));
0210:
0211: // do we want a legend
0212: setLegendIncluded(chartAttributes
0213: .selectSingleNode(INCLUDE_LEGEND_NODE_NAME));
0214:
0215: // get the chart title
0216: setTitle(chartAttributes.selectSingleNode(TITLE_NODE_NAME));
0217:
0218: // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema to
0219: // be well constructed and validate the XML .
0220: // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node
0221: // under which <subtitle> can exist.
0222:
0223: List subtitles = chartAttributes
0224: .selectNodes(SUBTITLE_NODE_NAME);
0225:
0226: if ((subtitles == null) || (subtitles.isEmpty())) {
0227: Node subTitlesNode = chartAttributes
0228: .selectSingleNode(SUBTITLES_NODE_NAME);
0229: if (subTitlesNode != null) {
0230: subtitles = subTitlesNode
0231: .selectNodes(SUBTITLE_NODE_NAME);
0232: }
0233: } else {
0234: // log a deprecation warning for this property...
0235: getLogger()
0236: .warn(
0237: Messages
0238: .getString(
0239: "CHART.WARN_DEPRECATED_CHILD", SUBTITLE_NODE_NAME, SUBTITLES_NODE_NAME));//$NON-NLS-1$
0240: getLogger()
0241: .warn(
0242: Messages
0243: .getString(
0244: "CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", SUBTITLE_NODE_NAME));//$NON-NLS-1$
0245: }
0246:
0247: if (subtitles != null) {
0248: addSubTitles(subtitles);
0249: }
0250:
0251: // get the paint sequence
0252: setPaintSequence(chartAttributes
0253: .selectSingleNode(PALETTE_NODE_NAME));
0254:
0255: // get the stacked value
0256: setStacked(chartAttributes.selectSingleNode(STACKED_NODE_NAME));
0257:
0258: // get the 3D value
0259: setThreeD(chartAttributes.selectSingleNode(THREED_NODE_NAME));
0260:
0261: // set the width
0262: setWidth(chartAttributes.selectSingleNode(WIDTH_NODE_NAME));
0263:
0264: // set the height
0265: setHeight(chartAttributes.selectSingleNode(HEIGHT_NODE_NAME));
0266:
0267: // set the dot width
0268: setDotWidth(chartAttributes
0269: .selectSingleNode(DOT_WIDTH_NODE_NAME));
0270:
0271: // set the dot height
0272: setDotHeight(chartAttributes
0273: .selectSingleNode(DOT_HEIGHT_NODE_NAME));
0274:
0275: // set vertical tick labels flag
0276: setDomainVerticalTickLabels(chartAttributes
0277: .selectSingleNode(DOMAIN_VERTICAL_TICK_LABELS_NODE_NAME));
0278:
0279: // set the border on or off
0280: setBorderVisible(chartAttributes
0281: .selectSingleNode(CHART_BORDER_VISIBLE_NODE_NAME));
0282:
0283: // set the border Paint
0284: setBorderPaint(JFreeChartEngine.getPaint(chartAttributes
0285: .selectSingleNode(CHART_BORDER_PAINT_NODE_NAME)));
0286:
0287: // set the title location
0288: setTitlePosition(chartAttributes
0289: .selectSingleNode(TITLE_POSITION_NODE_NAME));
0290:
0291: // set the title font
0292: setTitleFont(chartAttributes
0293: .selectSingleNode(TITLE_FONT_NODE_NAME));
0294:
0295: // set the domain title
0296: setDomainTitle(chartAttributes
0297: .selectSingleNode(DOMAIN_TITLE_NODE_NAME));
0298:
0299: // set the domain font
0300: setDomainTitleFont(chartAttributes
0301: .selectSingleNode(DOMAIN_TITLE_FONT_NODE_NAME));
0302:
0303: // set the range title
0304: setRangeTitle(chartAttributes
0305: .selectSingleNode(RANGE_TITLE_NODE_NAME));
0306:
0307: // the the range font
0308: setRangeTitleFont(chartAttributes
0309: .selectSingleNode(RANGE_TITLE_FONT_NODE_NAME));
0310:
0311: // set the range minimum
0312: setRangeMinimum(chartAttributes
0313: .selectSingleNode(RANGE_MINIMUM_NODE_NAME));
0314:
0315: // set the range minimum
0316: setRangeMaximum(chartAttributes
0317: .selectSingleNode(RANGE_MAXIMUM_NODE_NAME));
0318:
0319: // set the date minimum
0320: setDateMinimum(chartAttributes
0321: .selectSingleNode(DATE_MINIMUM_NODE_NAME));
0322:
0323: // set the date minimum
0324: setDateMaximum(chartAttributes
0325: .selectSingleNode(DATE_MAXIMUM_NODE_NAME));
0326:
0327: // set the Period type
0328: setDomainPeriodType(chartAttributes
0329: .selectSingleNode(DOMAIN_PERIOD_TYPE_NODE_NAME));
0330:
0331: // set the line style
0332: setLineStyle(chartAttributes
0333: .selectSingleNode(LINE_STYLE_NODE_NAME));
0334:
0335: // set the line width
0336: setLineWidth(chartAttributes
0337: .selectSingleNode(LINE_WIDTH_NODE_NAME));
0338:
0339: // set the marker visibility
0340: setMarkersVisible(chartAttributes
0341: .selectSingleNode(MARKER_VISIBLE_NODE_NAME));
0342:
0343: //set legend font
0344: setLegendFont(chartAttributes
0345: .selectSingleNode(LEGEND_FONT_NODE_NAME));
0346:
0347: // set legend border visible
0348: setLegendBorderVisible(chartAttributes
0349: .selectSingleNode(DISPLAY_LEGEND_BORDER_NODE_NAME));
0350:
0351: setTooltipContent(chartAttributes
0352: .selectSingleNode(TOOLTIP_CONTENT_NODE_NAME));
0353:
0354: setTooltipYFormat(chartAttributes
0355: .selectSingleNode(TOOLTIP_Y_FORMAT_NODE_NAME));
0356:
0357: setTooltipXFormat(chartAttributes
0358: .selectSingleNode(TOOLTIP_X_FORMAT_NODE_NAME));
0359: }
0360:
0361: private void setDataByColumn(IPentahoResultSet data) {
0362: // TODO Make this routine MDX friendly
0363: if (data == null) {
0364: noDataMessage = Messages
0365: .getString("CHART.USER_NO_DATA_AVAILABLE"); //$NON-NLS-1$
0366: return; // No data so we've got nothing to set
0367: // TODO come up with some sort of error strategy here.
0368: }
0369: boolean firstPass = true;
0370: String lastSeries = ""; //$NON-NLS-1$
0371: String seriesName = ""; //$NON-NLS-1$
0372: Class timePeriodClass = getTimePeriodClass(getDomainPeriodType());
0373: Object[] rowData = data.next();
0374: TimeSeries wrkSeries = null;
0375: while (rowData != null) {
0376: seriesName = (String) rowData[0];
0377: if (firstPass || !seriesName.equalsIgnoreCase(lastSeries)) {
0378: if (!firstPass) {
0379: addSeries(wrkSeries);
0380: }
0381: wrkSeries = new TimeSeries(seriesName, timePeriodClass);
0382: lastSeries = seriesName;
0383: firstPass = false;
0384: }
0385: RegularTimePeriod regularTimePeriod = RegularTimePeriod
0386: .createInstance(timePeriodClass, (Date) rowData[1],
0387: RegularTimePeriod.DEFAULT_TIME_ZONE);
0388: TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(
0389: regularTimePeriod, ((Number) rowData[2])
0390: .doubleValue());
0391: wrkSeries.add(timeSeriesDataItem);
0392: rowData = data.next();
0393: }
0394: if (!firstPass) {
0395: addSeries(wrkSeries);
0396: }
0397: if ((data.getRowCount() > 0) && (this .getSeriesCount() <= 0)) {
0398: noDataMessage = Messages
0399: .getString("CHART.USER_INCORRECT_DATA_FORMAT"); //$NON-NLS-1$
0400: }
0401:
0402: }
0403:
0404: private void setDataByRow(IPentahoResultSet data) {
0405: // TODO Make this routine MDX friendly
0406: if (data == null) {
0407: noDataMessage = Messages
0408: .getString("CHART.USER_NO_DATA_AVAILABLE"); //$NON-NLS-1$
0409: return; // No data so we've got nothing to set
0410: // TODO come up with some sort of error strategy here.
0411: }
0412: Class timePeriodClass = getTimePeriodClass(getDomainPeriodType());
0413: Object[] rowData = data.next();
0414: while (rowData != null) {
0415: String seriesName = (String) rowData[0];
0416: TimeSeries wrkSeries = new TimeSeries(seriesName,
0417: timePeriodClass);
0418: for (int column = 1; column < rowData.length - 1; column = column + 2) {
0419: TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(
0420: RegularTimePeriod.createInstance(
0421: timePeriodClass,
0422: (Date) rowData[column],
0423: RegularTimePeriod.DEFAULT_TIME_ZONE),
0424: ((Number) rowData[column + 1]).doubleValue());
0425: wrkSeries.add(timeSeriesDataItem);
0426: }
0427: addSeries(wrkSeries);
0428: rowData = data.next();
0429: }
0430:
0431: if ((data.getRowCount() > 0) && (this .getSeriesCount() <= 0)) {
0432: noDataMessage = Messages
0433: .getString("CHART.USER_INCORRECT_DATA_FORMAT"); //$NON-NLS-1$
0434: }
0435:
0436: }
0437:
0438: public static Class getTimePeriodClass(String timePeriodStr) {
0439: Class retClass = Millisecond.class;
0440: if (timePeriodStr.equalsIgnoreCase(SECOND_PERIOD_TYPE_STR)) {
0441: retClass = Second.class;
0442: } else if (timePeriodStr
0443: .equalsIgnoreCase(MINUTE_PERIOD_TYPE_STR)) {
0444: retClass = Minute.class;
0445: } else if (timePeriodStr.equalsIgnoreCase(HOUR_PERIOD_TYPE_STR)) {
0446: retClass = Hour.class;
0447: } else if (timePeriodStr.equalsIgnoreCase(DAY_PERIOD_TYPE_STR)) {
0448: retClass = Day.class;
0449: } else if (timePeriodStr.equalsIgnoreCase(WEEK_PERIOD_TYPE_STR)) {
0450: retClass = Week.class;
0451: } else if (timePeriodStr
0452: .equalsIgnoreCase(MONTH_PERIOD_TYPE_STR)) {
0453: retClass = Month.class;
0454: } else if (timePeriodStr
0455: .equalsIgnoreCase(QUARTER_PERIOD_TYPE_STR)) {
0456: retClass = Quarter.class;
0457: } else if (timePeriodStr.equalsIgnoreCase(YEAR_PERIOD_TYPE_STR)) {
0458: retClass = Year.class;
0459: }
0460: return retClass;
0461: }
0462:
0463: /**
0464: * @param backgroundPaint
0465: * The backgroundPaint to set.
0466: */
0467: public void setChartBackgroundPaint(Paint chartBackgroundPaint) {
0468: if (chartBackgroundPaint != null) {
0469: this .chartBackgroundPaint = chartBackgroundPaint;
0470: }
0471: }
0472:
0473: /**
0474: * Return the java.awt.Font to be used to display the dial title
0475: *
0476: * @return Font The Font for the title of this Pie
0477: */
0478: public Font getTitleFont() {
0479: return titleFont;
0480: }
0481:
0482: public void setTitleFont(Font titleFont) {
0483: this .titleFont = titleFont;
0484: }
0485:
0486: public void setTitleFont(Node titleFontNode) {
0487: Font font = JFreeChartEngine.getFont(titleFontNode);
0488: if (font != null) {
0489: setTitleFont(font);
0490: }
0491: }
0492:
0493: /**
0494: * @return Returns the backgroundPaint.
0495: */
0496: public Paint getChartBackgroundPaint() {
0497: return chartBackgroundPaint;
0498: }
0499:
0500: /**
0501: * @return Returns the chartType.
0502: */
0503: public int getChartType() {
0504: return chartType;
0505: }
0506:
0507: public static int getChartType(String typeStr) {
0508: if (typeStr != null) {
0509: if (LINE_CHART_STR.equalsIgnoreCase(typeStr)) {
0510: return JFreeChartEngine.LINE_CHART_TYPE;
0511: } else if (AREA_CHART_STR.equalsIgnoreCase(typeStr)) {
0512: return JFreeChartEngine.AREA_CHART_TYPE;
0513: } else if (STEP_CHART_STR.equalsIgnoreCase(typeStr)) {
0514: return JFreeChartEngine.STEP_CHART_TYPE;
0515: } else if (STEP_AREA_CHART_STR.equalsIgnoreCase(typeStr)) {
0516: return JFreeChartEngine.STEP_AREA_CHART_TYPE;
0517: } else if (DIFFERENCE_CHART_STR.equalsIgnoreCase(typeStr)) {
0518: return JFreeChartEngine.DIFFERENCE_CHART_TYPE;
0519: } else if (DOT_CHART_STR.equalsIgnoreCase(typeStr)) {
0520: return JFreeChartEngine.DOT_CHART_TYPE;
0521: }
0522: }
0523: return JFreeChartEngine.UNDEFINED_CHART_TYPE;
0524: }
0525:
0526: public void setChartType(Node chartTypeNode) {
0527: if (chartTypeNode != null) {
0528: String typeStr = chartTypeNode.getText();
0529: setChartType(getChartType(typeStr));
0530: }
0531: }
0532:
0533: /**
0534: * @param chartType
0535: * The chartType to set.
0536: */
0537: public void setChartType(int chartType) {
0538: this .chartType = chartType;
0539: }
0540:
0541: /**
0542: * @return Returns the threeD.
0543: */
0544: public boolean isThreeD() {
0545: return threeD;
0546: }
0547:
0548: public void setThreeD(Node threeDNode) {
0549: if (threeDNode != null) {
0550: String boolStr = threeDNode.getText();
0551: Boolean booleanValue = new Boolean(boolStr);
0552: setThreeD(booleanValue.booleanValue());
0553: }
0554: }
0555:
0556: /**
0557: * @param threeD
0558: * The threeD to set.
0559: */
0560: public void setThreeD(boolean threeD) {
0561: this .threeD = threeD;
0562: }
0563:
0564: /**
0565: * @return Returns the stacked.
0566: */
0567: public boolean isStacked() {
0568: return stacked;
0569: }
0570:
0571: public void setStacked(Node stackedNode) {
0572: if (stackedNode != null) {
0573: String boolStr = stackedNode.getText();
0574: Boolean booleanValue = new Boolean(boolStr);
0575: setStacked(booleanValue.booleanValue());
0576: }
0577: }
0578:
0579: /**
0580: * @param stacked
0581: * The stacked to set.
0582: */
0583: public void setStacked(boolean stacked) {
0584: this .stacked = stacked;
0585: }
0586:
0587: /**
0588: * @return Returns the verticalTickLabels.
0589: */
0590: public boolean isDomainVerticalTickLabels() {
0591: return domainVerticalTickLabels;
0592: }
0593:
0594: public void setDomainVerticalTickLabels(
0595: Node domainVerticalTickLabelsNode) {
0596: if (domainVerticalTickLabelsNode != null) {
0597: String boolStr = domainVerticalTickLabelsNode.getText();
0598: Boolean booleanValue = new Boolean(boolStr);
0599: setDomainVerticalTickLabels(booleanValue.booleanValue());
0600: }
0601: }
0602:
0603: /**
0604: * @param domainVerticalTickLabels
0605: * The domainVerticalLabels to set.
0606: */
0607: public void setDomainVerticalTickLabels(
0608: boolean domainVerticalTickLabels) {
0609: this .domainVerticalTickLabels = domainVerticalTickLabels;
0610: }
0611:
0612: /**
0613: * @return Returns the domainPeriodType.
0614: */
0615: public String getDomainPeriodType() {
0616: return domainPeriodType;
0617: }
0618:
0619: public void setDomainPeriodType(Node domainPeriodTypeNode) {
0620: if (domainPeriodTypeNode != null) {
0621: setDomainPeriodType(domainPeriodTypeNode.getText());
0622: }
0623: }
0624:
0625: /**
0626: * @param domainPeriodType
0627: * The domainPeriodType to set.
0628: */
0629: public void setDomainPeriodType(String domainPeriodType) {
0630: this .domainPeriodType = domainPeriodType;
0631: }
0632:
0633: /**
0634: * @return Returns the height.
0635: */
0636: public int getHeight() {
0637: return height;
0638: }
0639:
0640: public void setHeight(Node heightNode) {
0641: if (heightNode != null) {
0642: setHeight(Integer.parseInt(heightNode.getText()));
0643: }
0644: }
0645:
0646: /**
0647: * @param height
0648: * The height to set.
0649: */
0650: public void setHeight(int height) {
0651: this .height = height;
0652: }
0653:
0654: /**
0655: * @return Returns the width.
0656: */
0657: public int getWidth() {
0658: return width;
0659: }
0660:
0661: public void setWidth(Node widthNode) {
0662: if (widthNode != null) {
0663: setWidth(Integer.parseInt(widthNode.getText()));
0664: }
0665: }
0666:
0667: /**
0668: * @param width
0669: * The width to set.
0670: */
0671: public void setWidth(int width) {
0672: this .width = width;
0673: }
0674:
0675: /**
0676: * @return Returns the title.
0677: */
0678: public String getTitle() {
0679: return title;
0680: }
0681:
0682: public void setTitle(Node chartTitleNode) {
0683: if (chartTitleNode != null) {
0684: setTitle(chartTitleNode.getText());
0685: }
0686: }
0687:
0688: /**
0689: * @param title
0690: * The title to set.
0691: */
0692: public void setTitle(String title) {
0693: this .title = title;
0694: }
0695:
0696: /**
0697: * @return Returns the paintSequence.
0698: */
0699: public Paint[] getPaintSequence() {
0700: return paintSequence;
0701: }
0702:
0703: public void setPaintSequence(Node paletteNode) {
0704: if (paletteNode != null) {
0705: List colorNodes = paletteNode.selectNodes(COLOR_NODE_NAME);
0706: Paint[] paints = new Paint[colorNodes.size()];
0707: for (int i = 0; i < colorNodes.size(); i++) {
0708: paints[i] = JFreeChartEngine.getPaint((Node) colorNodes
0709: .get(i));
0710: }
0711: setPaintSequence(paints);
0712: }
0713: }
0714:
0715: /**
0716: * @param paintSequence
0717: * The paintSequence to set.
0718: */
0719: public void setPaintSequence(Paint[] paintSequence) {
0720: this .paintSequence = paintSequence;
0721: }
0722:
0723: /**
0724: * @return Returns the subTitles.
0725: */
0726: public List getSubtitles() {
0727: return subTitles;
0728: }
0729:
0730: public void addSubTitles(List subTitleNodes) {
0731: if (subTitleNodes != null) {
0732: Iterator iter = subTitleNodes.iterator();
0733: while (iter.hasNext()) {
0734: addSubTitle(((Node) iter.next()).getText());
0735: }
0736: }
0737: }
0738:
0739: public void addSubTitle(String subTitle) {
0740: subTitles.add(subTitle);
0741: }
0742:
0743: /**
0744: * @return Returns the chartBackgroundImage.
0745: */
0746: public Image getChartBackgroundImage() {
0747: return chartBackgroundImage;
0748: }
0749:
0750: public void setChartBackgroundImage(Node chartBackgroundImageNode) {
0751: setChartBackgroundImage(JFreeChartEngine.getImage(
0752: chartBackgroundImageNode, getSession()));
0753: }
0754:
0755: /**
0756: * @param chartBackgroundImage
0757: * The chartBackgroundImage to set.
0758: */
0759: public void setChartBackgroundImage(Image chartBackgroundImage) {
0760: this .chartBackgroundImage = chartBackgroundImage;
0761: }
0762:
0763: /**
0764: * @return Returns the legendIncluded.
0765: */
0766: public boolean isLegendIncluded() {
0767: return legendIncluded;
0768: }
0769:
0770: public void setLegendIncluded(Node legendNode) {
0771: if (legendNode != null) {
0772: String boolStr = legendNode.getText();
0773: Boolean booleanValue = new Boolean(boolStr);
0774: setLegendIncluded(booleanValue.booleanValue());
0775: }
0776: }
0777:
0778: /**
0779: * @param legendIncluded
0780: * The legendIncluded to set.
0781: */
0782: public void setLegendIncluded(boolean legendIncluded) {
0783: this .legendIncluded = legendIncluded;
0784: }
0785:
0786: public void setPlotBackgroundPaint(Paint plotBackgroundPaint) {
0787: if (plotBackgroundPaint != null) {
0788: this .plotBackgroundPaint = plotBackgroundPaint;
0789: }
0790: }
0791:
0792: public Paint getPlotBackgroundPaint() {
0793: return plotBackgroundPaint;
0794: }
0795:
0796: /**
0797: * @return Returns the plotBackgroundImage.
0798: */
0799: public Image getPlotBackgroundImage() {
0800: return plotBackgroundImage;
0801: }
0802:
0803: public void setPlotBackgroundImage(Node plotBackgroundImageNode) {
0804: setPlotBackgroundImage(JFreeChartEngine.getImage(
0805: plotBackgroundImageNode, getSession()));
0806: }
0807:
0808: /**
0809: * @param plotBackgroundImage
0810: * The plotBackgroundImage to set.
0811: */
0812: public void setPlotBackgroundImage(Image plotBackgroundImage) {
0813: this .plotBackgroundImage = plotBackgroundImage;
0814: }
0815:
0816: /**
0817: * @return Returns the orientation.
0818: */
0819: public PlotOrientation getOrientation() {
0820: return orientation;
0821: }
0822:
0823: public void setOrientation(Node orientationNode) {
0824: if (orientationNode != null) {
0825: String orientationStr = orientationNode.getText();
0826: if (VERTICAL_ORIENTATION.equalsIgnoreCase(orientationStr)) {
0827: setOrientation(PlotOrientation.VERTICAL);
0828: } else if (HORIZONTAL_ORIENTATION
0829: .equalsIgnoreCase(orientationStr)) {
0830: setOrientation(PlotOrientation.HORIZONTAL);
0831: }
0832: }
0833: }
0834:
0835: /**
0836: * @param orientation
0837: * The orientation to set.
0838: */
0839: public void setOrientation(PlotOrientation orientation) {
0840: this .orientation = orientation;
0841: }
0842:
0843: /**
0844: * @return Returns the borderVisible.
0845: */
0846: public boolean isBorderVisible() {
0847: return borderVisible;
0848: }
0849:
0850: public void setBorderVisible(Node borderVisibleNode) {
0851: if (borderVisibleNode != null) {
0852: String boolStr = borderVisibleNode.getText();
0853: Boolean booleanValue = new Boolean(boolStr);
0854: setBorderVisible(booleanValue.booleanValue());
0855: }
0856: }
0857:
0858: /**
0859: * @param borderVisible
0860: * The borderVisible to set.
0861: */
0862: public void setBorderVisible(boolean borderVisible) {
0863: this .borderVisible = borderVisible;
0864: }
0865:
0866: /**
0867: * @return Returns the borderPaint.
0868: */
0869: public Paint getBorderPaint() {
0870: return borderPaint;
0871: }
0872:
0873: /**
0874: * @param borderPaint
0875: * The borderPaint to set.
0876: */
0877: public void setBorderPaint(Paint borderPaint) {
0878: this .borderPaint = borderPaint;
0879: }
0880:
0881: public void setTitlePosition(Node titlePositionNode) {
0882: if (titlePositionNode != null) {
0883: String titlePositionStr = titlePositionNode.getText();
0884: if ("top".equalsIgnoreCase(titlePositionStr)) { //$NON-NLS-1$
0885: setTitlePosition(RectangleEdge.TOP);
0886: } else if ("left".equalsIgnoreCase(titlePositionStr)) { //$NON-NLS-1$
0887: setTitlePosition(RectangleEdge.LEFT);
0888: } else if ("bottom".equalsIgnoreCase(titlePositionStr)) { //$NON-NLS-1$
0889: setTitlePosition(RectangleEdge.BOTTOM);
0890: } else if ("right".equalsIgnoreCase(titlePositionStr)) { //$NON-NLS-1$
0891: setTitlePosition(RectangleEdge.RIGHT);
0892: }
0893: }
0894: }
0895:
0896: /**
0897: * @return Returns the titlePosition.
0898: */
0899: public RectangleEdge getTitlePosition() {
0900: return titlePosition;
0901: }
0902:
0903: /**
0904: * @param titlePosition
0905: * The titlePosition to set.
0906: */
0907: public void setTitlePosition(RectangleEdge titlePosition) {
0908: this .titlePosition = titlePosition;
0909: }
0910:
0911: public void setChartBackground(Node chartBackgroundNode) {
0912: if (chartBackgroundNode != null) {
0913: Node backgroundTypeNode = chartBackgroundNode
0914: .selectSingleNode(BACKGROUND_TYPE_ATTRIBUTE_NAME);
0915: if (backgroundTypeNode != null) {
0916: String backgroundTypeStr = backgroundTypeNode.getText();
0917: if (COLOR_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) {
0918: setChartBackgroundPaint(JFreeChartEngine
0919: .getPaint(chartBackgroundNode));
0920: setChartBackgroundImage((Image) null);
0921: } else if (IMAGE_TYPE_NAME
0922: .equalsIgnoreCase(backgroundTypeStr)) {
0923: setChartBackgroundImage(chartBackgroundNode);
0924: setChartBackgroundPaint(null);
0925: } else if (TEXTURE_TYPE_NAME
0926: .equalsIgnoreCase(backgroundTypeStr)) {
0927: setChartBackgroundPaint(JFreeChartEngine
0928: .getTexturePaint(chartBackgroundNode,
0929: getWidth(), getHeight(),
0930: getSession()));
0931: setChartBackgroundImage((Image) null);
0932: } else if (GRADIENT_TYPE_NAME
0933: .equalsIgnoreCase(backgroundTypeStr)) {
0934: setChartBackgroundPaint(JFreeChartEngine
0935: .getGradientPaint(chartBackgroundNode,
0936: getWidth(), getHeight()));
0937: setChartBackgroundImage((Image) null);
0938: }
0939: }
0940: }
0941: }
0942:
0943: public void setPlotBackground(Node plotBackgroundNode) {
0944: if (plotBackgroundNode != null) {
0945: Node backgroundTypeNode = plotBackgroundNode
0946: .selectSingleNode(BACKGROUND_TYPE_ATTRIBUTE_NAME);
0947: if (backgroundTypeNode != null) {
0948: String backgroundTypeStr = backgroundTypeNode.getText();
0949: if (COLOR_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) {
0950: setPlotBackgroundPaint(JFreeChartEngine
0951: .getPaint(plotBackgroundNode));
0952: setPlotBackgroundImage((Image) null);
0953: } else if (IMAGE_TYPE_NAME
0954: .equalsIgnoreCase(backgroundTypeStr)) {
0955: setPlotBackgroundImage(plotBackgroundNode);
0956: setPlotBackgroundPaint(null);
0957: } else if (TEXTURE_TYPE_NAME
0958: .equalsIgnoreCase(backgroundTypeStr)) {
0959: setPlotBackgroundPaint(JFreeChartEngine
0960: .getTexturePaint(plotBackgroundNode,
0961: getWidth(), getHeight(),
0962: getSession()));
0963: setPlotBackgroundImage((Image) null);
0964: } else if (GRADIENT_TYPE_NAME
0965: .equalsIgnoreCase(backgroundTypeStr)) {
0966: setPlotBackgroundPaint(JFreeChartEngine
0967: .getGradientPaint(plotBackgroundNode,
0968: getWidth(), getHeight()));
0969: setPlotBackgroundImage((Image) null);
0970: }
0971: }
0972: }
0973: }
0974:
0975: public void setDomainTitle(Node titleNode) {
0976: if (titleNode != null) {
0977: setDomainTitle(titleNode.getText());
0978: }
0979: }
0980:
0981: /**
0982: * @return Returns the domainTitle.
0983: */
0984: public String getDomainTitle() {
0985: return domainTitle;
0986: }
0987:
0988: /**
0989: * @param domainTitle
0990: * The domainTitle to set.
0991: */
0992: public void setDomainTitle(String domainTitle) {
0993: this .domainTitle = domainTitle;
0994: }
0995:
0996: public void setRangeTitle(Node titleNode) {
0997: if (titleNode != null) {
0998: setRangeTitle(titleNode.getText());
0999: }
1000: }
1001:
1002: /**
1003: * @return Returns the rangeTitle.
1004: */
1005: public String getRangeTitle() {
1006: return rangeTitle;
1007: }
1008:
1009: /**
1010: * @param rangeTitle
1011: * The rangeTitle to set.
1012: */
1013: public void setRangeTitle(String rangeTitle) {
1014: this .rangeTitle = rangeTitle;
1015: }
1016:
1017: public void setDomainTitleFont(Node titleFontNode) {
1018: Font font = JFreeChartEngine.getFont(titleFontNode);
1019: if (font != null) {
1020: setDomainTitleFont(font);
1021: }
1022: }
1023:
1024: /**
1025: * @return Returns the domainTitleFont.
1026: */
1027: public Font getDomainTitleFont() {
1028: return domainTitleFont;
1029: }
1030:
1031: /**
1032: * @param domainTitleFont
1033: * The domainTitleFont to set.
1034: */
1035: public void setDomainTitleFont(Font domainTitleFont) {
1036: this .domainTitleFont = domainTitleFont;
1037: }
1038:
1039: public void setRangeTitleFont(Node titleFontNode) {
1040: Font font = JFreeChartEngine.getFont(titleFontNode);
1041: if (font != null) {
1042: setRangeTitleFont(font);
1043: }
1044: }
1045:
1046: /**
1047: * @return Returns the rangeTitleFont.
1048: */
1049: public Font getRangeTitleFont() {
1050: return rangeTitleFont;
1051: }
1052:
1053: /**
1054: * @param rangeTitleFont
1055: * The rangeTitleFont to set.
1056: */
1057: public void setRangeTitleFont(Font rangeTitleFont) {
1058: this .rangeTitleFont = rangeTitleFont;
1059: }
1060:
1061: public boolean isDisplayLabels() {
1062: // TODO Auto-generated method stub
1063: return false;
1064: }
1065:
1066: public IPentahoSession getSession() {
1067: return session;
1068: }
1069:
1070: public void setSession(IPentahoSession session) {
1071: this .session = session;
1072: }
1073:
1074: //--------------------------------------------------
1075: /**
1076: * @return Returns the dot height.
1077: */
1078: public int getDotHeight() {
1079: return dotHeight;
1080: }
1081:
1082: public void setDotHeight(Node heightNode) {
1083: if (heightNode != null) {
1084: setDotHeight(Integer.parseInt(heightNode.getText()));
1085: }
1086: }
1087:
1088: /**
1089: * @param height
1090: * The dot height to set.
1091: */
1092: public void setDotHeight(int height) {
1093: this .dotHeight = height;
1094: }
1095:
1096: /**
1097: * @return Returns the dot width.
1098: */
1099: public int getDotWidth() {
1100: return dotWidth;
1101: }
1102:
1103: public void setDotWidth(Node widthNode) {
1104: if (widthNode != null) {
1105: setDotWidth(Integer.parseInt(widthNode.getText()));
1106: }
1107: }
1108:
1109: /**
1110: * @param width
1111: * The dot width to set.
1112: */
1113: public void setDotWidth(int width) {
1114: this .dotWidth = width;
1115: }
1116:
1117: /**
1118: *
1119: * @return returns the style set for the lines
1120: * @see ChartDefinition.LINE_STYLE_SOLID_STR
1121: * @see ChartDefinition.LINE_STYLE_DASH_STR
1122: * @see ChartDefinition.LINE_STYLE_DOT_STR
1123: * @see ChartDefinition.LINE_STYLE_DASHDOT_STR
1124: * @see ChartDefinition.LINE_STYLE_DASHDOTDOT_STR
1125: */
1126: public String getLineStyle() {
1127: return lineStyle;
1128: }
1129:
1130: /**
1131: *
1132: * @param lineStyle set the style for all line series
1133: * @see ChartDefinition.LINE_STYLE_SOLID_STR
1134: * @see ChartDefinition.LINE_STYLE_DASH_STR
1135: * @see ChartDefinition.LINE_STYLE_DOT_STR
1136: * @see ChartDefinition.LINE_STYLE_DASHDOT_STR
1137: * @see ChartDefinition.LINE_STYLE_DASHDOTDOT_STR
1138: */
1139: public void setLineStyle(String lineStyle) {
1140: this .lineStyle = lineStyle;
1141: }
1142:
1143: /**
1144: *
1145: * @param lineStyleNode set the style from an XML node
1146: */
1147: public void setLineStyle(Node lineStyleNode) {
1148: if (lineStyleNode != null) {
1149: setLineStyle(lineStyleNode.getText());
1150: }
1151: }
1152:
1153: /**
1154: *
1155: * @return the width of all line series
1156: * Valid values are float numbers zero or greater
1157: */
1158: public float getLineWidth() {
1159: return lineWidth;
1160: }
1161:
1162: /**
1163: *
1164: * @param lineWidth set the width of all line series
1165: * Valid values are float numbers zero or greater
1166: */
1167: public void setLineWidth(float lineWidth) {
1168: this .lineWidth = lineWidth;
1169: }
1170:
1171: /**
1172: *
1173: * @param lineWidthNode set the line width from an XML node
1174: */
1175: public void setLineWidth(Node lineWidthNode) {
1176: if (lineWidthNode != null) {
1177: setLineWidth(Float.parseFloat(lineWidthNode.getText()));
1178: }
1179: }
1180:
1181: /**
1182: *
1183: * @return boolean whether the markers (data points) for all series are displayed
1184: */
1185: public boolean isMarkersVisible() {
1186: return markersVisible;
1187: }
1188:
1189: /**
1190: *
1191: * @param markersVisible set whether the markers (data points) for all series should be displayed
1192: */
1193: public void setMarkersVisible(boolean markersVisible) {
1194: this .markersVisible = markersVisible;
1195: }
1196:
1197: /**
1198: *
1199: * @param markersVisibleNode set the markers visibility from an XML node
1200: */
1201: public void setMarkersVisible(Node markersVisibleNode) {
1202: if (markersVisibleNode != null) {
1203: String boolStr = markersVisibleNode.getText();
1204: Boolean booleanValue = new Boolean(boolStr);
1205: setMarkersVisible(booleanValue.booleanValue());
1206: }
1207: }
1208:
1209: /**
1210: * Return the java.awt.Font to be used to display the legend items
1211: *
1212: * @return Font The font for the legend items
1213: */
1214: public Font getLegendFont() {
1215: // TODO Auto-generated method stub
1216: return legendFont;
1217: }
1218:
1219: /**
1220: * Set java.awt.Font to be used to display the legend items
1221: *
1222: * @param Font The java.awt.Font for the legend items
1223: */
1224: public void setLegendFont(Font legendFont) {
1225: this .legendFont = legendFont;
1226: }
1227:
1228: public void setLegendFont(Node legendFontNode) {
1229: Font font = JFreeChartEngine.getFont(legendFontNode);
1230: if (font != null) {
1231: setLegendFont(font);
1232: }
1233: }
1234:
1235: public void setLegendBorderVisible(Node legendBorderVisibleNode) {
1236: if (legendBorderVisibleNode != null) {
1237: boolean legBorderVisible = (new Boolean(
1238: legendBorderVisibleNode.getText())).booleanValue();
1239: setLegendBorderVisible(legBorderVisible);
1240: }
1241: }
1242:
1243: /**
1244: * @param boolean legendBorderVisible
1245: * Set the visibility of the legend border.
1246: */
1247: public void setLegendBorderVisible(boolean legendBorderVisible) {
1248: this .legendBorderVisible = legendBorderVisible;
1249: }
1250:
1251: /**
1252: * Return the boolen that states if the legend border is visible
1253: *
1254: * @return boolean Is the legend border visible
1255: */
1256: public boolean isLegendBorderVisible() {
1257: // TODO Auto-generated method stub
1258: return legendBorderVisible;
1259: }
1260:
1261: /**
1262: * Return the range axis' minimum value
1263: *
1264: * @return double Range axis' minimum value
1265: */
1266: public double getRangeMinimum() {
1267: return rangeMinimum;
1268: }
1269:
1270: public void setRangeMinimum(Node rangeMinimumNode) {
1271: if (rangeMinimumNode != null) {
1272: setRangeMinimum(Double.parseDouble(rangeMinimumNode
1273: .getText()));
1274: }
1275:
1276: }
1277:
1278: /**
1279: * @param double rangeMinimum
1280: * Set the minimum value of the range axis.
1281: */
1282: public void setRangeMinimum(double rangeMinimum) {
1283: this .rangeMinimum = rangeMinimum;
1284: }
1285:
1286: /**
1287: * Return the range axis' maximum value
1288: *
1289: * @return double Range axis' maximum value
1290: */
1291: public double getRangeMaximum() {
1292: return rangeMaximum;
1293: }
1294:
1295: public void setRangeMaximum(Node rangeMaximumNode) {
1296: if (rangeMaximumNode != null) {
1297: setRangeMaximum(Double.parseDouble(rangeMaximumNode
1298: .getText()));
1299: }
1300:
1301: }
1302:
1303: public void setDateMaximum(Date dateMaximum) {
1304: this .dateMaximum = dateMaximum;
1305: }
1306:
1307: public Date getDateMaximum() {
1308: return dateMaximum;
1309: }
1310:
1311: public void setDateMaximum(Node dateMaximumNode) {
1312: if (dateMaximumNode != null) {
1313: try {
1314: setDateMaximum(DateFormat.getDateInstance().parse(
1315: dateMaximumNode.getText()));
1316: } catch (ParseException e) {
1317: getLogger()
1318: .error(
1319: Messages
1320: .getString(
1321: "TimeSeriesCollectionChartDefinition.ERROR_0001_INVALID_DATE", //$NON-NLS-1$
1322: dateMaximumNode
1323: .getText()), e);
1324: }
1325: }
1326: }
1327:
1328: public void setDateMinimum(Date dateMinimum) {
1329: this .dateMinimum = dateMinimum;
1330: }
1331:
1332: public Date getDateMinimum() {
1333: return dateMinimum;
1334: }
1335:
1336: public void setDateMinimum(Node dateMinimumNode) {
1337: if (dateMinimumNode != null) {
1338: try {
1339: setDateMinimum(DateFormat.getDateInstance().parse(
1340: dateMinimumNode.getText()));
1341: } catch (ParseException e) {
1342: getLogger()
1343: .error(
1344: Messages
1345: .getString(
1346: "TimeSeriesCollectionChartDefinition.ERROR_0001_INVALID_DATE", //$NON-NLS-1$
1347: dateMinimumNode
1348: .getText()), e);
1349: }
1350: }
1351: }
1352:
1353: /**
1354: * @param double rangeMaximum
1355: * Set the maximum value of the range axis.
1356: */
1357: public void setRangeMaximum(double rangeMaximum) {
1358: this .rangeMaximum = rangeMaximum;
1359: }
1360:
1361: public String getNoDataMessage() {
1362: return noDataMessage;
1363: }
1364:
1365: public String getTooltipContent() {
1366: return tooltipContent;
1367: }
1368:
1369: public void setTooltipContent(String tooltipContent) {
1370: this .tooltipContent = tooltipContent;
1371: }
1372:
1373: public String getTooltipXFormat() {
1374: return tooltipXFormat;
1375: }
1376:
1377: public void setTooltipXFormat(String tooltipXFormat) {
1378: this .tooltipXFormat = tooltipXFormat;
1379: }
1380:
1381: public String getTooltipYFormat() {
1382: return tooltipYFormat;
1383: }
1384:
1385: public void setTooltipYFormat(String tooltipYFormat) {
1386: this .tooltipYFormat = tooltipYFormat;
1387: }
1388:
1389: public void setTooltipContent(Node node) {
1390: if (node != null) {
1391: setTooltipContent(node.getText());
1392: }
1393: }
1394:
1395: public void setTooltipXFormat(Node node) {
1396: if (node != null) {
1397: setTooltipXFormat(node.getText());
1398: }
1399: }
1400:
1401: public void setTooltipYFormat(Node node) {
1402: if (node != null) {
1403: setTooltipYFormat(node.getText());
1404: }
1405: }
1406:
1407: }
|