changeset 9524:9dc6427059b2

Added more metadata to chart exports
author gernotbelger
date Mon, 01 Oct 2018 17:45:43 +0200
parents d421c2bf0195
children 967ca59cc11a
files artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java artifacts/src/main/resources/messages.properties artifacts/src/main/resources/messages_de.properties
diffstat 3 files changed, 57 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java	Mon Oct 01 17:08:50 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java	Mon Oct 01 17:45:43 2018 +0200
@@ -34,6 +34,7 @@
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Settings;
 import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.ArtifactCollection;
 import org.dive4elements.artifacts.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.CallMeta;
@@ -488,16 +489,21 @@
             return;
 
         final Collection<String> metadata = buildMetadata();
-        final String text = StringUtils.join(metadata, " - ");
-
-        /** The default font. */
-        final Font titleFont = new Font("SansSerif", Font.ITALIC, 10);
 
-        final TextTitle subtitle = new TextTitle(text, titleFont);
-        subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
-        subtitle.setMargin(new RectangleInsets(10, 10, 10, 10));
+        for (final String text : metadata) {
 
-        chart.addSubtitle(subtitle);
+            /** The default font. */
+            final Font titleFont = new Font("SansSerif", Font.ITALIC, 10);
+
+            final TextTitle subtitle = new TextTitle(text, titleFont);
+            subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
+            subtitle.setTextAlignment(HorizontalAlignment.LEFT);
+            subtitle.setMargin(new RectangleInsets(5, 10, 0, 10));
+            subtitle.setPadding(RectangleInsets.ZERO_INSETS);
+            subtitle.getFrame();
+
+            chart.addSubtitle(subtitle);
+        }
     }
 
     private Collection<String> buildMetadata() {
@@ -509,23 +515,57 @@
             return Collections.emptyList();
         }
 
+        final CollectionCallContext ccc = (CollectionCallContext) this.context;
+        final ArtifactCollection collection = ccc.getCollection();
+
         final List<String> subtitles = new ArrayList<>();
 
+        final List<String> firstLine = new ArrayList<>();
+        final List<String> secondLine = new ArrayList<>();
+
         /* version */
         final String version = FLYS.VERSION;
-        subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version));
+        firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version));
 
         /* user */
         // REMARK: the use inside the collection is a fake user and hence we cant use it here.
         // final User user = collection.getUser();
         final String userName = CalculationUtils.findArtifactUser(this.context, getArtifact());
-        subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName));
+        firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName));
 
         /* creation date */
         final Locale locale = Resources.getLocale(meta);
         final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
         final String dateText = df.format(new Date());
-        subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText));
+        firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText));
+
+        /* project name */
+        final String collectionName = collection.getName();
+        final String collectionID = collection.identifier();
+        final String projectName = collectionName == null || collectionName.isEmpty() ? collectionID : collectionName;
+        secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.projectname", "default", projectName));
+
+        /* module name */
+        final String moduleName = Resources.getMsg(meta, "module." + this.master.getName());
+        secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.modulename", "default", moduleName));
+
+        /* calculation mode */
+        if (this.master instanceof D4EArtifact) {
+
+            final D4EArtifact artifact = (D4EArtifact) this.master;
+            // REMARK: relies on the fact that all modules use the same data-key 'calculation_mode'
+            final String calculationMode = artifact.getDataAsString("calculation_mode");
+            if (calculationMode != null) {
+                /* but not all modules have that (i.e. Chart, Map, ...) */
+
+                final String calculationName = Resources.getMsg(meta, calculationMode, "XXX");
+                if (!"XXX".contentEquals(calculationName))
+                    secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.calcmode", "calcmode", calculationName));
+            }
+        }
+
+        subtitles.add(StringUtils.join(firstLine, " - "));
+        subtitles.add(StringUtils.join(secondLine, " - "));
 
         return subtitles;
     }
--- a/artifacts/src/main/resources/messages.properties	Mon Oct 01 17:08:50 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Mon Oct 01 17:45:43 2018 +0200
@@ -1349,6 +1349,9 @@
 chart.subtitle.metadata.version = FLYS Version: {0}
 chart.subtitle.metadata.user = User: {0}
 chart.subtitle.metadata.creationdate = Time of Creation: {0}
+chart.subtitle.metadata.projectname = Project: {0}
+chart.subtitle.metadata.modulename = Module: {0}
+chart.subtitle.metadata.calcmode = Calculation: {0}
 
 state.title.distance_state = Choose Calculation Range [km]
 state.title.location_distance_state = Choose Calculation Location(s)/Range [km] 
--- a/artifacts/src/main/resources/messages_de.properties	Mon Oct 01 17:08:50 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Mon Oct 01 17:45:43 2018 +0200
@@ -1349,6 +1349,9 @@
 chart.subtitle.metadata.version = FLYS-Version: {0}
 chart.subtitle.metadata.user = Bearbeiter: {0}
 chart.subtitle.metadata.creationdate = Datum der Erstellung: {0}
+chart.subtitle.metadata.projectname = Projekt: {0}
+chart.subtitle.metadata.modulename = Modul: {0}
+chart.subtitle.metadata.calcmode = Berechnungsart: {0}
 
 state.title.distance_state = Berechnungsstrecke w\u00e4hlen [km]
 state.title.location_distance_state = Berechnungsort(e)/-strecke w\u00e4hlen [km] 

http://dive4elements.wald.intevation.org