Skip to content

Package: JavaFxAudioExplorerPresentationDelegate

JavaFxAudioExplorerPresentationDelegate

nameinstructionbranchcomplexitylinemethod
JavaFxAudioExplorerPresentationDelegate()
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%
bind(AudioExplorerPresentation.Properties, UserAction)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
focusOnMediaItems()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getMemento()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
initialize()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
lambda$populateItems$0(Optional)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
lambda$renderDetails$1(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$setCoverArt$2(URI)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
onKeyPressed(KeyEvent)
M: 30 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
populateBrowsers(PresentationModel)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
populateItems(PresentationModel, Optional)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
renderDetails(String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setCoverArt(Optional)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
showUp(Object)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 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.audio.explorer.impl.javafx;
28:
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import java.util.Optional;
32: import java.util.stream.Stream;
33: import java.net.URI;
34: import javafx.fxml.FXML;
35: import javafx.scene.control.Button;
36: import javafx.scene.control.Label;
37: import javafx.scene.control.ListView;
38: import javafx.scene.image.Image;
39: import javafx.scene.image.ImageView;
40: import javafx.scene.input.KeyCode;
41: import javafx.scene.input.KeyEvent;
42: import javafx.scene.layout.HBox;
43: import javafx.scene.layout.Pane;
44: import javafx.scene.layout.VBox;
45: import it.tidalwave.role.ui.PresentationModel;
46: import it.tidalwave.role.ui.UserAction;
47: import it.tidalwave.role.ui.javafx.JavaFXBinder;
48: import it.tidalwave.bluemarine2.ui.audio.explorer.AudioExplorerPresentation;
49: import it.tidalwave.bluemarine2.ui.audio.renderer.AudioRendererPresentation;
50: import lombok.Getter;
51: import lombok.ToString;
52: import lombok.extern.slf4j.Slf4j;
53: import static java.util.stream.Collectors.*;
54: import static it.tidalwave.bluemarine2.ui.impl.javafx.NodeFactory.label;
55:
56: /***********************************************************************************************************************
57: *
58: * The JavaFX Delegate for {@link AudioRendererPresentation}.
59: *
60: * @stereotype JavaFXDelegate
61: *
62: * @author Fabrizio Giudici
63: *
64: **********************************************************************************************************************/
65: @Slf4j
66: public class JavaFxAudioExplorerPresentationDelegate implements AudioExplorerPresentation
67: {
68: @Getter @ToString
69: static class Memento
70: {
71: private final int selectedIndex;
72:
73: public Memento()
74: {
75: selectedIndex = 0;
76: }
77:
78: public Memento (@Nonnull final ListView<PresentationModel> lvFiles)
79: {
80: // TODO: add further properties, such as the precise scroller position
81: selectedIndex = lvFiles.getSelectionModel().getSelectedIndex();
82: }
83:
84: public void applyTo (@Nonnull final ListView<PresentationModel> lvFiles)
85: {
86: lvFiles.getSelectionModel().select(selectedIndex);
87: lvFiles.scrollTo(selectedIndex);
88: }
89: }
90:
91: @FXML
92: private ListView<PresentationModel> lvFiles;
93:
94: @FXML
95: private Button btUp;
96:
97: @FXML
98: private Label lbFolderName;
99:
100: @FXML
101: private HBox hbBrowserButtons;
102:
103: @FXML
104: private Pane pnCoverArt;
105:
106: @FXML
107: private ImageView ivCoverArt;
108:
109: @FXML
110: private VBox vbDetails;
111:
112: @Inject
113: private JavaFXBinder binder;
114:
115: @FXML
116: private void initialize()
117: {
118: pnCoverArt.prefHeightProperty().bind(pnCoverArt.widthProperty());
119: ivCoverArt.fitWidthProperty().bind(pnCoverArt.widthProperty().multiply(0.9));
120: ivCoverArt.fitHeightProperty().bind(pnCoverArt.heightProperty().multiply(0.9));
121: }
122:
123: @Override
124: public void bind (@Nonnull final Properties properties, @Nonnull final UserAction upAction)
125: {
126: binder.bind(btUp, upAction);
127: lbFolderName.textProperty().bind(properties.folderNameProperty());
128: }
129:
130: @Override
131: public void showUp (@Nonnull final Object control)
132: {
133: }
134:
135: @Override
136: public void populateBrowsers (@Nonnull final PresentationModel pm)
137: {
138: binder.bindToggleButtons(hbBrowserButtons, pm);
139: }
140:
141: @Override
142: public void populateItems (@Nonnull final PresentationModel pm, @Nonnull final Optional<Object> optionalMemento)
143: {
144: binder.bind(lvFiles, pm, () ->
145: {
146:• if (!lvFiles.getItems().isEmpty())
147: {
148: ((Memento)optionalMemento.orElse(new Memento())).applyTo(lvFiles);
149: lvFiles.requestFocus();
150: }
151: });
152: }
153:
154: @Override
155: public void renderDetails (@Nonnull final String entityDetails)
156: {
157: vbDetails.getChildren().setAll(Stream.of(entityDetails.split("\n"))
158: .map(s -> label("track-details", s))
159: .collect(toList()));
160: }
161:
162: @Override
163: public void focusOnMediaItems()
164: {
165: lvFiles.requestFocus();
166: }
167:
168: @Override @Nonnull
169: public Object getMemento()
170: {
171: return new Memento(lvFiles);
172: }
173:
174: @Override
175: public void setCoverArt (@Nonnull final Optional<URI> optionalCoverArtUri)
176: {
177: ivCoverArt.setImage(optionalCoverArtUri.map(uri -> new Image(uri.toString())).orElse(null));
178: }
179:
180: /*******************************************************************************************************************
181: *
182: * With a remote there's no TAB key, so we must emulate some tab control with left and right arrows.
183: *
184: * FIXME: try to generalise (e.g. cyclefocus?) and move to JavaFxApplicationPresentationDelegate.
185: *
186: * @param event the key event
187: *
188: ******************************************************************************************************************/
189: @FXML
190: public void onKeyPressed (@Nonnull final KeyEvent event)
191: {
192: log.debug("onKeyPressed({})", event);
193:
194:• if (lvFiles.isFocused())
195: {
196:• if (event.getCode().equals(KeyCode.LEFT))
197: {
198: btUp.requestFocus();
199: }
200:• else if (event.getCode().equals(KeyCode.RIGHT))
201: {
202: hbBrowserButtons.getChildren().get(0).requestFocus();
203: }
204: }
205: }
206: }