comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java @ 315:63f8b3fb7d9a

Localization of chart axis with locale which fits best to server and browser settings. gnv-artifacts/trunk@373 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 26 Nov 2009 08:47:44 +0000
parents f0f106c7b906
children 22a6493e8460
comparison
equal deleted inserted replaced
314:6f72e335e2c9 315:63f8b3fb7d9a
1 package de.intevation.gnv.chart; 1 package de.intevation.gnv.chart;
2 2
3 import java.awt.Color; 3 import java.awt.Color;
4 import java.text.NumberFormat;
4 import java.util.Collection; 5 import java.util.Collection;
5 import java.util.Iterator; 6 import java.util.Iterator;
7 import java.util.Locale;
6 8
7 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
8 10
9 import org.jfree.chart.JFreeChart; 11 import org.jfree.chart.JFreeChart;
10 import org.jfree.chart.ChartFactory; 12 import org.jfree.chart.ChartFactory;
13 import org.jfree.chart.axis.Axis;
11 import org.jfree.chart.axis.NumberAxis; 14 import org.jfree.chart.axis.NumberAxis;
12 import org.jfree.chart.axis.NumberTickUnit; 15 import org.jfree.chart.axis.NumberTickUnit;
13 import org.jfree.chart.axis.AxisLocation; 16 import org.jfree.chart.axis.AxisLocation;
14 import org.jfree.chart.plot.PlotOrientation; 17 import org.jfree.chart.plot.PlotOrientation;
15 import org.jfree.chart.plot.XYPlot; 18 import org.jfree.chart.plot.XYPlot;
34 protected PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL; 37 protected PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL;
35 38
36 protected abstract void initData(); 39 protected abstract void initData();
37 protected abstract void addValue(Result row, Series series); 40 protected abstract void addValue(Result row, Series series);
38 protected abstract void addSeries(Series series, int idx); 41 protected abstract void addSeries(Series series, int idx);
42 protected abstract void localizeDomainAxis(Axis axis, Locale locale);
39 protected abstract String createSeriesName( 43 protected abstract String createSeriesName(
40 String breakPoint1, 44 String breakPoint1,
41 String breakPoint2, 45 String breakPoint2,
42 String breakPoint3 46 String breakPoint3
43 ); 47 );
67 } 71 }
68 72
69 73
70 protected void prepareAxis(String seriesKey, int idx) { 74 protected void prepareAxis(String seriesKey, int idx) {
71 log.debug("prepare axis of xychart"); 75 log.debug("prepare axis of xychart");
72 XYPlot plot = chart.getXYPlot(); 76
73 NumberAxis axis = new NumberAxis(seriesKey); 77 XYPlot plot = chart.getXYPlot();
78 Axis xAxis = plot.getDomainAxis();
79 NumberAxis yAxis = new NumberAxis(seriesKey);
80
81 localizeDomainAxis(xAxis, locale);
82 localizeRangeAxis(yAxis, locale);
74 83
75 if (seriesKey.contains("richtung")) { 84 if (seriesKey.contains("richtung")) {
76 axis.setTickUnit(new NumberTickUnit(30.0)); 85 yAxis.setTickUnit(new NumberTickUnit(30.0));
77 axis.setUpperBound(360.0); 86 yAxis.setUpperBound(360.0);
78 axis.setLowerBound(0.0); 87 yAxis.setLowerBound(0.0);
79 plot.setRangeAxis(idx, axis); 88 plot.setRangeAxis(idx, yAxis);
80 } 89 }
81 else { 90 else {
82 axis.setFixedDimension(10.0); 91 yAxis.setFixedDimension(10.0);
83 axis.setAutoRangeIncludesZero(false); 92 yAxis.setAutoRangeIncludesZero(false);
84 plot.setRangeAxis(idx, axis); 93 plot.setRangeAxis(idx, yAxis);
85 axis.configure(); 94 yAxis.configure();
86 } 95 }
87 96
88 if (idx % 2 != 0) 97 if (idx % 2 != 0)
89 plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_RIGHT); 98 plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_RIGHT);
90 else 99 else
95 renderer.setSeriesPaint(idx, COLOR[idx%COLOR.length]); 104 renderer.setSeriesPaint(idx, COLOR[idx%COLOR.length]);
96 plot.setRenderer(idx, renderer); 105 plot.setRenderer(idx, renderer);
97 } 106 }
98 107
99 108
109 protected void localizeRangeAxis(Axis axis, Locale locale) {
110 if (locale == null)
111 return;
112
113 log.debug(
114 "Set language of axis [" + axis.getLabel() + "] " +
115 "to " + locale.toString()
116 );
117
118 NumberFormat format = NumberFormat.getInstance(locale);
119 ((NumberAxis) axis).setNumberFormatOverride(format);
120 }
121
122
100 protected String findValueTitle(Collection values, String id) { 123 protected String findValueTitle(Collection values, String id) {
101 log.debug("find description of dataset"); 124 log.debug("find description of dataset");
102 125
103 if (values != null){ 126 if (values != null){
104 Iterator it = values.iterator(); 127 Iterator it = values.iterator();
105 while (it.hasNext()) { 128 while (it.hasNext()) {
106 KeyValueDescibeData data = (KeyValueDescibeData) it.next(); 129 KeyValueDescibeData data = (KeyValueDescibeData) it.next();
107 130
108 if (id.equals(data.getKey())) 131 if (id.equals(data.getKey()))
109 return data.getValue(); 132 return data.getValue();
110 } 133 }
111 } 134 }
112 return ""; 135 return "";
113 } 136 }
114 } 137 }
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 : 138 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org