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