# HG changeset patch # User Ingo Weinzierl # Date 1317117979 0 # Node ID 4a8251eae2173b09bfb3620c985172de01b8e986 # Parent 2df1f9facd6c64ba6e8ec479c655fed453323079 Bugfix: #68 Set number format of chart plot axes based on the CallMeta instance for each request. flys-artifacts/trunk@2832 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 2df1f9facd6c -r 4a8251eae217 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Sep 27 10:00:29 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Sep 27 10:06:19 2011 +0000 @@ -1,3 +1,16 @@ +2011-09-27 Ingo Weinzierl + + flys/issue68 (Diagramm: Werte an der Y-Achse benötigen i18n) + + * src/main/java/de/intevation/flys/exports/ChartGenerator.java: Added a + method to retrieve the current/preferred locale specified by CallMeta. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: + Introduced two methods localizeDomainAxis() and localizeRangeAxis(). + Both methods of this class override the NumberFormat used to format axes + numbers. Those methods are called by localizeAxes() - which has private + access - for each domain and range axis of the current XYPlot. + 2011-09-27 Sascha L. Teichmann * doc/conf/cache.xml: Number of cached annotations was much diff -r 2df1f9facd6c -r 4a8251eae217 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Sep 27 10:00:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Sep 27 10:06:19 2011 +0000 @@ -2,6 +2,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.Locale; import javax.xml.xpath.XPathConstants; @@ -14,6 +15,8 @@ import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.PreferredLocale; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; @@ -84,6 +87,22 @@ } + protected Locale getLocale() { + CallMeta meta = context.getMeta(); + PreferredLocale[] prefs = meta.getLanguages(); + + int len = prefs != null ? prefs.length : 0; + + Locale[] locales = new Locale[len]; + + for (int i = 0; i < len; i++) { + locales[i] = prefs[i].getLocale(); + } + + return meta.getPreferredLocale(locales); + } + + protected String msg(String key, String def) { return Resources.getMsg(context.getMeta(), key, def); } diff -r 2df1f9facd6c -r 4a8251eae217 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Sep 27 10:00:29 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Sep 27 10:06:19 2011 +0000 @@ -6,6 +6,8 @@ import java.io.IOException; +import java.text.NumberFormat; + import org.apache.log4j.Logger; import org.jfree.chart.ChartFactory; @@ -107,6 +109,7 @@ addSubtitles(chart); adjustPlot(plot); adjustAxes(plot); + localizeAxes(plot); removeEmptyRangeAxes(plot); @@ -335,6 +338,62 @@ } + /** + * This method walks over all axes (domain and range) of plot and + * calls localizeDomainAxis() for domain axes or localizeRangeAxis() for + * range axes. + * + * @param plot The XYPlot. + */ + private void localizeAxes(XYPlot plot) { + for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) { + ValueAxis axis = plot.getDomainAxis(i); + + if (axis != null) { + localizeDomainAxis(axis); + } + else { + logger.warn("Domain axis at " + i + " is null."); + } + } + + for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { + ValueAxis axis = plot.getRangeAxis(i); + + if (axis != null) { + localizeRangeAxis(axis); + } + else { + logger.warn("Range axis at " + i + " is null."); + } + } + } + + + /** + * Overrides the NumberFormat with the NumberFormat for the current locale + * that is provided by getLocale(). + * + * @param domainAxis The domain axis that needs localization. + */ + protected void localizeDomainAxis(ValueAxis domainAxis) { + NumberFormat nf = NumberFormat.getInstance(getLocale()); + ((NumberAxis) domainAxis).setNumberFormatOverride(nf); + } + + + /** + * Overrides the NumberFormat with the NumberFormat for the current locale + * that is provided by getLocale(). + * + * @param domainAxis The domain axis that needs localization. + */ + protected void localizeRangeAxis(ValueAxis rangeAxis) { + NumberFormat nf = NumberFormat.getInstance(getLocale()); + ((NumberAxis) rangeAxis).setNumberFormatOverride(nf); + } + + protected void applyThemes(XYPlot plot) { if (first != null) { applyThemes(plot, first, 0);