Content of file JavaFxAudioExplorerPresentationDelegate.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>JavaFxAudioExplorerPresentationDelegate.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">blueMarine II :: CEC :: Navigation Adapter</a> > <a href="../index.html" class="el_bundle">it-tidalwave-bluemarine2-ui-javafx</a> > <a href="index.source.html" class="el_package">it.tidalwave.bluemarine2.ui.audio.explorer.impl.javafx</a> > <span class="el_source">JavaFxAudioExplorerPresentationDelegate.java</span></div><h1>JavaFxAudioExplorerPresentationDelegate.java</h1><pre class="source lang-java linenums">/*
* *********************************************************************************************************************
*
* blueMarine II: Semantic Media Centre
* http://tidalwave.it/projects/bluemarine2
*
* Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
*
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
* git clone https://bitbucket.org/tidalwave/bluemarine2-src
* git clone https://github.com/tidalwave-it/bluemarine2-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.bluemarine2.ui.audio.explorer.impl.javafx;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Optional;
import java.util.stream.Stream;
import java.net.URI;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import it.tidalwave.role.ui.PresentationModel;
import it.tidalwave.role.ui.UserAction;
import it.tidalwave.role.ui.javafx.JavaFXBinder;
import it.tidalwave.bluemarine2.ui.audio.explorer.AudioExplorerPresentation;
import it.tidalwave.bluemarine2.ui.audio.renderer.AudioRendererPresentation;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import static java.util.stream.Collectors.*;
import static it.tidalwave.bluemarine2.ui.impl.javafx.NodeFactory.label;
/***********************************************************************************************************************
*
* The JavaFX Delegate for {@link AudioRendererPresentation}.
*
* @stereotype JavaFXDelegate
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L65">@Slf4j</span>
<span class="nc" id="L66">public class JavaFxAudioExplorerPresentationDelegate implements AudioExplorerPresentation</span>
{
<span class="nc" id="L68"> @Getter @ToString</span>
static class Memento
{
<span class="nc" id="L71"> private final int selectedIndex;</span>
public Memento()
<span class="nc" id="L74"> {</span>
<span class="nc" id="L75"> selectedIndex = 0;</span>
<span class="nc" id="L76"> }</span>
public Memento (@Nonnull final ListView<PresentationModel> lvFiles)
<span class="nc" id="L79"> {</span>
// TODO: add further properties, such as the precise scroller position
| add further properties, such as the precise scroller position | |
<span class="nc" id="L81"> selectedIndex = lvFiles.getSelectionModel().getSelectedIndex();</span>
<span class="nc" id="L82"> }</span>
public void applyTo (@Nonnull final ListView<PresentationModel> lvFiles)
{
<span class="nc" id="L86"> lvFiles.getSelectionModel().select(selectedIndex);</span>
<span class="nc" id="L87"> lvFiles.scrollTo(selectedIndex);</span>
<span class="nc" id="L88"> }</span>
}
@FXML
private ListView<PresentationModel> lvFiles;
@FXML
private Button btUp;
@FXML
private Label lbFolderName;
@FXML
private HBox hbBrowserButtons;
@FXML
private Pane pnCoverArt;
@FXML
private ImageView ivCoverArt;
@FXML
private VBox vbDetails;
@Inject
private JavaFXBinder binder;
@FXML
private void initialize()
{
<span class="nc" id="L118"> pnCoverArt.prefHeightProperty().bind(pnCoverArt.widthProperty());</span>
<span class="nc" id="L119"> ivCoverArt.fitWidthProperty().bind(pnCoverArt.widthProperty().multiply(0.9));</span>
<span class="nc" id="L120"> ivCoverArt.fitHeightProperty().bind(pnCoverArt.heightProperty().multiply(0.9));</span>
<span class="nc" id="L121"> }</span>
@Override
public void bind (@Nonnull final Properties properties, @Nonnull final UserAction upAction)
{
<span class="nc" id="L126"> binder.bind(btUp, upAction);</span>
<span class="nc" id="L127"> lbFolderName.textProperty().bind(properties.folderNameProperty());</span>
<span class="nc" id="L128"> }</span>
@Override
public void showUp (@Nonnull final Object control)
{
<span class="nc" id="L133"> }</span>
@Override
public void populateBrowsers (@Nonnull final PresentationModel pm)
{
<span class="nc" id="L138"> binder.bindToggleButtons(hbBrowserButtons, pm);</span>
<span class="nc" id="L139"> }</span>
@Override
public void populateItems (@Nonnull final PresentationModel pm, @Nonnull final Optional<Object> optionalMemento)
{
<span class="nc" id="L144"> binder.bind(lvFiles, pm, () -></span>
{
<span class="nc bnc" id="L146" title="All 2 branches missed."> if (!lvFiles.getItems().isEmpty())</span>
{
<span class="nc" id="L148"> ((Memento)optionalMemento.orElse(new Memento())).applyTo(lvFiles);</span>
<span class="nc" id="L149"> lvFiles.requestFocus();</span>
}
<span class="nc" id="L151"> });</span>
<span class="nc" id="L152"> }</span>
@Override
public void renderDetails (@Nonnull final String entityDetails)
{
<span class="nc" id="L157"> vbDetails.getChildren().setAll(Stream.of(entityDetails.split("\n"))</span>
<span class="nc" id="L158"> .map(s -> label("track-details", s))</span>
<span class="nc" id="L159"> .collect(toList()));</span>
<span class="nc" id="L160"> }</span>
@Override
public void focusOnMediaItems()
{
<span class="nc" id="L165"> lvFiles.requestFocus();</span>
<span class="nc" id="L166"> }</span>
@Override @Nonnull
public Object getMemento()
{
<span class="nc" id="L171"> return new Memento(lvFiles);</span>
}
@Override
public void setCoverArt (@Nonnull final Optional<URI> optionalCoverArtUri)
{
<span class="nc" id="L177"> ivCoverArt.setImage(optionalCoverArtUri.map(uri -> new Image(uri.toString())).orElse(null));</span>
<span class="nc" id="L178"> }</span>
/*******************************************************************************************************************
*
* With a remote there's no TAB key, so we must emulate some tab control with left and right arrows.
*
* FIXME: try to generalise (e.g. cyclefocus?) and move to JavaFxApplicationPresentationDelegate.
*
* @param event the key event
*
******************************************************************************************************************/
@FXML
public void onKeyPressed (@Nonnull final KeyEvent event)
{
<span class="nc" id="L192"> log.debug("onKeyPressed({})", event);</span>
<span class="nc bnc" id="L194" title="All 2 branches missed."> if (lvFiles.isFocused())</span>
{
<span class="nc bnc" id="L196" title="All 2 branches missed."> if (event.getCode().equals(KeyCode.LEFT))</span>
{
<span class="nc" id="L198"> btUp.requestFocus();</span>
}
<span class="nc bnc" id="L200" title="All 2 branches missed."> else if (event.getCode().equals(KeyCode.RIGHT))</span>
{
<span class="nc" id="L202"> hbBrowserButtons.getChildren().get(0).requestFocus();</span>
}
}
<span class="nc" id="L205"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>