Skip to content

Package: TrackCustomGraphicProvider

TrackCustomGraphicProvider

nameinstructionbranchcomplexitylinemethod
TrackCustomGraphicProvider(Track)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
diskLabel(int, int)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getGraphic()
M: 44 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
lambda$trackLabel$0(int, Integer)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$trackLabel$1(Integer)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
trackLabel(MediaItem.Metadata)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

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.impl.javafx.role;
28:
29: import javax.annotation.Nonnull;
30: import javafx.scene.Node;
31: import it.tidalwave.ui.role.javafx.CustomGraphicProvider;
32: import it.tidalwave.dci.annotation.DciRole;
33: import it.tidalwave.bluemarine2.model.MediaItem.Metadata;
34: import it.tidalwave.bluemarine2.model.audio.Track;
35: import lombok.RequiredArgsConstructor;
36: import static it.tidalwave.role.ui.Displayable._Displayable_;
37: import static it.tidalwave.bluemarine2.util.Formatters.*;
38: import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.*;
39: import static it.tidalwave.bluemarine2.ui.impl.javafx.NodeFactory.*;
40:
41: /***********************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: @RequiredArgsConstructor @DciRole(datumType = Track.class)
47: public class TrackCustomGraphicProvider implements CustomGraphicProvider
48: {
49: @Nonnull
50: private final Track track;
51:
52: @Override @Nonnull
53: public Node getGraphic()
54: {
55: final Metadata metadata = track.getMetadata();
56: return hBox("cell-container",
57: label("track-icon", ""),
58: label("track-index", trackLabel(metadata)),
59: label("track-label", track.as(_Displayable_).getDisplayName()),
60: label("track-duration", format(metadata.get(DURATION).get())));
61: }
62:
63: @Nonnull
64: private static String trackLabel (@Nonnull final Metadata metadata)
65: {
66: final int diskCount = metadata.get(DISK_COUNT).orElse(1);
67: return String.format("%s%s.",
68: metadata.get(DISK_NUMBER).map(diskNumber -> diskLabel(diskNumber, diskCount)).orElse(""),
69: metadata.get(TRACK_NUMBER).map(trackNumber -> "" + trackNumber).orElse(""));
70: }
71:
72: @Nonnull
73: private static String diskLabel (final int diskNumber, final int diskCount)
74: {
75:• return (diskCount == 1) ? "" : String.format("%d.", diskNumber);
76: }
77: }