Displays HTML content as a "panel". @param The class of the controller
| 38 | * @param <T> The class of the controller |
| 39 | */ |
| 40 | public final class JFXPanelFromResource<T> extends JFXPanel implements Controllable<T> |
| 41 | { |
| 42 | |
| 43 | private final FXMLLoader fxmlLoader = new FXMLLoader(); |
| 44 | |
| 45 | /** |
| 46 | * @param klass the class that contains the resource load |
| 47 | * @param resourceName the relative filename of the FXML file to load. |
| 48 | */ |
| 49 | public JFXPanelFromResource(Class<? extends T> klass, String resourceName) |
| 50 | { |
| 51 | URL resource = klass.getResource(resourceName); |
| 52 | Objects.requireNonNull(resource); |
| 53 | Logging.debugPrint(String.format("location for %s (%s) is %s", resourceName, klass, resource)); |
| 54 | fxmlLoader.setLocation(resource); |
| 55 | fxmlLoader.setResources(LanguageBundle.getBundle()); |
| 56 | Platform.runLater(() -> { |
| 57 | try |
| 58 | { |
| 59 | Scene scene = fxmlLoader.load(); |
| 60 | this.setScene(scene); |
| 61 | } catch (IOException e) |
| 62 | { |
| 63 | Logging.errorPrint(String.format("failed to load stream fxml (%s/%s/%s)", |
| 64 | resourceName, klass, resource), e); |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public T getController() |
| 71 | { |
| 72 | if (Platform.isFxApplicationThread()) |
| 73 | { |
| 74 | return fxmlLoader.getController(); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | return GuiUtility.runOnJavaFXThreadNow(fxmlLoader::getController); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | public T getControllerFromJavaFXThread() |
| 83 | { |
| 84 | GuiAssertions.assertIsJavaFXThread(); |
| 85 | return fxmlLoader.getController(); |
| 86 | } |
| 87 | |
| 88 | public void showAsStage(String title) |
| 89 | { |
| 90 | Platform.runLater(() -> { |
| 91 | Stage stage = new Stage(); |
| 92 | stage.setTitle(title); |
| 93 | stage.setScene(getScene()); |
| 94 | stage.sizeToScene(); |
| 95 | stage.show(); |
| 96 | }); |
| 97 | } |
nothing calls this directly
no outgoing calls
no test coverage detected