package market.guess.ui.desktop.util; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URL; import javafx.css.PseudoClass; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Parent; import market.guess.ui.desktop.AppView; /** Shared JavaFX view mechanics, pseudo-class management, and FXML root loading. */ public final class Views { private Views() {} public static final PseudoClass SELECTED = PseudoClass.getPseudoClass("selected"); public static void setSelected(Node node, boolean selected) { if (node != null) { node.pseudoClassStateChanged(SELECTED, selected); } } public static void loadRoot(Parent root, String fxmlName) { URL res = AppView.class.getResource(fxmlName); if (res == null) { res = AppView.class.getResource("/market/guess/ui/desktop/" + fxmlName); } if (res == null) { throw new IllegalArgumentException("Cannot find FXML resource: " + fxmlName); } FXMLLoader loader = new FXMLLoader(res); loader.setRoot(root); loader.setController(root); try { loader.load(); } catch (IOException e) { throw new UncheckedIOException("Failed to load " + fxmlName, e); } } }