1 /* 2 * ************************************************************************************************************************************************************* 3 * 4 * SteelBlue: DCI User Interfaces 5 * http://tidalwave.it/projects/steelblue 6 * 7 * Copyright (C) 2015 - 2025 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 the License. 12 * 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 an "AS IS" BASIS, WITHOUT WARRANTIES OR 17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 18 * 19 * ************************************************************************************************************************************************************* 20 * 21 * git clone https://bitbucket.org/tidalwave/steelblue-src 22 * git clone https://github.com/tidalwave-it/steelblue-src 23 * 24 * ************************************************************************************************************************************************************* 25 */ 26 package it.tidalwave.ui.javafx.impl.common; 27 28 import jakarta.annotation.Nonnull; 29 import java.util.concurrent.Callable; 30 import java.util.concurrent.Executor; 31 import javafx.scene.effect.BoxBlur; 32 import javafx.stage.Window; 33 import lombok.RequiredArgsConstructor; 34 import lombok.Setter; 35 36 /*************************************************************************************************************************************************************** 37 * 38 * @author Fabrizio Giudici 39 * 40 **************************************************************************************************************************************************************/ 41 @RequiredArgsConstructor 42 public abstract class DelegateSupport 43 { 44 @Nonnull 45 protected final Executor executor; 46 47 @Setter 48 protected Window mainWindow; 49 50 /*********************************************************************************************************************************************************** 51 * Runs the given (@link Callable} while disabling the given {@link Window}. 52 * 53 * @param window the {@code Window} to disable 54 * @param callable the (@code Callable} to run 55 * @return the (@code Callable} result 56 **********************************************************************************************************************************************************/ 57 protected <T> T runWhileDisabling (@Nonnull final Window window, @Nonnull final Callable<T> callable) 58 { 59 final var root = window.getScene().getRoot(); 60 final var effect = root.getEffect(); 61 final var disabled = root.isDisable(); 62 63 try 64 { 65 root.setDisable(true); 66 root.setEffect(createDisablingEffect()); 67 return callable.call(); 68 } 69 catch (Exception e) 70 { 71 throw new RuntimeException(e); 72 } 73 finally 74 { 75 root.setEffect(effect); 76 root.setDisable(disabled); 77 } 78 } 79 80 /*********************************************************************************************************************************************************** 81 * TODO: delegate to a provider 82 **********************************************************************************************************************************************************/ 83 @Nonnull 84 private BoxBlur createDisablingEffect() 85 { 86 final var bb = new BoxBlur(); 87 bb.setWidth(5); 88 bb.setHeight(5); 89 bb.setIterations(3); 90 return bb; 91 } 92 93 /*********************************************************************************************************************************************************** 94 * TODO: delegate to a provider 95 **********************************************************************************************************************************************************/ 96 public static boolean isOSX() 97 { 98 return System.getProperty("os.name").contains("OS X"); 99 } 100 }