ingo@445: package de.intevation.flys.utils; ingo@445: ingo@445: import java.text.NumberFormat; ingo@445: import java.util.Locale; ingo@445: ingo@445: import de.intevation.artifacts.CallContext; ingo@445: ingo@445: import de.intevation.flys.artifacts.resources.Resources; ingo@445: ingo@445: ingo@445: public final class Formatter { ingo@445: ingo@445: // WATERLEVEL FORMATTER CONSTANTS ingo@445: public static final int WATERLEVEL_KM_MIN_DIGITS = 3; ingo@445: public static final int WATERLEVEL_KM_MAX_DIGITS = 3; ingo@445: public static final int WATERLEVEL_W_MIN_DIGITS = 0; ingo@445: public static final int WATERLEVEL_W_MAX_DIGITS = 2; ingo@445: public static final int WATERLEVEL_Q_MIN_DIGITS = 0; ingo@445: public static final int WATERLEVEL_Q_MAX_DIGITS = 2; ingo@445: ingo@445: ingo@445: // COMPUTED DISCHARGE CURVE FORMATTER CONSTANTS ingo@445: public static final int COMPUTED_DISCHARGE_W_MIN_DIGITS = 2; ingo@445: public static final int COMPUTED_DISCHARGE_W_MAX_DIGITS = 2; ingo@445: public static final int COMPUTED_DISCHARGE_Q_MIN_DIGITS = 0; ingo@445: public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 0; ingo@445: ingo@445: ingo@445: // DURATION CURVE FORMATTER CONSTANTS ingo@445: public static final int DURATION_W_MIN_DIGITS = 0; ingo@445: public static final int DURATION_W_MAX_DIGITS = 2; ingo@445: public static final int DURATION_Q_MIN_DIGITS = 0; ingo@445: public static final int DURATION_Q_MAX_DIGITS = 1; ingo@445: public static final int DURATION_D_MIN_DIGITS = 0; ingo@445: public static final int DURATION_D_MAX_DIGITS = 0; ingo@445: ingo@445: ingo@445: public static NumberFormat getFormatter(CallContext c, int min, int max){ ingo@445: Locale locale = Resources.getLocale(c.getMeta()); ingo@445: NumberFormat nf = NumberFormat.getInstance(locale); ingo@445: ingo@445: nf.setMaximumFractionDigits(max); ingo@445: nf.setMinimumFractionDigits(min); ingo@445: ingo@445: return nf; ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for kilometer values in waterlevel exports. ingo@445: * ingo@445: * @return the number formatter for kilometer values. ingo@445: */ ingo@445: public static NumberFormat getWaterlevelKM(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: WATERLEVEL_KM_MIN_DIGITS, ingo@445: WATERLEVEL_KM_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for W values in waterlevel exports. ingo@445: * ingo@445: * @return the number formatter for W values. ingo@445: */ ingo@445: public static NumberFormat getWaterlevelW(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: WATERLEVEL_W_MIN_DIGITS, ingo@445: WATERLEVEL_W_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for Q values in waterlevel exports. ingo@445: * ingo@445: * @return the number formatter for Q values. ingo@445: */ ingo@445: public static NumberFormat getWaterlevelQ(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: WATERLEVEL_Q_MIN_DIGITS, ingo@445: WATERLEVEL_Q_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for W values in exports of computed ingo@445: * discharge curves. ingo@445: * ingo@445: * @return the number formatter for W values. ingo@445: */ ingo@445: public static NumberFormat getComputedDischargeW(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: COMPUTED_DISCHARGE_W_MIN_DIGITS, ingo@445: COMPUTED_DISCHARGE_W_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for Q values in exports of computed ingo@445: * discharge curves. ingo@445: * ingo@445: * @return the number formatter for Q values. ingo@445: */ ingo@445: public static NumberFormat getComputedDischargeQ(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: COMPUTED_DISCHARGE_Q_MIN_DIGITS, ingo@445: COMPUTED_DISCHARGE_Q_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for W values in duration curve exports. ingo@445: * ingo@445: * @return the number formatter for W values. ingo@445: */ ingo@445: public static NumberFormat getDurationW(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: DURATION_W_MIN_DIGITS, ingo@445: DURATION_W_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for Q values in duration curve exports. ingo@445: * ingo@445: * @return the number formatter for W values. ingo@445: */ ingo@445: public static NumberFormat getDurationQ(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: DURATION_Q_MIN_DIGITS, ingo@445: DURATION_Q_MAX_DIGITS); ingo@445: } ingo@445: ingo@445: ingo@445: /** ingo@445: * Returns the number formatter for D values in duration curve exports. ingo@445: * ingo@445: * @return the number formatter for W values. ingo@445: */ ingo@445: public static NumberFormat getDurationD(CallContext context) { ingo@445: return getFormatter( ingo@445: context, ingo@445: DURATION_D_MIN_DIGITS, ingo@445: DURATION_D_MAX_DIGITS); ingo@445: } ingo@445: } ingo@445: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :