Search in sources :

Example 1 with MeterInterval

use of org.jfree.chart.plot.MeterInterval in project pentaho-platform by pentaho.

the class JFreeChartEngine method updatePlot.

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());
    plot.setNoDataMessage(chartDefinition.getNoDataMessage());
    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }
    // TODO define outline stroke
    plot.setOutlineStroke(null);
    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }
            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }
    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            // $NON-NLS-1$
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}");
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext(); ) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                // $NON-NLS-1$
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})");
                pie.setLabelGenerator(labelGen);
            } else {
                // $NON-NLS-1$
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})");
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }
        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));
    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }
            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }
        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }
            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }
            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }
        }
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) MeterInterval(org.jfree.chart.plot.MeterInterval) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) Range(org.jfree.data.Range) CategoryPlot(org.jfree.chart.plot.CategoryPlot) MeterPlot(org.jfree.chart.plot.MeterPlot) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) XYPlot(org.jfree.chart.plot.XYPlot) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) Iterator(java.util.Iterator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) List(java.util.List) DefaultDrawingSupplier(org.jfree.chart.plot.DefaultDrawingSupplier)

Example 2 with MeterInterval

use of org.jfree.chart.plot.MeterInterval in project SIMVA-SoS by SESoS.

the class MeterChartTest method testDrawWithNullInfo.

/**
 * Draws the chart with a single range.  At one point, this caused a null
 * pointer exception (fixed now).
 */
@Test
public void testDrawWithNullInfo() {
    MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0));
    plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0)));
    JFreeChart chart = new JFreeChart(plot);
    BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
    g2.dispose();
// FIXME we should really assert a value here
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) MeterInterval(org.jfree.chart.plot.MeterInterval) Rectangle2D(java.awt.geom.Rectangle2D) Range(org.jfree.data.Range) MeterPlot(org.jfree.chart.plot.MeterPlot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Test(org.junit.Test)

Example 3 with MeterInterval

use of org.jfree.chart.plot.MeterInterval in project dhis2-core by dhis2.

the class DefaultChartService method getGaugeChart.

private JFreeChart getGaugeChart(PlotData plotData, ValueDataset dataSet) {
    MeterPlot meterPlot = new MeterPlot(dataSet);
    meterPlot.setUnits("");
    meterPlot.setRange(new Range(0.0d, 100d));
    for (int i = 0; i < 10; i++) {
        double start = i * 10d;
        double end = start + 10d;
        String label = String.valueOf(start);
        meterPlot.addInterval(new MeterInterval(label, new Range(start, end), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY));
    }
    meterPlot.setMeterAngle(180);
    meterPlot.setDialBackgroundPaint(COLOR_LIGHT_GRAY);
    meterPlot.setDialShape(DialShape.CHORD);
    meterPlot.setNeedlePaint(COLORS[0]);
    meterPlot.setTickLabelsVisible(true);
    meterPlot.setTickLabelFont(LABEL_FONT);
    meterPlot.setTickLabelPaint(Color.BLACK);
    meterPlot.setTickPaint(COLOR_LIGHTER_GRAY);
    meterPlot.setValueFont(TITLE_FONT);
    meterPlot.setValuePaint(Color.BLACK);
    JFreeChart meterChart = new JFreeChart(plotData.getName(), meterPlot);
    setBasicConfig(meterChart, plotData);
    meterChart.removeLegend();
    return meterChart;
}
Also used : MeterInterval(org.jfree.chart.plot.MeterInterval) Range(org.jfree.data.Range) MeterPlot(org.jfree.chart.plot.MeterPlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with MeterInterval

use of org.jfree.chart.plot.MeterInterval in project pentaho-platform by pentaho.

the class DialWidgetDefinition method createDial.

/*
   * public ThermometerWidgetDefinition createThermometer( Document doc ) { // TODO implement this to return a
   * ThermometerWidgetDefinition object return null; }
   */
/**
 * Create a dial definition object from an XML document
 *
 * @param doc
 *          definition XML document
 * @return Dial definition object
 */
public static void createDial(final DialWidgetDefinition widgetDefinition, final Node dialNode, final int width, final int height, final IPentahoSession session) {
    // $NON-NLS-1$
    Node node = dialNode.selectSingleNode("units");
    if (node != null) {
        String units = node.getText();
        widgetDefinition.setUnits(units);
    }
    // set the background Paint
    // $NON-NLS-1$
    Paint paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("background-color"));
    if (paint == null) {
        // $NON-NLS-1$
        Element backgroundNode = (Element) dialNode.selectSingleNode("chart-background");
        if (backgroundNode != null) {
            // $NON-NLS-1$
            String backgroundType = backgroundNode.attributeValue("type");
            if ("texture".equals(backgroundType)) {
                // $NON-NLS-1$
                paint = JFreeChartEngine.getTexturePaint(backgroundNode, width, height, session);
            } else if ("gradient".equals(backgroundType)) {
                // $NON-NLS-1$
                paint = JFreeChartEngine.getGradientPaint(backgroundNode, width, height);
            }
        }
    } else {
        // log a deprecation warning for background-color ...
        DialWidgetDefinition.getLogger().warn(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Messages.getInstance().getString("CHART.WARN_DEPRECATED_PROPERTY", "background-color", "chart-background"));
        DialWidgetDefinition.getLogger().warn(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "background-color"));
    }
    if (paint != null) {
        widgetDefinition.setChartBackgroundPaint(paint);
    }
    // set the dial background Paint
    // $NON-NLS-1$
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("plot-background-color"));
    if (paint == null) {
        // $NON-NLS-1$
        Element backgroundNode = (Element) dialNode.selectSingleNode("plot-background");
        if (backgroundNode != null) {
            // $NON-NLS-1$
            String backgroundType = backgroundNode.attributeValue("type");
            if ("texture".equals(backgroundType)) {
                // $NON-NLS-1$
                paint = JFreeChartEngine.getTexturePaint(backgroundNode, width, height, session);
            } else if ("gradient".equals(backgroundType)) {
                // $NON-NLS-1$
                paint = JFreeChartEngine.getGradientPaint(backgroundNode, width, height);
            }
        }
    } else {
        // log a deprecation warning for plot-background-color ...
        DialWidgetDefinition.getLogger().warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_PROPERTY", "plot-background-color", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "plot-background"));
        DialWidgetDefinition.getLogger().warn(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "plot-background-color"));
    }
    if (paint != null) {
        widgetDefinition.setPlotBackgroundPaint(paint);
    }
    // set the needle Paint
    // $NON-NLS-1$
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("needle-color"));
    if (paint != null) {
        widgetDefinition.setNeedlePaint(paint);
    }
    // set the tick Paint
    // $NON-NLS-1$
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("tick-color"));
    if (paint != null) {
        widgetDefinition.setTickPaint(paint);
    }
    // $NON-NLS-1$
    Node tmpNode = dialNode.selectSingleNode("tick-interval");
    if (tmpNode != null) {
        // $NON-NLS-1$
        widgetDefinition.setTickSize(Integer.parseInt(dialNode.selectSingleNode("tick-interval").getText()));
    }
    // set the value Paint
    // $NON-NLS-1$
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("value-color"));
    if (paint != null) {
        widgetDefinition.setValuePaint(paint);
    }
    // TODO get this from the XML document
    widgetDefinition.setDialShape(DialShape.CHORD);
    // $NON-NLS-1$
    Node titleFontNode = dialNode.selectSingleNode("title-font");
    if (titleFontNode != null) {
        // $NON-NLS-1$
        Node fontNode = titleFontNode.selectSingleNode("font");
        if (fontNode != null) {
            String titleFontStr = fontNode.getText().trim();
            if (!"".equals(titleFontStr)) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                Node titleFontSizeNode = titleFontNode.selectSingleNode("size");
                int size = titleFontSizeNode != null ? Integer.parseInt(titleFontSizeNode.getText()) : 12;
                widgetDefinition.setTitleFont(new Font(titleFontStr, Font.BOLD, size));
            }
        } else {
            String titleFontStr = titleFontNode.getText().trim();
            if (!"".equals(titleFontStr)) {
                // $NON-NLS-1$
                widgetDefinition.setTitleFont(new Font(titleFontStr, Font.ITALIC, 24));
            }
        }
    }
    // $NON-NLS-1$
    Node valueFontNode = dialNode.selectSingleNode("domain-tick-font");
    if (valueFontNode != null) {
        // $NON-NLS-1$
        Node fontNode = valueFontNode.selectSingleNode("font");
        if (fontNode != null) {
            String fontStr = fontNode.getText().trim();
            if (!"".equals(fontStr)) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                Node valueFontSizeNode = valueFontNode.selectSingleNode("size");
                int size = valueFontSizeNode != null ? Integer.parseInt(valueFontSizeNode.getText()) : 12;
                widgetDefinition.setValueFont(new Font(fontStr, Font.BOLD, size));
            }
        } else {
            String fontStr = valueFontNode.getText().trim();
            if (!"".equals(fontStr)) {
                // $NON-NLS-1$
                widgetDefinition.setValueFont(new Font(fontStr, Font.ITALIC, 24));
            }
        }
    }
    // set any intervals that are defined in the document
    // A list of interval nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <interval> as a child of the main node , and now require an <intervals> parent node
    // under which <intervals> can exist.
    // $NON-NLS-1$
    List intervals = dialNode.selectNodes("interval");
    if ((intervals == null) || (intervals.isEmpty())) {
        // $NON-NLS-1$
        Node intervalsNode = dialNode.selectSingleNode("intervals");
        if (intervalsNode != null) {
            // $NON-NLS-1$
            intervals = intervalsNode.selectNodes("interval");
        }
    } else {
        // log a deprecation warning for this property...
        DialWidgetDefinition.getLogger().warn(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", "interval", "intervals"));
        DialWidgetDefinition.getLogger().warn(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "interval"));
    }
    if (intervals != null) {
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            // get the interval node
            Node intervalNode = (Node) intervalIterator.next();
            // get the interval name
            // $NON-NLS-1$
            String label = intervalNode.selectSingleNode("label").getText();
            // get the range of the interval
            // $NON-NLS-1$
            double minimum = Double.parseDouble(intervalNode.selectSingleNode("minimum").getText());
            // $NON-NLS-1$
            double maximum = Double.parseDouble(intervalNode.selectSingleNode("maximum").getText());
            Range range = new Range(minimum, maximum);
            // $NON-NLS-1$
            Paint backgroundPaint = JFreeChartEngine.getPaint(intervalNode.selectSingleNode("color"));
            if (backgroundPaint == null) {
                // $NON-NLS-1$
                Element backgroundNode = (Element) intervalNode.selectSingleNode("interval-background");
                if (backgroundNode != null) {
                    // $NON-NLS-1$
                    String backgroundType = backgroundNode.attributeValue("type");
                    if ("texture".equals(backgroundType)) {
                        // $NON-NLS-1$
                        backgroundPaint = JFreeChartEngine.getTexturePaint(backgroundNode, width, height, session);
                    } else if ("gradient".equals(backgroundType)) {
                        // $NON-NLS-1$
                        backgroundPaint = JFreeChartEngine.getGradientPaint(backgroundNode, width, height);
                    }
                }
            }
            // get the text color of the interval
            // $NON-NLS-1$
            String textColor = intervalNode.selectSingleNode("text-color").getText();
            Stroke outlineStroke;
            if (intervalNode.selectSingleNode("stroke-width") != null) {
                // $NON-NLS-1$
                outlineStroke = // $NON-NLS-1$
                new BasicStroke(Float.parseFloat(intervalNode.selectSingleNode("stroke-width").getText()));
            } else {
                outlineStroke = new BasicStroke();
            }
            Paint outlinePaint = JFreeChartEngine.getPaint(textColor);
            // create the interval object
            MeterInterval interval = new MeterInterval(label, range, outlinePaint, outlineStroke, backgroundPaint);
            // add the interval to the widget
            widgetDefinition.addInterval(interval);
        }
    }
    // get the chart subtitles
    // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node
    // under which <subtitle> can exist.
    List subtitles = dialNode.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME);
    if ((subtitles == null) || (subtitles.isEmpty())) {
        Node subTitlesNode = dialNode.selectSingleNode(ChartDefinition.SUBTITLES_NODE_NAME);
        if (subTitlesNode != null) {
            subtitles = subTitlesNode.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME);
        }
    } else {
        // log a deprecation warning for this property...
        DialWidgetDefinition.getLogger().warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", ChartDefinition.SUBTITLE_NODE_NAME, // $NON-NLS-1$
        ChartDefinition.SUBTITLES_NODE_NAME));
        DialWidgetDefinition.getLogger().warn(Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", // $NON-NLS-1$
        ChartDefinition.SUBTITLE_NODE_NAME));
    }
    if (subtitles != null) {
        widgetDefinition.addSubTitles(subtitles);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) MeterInterval(org.jfree.chart.plot.MeterInterval) Node(org.dom4j.Node) Element(org.dom4j.Element) Paint(java.awt.Paint) Range(org.jfree.data.Range) Paint(java.awt.Paint) Font(java.awt.Font) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

MeterInterval (org.jfree.chart.plot.MeterInterval)4 Range (org.jfree.data.Range)4 MeterPlot (org.jfree.chart.plot.MeterPlot)3 Iterator (java.util.Iterator)2 List (java.util.List)2 BasicStroke (java.awt.BasicStroke)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 Paint (java.awt.Paint)1 Stroke (java.awt.Stroke)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 Element (org.dom4j.Element)1 Node (org.dom4j.Node)1 JFreeChart (org.jfree.chart.JFreeChart)1 CategoryAxis (org.jfree.chart.axis.CategoryAxis)1 DateAxis (org.jfree.chart.axis.DateAxis)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 NumberTickUnit (org.jfree.chart.axis.NumberTickUnit)1