sascha@446: package de.intevation.gnv.chart; sascha@446: sascha@446: import java.util.Locale; sascha@446: sascha@446: import java.awt.Color; sascha@446: import java.awt.Paint; sascha@446: sascha@446: import de.intevation.gnv.math.AttributedXYColumns; sascha@446: sascha@446: import de.intevation.gnv.jfreechart.PolygonDataset; sascha@446: import de.intevation.gnv.jfreechart.PolygonPlot; sascha@446: import de.intevation.gnv.jfreechart.PolygonRenderer; sascha@446: sascha@446: import de.intevation.gnv.raster.Palette; sascha@446: sascha@446: import org.jfree.chart.JFreeChart; sascha@446: sascha@446: import org.jfree.chart.plot.PlotOrientation; sascha@446: sascha@446: import org.jfree.chart.axis.ValueAxis; sascha@446: import org.jfree.chart.axis.NumberAxis; sascha@446: import org.jfree.chart.axis.SymbolAxis; sascha@446: sascha@446: import org.jfree.chart.title.PaintScaleLegend; sascha@446: sascha@446: import org.jfree.chart.renderer.LookupPaintScale; sascha@446: sascha@446: import org.jfree.ui.RectangleEdge; sascha@446: import org.jfree.ui.RectangleInsets; sascha@446: sascha@446: /** sascha@446: * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) sascha@446: * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) sascha@446: */ sascha@446: public class VerticalCrossSectionChart sascha@446: implements Chart sascha@446: { sascha@446: public static final class PalettePaintLookup sascha@446: implements PolygonRenderer.PaintLookup sascha@446: { sascha@446: private Palette palette; sascha@446: sascha@446: public PalettePaintLookup(Palette palette) { sascha@446: this.palette = palette; sascha@446: } sascha@446: sascha@446: public Paint getPaint(int index) { sascha@446: return index < 0 sascha@446: ? Color.black sascha@446: : palette.getColor(index); sascha@446: } sascha@446: } // class PalettePaintLookup sascha@446: sascha@446: protected JFreeChart chart; sascha@446: sascha@446: protected AttributedXYColumns columns; sascha@446: protected Palette palette; sascha@446: protected Locale locale; sascha@446: sascha@446: public VerticalCrossSectionChart() { sascha@446: } sascha@446: sascha@446: public VerticalCrossSectionChart( sascha@446: AttributedXYColumns columns, sascha@446: Palette palette, sascha@446: Locale locale sascha@446: ) { sascha@446: this.columns = columns; sascha@446: this.palette = palette; sascha@446: this.locale = locale; sascha@446: } sascha@446: sascha@446: protected JFreeChart createChart() { sascha@446: sascha@446: String title = "Neues 2D-Diagramm"; sascha@446: String xAxis = "x-Achse des Diagramms"; sascha@446: String yAxis = "y-Achse des Diagramms"; sascha@446: boolean legendB = false; sascha@446: boolean tooltips = false; sascha@446: boolean urls = false; sascha@446: sascha@446: PlotOrientation po = PlotOrientation.HORIZONTAL; sascha@446: PolygonDataset data = columns.getPolygonDataset(); sascha@446: sascha@446: PolygonRenderer renderer = new PolygonRenderer( sascha@446: new PalettePaintLookup(palette)); sascha@446: sascha@446: ValueAxis domainAxis = new NumberAxis(xAxis); sascha@446: ValueAxis rangeAxis = new NumberAxis(yAxis); sascha@446: sascha@446: PolygonPlot plot = new PolygonPlot( sascha@446: data, sascha@446: renderer, sascha@446: domainAxis, sascha@446: rangeAxis, sascha@446: null); sascha@446: sascha@446: int colors = palette.getSize(); sascha@446: LookupPaintScale lookupPaint = sascha@446: new LookupPaintScale(-0.5d, colors-0.5d, Color.white); sascha@446: sascha@446: Color color = null; sascha@446: sascha@446: String [] labels = new String[colors]; sascha@446: for (int i = 0; i < colors; i++) { sascha@446: color = palette.getColor(colors-1-i); sascha@446: labels[i] = palette.getEntryByIndex(colors-1-i).getDescription(); sascha@446: lookupPaint.add(i-0.5d, color); sascha@446: } sascha@446: sascha@446: JFreeChart chart = new JFreeChart( sascha@446: title, sascha@446: JFreeChart.DEFAULT_TITLE_FONT, sascha@446: plot, sascha@446: legendB); sascha@446: sascha@446: chart.removeLegend(); sascha@446: sascha@446: SymbolAxis scale = new SymbolAxis("Temperatur", labels); sascha@446: scale.setRange(-1.5d, colors+0.5d); sascha@446: scale.setGridBandsVisible(false); sascha@446: scale.setPlot(plot); sascha@446: sascha@446: PaintScaleLegend legend = new PaintScaleLegend( sascha@446: lookupPaint, scale); sascha@446: legend.setMargin(new RectangleInsets(3d, 10d, 3d, 10d)); sascha@446: legend.setPosition(RectangleEdge.LEFT); sascha@446: legend.setAxisOffset(5d); sascha@446: sascha@446: chart.addSubtitle(legend); sascha@446: sascha@446: return chart; sascha@446: } sascha@446: sascha@446: public JFreeChart generateChart() { sascha@446: if (chart == null) { sascha@446: chart = createChart(); sascha@446: } sascha@446: return chart; sascha@446: } sascha@446: } sascha@446: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :