Fork me on GitHub

Application Layer

How to create your first start class.

Create your first Application

First Class to extend

JRebirth Application Framework offers a custom class that extends the basic javafx.Application class, the aim is to automatically start the JRebirth underlying Application Framework.

Short UML Diagram:

So you must extend org.jrebirth.core.application.AbstractApplication to be able to use JRebirth features.

If you have used the Maven archetype org.jrebirth.archetype you will obtain this source code :

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
public final class SampleApplication extends AbstractApplication<StackPane> {
 
    /**
     * Application launcher.
     *
     * @param args the command line arguments
     */
    public static void main(final String... args) {
        Application.launch(SampleApplication.class, args);
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public Class<? extends Model> getFirstModelClass() {
        return SampleModel.class;
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    protected String getApplicationTitle() {
        return "Sample Application - Powered by JRebirth";
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    protected void customizeStage(final Stage stage) {
        stage.setFullScreen(false);
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    protected void customizeScene(final Scene scene) {
        scene.getStylesheets().add("style/sample.css");
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public List<FontItem> getFontToPreload() {
        return Arrays.asList(new FontItem[] {
                SampleFonts.SPLASH
        });
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public List<Wave> getPreBootWaveList() {
        return Collections.emptyList();
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public List<Wave> getPostBootWaveList() {
        return Collections.emptyList();
    }
     
}

This class skeleton provides some hooks to allow customization of the application start up.
The AbstractApplication is using a generic type that represents the first JavaFX node hold by the scene. This node will be instantiated automatically by the framework and could be accessed by calling the protected method getRootNode().

First Model Class

The method Class<? extends Model> getFirstModelClass() is mandatory to define which UI model will be attached to the root node of the scene.

This first model will be created into the JRebirth Thread Pool, then it will be attached to the root node into the JavaFX Application Thread.

Application Title

The method String getApplicationTitle() is simply used to define the name of the application displayed by the stage (OS window) and used by OS task bar.

Stage customization

The first stage object is provided by the JavaFX launcher, the method void customizeStage(final Stage stage) allows doing some stage customizations.

Scene customization

The scene object automatically attached to the default stage stage is built by the protected method Scene buildScene() that could be overridden as needed. By defaut it creates a default scene with these attributes :

  • Width = 800
  • Height = 600
  • Background Color = Transparent
  • Root = Automatically built according to the generic type used

Theses attributes will be customizable soon with a properties file. TODO

Another method let you customize the scene : void customizeSscene(final Scene scene) . For example you can listen some key binding to perform a global action. The Presentation application uses it to listen <Ctrl> + <+> and <Ctrl> + <-> key combo to zoom in/out the whole scene.

This method is also useful to attach a stylesheet to the scene like this : scene.getStylesheets().add("style/sample.css");

Fonts preloading

JavaFX applications are able to use fonts throught programmatic declarations or with CSS declaration (in .css files. or inline).
If font used by CSS are not provided by the platform running the application, it must be provided and loaded by the application.
JRebirth provides a simple way to embed and declare font: this mechanism is explained in the custom topic: Managing Fonts.

The method List<FontEnum> getFontToPreload() is used to preload fonts to allow them to be used by CSS declaration. They are loaded at boot in the same time than stylesheets.

Running Waves

The JRebirth Application class allow running Waves before and after the creation of the first model class.

A Wave is a JRebirth Event that could be process by any JRebirth components, they are carrying throught JRebirth classes and threads.

You can add your own wave with the two following methods :

  • List<Wave> getPreBootWaveList()
  • List<Wave> getPostBootWaveList()

The waves returnes will be processed sequentially althought they could be processed by different threads.

In this method you are allowed to call visible methods from the javafx.application.Application class, in example the getParameter() will give you the arguments passed to command line

Don't forget that you can chain your waves if you need to do more than one thing.

JRebirth Analyzer example :

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@Override
public List<Wave> getPostBootWaveList() {
 
    final List<Wave> waveList = new ArrayList<>();
    final Parameters p = getParameters();
    if (p.getRaw().size() >= 1) {
        final String etdFile = p.getRaw().get(0);
        final File file = new File(etdFile);
        if (file.exists()) {
 
            waveList.add(
                    WaveBuilder.create()
                            .waveGroup(WaveGroup.RETURN_DATA)
                            .waveType(LoadEdtFileService.DO_LOAD_EVENTS)
                            .relatedClass(LoadEdtFileService.class)
                            .data(WaveData.build(EditorWaves.EVENTS_FILE, file))
                            .build()
                    );
 
            waveList.add(
                    WaveBuilder.create()
                            .waveType(EditorWaves.DO_PLAY)
                            .build()
                    );
        }
    }
    return waveList;
}

Default key shortcuts

The AbstractApplication class is using two defaults hotkey:

  • KeyCode getFullScreenKeyCode() => to go to to fullscreen mode (default is < F10 >)
  • KeyCode getIconifiedKeyCode() => to go to iconified mode (default is < F11 >)

These methods could be overridden if you want to change them, you can avoid these shortcut by returning null .

Exception Manager

JRebirth creates its own uncaught exception handlers in order to log exceptions that were not caught by application code.
It's possible to customize them by overriding methods listed hereafter:

  • UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
  • UncaughtExceptionHandler getJatUncaughtExceptionHandler()
  • UncaughtExceptionHandler getJitUncaughtExceptionHandler()