Content of file DelegateSupport.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>DelegateSupport.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">SteelBlue - JavaFX Bindings</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.role.ui.javafx.impl.common</a> &gt; <span class="el_source">DelegateSupport.java</span></div><h1>DelegateSupport.java</h1><pre class="source lang-java linenums">/*
 * *********************************************************************************************************************
 *
 * SteelBlue: DCI User Interfaces
 * http://tidalwave.it/projects/steelblue
 *
 * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
 *
 * *********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); 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 &quot;AS IS&quot; 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/steelblue-src
 * git clone https://github.com/tidalwave-it/steelblue-src
 *
 * *********************************************************************************************************************
 */
package it.tidalwave.role.ui.javafx.impl.common;

import javax.annotation.Nonnull;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import javafx.application.Platform;
import javafx.scene.Parent;
import javafx.scene.effect.BoxBlur;
import javafx.scene.effect.Effect;
import javafx.stage.Window;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="pc bpc" id="L45" title="1 of 2 branches missed.">@RequiredArgsConstructor</span>
public abstract class DelegateSupport
  {
    @Nonnull
    protected final Executor executor;

<span class="nc" id="L51">    @Setter</span>
    protected Window mainWindow;

    /*******************************************************************************************************************
     *
     * Runs the given (@link Callable} while disabling the given {@link Window}.
     *
     * @param  window    the {@code Window} to disable
     * @param  callable  the (@code Callable} to run
     * @return           the (@code Callable} result
     *
     ******************************************************************************************************************/
    protected &lt;T&gt; T runWhileDisabling (@Nonnull final Window window, @Nonnull final Callable&lt;T&gt; callable)
      {
<span class="nc" id="L65">        final Parent root = window.getScene().getRoot();</span>
<span class="nc" id="L66">        final Effect effect = root.getEffect();</span>
<span class="nc" id="L67">        final boolean disabled = root.isDisable();</span>

        try
          {
<span class="nc" id="L71">            root.setDisable(true);</span>
<span class="nc" id="L72">            root.setEffect(createDisablingEffect());</span>
<span class="nc" id="L73">            return callable.call();</span>
          }
<span class="nc" id="L75">        catch (Exception e)</span>
          {
<span class="nc" id="L77">            throw new RuntimeException(e);</span>
          }
        finally
          {
<span class="nc" id="L81">            root.setEffect(effect);</span>
<span class="nc" id="L82">            root.setDisable(disabled);</span>
          }
      }

    /*******************************************************************************************************************
     *
     * TODO: delegate to a provider
delegate to a provider
* ******************************************************************************************************************/ @Nonnull private BoxBlur createDisablingEffect() { <span class="nc" id="L94"> final BoxBlur bb = new BoxBlur();</span> <span class="nc" id="L95"> bb.setWidth(5);</span> <span class="nc" id="L96"> bb.setHeight(5);</span> <span class="nc" id="L97"> bb.setIterations(3);</span> <span class="nc" id="L98"> return bb;</span> } /******************************************************************************************************************* * * TODO: delegate to a provider * ******************************************************************************************************************/ public static boolean isOSX() { <span class="nc" id="L108"> return System.getProperty(&quot;os.name&quot;).contains(&quot;OS X&quot;);</span> } /******************************************************************************************************************* * * * ******************************************************************************************************************/ protected void assertIsFxApplicationThread() { <span class="nc bnc" id="L118" title="All 2 branches missed."> if (!Platform.isFxApplicationThread())</span> { <span class="nc" id="L120"> throw new AssertionError(&quot;Must run in the JavaFX Application Thread&quot;);</span> } <span class="nc" id="L122"> }</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>