Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java @ 9311:7c7f73e5e01e
Moved chart metadata line to top of chart. Minor cleanup.
author | gernotbelger |
---|---|
date | Thu, 26 Jul 2018 11:16:06 +0200 |
parents | 4082b8429353 |
children | 094ed9d1f2ad |
comparison
equal
deleted
inserted
replaced
9310:819dbd073624 | 9311:7c7f73e5e01e |
---|---|
19 import java.awt.image.BufferedImage; | 19 import java.awt.image.BufferedImage; |
20 import java.io.IOException; | 20 import java.io.IOException; |
21 import java.io.OutputStream; | 21 import java.io.OutputStream; |
22 import java.text.DateFormat; | 22 import java.text.DateFormat; |
23 import java.util.ArrayList; | 23 import java.util.ArrayList; |
24 import java.util.Collection; | |
25 import java.util.Collections; | |
24 import java.util.Date; | 26 import java.util.Date; |
25 import java.util.List; | 27 import java.util.List; |
26 import java.util.Locale; | 28 import java.util.Locale; |
27 import java.util.Map; | 29 import java.util.Map; |
28 import java.util.SortedMap; | 30 import java.util.SortedMap; |
29 import java.util.TreeMap; | 31 import java.util.TreeMap; |
30 | 32 |
31 import javax.xml.xpath.XPathConstants; | 33 import javax.xml.xpath.XPathConstants; |
32 | 34 |
35 import org.apache.commons.lang.StringUtils; | |
33 import org.apache.log4j.Logger; | 36 import org.apache.log4j.Logger; |
37 import org.dive4elements.artifactdatabase.CollectionCallContext; | |
34 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 38 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
35 import org.dive4elements.artifactdatabase.state.Settings; | 39 import org.dive4elements.artifactdatabase.state.Settings; |
36 import org.dive4elements.artifacts.Artifact; | 40 import org.dive4elements.artifacts.Artifact; |
41 import org.dive4elements.artifacts.ArtifactCollection; | |
37 import org.dive4elements.artifacts.ArtifactNamespaceContext; | 42 import org.dive4elements.artifacts.ArtifactNamespaceContext; |
38 import org.dive4elements.artifacts.CallContext; | 43 import org.dive4elements.artifacts.CallContext; |
39 import org.dive4elements.artifacts.CallMeta; | 44 import org.dive4elements.artifacts.CallMeta; |
40 import org.dive4elements.artifacts.PreferredLocale; | 45 import org.dive4elements.artifacts.PreferredLocale; |
41 import org.dive4elements.artifacts.common.utils.XMLUtils; | 46 import org.dive4elements.artifacts.common.utils.XMLUtils; |
65 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | 70 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
66 import org.jfree.chart.title.TextTitle; | 71 import org.jfree.chart.title.TextTitle; |
67 import org.jfree.data.Range; | 72 import org.jfree.data.Range; |
68 import org.jfree.data.general.Series; | 73 import org.jfree.data.general.Series; |
69 import org.jfree.data.xy.XYDataset; | 74 import org.jfree.data.xy.XYDataset; |
75 import org.jfree.ui.HorizontalAlignment; | |
70 import org.jfree.ui.RectangleInsets; | 76 import org.jfree.ui.RectangleInsets; |
71 import org.w3c.dom.Document; | 77 import org.w3c.dom.Document; |
72 import org.w3c.dom.Element; | 78 import org.w3c.dom.Element; |
73 | 79 |
74 /** | 80 /** |
465 | 471 |
466 ChartExportHelper.exportCSV(this.out, chart, this.context); | 472 ChartExportHelper.exportCSV(this.out, chart, this.context); |
467 } | 473 } |
468 } | 474 } |
469 | 475 |
476 protected final void generateTitles(final JFreeChart chart) { | |
477 /* add metadata title before real title */ | |
478 addMetadataSubtitle(chart); | |
479 | |
480 /* add the real chart title, but as subtitle after the metadata */ | |
481 final String chartTitle = getChartTitle(this.context); | |
482 if (chartTitle != null) { | |
483 final TextTitle title = new TextTitle(chartTitle, JFreeChart.DEFAULT_TITLE_FONT); | |
484 chart.addSubtitle(title); | |
485 } | |
486 | |
487 addSubtitles(this.context, chart); | |
488 } | |
489 | |
490 | |
470 /** | 491 /** |
471 * Adds a metadata sub-title to the chart if it gets exported | 492 * Adds a metadata sub-title to the chart if it gets exported |
472 */ | 493 */ |
473 protected final void addMetadataSubtitle(final CallContext context, final JFreeChart chart) { | 494 protected final void addMetadataSubtitle(final JFreeChart chart) { |
474 if ((!isExport() || !isExportMetadata())) | 495 if ((!isExport() || !isExportMetadata())) |
475 return; | 496 return; |
476 | 497 |
498 final Collection<String> metadata = buildMetadata(); | |
499 final String text = StringUtils.join(metadata, " - "); | |
500 | |
501 /** The default font. */ | |
502 final Font titleFont = new Font("SansSerif", Font.ITALIC, 10); | |
503 | |
504 final TextTitle subtitle = new TextTitle(text, titleFont); | |
505 subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); | |
506 subtitle.setMargin(new RectangleInsets(10,10,10,10)); | |
507 | |
508 chart.addSubtitle(subtitle); | |
509 } | |
510 | |
511 private Collection<String> buildMetadata() { | |
512 | |
513 final CallMeta meta = this.context.getMeta(); | |
514 | |
515 if (!(this.context instanceof CollectionCallContext)) { | |
516 /* should never happen */ | |
517 return Collections.emptyList(); | |
518 } | |
519 | |
520 final CollectionCallContext ccc = (CollectionCallContext) this.context; | |
521 final ArtifactCollection collection = ccc.getCollection(); | |
522 | |
523 final List<String> subtitles = new ArrayList<>(); | |
524 | |
525 /* version */ | |
477 final String version = FLYS.VERSION; | 526 final String version = FLYS.VERSION; |
478 final String user = CalculationUtils.findArtifactUser(context, getArtifact()); | 527 subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version)); |
479 final Locale locale = Resources.getLocale(context.getMeta()); | 528 |
529 /* user */ | |
530 // REMARK: the use inside the collection is a fake user and hence we cant use it here. | |
531 // final User user = collection.getUser(); | |
532 final String userName = CalculationUtils.findArtifactUser(this.context, getArtifact()); | |
533 subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName)); | |
534 | |
535 /* creation date */ | |
536 final Locale locale = Resources.getLocale(meta); | |
480 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | 537 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); |
481 final String dateText = df.format(new Date()); | 538 final String dateText = df.format(new Date()); |
482 | 539 subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText)); |
483 final String text = Resources.getMsg(context.getMeta(), "chart.subtitle.metadata", "default", version, user, dateText); | 540 |
484 | 541 return subtitles; |
485 chart.addSubtitle(new TextTitle(text)); | |
486 } | 542 } |
487 | 543 |
488 private boolean isExportMetadata() { | 544 private boolean isExportMetadata() { |
489 final ChartSettings chartSettings = getChartSettings(); | 545 final ChartSettings chartSettings = getChartSettings(); |
490 if (chartSettings == null) | 546 if (chartSettings == null) |