Dev tools
While you build a UI, the dev jar adds an inspector, reload shortcuts, a hot reload, a profiler and warnings. The prod jar has none of them, so the application you ship carries no debug code.
You will learn
- How to turn the dev tools on
- How to inspect the nodes of a UI
- How to reload a UI while you work
- How to find slow loads and slow frames
- How to read the warnings of JOID
Turn the dev tools on
Section titled “Turn the dev tools on”Put the dev jar of your backend on the classpath, as Installation shows: JOID turns its dev mode on when it finds the dev classes, and there is nothing to call.
The line that JOID prints when the backend registers confirms it with loaded in dev mode.
Your own code reads the mode with JOIDEnv.isDevMode, for example to show a text during development only:
if (JOIDEnv.isDevMode()) { TextNode.create(20, 20).text(Text.create("Dev build", style)).attach(this);}JOIDEnv.devMode(false) turns the dev mode off while the dev jar runs, to see a screen as the prod jar draws it; turning it on throws IllegalStateException on the prod jar, which has no dev classes.
Inspect a UI
Section titled “Inspect a UI”Press F3 to show or hide the dev panel, in the bottom-right corner of the UI on top.
Drag it to move it.
Its three buttons are Inspect, Reload and Grid, next to the frame rate of the UI; hover one to read its shortcut.
Inspect is on when the panel shows.
Ctrl reaches the node behind it.
| Key or click, panel shown | Effect |
|---|---|
I | Turns Inspect off or on: the node under the pointer is outlined, with its class and its render time. Hold Ctrl to outline the node at the back of the pile under the pointer instead of the one in front. |
| Left click | Locks the outlined node; the panel grows and lists its bounds, its listeners, its hierarchy, its children and the values of its fields, and the wheel scrolls the list. A click on the hierarchy line locks the parent, a click on a child locks that child. |
Enter | Locks the parent of the inspected node. |
| Right click | Unlocks the node. |
G | Shows the grid: the center lines of the canvas and the distances from the pointer to its four edges, in design pixels. A right click changes its color. |
R | Reloads the UI, as Ctrl+R does. |
The dev mode adds zoom shortcuts to every zoomable UI: Ctrl or Alt with = (the key of +) or the + of the numeric keypad, and with -, zoom it by steps of 0.1, and Alt with the wheel by small steps, with Shift for larger ones.
Reload a UI while you work
Section titled “Reload a UI while you work”| Shortcut | Calls |
|---|---|
Ctrl+R or F5 | UI.reload |
Ctrl+Shift+R or Shift+F5 | UI.renew |
Ctrl+R keeps the count, Ctrl+Shift+R resets it.
Rebuild an open UI explains what each of them keeps.
A reload that fails prints the exception instead of stopping the program: [JOID] The reload of MenuUI failed: … with the message of an IllegalStateException, such as a missing setting, or else [JOID] The reload of MenuUI failed (…), fix init() then reload it again.
A UI without a constructor without argument cannot be renewed: [JOID] The reload of MenuUI failed: The UI … has no constructor without argument, it cannot be renewed: use Ctrl + R to reload it instead.
Hot reload reloads a UI by itself.
JOID watches the folder or the jar file that the classes of the UI come from, and reloads the UI about a second after a .class file of that folder, or the jar file, changes.
A class loader that gives each class the location of its own file, a jar: URL to its entry in a jar or the URL of its .class file, leads JOID to that jar or to the root folder of the classes.
The console tells you each step, and every reload, by a shortcut or by hot reload, prints its time on one line:
[JOID] Hot reload is on for MenuUI, it reloads when its classes change[JOID] MenuUI.class changed, the UIs that use it reload[JOID] MenuUI reloaded in 4.12msJOID loads no new code itself: start your application in debug mode from your IDE, so that the IDE replaces the method bodies when you compile, and hot reload runs the new init().
A change that the JVM cannot swap, such as an added field or an added method, needs a restart.
When the classes of a UI come from neither a folder nor a jar file, JOID prints [JOID] Hot reload is off for …: its classes are not loaded from a folder or a jar file, run it from one of them to reload it once.
Find slow loads and slow frames
Section titled “Find slow loads and slow frames”The profiler writes each load of a UI on the standard output, except a reload, which prints its own line, and each slow frame on the error output:
[JOID] MenuUI loaded in 18.40ms[JOID] MenuUI took 21.73ms to draw a frame, more than the 16.66ms of 60 fps: …The profiler skips the first frame after each load or reload of the UI: that frame prepares everything the UI draws for the first time, such as its shaders, its glyphs and the framebuffers of its effects, and takes far longer than the next ones.
The slow-frame line ends with its advice: move the heavy work out of draw(), the method of a node that draws itself (Custom nodes), or spread it over several frames.
The inspector tells you which node is slow: its label gives the render time of the node under the pointer.
Performance explains what to look for.
Turn the profiler or the hot reload off for one UI with UIDataDebug, for example a UI that is slow on purpose or loaded from generated classes:
@UIDataDebug(profiler = false, hotreload = false)public class ChartUI extends UI {While the UI runs, UI.getDebug changes the same settings: super.getDebug().profiler(false) silences the profiler at once, and a change of hotreload applies at the next frame.
Read the warnings
Section titled “Read the warnings”When JOID cannot do what your code asks, it prints a line that starts with [JOID] on the error output, most of the time once per cause.
For example: a setter that cannot follow its signals, a shader that the driver refuses, a resource that cannot be read, a font weight that the font does not have, a window UI bridge without a tooltip style.
Most warnings print with the dev jar only. The dev mode also draws a resource that cannot be read as a magenta and black checkerboard, where the prod jar draws nothing (Know when an image is loaded).
Warnings and errors lists every message with its cause and its fix.
Before you ship, Ship your application switches to the prod jar and checks what changes.
- The dev jar turns the dev mode on by itself;
JOIDEnv.isDevMode()reads it. F3shows the dev panel: Inspect (I), Grid (G), Reload (R); a click locks a node and lists its properties.Ctrl+Rreloads the UI andCtrl+Shift+Rrenews it (Rebuild an open UI).- Hot reload reloads a UI when its classes change; pair it with the debug mode of your IDE.
- The profiler prints load times and frames over 16.66 ms;
@UIDataDebugturns it off for one UI. [JOID]warnings explain what JOID could not do; the reference lists them all.
Try it
Section titled “Try it”A reload that changes nothing.
You changed a color in init() and pressed Ctrl+R, but the UI still shows the old color.
What is missing?
Solution
The new code never reached the JVM.
Start the application in debug mode so that the IDE swaps the method body when you compile; then Ctrl+R, or the hot reload, runs the new init().
The node behind. Inspect outlines a bar that sits on a card, but you want the render time of the card. How do you reach it?
Solution
Hold Ctrl: Inspect outlines the node at the back of the pile under the pointer, here the card, with its render time.
