Top Fields Constructors Methods
com.airhacks.afterburner.views

public Class ViewLoader

extends Object
Class Inheritance
Imports
java.io.IOException, java.net.URL, java.util.ResourceBundle, java.util.concurrent.CompletableFuture, .Executor, .ExecutorService, .Executors, java.util.function.Consumer, .Function, .Supplier, javafx.application.Platform, javafx.fxml.FXMLLoader, javafx.scene.Parent, javafx.util.Callback, com.airhacks.afterburner.injection.PresenterFactory, org.slf4j.Logger, .LoggerFactory

Author
adam-bien.com

Field Summary

Modifier and TypeField and Description
private static final String
protected String
protected final Class<?>
private static final String
private static final String
protected static Executor
protected FXMLLoader
private static final Logger
protected static final ExecutorService
protected URL

Constructor Summary

AccessConstructor and Description
private
ViewLoader(Class<?> clazz)

Method Summary

Modifier and TypeMethod and Description
private void
public ViewLoader
controller(Object root)

Sets the given class as controller.

public Void

Returns:

nothing
exceptionReporter
(Throwable
exception to report
t
)

private String

Returns:

the conventional name of the bss file expected.
getBinaryStyleSheetName
()

.bss files are binary encoded css files which javafx produces.

private String
protected String

Returns:

the conventional name with stripped ending
getConventionalName
(boolean
indicates whether the simple class name should be converted to lowercase of left unchanged
lowercase
,
String
the suffix to append
ending
)

protected String

Returns:

the name of the view without the "View" prefix.
getConventionalName
(boolean
indicates whether the simple class name should be
lowercase
)

private static ExecutorService
private String

Returns:

the name of the fxml file derived from the FXML view. e.g. The name for the AirhacksView is going to be airhacks.fxml.
getFXMLName
()

private String
getResourceCamelOrLowerCase(boolean mandatory, String ending)

private String
public ViewLoader
inject(Function<String, Object>
the function used as a injection source.
injectionContext
)

Specifies the injection source used to construct the controller.

public ViewLoaderResult

Returns:

a composite object giving access to the loaded root node and initialized controller
load
()

Synchronously loads the FXML file and associated resources.

public void
load(Consumer<Parent>
the callback that receives the loaded root node
consumer
)

Synchronously loads the FXML file and associated resources and invokes the created root node to the given consumer within the FX UI thread.

public void
loadAsync(Consumer<Parent>
the callback that receives the loaded root node
consumer
)

Asynchronously loads the FXML file and associated resources using an internal thread pool and invokes the created root node to the given consumer within the FX UI thread.

public ViewLoader
root(Object
the object used as the root
root
)

Sets the root of the object hierarchy.

private static String
private void
public static ViewLoader
view(Class<? extends Object> clazz)

Initialized the ViewLoader to load the given view.

public static ViewLoader
view(Object root)

Initialized the ViewLoader to load the given view.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BSS_FILE_ENDINGback to summary
private static final String BSS_FILE_ENDING
bundleNameback to summary
protected String bundleName
clazzback to summary
protected final Class<?> clazz
CSS_FILE_ENDINGback to summary
private static final String CSS_FILE_ENDING
DEFAULT_ENDINGback to summary
private static final String DEFAULT_ENDING
FX_PLATFORM_EXECUTORback to summary
protected static Executor FX_PLATFORM_EXECUTOR
fxmlLoaderback to summary
protected FXMLLoader fxmlLoader
LOGGERback to summary
private static final Logger LOGGER
PARENT_CREATION_POOLback to summary
protected static final ExecutorService PARENT_CREATION_POOL
resourceback to summary
protected URL resource

Constructor Detail

ViewLoaderback to summary
private ViewLoader(Class<?> clazz)

Method Detail

addCSSIfAvailableback to summary
private void addCSSIfAvailable(Parent parent)
controllerback to summary
public ViewLoader controller(Object root)

Sets the given class as controller. We don't use FXMLLoader#setController(Object) since then the fx:controller attribute is no longer allowed in the fxml file and we loose IDE support.

exceptionReporterback to summary
public Void exceptionReporter(Throwable t)
Parameters
t:Throwable

exception to report

Returns:Void

nothing

getBinaryStyleSheetNameback to summary
private String getBinaryStyleSheetName()

.bss files are binary encoded css files which javafx produces.

Returns:String

the conventional name of the bss file expected.

getBundleNameback to summary
private String getBundleName()
getConventionalNameback to summary
protected String getConventionalName(boolean lowercase, String ending)
Parameters
lowercase:boolean

indicates whether the simple class name should be converted to lowercase of left unchanged

ending:String

the suffix to append

Returns:String

the conventional name with stripped ending

getConventionalNameback to summary
protected String getConventionalName(boolean lowercase)
Parameters
lowercase:boolean

indicates whether the simple class name should be

Returns:String

the name of the view without the "View" prefix.

getExecutorServiceback to summary
private static ExecutorService getExecutorService()
getFXMLNameback to summary
private String getFXMLName()
Returns:String

the name of the fxml file derived from the FXML view. e.g. The name for the AirhacksView is going to be airhacks.fxml.

getResourceCamelOrLowerCaseback to summary
private String getResourceCamelOrLowerCase(boolean mandatory, String ending)
getStyleSheetNameback to summary
private String getStyleSheetName()
injectback to summary
public ViewLoader inject(Function<String, Object> injectionContext)

Specifies the injection source used to construct the controller. Values matching for the keys are going to be used for injection into the corresponding controller.

Parameters
injectionContext:Function<String, Object>

the function used as a injection source.

loadback to summary
public ViewLoaderResult load() throws IllegalStateException

Synchronously loads the FXML file and associated resources.

Returns:ViewLoaderResult

a composite object giving access to the loaded root node and initialized controller

Exceptions
IllegalStateException:
if an exception occurred during loading and parsing of the FXML file
loadback to summary
public void load(Consumer<Parent> consumer)

Synchronously loads the FXML file and associated resources and invokes the created root node to the given consumer within the FX UI thread.

Parameters
consumer:Consumer<Parent>

the callback that receives the loaded root node

loadAsyncback to summary
public void loadAsync(Consumer<Parent> consumer)

Asynchronously loads the FXML file and associated resources using an internal thread pool and invokes the created root node to the given consumer within the FX UI thread.

Parameters
consumer:Consumer<Parent>

the callback that receives the loaded root node

rootback to summary
public ViewLoader root(Object root)

Sets the root of the object hierarchy. The value passed to this method is used as the value of the <fx:root> tag. This method must be called prior to loading the document when using <fx:root>.

Parameters
root:Object

the object used as the root

stripEndingback to summary
private static String stripEnding(String clazz)
updateControllerFactoryback to summary
private void updateControllerFactory(Function<String, Object> injectionContext)
viewback to summary
public static ViewLoader view(Class<? extends Object> clazz)

Initialized the ViewLoader to load the given view. The fxml (or other resources) are not yet loaded.

viewback to summary
public static ViewLoader view(Object root)

Initialized the ViewLoader to load the given view. The given object is used as the controller. The fxml (or other resources) are not yet loaded.