Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java @ 3871:a65eb6d44122
i18n for area label (fix issue487).
flys-artifacts/trunk@5504 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 18 Sep 2012 12:03:15 +0000 |
parents | 2a8919e0ed28 |
children | d12f108ccc9c |
comparison
equal
deleted
inserted
replaced
3870:0c16eace7b6c | 3871:a65eb6d44122 |
---|---|
119 import org.jfree.chart.renderer.xy.XYItemRenderer; | 119 import org.jfree.chart.renderer.xy.XYItemRenderer; |
120 import org.jfree.chart.renderer.xy.XYItemRendererState; | 120 import org.jfree.chart.renderer.xy.XYItemRendererState; |
121 | 121 |
122 import gnu.trove.TDoubleArrayList; | 122 import gnu.trove.TDoubleArrayList; |
123 | 123 |
124 import de.intevation.flys.artifacts.resources.Resources; | |
124 import de.intevation.flys.artifacts.math.Linear; | 125 import de.intevation.flys.artifacts.math.Linear; |
126 | |
127 import java.text.NumberFormat; | |
125 | 128 |
126 import org.apache.log4j.Logger; | 129 import org.apache.log4j.Logger; |
127 | 130 |
128 /** | 131 /** |
129 * A renderer for an {@link XYPlot} that highlights the differences between two | 132 * A renderer for an {@link XYPlot} that highlights the differences between two |
176 /** The background color of the label showing the calculated area. */ | 179 /** The background color of the label showing the calculated area. */ |
177 protected Color labelBGColor; | 180 protected Color labelBGColor; |
178 | 181 |
179 /** Font to draw label of calculated area with. */ | 182 /** Font to draw label of calculated area with. */ |
180 protected Font labelFont; | 183 protected Font labelFont; |
184 | |
185 /** Template to create i18ned label for area. */ | |
186 protected String areaLabelTamplate; | |
187 | |
188 /** NumberFormat to use for area. */ | |
189 protected NumberFormat areaLabelNumberFormat; | |
181 | 190 |
182 protected int areaCalculationMode; | 191 protected int areaCalculationMode; |
183 | 192 |
184 protected double positiveArea; | 193 protected double positiveArea; |
185 protected double negativeArea; | 194 protected double negativeArea; |
257 } | 266 } |
258 | 267 |
259 public void setAreaCalculationMode(int areaCalculationMode) { | 268 public void setAreaCalculationMode(int areaCalculationMode) { |
260 this.areaCalculationMode = areaCalculationMode; | 269 this.areaCalculationMode = areaCalculationMode; |
261 } | 270 } |
271 | |
272 | |
273 /** Set template to use to create area label (e.g. 'Area=%dm2'). */ | |
274 public void setAreaLabelTemplate(String areaTemplate) { | |
275 this.areaLabelTamplate = areaTemplate; | |
276 } | |
277 | |
278 | |
279 public void setAreaLabelNumberFormat(NumberFormat nf) { | |
280 this.areaLabelNumberFormat = nf; | |
281 } | |
282 | |
262 | 283 |
263 public boolean isLabelArea() { | 284 public boolean isLabelArea() { |
264 return this.labelArea; | 285 return this.labelArea; |
265 } | 286 } |
266 | 287 |
878 plot, domainAxis, rangeAxis, | 899 plot, domainAxis, rangeAxis, |
879 dataset, series, item, crosshairState); | 900 dataset, series, item, crosshairState); |
880 } | 901 } |
881 | 902 |
882 // Find geometric middle, calculate area and paint a string with it here. | 903 // Find geometric middle, calculate area and paint a string with it here. |
883 // TODO also i18n | 904 if (pass == 1 && this.labelArea && areaLabelNumberFormat != null && areaLabelTamplate != null) { |
884 if (pass == 1 && this.labelArea) { | |
885 double center_x = centroid.getX(); | 905 double center_x = centroid.getX(); |
886 double center_y = centroid.getY(); | 906 double center_y = centroid.getY(); |
887 center_x = domainAxis.valueToJava2D(center_x, dataArea, | 907 center_x = domainAxis.valueToJava2D(center_x, dataArea, |
888 plot.getDomainAxisEdge()); | 908 plot.getDomainAxisEdge()); |
889 center_y = rangeAxis.valueToJava2D(center_y, dataArea, | 909 center_y = rangeAxis.valueToJava2D(center_y, dataArea, |
902 } | 922 } |
903 if (area != 0f) { | 923 if (area != 0f) { |
904 Color oldColor = g2.getColor(); | 924 Color oldColor = g2.getColor(); |
905 Font oldFont = g2.getFont(); | 925 Font oldFont = g2.getFont(); |
906 g2.setFont(labelFont); | 926 g2.setFont(labelFont); |
907 String labelText = "Area= " + area + "m2"; | 927 String labelText = String.format(this.areaLabelTamplate, |
928 areaLabelNumberFormat.format(area)); | |
908 if (labelBGColor != null) { | 929 if (labelBGColor != null) { |
909 EnhancedLineAndShapeRenderer.drawTextBox(g2, labelText, | 930 EnhancedLineAndShapeRenderer.drawTextBox(g2, labelText, |
910 (float)center_x, (float)center_y, labelBGColor); | 931 (float)center_x, (float)center_y, labelBGColor); |
911 } | 932 } |
912 g2.setColor(labelColor); | 933 g2.setColor(labelColor); |