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(MobileApplication.HOME_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.
Type | Property and Description |
---|---|
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 | Field and Description |
---|---|
static java.lang.String |
HOME_VIEW
All Glisten-based applications should define one
View with its
name specified as HOME_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).
|
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.
|
java.lang.String |
getTitle()
Gets the value of the property title.
|
View |
getView()
Gets the value of the property view.
|
void |
hideLayer(java.lang.String layerName)
Attempts to hide a layer with the given name.
|
void |
postInit(javafx.scene.Scene scene)
Intended for adding aditional initilization code
|
java.util.Optional<View> |
retrieveView(java.lang.String viewname)
Attempts to retrieve the view represented by the given view name.
|
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 text) |
void |
start(javafx.stage.Stage primaryStage) |
void |
switchToPreviousView()
Attempts to switch to a previously used view if one exists
|
void |
switchView(java.lang.String viewName)
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 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.protected MobileApplication()
public static MobileApplication getInstance()
public final void start(javafx.stage.Stage primaryStage) throws java.lang.Exception
start
in class javafx.application.Application
java.lang.Exception
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()
getView()
public final View getView()
public final GlassPane getGlassPane()
GlassPane
instance that is part of this application.public void postInit(javafx.scene.Scene scene)
scene
- application scenepublic final void switchView(java.lang.String viewName)
public final void switchToPreviousView()
public final java.util.Optional<View> retrieveView(java.lang.String viewname)
Optional
, to prevent null pointer
exceptions.public 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 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 void showLayer(java.lang.String layerName)
Layer.show()
.public final void hideLayer(java.lang.String layerName)
Layer.hide()
.public final double getScreenHeight()
public final double getScreenWidth()
public void showMessage(java.lang.String text)