blob: 50d9c364bb086841e652ffa6af050461475bb7f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
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);
}
}
}
|