Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java @ 9524:9dc6427059b2
Added more metadata to chart exports
author | gernotbelger |
---|---|
date | Mon, 01 Oct 2018 17:45:43 +0200 |
parents | 853f2dafc16e |
children | ef5754ba5573 |
comparison
equal
deleted
inserted
replaced
9523:d421c2bf0195 | 9524:9dc6427059b2 |
---|---|
32 import org.apache.log4j.Logger; | 32 import org.apache.log4j.Logger; |
33 import org.dive4elements.artifactdatabase.CollectionCallContext; | 33 import org.dive4elements.artifactdatabase.CollectionCallContext; |
34 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 34 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
35 import org.dive4elements.artifactdatabase.state.Settings; | 35 import org.dive4elements.artifactdatabase.state.Settings; |
36 import org.dive4elements.artifacts.Artifact; | 36 import org.dive4elements.artifacts.Artifact; |
37 import org.dive4elements.artifacts.ArtifactCollection; | |
37 import org.dive4elements.artifacts.ArtifactNamespaceContext; | 38 import org.dive4elements.artifacts.ArtifactNamespaceContext; |
38 import org.dive4elements.artifacts.CallContext; | 39 import org.dive4elements.artifacts.CallContext; |
39 import org.dive4elements.artifacts.CallMeta; | 40 import org.dive4elements.artifacts.CallMeta; |
40 import org.dive4elements.artifacts.PreferredLocale; | 41 import org.dive4elements.artifacts.PreferredLocale; |
41 import org.dive4elements.artifacts.common.utils.XMLUtils; | 42 import org.dive4elements.artifacts.common.utils.XMLUtils; |
486 protected final void addMetadataSubtitle(final JFreeChart chart) { | 487 protected final void addMetadataSubtitle(final JFreeChart chart) { |
487 if ((!isExport() || !isExportMetadata())) | 488 if ((!isExport() || !isExportMetadata())) |
488 return; | 489 return; |
489 | 490 |
490 final Collection<String> metadata = buildMetadata(); | 491 final Collection<String> metadata = buildMetadata(); |
491 final String text = StringUtils.join(metadata, " - "); | 492 |
492 | 493 for (final String text : metadata) { |
493 /** The default font. */ | 494 |
494 final Font titleFont = new Font("SansSerif", Font.ITALIC, 10); | 495 /** The default font. */ |
495 | 496 final Font titleFont = new Font("SansSerif", Font.ITALIC, 10); |
496 final TextTitle subtitle = new TextTitle(text, titleFont); | 497 |
497 subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); | 498 final TextTitle subtitle = new TextTitle(text, titleFont); |
498 subtitle.setMargin(new RectangleInsets(10, 10, 10, 10)); | 499 subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); |
499 | 500 subtitle.setTextAlignment(HorizontalAlignment.LEFT); |
500 chart.addSubtitle(subtitle); | 501 subtitle.setMargin(new RectangleInsets(5, 10, 0, 10)); |
502 subtitle.setPadding(RectangleInsets.ZERO_INSETS); | |
503 subtitle.getFrame(); | |
504 | |
505 chart.addSubtitle(subtitle); | |
506 } | |
501 } | 507 } |
502 | 508 |
503 private Collection<String> buildMetadata() { | 509 private Collection<String> buildMetadata() { |
504 | 510 |
505 final CallMeta meta = this.context.getMeta(); | 511 final CallMeta meta = this.context.getMeta(); |
507 if (!(this.context instanceof CollectionCallContext)) { | 513 if (!(this.context instanceof CollectionCallContext)) { |
508 /* should never happen */ | 514 /* should never happen */ |
509 return Collections.emptyList(); | 515 return Collections.emptyList(); |
510 } | 516 } |
511 | 517 |
518 final CollectionCallContext ccc = (CollectionCallContext) this.context; | |
519 final ArtifactCollection collection = ccc.getCollection(); | |
520 | |
512 final List<String> subtitles = new ArrayList<>(); | 521 final List<String> subtitles = new ArrayList<>(); |
522 | |
523 final List<String> firstLine = new ArrayList<>(); | |
524 final List<String> secondLine = new ArrayList<>(); | |
513 | 525 |
514 /* version */ | 526 /* version */ |
515 final String version = FLYS.VERSION; | 527 final String version = FLYS.VERSION; |
516 subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version)); | 528 firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version)); |
517 | 529 |
518 /* user */ | 530 /* user */ |
519 // REMARK: the use inside the collection is a fake user and hence we cant use it here. | 531 // REMARK: the use inside the collection is a fake user and hence we cant use it here. |
520 // final User user = collection.getUser(); | 532 // final User user = collection.getUser(); |
521 final String userName = CalculationUtils.findArtifactUser(this.context, getArtifact()); | 533 final String userName = CalculationUtils.findArtifactUser(this.context, getArtifact()); |
522 subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName)); | 534 firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName)); |
523 | 535 |
524 /* creation date */ | 536 /* creation date */ |
525 final Locale locale = Resources.getLocale(meta); | 537 final Locale locale = Resources.getLocale(meta); |
526 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); | 538 final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); |
527 final String dateText = df.format(new Date()); | 539 final String dateText = df.format(new Date()); |
528 subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText)); | 540 firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText)); |
541 | |
542 /* project name */ | |
543 final String collectionName = collection.getName(); | |
544 final String collectionID = collection.identifier(); | |
545 final String projectName = collectionName == null || collectionName.isEmpty() ? collectionID : collectionName; | |
546 secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.projectname", "default", projectName)); | |
547 | |
548 /* module name */ | |
549 final String moduleName = Resources.getMsg(meta, "module." + this.master.getName()); | |
550 secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.modulename", "default", moduleName)); | |
551 | |
552 /* calculation mode */ | |
553 if (this.master instanceof D4EArtifact) { | |
554 | |
555 final D4EArtifact artifact = (D4EArtifact) this.master; | |
556 // REMARK: relies on the fact that all modules use the same data-key 'calculation_mode' | |
557 final String calculationMode = artifact.getDataAsString("calculation_mode"); | |
558 if (calculationMode != null) { | |
559 /* but not all modules have that (i.e. Chart, Map, ...) */ | |
560 | |
561 final String calculationName = Resources.getMsg(meta, calculationMode, "XXX"); | |
562 if (!"XXX".contentEquals(calculationName)) | |
563 secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.calcmode", "calcmode", calculationName)); | |
564 } | |
565 } | |
566 | |
567 subtitles.add(StringUtils.join(firstLine, " - ")); | |
568 subtitles.add(StringUtils.join(secondLine, " - ")); | |
529 | 569 |
530 return subtitles; | 570 return subtitles; |
531 } | 571 } |
532 | 572 |
533 private boolean isExportMetadata() { | 573 private boolean isExportMetadata() { |