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