Class MegalodonteApp

java.lang.Object
megalodonte.application.MegalodonteApp

public final class MegalodonteApp extends Object
Main entry point for Megalodonte applications. Provides static factory methods to launch a JavaFX application with the framework's bootstrap lifecycle.

Typical usage:

MegalodonteApp.appName("My App");
MegalodonteApp.run(MyHost.class, args, context -> {
    context.useRouter(AppRouter.build()).start();
});
  • Constructor Details

    • MegalodonteApp

      public MegalodonteApp()
  • Method Details

    • getCurrentContext

      public static Context getCurrentContext()
      Returns the application context, available after run(Consumer, Consumer) has been called. @return the context
    • getArgs

      public static String[] getArgs()
      Returns the command-line arguments passed to the application. @return the arguments array
    • appName

      public static void appName(String name)
      Sets the application display name. Used by LinuxDesktopEntry for the dev-mode .desktop file and by Bootstrap for javafx.application.name. Must be called before run(Consumer, Consumer).
      Parameters:
      name - the application display name
    • appIcon

      public static void appIcon(String classpathResourcePath)
      Classpath resource path (e.g. "/assets/app_ico.png") for the app's icon. Applied to the primary stage and inherited by windows spawned through the router, unless a route declares its own icon. On Linux it is also used to seed the dev-mode .desktop entry — see LinuxDesktopEntry. This gets the dock/taskbar icon working when running straight from a JVM (IDE, gradle run, ...) instead of an installed package. Pair with a custom launcher class (see the run(Class, ...) overloads below) to also get a WM_CLASS unique to your app.
      Parameters:
      classpathResourcePath - classpath resource path (e.g. "/assets/app_icon.png")
    • run

      public static void run(Consumer<Context> contextHandler, Consumer<MegalodonteApp.Event> onEvent)
      Launches the application using the default JavaFXHost launcher.
      Parameters:
      contextHandler - called once during bootstrap with the application Context
      onEvent - called for framework events (e.g. MegalodonteApp.Event.CloseRequest)
    • run

      public static void run(Consumer<Context> contextHandler)
      Launches the application using the default JavaFXHost launcher.
      Parameters:
      contextHandler - called once during bootstrap with the application Context
    • run

      public static void run(String[] args, Consumer<Context> contextHandler, Consumer<MegalodonteApp.Event> onEvent)
      Launches the application with command-line arguments.
      Parameters:
      args - command-line arguments forwarded to JavaFX
      contextHandler - called once during bootstrap with the application Context
      onEvent - called for framework events
    • run

      public static void run(String[] args, Consumer<Context> contextHandler)
      Launches the application with command-line arguments.
      Parameters:
      args - command-line arguments forwarded to JavaFX
      contextHandler - called once during bootstrap with the application Context
    • run

      public static void run(Class<? extends javafx.application.Application> appClass, String[] args, Consumer<Context> contextHandler, Consumer<MegalodonteApp.Event> onEvent)
      Same as run(String[], Consumer, Consumer), but launching through appClass instead of the shared default JavaFXHost.

      On Linux/GTK, the running window's WM_CLASS is the launched Application subclass's fully-qualified name (confirmed via xprop WM_CLASS — appName(String) alone does not affect it). Every app defaulting to JavaFXHost therefore reports the same WM_CLASS, and GNOME's dock/taskbar can't tell them apart (same icon, same grouping). Pass your own MegalodonteApplication subclass here to get a WM_CLASS — and taskbar icon — unique to your app:

      public static class AppHost extends MegalodonteApplication {}
      
      static void main(String[] args) {
          MegalodonteApp.run(AppHost.class, args, Main::start, Main::onEvent);
      }
      
    • run

      public static void run(Class<? extends javafx.application.Application> appClass, String[] args, Consumer<Context> contextHandler)
    • run

      public static void run(Class<? extends javafx.application.Application> appClass, Consumer<Context> contextHandler, Consumer<MegalodonteApp.Event> onEvent)
    • run

      public static void run(Class<? extends javafx.application.Application> appClass, Consumer<Context> contextHandler)