9150
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.common; |
|
11 |
|
12 import java.text.DateFormat; |
|
13 import java.text.NumberFormat; |
|
14 import java.util.Date; |
|
15 import java.util.Locale; |
|
16 |
|
17 import org.apache.commons.lang.math.DoubleRange; |
|
18 import org.dive4elements.artifacts.CallContext; |
|
19 import org.dive4elements.river.FLYS; |
|
20 import org.dive4elements.river.artifacts.resources.Resources; |
9195
|
21 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
9150
|
22 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
|
23 |
|
24 /** |
|
25 * @author Domenico Nardi Tironi |
|
26 * |
|
27 */ |
9195
|
28 public final class ExportContextPDF extends AbstractExportContext { |
9150
|
29 |
9195
|
30 public ExportContextPDF(final CallContext context, final AbstractCalculationResults<?> results) { |
|
31 super(context, results); |
9150
|
32 } |
|
33 |
9195
|
34 // TODO: rename |
|
35 public String msgPdf(final SInfoResultType type) { |
|
36 return type.getPdfHeader(getContext().getMeta()); |
9150
|
37 } |
|
38 |
|
39 public void addJRMetadata(final MetaAndTableJRDataSource source, final String key, final IResultType type) { |
9195
|
40 source.addMetaData(key, type.getPdfHeader(getContext().getMeta())); |
|
41 } |
|
42 |
|
43 public void addJRMetadata(final MetaAndTableJRDataSource source, final String key, final String msg) { |
|
44 source.addMetaData(key, msg); |
9150
|
45 } |
|
46 |
|
47 // *** CUSTOM STUFF that is used multiple times ***/// |
9195
|
48 public void addJRMetaDataDefaults(final MetaAndTableJRDataSource source) { |
9150
|
49 |
|
50 source.addMetaData("header", msg(I18NStrings.CSV_META_HEADER_RESULT_LABEL)); |
9195
|
51 source.addMetaData("calcMode", getResults().getCalcModeLabel()); |
9150
|
52 |
|
53 source.addMetaData("version_label", msg(I18NStrings.CSV_META_VERSION_LABEL)); |
|
54 source.addMetaData("version", FLYS.VERSION); |
|
55 |
|
56 source.addMetaData("user_label", msg(I18NStrings.CSV_META_USER_LABEL)); |
9195
|
57 source.addMetaData("user", getResults().getUser()); |
9150
|
58 |
9195
|
59 final Locale locale = Resources.getLocale(getContext().getMeta()); |
9150
|
60 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); |
|
61 source.addMetaData("date_label", msg(I18NStrings.CSV_META_CREATION_LABEL)); |
|
62 source.addMetaData("date", df.format(new Date())); |
|
63 } |
|
64 |
9195
|
65 public void addJRMetaDataUSINFO(final MetaAndTableJRDataSource source) { |
9150
|
66 |
|
67 /* general metadata */ |
9195
|
68 addJRMetaDataDefaults(source); |
9150
|
69 |
9195
|
70 final RiverInfo river = getResults().getRiver(); |
9150
|
71 final String wstUnitName = river.getWstUnit(); |
|
72 |
|
73 source.addMetaData("river_label", msg(I18NStrings.CSV_META_RIVER_LABEL)); |
|
74 source.addMetaData("river", river.getName()); |
|
75 source.addMetaData("river_unit", wstUnitName); |
|
76 |
9195
|
77 final DoubleRange calcRange = getResults().getCalcRange(); |
9150
|
78 final NumberFormat kmFormatter = getKmFormatter(); |
|
79 final String rangeValue = String.format("%s - %s", kmFormatter.format(calcRange.getMinimumDouble()), kmFormatter.format(calcRange.getMaximumDouble())); |
|
80 source.addMetaData("range_label", msg(I18NStrings.CSV_META_RANGE_LABEL)); |
|
81 source.addMetaData("range", rangeValue); |
|
82 } |
|
83 } |