comparison artifacts/src/main/java/org/dive4elements/river/utils/ThemeUtil.java @ 6170:194a99865d73

createWSPLGENClassName() now respects user locale (#767).
author Christian Lins <christian.lins@intevation.de>
date Mon, 03 Jun 2013 14:56:10 +0200
parents ebfc161cc5c4
children 8b03a7589101
comparison
equal deleted inserted replaced
6169:bd291447fef1 6170:194a99865d73
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.utils; 9 package org.dive4elements.river.utils;
10 10
11 import org.dive4elements.artifacts.CallMeta;
11 import org.dive4elements.artifacts.common.utils.XMLUtils; 12 import org.dive4elements.artifacts.common.utils.XMLUtils;
12 import org.dive4elements.river.artifacts.model.MapserverStyle; 13 import org.dive4elements.river.artifacts.model.MapserverStyle;
13 import org.dive4elements.river.artifacts.model.MapserverStyle.Clazz; 14 import org.dive4elements.river.artifacts.model.MapserverStyle.Clazz;
14 import org.dive4elements.river.artifacts.model.MapserverStyle.Expression; 15 import org.dive4elements.river.artifacts.model.MapserverStyle.Expression;
15 import org.dive4elements.river.artifacts.model.MapserverStyle.Label; 16 import org.dive4elements.river.artifacts.model.MapserverStyle.Label;
16 import org.dive4elements.river.artifacts.model.MapserverStyle.Style; 17 import org.dive4elements.river.artifacts.model.MapserverStyle.Style;
18 import org.dive4elements.river.artifacts.resources.Resources;
17 19
18 import java.awt.Color; 20 import java.awt.Color;
19 import java.awt.Font; 21 import java.awt.Font;
22 import java.text.NumberFormat;
23 import java.util.Locale;
20 24
21 import org.apache.log4j.Logger; 25 import org.apache.log4j.Logger;
22 import org.w3c.dom.Document; 26 import org.w3c.dom.Document;
23 27
24 28
667 * given number of color classes for the MapserverStyle. 671 * given number of color classes for the MapserverStyle.
668 * @param theme 672 * @param theme
669 * @return String representation of the MapserverStyle 673 * @return String representation of the MapserverStyle
670 */ 674 */
671 public static String createDynamicMapserverStyle(Document theme, 675 public static String createDynamicMapserverStyle(Document theme,
672 float from, float to, float step) 676 float from, float to, float step, CallMeta meta)
673 { 677 {
674 MapserverStyle ms = new MapserverStyle(); 678 MapserverStyle ms = new MapserverStyle();
675 679
676 String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null); 680 String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null);
677 Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215); 681 Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215);
699 newColor.append(startColor.getGreen() + Math.round(n * gd)); 703 newColor.append(startColor.getGreen() + Math.round(n * gd));
700 newColor.append(' '); 704 newColor.append(' ');
701 newColor.append(startColor.getBlue() + Math.round(n * bd)); 705 newColor.append(startColor.getBlue() + Math.round(n * bd));
702 706
703 String expr = createWSPLGENClassExpression(from + n * step, step, n + 1, numClasses); 707 String expr = createWSPLGENClassExpression(from + n * step, step, n + 1, numClasses);
704 String name = createWSPLGENClassName(from + n * step, step, n + 1, numClasses); 708 String name = createWSPLGENClassName(from + n * step, step, n + 1, numClasses, meta);
705 709
706 Clazz c = new Clazz(name); 710 Clazz c = new Clazz(name);
707 Style s = new Style(); 711 Style s = new Style();
708 s.setColor(newColor.toString()); 712 s.setColor(newColor.toString());
709 s.setSize(5); 713 s.setSize(5);
726 return "[DIFF] >= " + val; 730 return "[DIFF] >= " + val;
727 } 731 }
728 } 732 }
729 733
730 // FIXME: i18n 734 // FIXME: i18n
731 protected static String createWSPLGENClassName(float val, float step, int idx, int maxIdx) { 735 protected static String createWSPLGENClassName(float val, float step, int idx, int maxIdx, CallMeta meta) {
736 Locale locale = Resources.getLocale(meta);
737 NumberFormat nf = NumberFormat.getInstance(locale);
732 if (idx < maxIdx) { 738 if (idx < maxIdx) {
733 return "[Differenz] >= " + val + "m UND [Differenz] < " + (val + step) + "m"; 739 return "[Differenz] >= "
740 + nf.format(val)
741 + " m UND [Differenz] < "
742 + nf.format(val + step)
743 + " m";
734 } 744 }
735 else { 745 else {
736 return "[Differenz] >= " + val + "m"; 746 return "[Differenz] >= "
747 + nf.format(val) + " m";
737 } 748 }
738 } 749 }
739 750
740 751
741 public static String createMapserverStyle(Document theme) { 752 public static String createMapserverStyle(Document theme) {

http://dive4elements.wald.intevation.org