Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java @ 6172:58a613798386
Implement PDF export for SQ Relation
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 03 Jun 2013 17:15:09 +0200 |
parents | af13ceeba52a |
children | a82a724356f0 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Mon Jun 03 16:26:10 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java Mon Jun 03 17:15:09 2013 +0200 @@ -11,6 +11,7 @@ import java.text.DateFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; +import java.text.DecimalFormat; import java.util.Locale; import org.dive4elements.artifacts.CallContext; @@ -87,6 +88,12 @@ public static final int FIX_DELTA_W_DELTA_Q_MIN_DIGITS = 0; public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2; + public static final int VARIANCE_MIN_DIGITS = 0; + public static final int VARIANCE_MAX_DIGITS = 4; + + // SQ Relation + public static final int SQ_RELATION_MAX_DIGITS = 8; + public static final int SQ_RELATION_MIN_DIGITS = 0; /** * Creates a localized NumberFormatter with given range of decimal digits. @@ -106,7 +113,6 @@ return nf; } - public static NumberFormat getFormatter(CallContext c, int min, int max){ return getFormatter(c.getMeta(), min, max); } @@ -124,6 +130,32 @@ return NumberFormat.getInstance(locale); } + /** + * Returns a formatter in engineering notation + */ + public static NumberFormat getEngFormatter(CallContext c) { + NumberFormat nf = getRawFormatter(c); + if (nf instanceof DecimalFormat) { + DecimalFormat df = (DecimalFormat)nf; + df.applyPattern("##0.#####E0"); + } + return nf; + } + + /** + * Returns a number formatter that uses an exponent after max digits + */ + public static NumberFormat getScientificFormater(CallContext c, int min, int max) { + NumberFormat nf = getRawFormatter(c); + if (nf instanceof DecimalFormat) { + DecimalFormat df = (DecimalFormat)nf; + df.applyPattern("0.0E0"); + df.setMaximumFractionDigits(max); + df.setMinimumFractionDigits(min); + } + return nf; + } + /** * Returns a date formatter with SHORT style. @@ -398,6 +430,21 @@ FIX_DELTA_W_DELTA_W_MAX_DIGITS); } + public static NumberFormat getVariance(CallContext context) { + return getFormatter( + context, + VARIANCE_MIN_DIGITS, + VARIANCE_MAX_DIGITS); + } + + public static NumberFormat getSQRelation(CallContext context) { + // Would be nice if E0 would not be shown + return getScientificFormater( + context, + SQ_RELATION_MIN_DIGITS, + SQ_RELATION_MAX_DIGITS); + } + public static NumberFormat getMeterFormat(CallContext context) { return getFormatter( context,