comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java @ 450:20a480753ff9

Render labels in vertical cross section charts. gnv-artifacts/trunk@498 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Jan 2010 02:49:42 +0000
parents c7ca2fce041f
children 79e80c289018
comparison
equal deleted inserted replaced
449:c7ca2fce041f 450:20a480753ff9
1 package de.intevation.gnv.chart; 1 package de.intevation.gnv.chart;
2 2
3 import java.util.Locale; 3 import java.util.Locale;
4
5 import java.text.NumberFormat;
4 6
5 import java.awt.Color; 7 import java.awt.Color;
6 import java.awt.Paint; 8 import java.awt.Paint;
7 9
8 import java.util.HashSet; 10 import java.util.HashSet;
52 ? Color.black 54 ? Color.black
53 : palette.getColor(index); 55 : palette.getColor(index);
54 } 56 }
55 } // class PalettePaintLookup 57 } // class PalettePaintLookup
56 58
59 public static class LocalizedLabelGenerator
60 extends PolygonRenderer.DefaultLabelGenerator
61 {
62 protected NumberFormat format;
63
64 public LocalizedLabelGenerator() {
65 }
66
67 public LocalizedLabelGenerator(NumberFormat format) {
68 this.format = format;
69 }
70
71 protected String toString(Object label) {
72 return label instanceof Number
73 ? format.format(((Number)label).doubleValue())
74 : super.toString(label);
75 }
76 } // class LocalizedLabelGenerator
77
57 protected JFreeChart chart; 78 protected JFreeChart chart;
58 79
59 protected AttributedXYColumns columns; 80 protected AttributedXYColumns columns;
60 protected Palette palette; 81 protected Palette palette;
61 protected Locale locale; 82 protected Locale locale;
93 if (fill != null) { 114 if (fill != null) {
94 usedColors.add(fill); 115 usedColors.add(fill);
95 } 116 }
96 } 117 }
97 118
119 NumberFormat format = NumberFormat.getInstance(locale);
120 format.setMinimumFractionDigits(0);
121 format.setMaximumFractionDigits(2);
122
98 PolygonRenderer renderer = new PolygonRenderer( 123 PolygonRenderer renderer = new PolygonRenderer(
99 new PalettePaintLookup(palette)); 124 new PalettePaintLookup(palette),
125 new LocalizedLabelGenerator(format));
100 126
101 ValueAxis domainAxis = new NumberAxis(xAxis); 127 ValueAxis domainAxis = new NumberAxis(xAxis);
102 ValueAxis rangeAxis = new NumberAxis(yAxis); 128 ValueAxis rangeAxis = new NumberAxis(yAxis);
103 129
104 PolygonPlot plot = new PolygonPlot( 130 PolygonPlot plot = new PolygonPlot(

http://dive4elements.wald.intevation.org