location = new URL(locationString);
} catch (final MalformedURLException e) {
throw new RuntimeException(String.format("Cannot construct URL from string '%s'.", locationString), e);
}
}
final FXMLLoader fxmlLoader = new FXMLLoader(location);
final String resourcesString = annotation.resources();
if (!resourcesString.isEmpty()) {
fxmlLoader.setResources(ResourceBundle.getBundle(resourcesString));
}
fxmlLoader.setCharset(Charset.forName(annotation.charset()));
fxmlLoader.setController(instance);
fxmlLoader.setRoot(instance);
// Actual instantiation of the component has to happen on the JavaFX thread.
// We simply delegate the loading.
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
final Object loaded = fxmlLoader.load();
if (loaded != instance) {
throw new IllegalStateException("Loading of FXML component went terribly wrong! :-(");
}
} catch (final IOException e) {
throw new RuntimeException(e);