public class MobileApplication
extends javafx.application.Application
Application
class is to JavaFX applications. In fact, MobileApplication extends from
Application
, so the importance of this class should be clear.
Unlike Application
, MobileApplication
does not require
any specific methods to be implemented. There are requirements on the
developer, however. In particular, the developer of a mobile application has
to specify the views and layers in their application, and provide these to
the MobileApplication
instance as factories that can be called
on-demand.
The most important view factory is the one that specifies the 'home view', which is shown when the application first starts. For example, here is the code to create a view factory for the home view:
addViewFactory(MobileApplication.HOME_VIEW, () -> {
// normal JavaFX code to create a scenegraph of nodes
Node homeViewContent = ...;
return new View(homeViewContent);
});
Note in the code above that we call the
addViewFactory(String, Supplier)
method of the
MobileApplication
class, and we provide two arguments:
HOME_VIEW
public static field, but this can be
any String, as long as it is unique to your application (i.e. don't add
multiple view factories with the same name!).Supplier
implementation that, when called by
Glisten, should return a new instance of this particular View
. Note
that the returned object is a View
instance.
With this view defined (along with other views relevant to your
application), switching between views is simply a matter of calling
MobileApplication.getInstance().switchView("view-name")
, which
"view-name" is replaced by the name of the view you wish to go to (or, if
you wish to return home, simply HOME_VIEW
).
Similar functionality exists for layers
, which
make use of the GlassPane
to appear above the rest of your
application user interface.
The Application.init()
method, intended as in any JavaFX application to
perform initialization prior to the actual starting of the application, can
be overridden to add the views to the view factory. But, since there is no
scene or stage available yet, the developer can't switch to any view from
here.
Once the start(javafx.stage.Stage)
method is called, the stage,
the scene and the glasspane are initialized, so the developer can use the
postInit(javafx.scene.Scene)
method to select a Swatch
, add
an stylesheet or switch to a view, among others.
MobileApplication also installs application wide AppBar
and
NavigationDrawer
. A developer can simply call getAppBar()
or getDrawer()
to access these controls.
Type | Property and Description |
---|---|
javafx.beans.property.ObjectProperty<Swatch> |
swatch
Specifies the
Swatch that should be used for the whole scene. |
javafx.beans.property.StringProperty |
title
The title of the application.
|
javafx.beans.property.ReadOnlyObjectProperty<View> |
view
The currently showing
View within this application. |
Modifier and Type | Class and Description |
---|---|
static class |
MobileApplication.MobileEvent
Event class for events related to MobileApplication.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
HOME_VIEW
All Glisten-based applications should define one
View with its
name specified as HOME_VIEW . |
static java.lang.String |
SPLASH_VIEW
A Glisten-based application defines a
View with its
name specified as SPLASH_VIEW intended to be a one-time splash view. |
Modifier | Constructor and Description |
---|---|
protected |
MobileApplication()
Creates a new instance of MobileApplication.
|
Modifier and Type | Method and Description |
---|---|
void |
addLayerFactory(java.lang.String layerName,
java.util.function.Supplier<Layer> supplier)
Adds a new layer factory to this application, if the given layer name is
unique (otherwise an IllegalArgumentException is thrown).
|
void |
addViewFactory(java.lang.String viewName,
java.util.function.Supplier<View> supplier)
Adds a new view factory to this application, if the given view name is
unique (otherwise an IllegalArgumentException is thrown).
|
protected java.net.URLStreamHandlerFactory |
createUserURLStreamHandlerFactory()
URL handling is under control of mobile application.
|
AppBar |
getAppBar()
Returns the
AppBar instance that is a part of this application. |
NavigationDrawer |
getDrawer()
Returns the
NavigationDrawer instance that is a part of this application. |
GlassPane |
getGlassPane()
Returns the
GlassPane instance that is part of this application. |
static MobileApplication |
getInstance()
Returns the single instance of the MobileApplication.
|
double |
getScreenHeight()
Returns the height of the screen that this application is running on.
|
double |
getScreenWidth()
Returns the width of the screen that this application is running on.
|
StatusBar |
getStatusBar()
Returns the
StatusBar instance that is a part of this application. |
Swatch |
getSwatch()
Gets the value of the property swatch.
|
java.lang.String |
getTitle()
Gets the value of the property title.
|
View |
getView()
Gets the value of the property view.
|
<T extends View> |
goHome()
Returns to the home view and clears view stack.
|
void |
hideLayer(java.lang.String layerName)
Attempts to hide a layer with the given name.
|
boolean |
isLayerPresent(java.lang.String layerName)
Returns true if a layer factory with the layer name exists in the application.
|
boolean |
isViewPresent(java.lang.String viewName)
Returns true if a view factory with the view name exists in the application.
|
void |
postInit(javafx.scene.Scene scene)
Intended for adding additional initialization code.
|
boolean |
removeLayerFactory(java.lang.String layerName)
Removes a layer factory with the given layer name from this application,
if it is present (optional operation).
|
boolean |
removeViewFactory(java.lang.String viewName)
Removes a view factory with the given view name from this application,
if it is present (optional operation).
|
java.util.Optional<View> |
retrieveView(java.lang.String viewName)
Attempts to retrieve the view represented by the given view name.
|
void |
setSwatch(Swatch swatch)
Sets the value of the property swatch.
|
void |
setTitle(java.lang.String title)
Sets the value of the property title.
|
void |
showLayer(java.lang.String layerName)
Attempts to show a layer with the given name.
|
void |
showMessage(java.lang.String message)
Shows a
Snackbar with the supplied message. |
void |
showMessage(java.lang.String message,
java.lang.String buttonText,
javafx.event.EventHandler<javafx.event.ActionEvent> evtHandler)
Shows a
Snackbar with the supplied message and an action text. |
void |
start(javafx.stage.Stage primaryStage) |
javafx.beans.property.ObjectProperty<Swatch> |
swatchProperty()
Specifies the
Swatch that should be used for the whole scene. |
<T extends View> |
switchToPreviousView()
Attempts to switch to a previously used view if one exists.
|
<T extends View> |
switchView(java.lang.String viewName)
Attempts to switch the view from the current view to a view represented by
the given view name.
|
<T extends View> |
switchView(java.lang.String viewName,
ViewStackPolicy viewStackPolicy)
Attempts to switch the view from the current view to a view represented by
the given view name.
|
javafx.beans.property.StringProperty |
titleProperty()
The title of the application.
|
javafx.beans.property.ReadOnlyObjectProperty<View> |
viewProperty()
The currently showing
View within this application. |
public final javafx.beans.property.StringProperty titleProperty
getTitle()
,
setTitle(String)
public final javafx.beans.property.ReadOnlyObjectProperty<View> viewProperty
View
within this application.getView()
public final javafx.beans.property.ObjectProperty<Swatch> swatchProperty
Swatch
that should be used for the whole scene.
If this property has a null value the default swatch will be used.getSwatch()
,
setSwatch(Swatch)
public static final java.lang.String HOME_VIEW
View
with its
name specified as HOME_VIEW
. This View will then become the default
view of the user interface.public static final java.lang.String SPLASH_VIEW
View
with its
name specified as SPLASH_VIEW
intended to be a one-time splash view.
After a given amount of time or certain event, this view will be dismissed
giving access to the HOME_VIEW
or any other view.protected MobileApplication()
public static MobileApplication getInstance()
public final void start(javafx.stage.Stage primaryStage)
start
in class javafx.application.Application
public final javafx.beans.property.StringProperty titleProperty()
getTitle()
,
setTitle(String)
public final void setTitle(java.lang.String title)
public final java.lang.String getTitle()
public final javafx.beans.property.ReadOnlyObjectProperty<View> viewProperty()
View
within this application.getView()
public final View getView()
View
within this application.public final javafx.beans.property.ObjectProperty<Swatch> swatchProperty()
Swatch
that should be used for the whole scene.
If this property has a null value the default swatch will be used.getSwatch()
,
setSwatch(Swatch)
public final Swatch getSwatch()
Swatch
that should be used for the whole scene.
If this property has a null value the default swatch will be used.public final void setSwatch(Swatch swatch)
Swatch
that should be used for the whole scene.
If this property has a null value the default swatch will be used.public final GlassPane getGlassPane()
GlassPane
instance that is part of this application.GlassPane
instance of this application.public final AppBar getAppBar()
AppBar
instance that is a part of this application.AppBar
instance of the current application.public final NavigationDrawer getDrawer()
NavigationDrawer
instance that is a part of this application.NavigationDrawer
instance of the current application.public final StatusBar getStatusBar()
StatusBar
instance that is a part of this application. Note that
not all platforms have a status bar.StatusBar
instance of the current application.public void postInit(javafx.scene.Scene scene)
scene
- application scene.public final <T extends View> java.util.Optional<T> switchView(java.lang.String viewName)
T
- the view typeviewName
- name of the view to switch to.public final <T extends View> java.util.Optional<T> switchView(java.lang.String viewName, ViewStackPolicy viewStackPolicy)
T
- the view typeviewName
- name of the view to switch to.viewStackPolicy
- ViewStackPolicy
.public final <T extends View> java.util.Optional<T> switchToPreviousView()
T
- the view typepublic final <T extends View> java.util.Optional<T> goHome()
T
- the view typepublic final java.util.Optional<View> retrieveView(java.lang.String viewName)
Optional
, to prevent null pointer
exceptions.viewName
- The name of the View
- this will be used at other points
in the application lifecycle to reference this view, and to
switch to it
.Optional
with the View
, if not emptypublic final void addViewFactory(java.lang.String viewName, java.util.function.Supplier<View> supplier)
viewName
- The name of the view - this will be used at other points
in the application lifecycle to reference this view, and to
switch to it
.supplier
- A Supplier
instance that, when called, should
return the view. This view is cached inside the mobile application,
and as such is reused throughout the life of the application
instance.public final boolean removeViewFactory(java.lang.String viewName)
viewName
- The name of the view which is mapped to the view factory.public final boolean isViewPresent(java.lang.String viewName)
viewName
- The name of the view which is mapped to the view factory.public final void addLayerFactory(java.lang.String layerName, java.util.function.Supplier<Layer> supplier)
layerName
- The name of the layer - this will be used at other points
in the application lifecycle to reference this layer, and to
show it
.supplier
- A Supplier
instance that, when called, should
return the Layer
. This layer is cached inside the mobile
application, and as such is reused throughout the life of the
application instance.public final boolean removeLayerFactory(java.lang.String layerName)
layerName
- The name of the layer which is mapped to the layer factory.public final boolean isLayerPresent(java.lang.String layerName)
layerName
- The name of the layer which is mapped to the layer factory.public final void showLayer(java.lang.String layerName)
Layer.show()
.layerName
- The name of the layer which is mapped to the layer factory.public final void hideLayer(java.lang.String layerName)
Layer.hide()
.layerName
- The name of the layer which is mapped to the layer factory.public final double getScreenHeight()
public final double getScreenWidth()
public void showMessage(java.lang.String message)
Snackbar
with the supplied message.message
- A String
messagepublic void showMessage(java.lang.String message, java.lang.String buttonText, javafx.event.EventHandler<javafx.event.ActionEvent> evtHandler)
Snackbar
with the supplied message and an action text.message
- A String
message.buttonText
- A String
text to set action text caption.evtHandler
- An EventHandler
with the action to be invoked when the
user clicks the action text.protected java.net.URLStreamHandlerFactory createUserURLStreamHandlerFactory()