AudioFileDetailRendererSelectable.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * blueMarine II: Semantic Media Centre
  5.  * http://tidalwave.it/projects/bluemarine2
  6.  *
  7.  * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *********************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  12.  * the License. You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/bluemarine2-src
  23.  * git clone https://github.com/tidalwave-it/bluemarine2-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.bluemarine2.ui.audio.explorer.impl;

  28. import javax.annotation.Nonnull;
  29. import it.tidalwave.dci.annotation.DciRole;
  30. import it.tidalwave.bluemarine2.model.MediaItem;
  31. import it.tidalwave.bluemarine2.model.audio.AudioFile;
  32. import it.tidalwave.bluemarine2.model.audio.Record;
  33. import it.tidalwave.bluemarine2.model.role.AudioFileSupplier;
  34. import static java.util.stream.Collectors.*;
  35. import static it.tidalwave.role.ui.Displayable._Displayable_;
  36. import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.BIT_RATE;
  37. import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.SAMPLE_RATE;
  38. import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.YEAR;

  39. /***********************************************************************************************************************
  40.  *
  41.  * The role for an {@link AudioFileSupplier} that is capable to render details upon selection, in the context of
  42.  * {@link DefaultAudioExplorerPresentationControl}.
  43.  *
  44.  * @stereotype  Role
  45.  *
  46.  * @author  Fabrizio Giudici
  47.  *
  48.  **********************************************************************************************************************/
  49. @DciRole(datumType = AudioFileSupplier.class, context = DefaultAudioExplorerPresentationControl.class)
  50. public class AudioFileDetailRendererSelectable extends DetailRendererSelectable<AudioFileSupplier>
  51.   {
  52.     public AudioFileDetailRendererSelectable (@Nonnull final AudioFileSupplier audioFileSupplier)
  53.       {
  54.         super(audioFileSupplier);
  55.       }

  56.     @Override
  57.     protected void renderDetails()
  58.       {
  59.         final AudioFile audioFile = this.owner.getAudioFile();
  60.         final MediaItem.Metadata metadata = audioFile.getMetadata();

  61.         final String details = String.format("%s%n%s%n%s%n%s%n%s",
  62.             audioFile.findMakers().stream().map(m -> m.as(_Displayable_).getDisplayName())
  63.                                   .collect(joining(", ", "Artist: ", "")),
  64.             audioFile.findComposers().stream().map(e -> e.as(_Displayable_).getDisplayName())
  65.                                      .collect(joining(", ", "Composer: ", "")),
  66.             metadata.get(BIT_RATE).map(br -> "Bit rate: " + br + " kbps").orElse(""),
  67.             metadata.get(SAMPLE_RATE).map(sr -> String.format("Sample rate: %.1f kHz", sr / 1000.0)).orElse(""),
  68.             metadata.get(YEAR).map(y -> "Year: " + y).orElse(""));

  69.         renderDetails(details);
  70.         renderCoverArt(audioFile.getRecord().flatMap(Record::getImageUrl));
  71.       }
  72.   }