ingo@445: package de.intevation.flys.utils; ingo@445: ingo@2258: import java.text.DateFormat; ingo@445: import java.text.NumberFormat; ingo@445: import java.util.Locale; ingo@445: ingo@445: import de.intevation.artifacts.CallContext; sascha@2290: import de.intevation.artifacts.CallMeta; ingo@445: ingo@445: import de.intevation.flys.artifacts.resources.Resources; ingo@445: ingo@445: ingo@445: public final class Formatter { ingo@445: sascha@2290: // KMS IN ERROR REPORTS. sascha@2305: public static final int CALCULATION_REPORT_KM_MIN_DIGITS = 1; sascha@2290: public static final int CALCULATION_REPORT_KM_MAX_DIGITS = 3; sascha@2290: 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@1683: public static final int COMPUTED_DISCHARGE_Q_MAX_DIGITS = 2; ingo@445: ingo@445: ingo@2258: // HISTORICAL DISCHARGE CURVE FORMATTER CONSTANTS ingo@2258: public static final int HISTORICAL_DISCHARGE_W_MIN_DIGITS = 0; ingo@2258: public static final int HISTORICAL_DISCHARGE_W_MAX_DIGITS = 2; ingo@2258: public static final int HISTORICAL_DISCHARGE_Q_MIN_DIGITS = 0; ingo@2258: public static final int HISTORICAL_DISCHARGE_Q_MAX_DIGITS = 2; ingo@2258: ingo@2258: 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@2702: // FLOW VELOCITY FORMATTER CONSTANTS ingo@2702: public static final int FLOW_VELOCITY_KM_MIN_DIGITS = 3; ingo@2702: public static final int FLOW_VELOCITY_KM_MAX_DIGITS = 3; ingo@2702: public static final int FLOW_VELOCITY_VALUES_MIN_DIGITS = 2; ingo@2702: public static final int FLOW_VELOCITY_VALUES_MAX_DIGITS = 2; ingo@2702: public static final int FLOW_VELOCITY_Q_MIN_DIGITS = 0; ingo@2702: public static final int FLOW_VELOCITY_Q_MAX_DIGITS = 2; ingo@2702: ingo@2702: ingo@2714: // MIDDLE BED HEIGHT FORMATTER CONSTANTS ingo@2714: public static final int MIDDLE_BED_HEIGHT_KM_MIN_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_KM_MAX_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS = 2; ingo@2714: public static final int MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS = 2; ingo@2714: public static final int MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS = 0; ingo@2714: public static final int MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS = 0; ingo@2714: public static final int MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS = 3; ingo@2714: public static final int MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS = 3; ingo@2714: sascha@2787: public static final int FIX_DELTA_W_KM_MIN_DIGITS = 3; sascha@2787: public static final int FIX_DELTA_W_KM_MAX_DIGITS = 3; sascha@2787: public static final int FIX_DELTA_W_DELTA_W_MIN_DIGITS = 3; sascha@2787: public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3; sascha@2787: sascha@2290: public static NumberFormat getFormatter(CallMeta m, int min, int max){ sascha@2290: Locale locale = Resources.getLocale(m); 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: sascha@2290: public static NumberFormat getFormatter(CallContext c, int min, int max){ sascha@2290: return getFormatter(c.getMeta(), min, max); sascha@2290: } sascha@2290: ingo@445: ingo@445: /** ingo@2087: * Returns a number formatter with no max or min digits set. ingo@2087: * ingo@2087: * @param c The CallContext. ingo@2087: * ingo@2087: * @return a number formatter. ingo@2087: */ ingo@2087: public static NumberFormat getRawFormatter(CallContext c) { ingo@2087: Locale locale = Resources.getLocale(c.getMeta()); ingo@2087: return NumberFormat.getInstance(locale); ingo@2087: } ingo@2087: ingo@2087: ingo@2087: /** ingo@2258: * Returns a date formatter with SHORT style. ingo@2258: */ ingo@2258: public static DateFormat getShortDateFormat(CallContext cc) { ingo@2258: Locale locale = Resources.getLocale(cc.getMeta()); ingo@2258: return DateFormat.getDateInstance(DateFormat.SHORT, locale); ingo@2258: } ingo@2258: ingo@2258: ingo@2258: /** raimund@2588: * Returns a date formatter with MEDIUM style. raimund@2588: */ raimund@2588: public static DateFormat getMediumDateFormat(CallContext cc) { raimund@2588: Locale locale = Resources.getLocale(cc.getMeta()); raimund@2588: return DateFormat.getDateInstance(DateFormat.MEDIUM, locale); raimund@2588: } raimund@2588: raimund@2588: raimund@2588: /** 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@2258: * Returns the number formatter for W values in exports of historical ingo@2258: * discharge curves. ingo@2258: * ingo@2258: * @return the number formatter for W values. ingo@2258: */ ingo@2258: public static NumberFormat getHistoricalDischargeW(CallContext context) { ingo@2258: return getFormatter( ingo@2258: context, ingo@2258: HISTORICAL_DISCHARGE_W_MIN_DIGITS, ingo@2258: HISTORICAL_DISCHARGE_W_MAX_DIGITS); ingo@2258: } ingo@2258: ingo@2258: ingo@2258: /** ingo@2258: * Returns the number formatter for Q values in exports of historical ingo@2258: * discharge curves. ingo@2258: * ingo@2258: * @return the number formatter for Q values. ingo@2258: */ ingo@2258: public static NumberFormat getHistoricalDischargeQ(CallContext context) { ingo@2258: return getFormatter( ingo@2258: context, ingo@2258: HISTORICAL_DISCHARGE_Q_MIN_DIGITS, ingo@2258: HISTORICAL_DISCHARGE_Q_MAX_DIGITS); ingo@2258: } ingo@2258: ingo@2258: ingo@2258: /** 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: } sascha@2290: sascha@2290: public static NumberFormat getCalculationKm(CallMeta meta) { sascha@2290: return getFormatter( sascha@2290: meta, sascha@2290: CALCULATION_REPORT_KM_MIN_DIGITS, sascha@2290: CALCULATION_REPORT_KM_MAX_DIGITS); sascha@2290: } ingo@2702: ingo@2702: ingo@2702: public static NumberFormat getFlowVelocityKM(CallContext context) { ingo@2702: return getFormatter( ingo@2702: context, ingo@2702: FLOW_VELOCITY_KM_MIN_DIGITS, ingo@2702: FLOW_VELOCITY_KM_MAX_DIGITS); ingo@2702: } ingo@2702: ingo@2702: ingo@2702: public static NumberFormat getFlowVelocityValues(CallContext context) { ingo@2702: return getFormatter( ingo@2702: context, ingo@2702: FLOW_VELOCITY_VALUES_MIN_DIGITS, ingo@2702: FLOW_VELOCITY_VALUES_MAX_DIGITS); ingo@2702: } ingo@2702: ingo@2702: ingo@2702: public static NumberFormat getFlowVelocityQ(CallContext context) { ingo@2702: return getFormatter( ingo@2702: context, ingo@2702: FLOW_VELOCITY_Q_MIN_DIGITS, ingo@2702: FLOW_VELOCITY_Q_MAX_DIGITS); ingo@2702: } ingo@2714: ingo@2714: ingo@2714: public static NumberFormat getMiddleBedHeightKM(CallContext context) { ingo@2714: return getFormatter( ingo@2714: context, ingo@2714: MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, ingo@2714: MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); ingo@2714: } ingo@2714: ingo@2714: ingo@2714: public static NumberFormat getMiddleBedHeightHeight(CallContext context) { ingo@2714: return getFormatter( ingo@2714: context, ingo@2714: MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, ingo@2714: MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); ingo@2714: } ingo@2714: ingo@2714: ingo@2714: public static NumberFormat getMiddleBedHeightUncert(CallContext context) { ingo@2714: return getFormatter( ingo@2714: context, ingo@2714: MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, ingo@2714: MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); ingo@2714: } ingo@2714: ingo@2714: ingo@2714: public static NumberFormat getMiddleBedHeightDataGap(CallContext context) { ingo@2714: return getFormatter( ingo@2714: context, ingo@2714: MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, ingo@2714: MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); ingo@2714: } ingo@2714: ingo@2714: ingo@2714: public static NumberFormat getMiddleBedHeightSounding(CallContext context) { ingo@2714: return getFormatter( ingo@2714: context, ingo@2714: MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, ingo@2714: MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); ingo@2714: } ingo@2714: ingo@2714: ingo@2714: public static NumberFormat getMiddleBedHeightWidth(CallContext context) { ingo@2714: return getFormatter( ingo@2714: context, ingo@2714: MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS, ingo@2714: MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS); ingo@2714: } sascha@2787: sascha@2787: public static NumberFormat getFixDeltaWKM(CallContext context) { sascha@2787: return getFormatter( sascha@2787: context, sascha@2787: FIX_DELTA_W_KM_MIN_DIGITS, sascha@2787: FIX_DELTA_W_KM_MAX_DIGITS); sascha@2787: } sascha@2787: sascha@2787: public static NumberFormat getFixDeltaWDeltaW(CallContext context) { sascha@2787: return getFormatter( sascha@2787: context, sascha@2787: FIX_DELTA_W_DELTA_W_MIN_DIGITS, sascha@2787: FIX_DELTA_W_DELTA_W_MAX_DIGITS); sascha@2787: } ingo@445: } ingo@445: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :