diff --git a/README.md b/README.md index f7237ed..78fe80a 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,16 @@ In addition, it is also highly beginner-friendly, making it accessible to everyo vertical().add(text("Hello World!")) ```
-3 lines example +Minimal example ```java import com.osiris.desku.App; import static com.osiris.desku.Statics; public class Main { public static void main(String[] args) throws Exception { - App.init(new DesktopUIManager()); + App.uis = new DesktopUIManager(); // Not needed when using the Desku-Gradle-Starter-App App.name = "My-App"; + App.init(); App.uis.create(() -> { return vertical().add(text("Hello World!")); }); @@ -37,9 +38,10 @@ import static com.osiris.desku.Statics; // Low-code Java UI via static methods public class Main { public static void main(String[] args) throws Exception { - // Setup app details. - App.init(new DesktopUIManager()); // Not needed when using the Desku-Gradle-Starter-App + // Setup app details and init. + App.uis = new DesktopUIManager(); // Not needed when using the Desku-Gradle-Starter-App App.name = "My-App"; + App.init(); // Create routes. // This is only for demonstration. diff --git a/src/main/java/com/osiris/desku/App.java b/src/main/java/com/osiris/desku/App.java index da6db02..15974f0 100644 --- a/src/main/java/com/osiris/desku/App.java +++ b/src/main/java/com/osiris/desku/App.java @@ -110,6 +110,7 @@ public static void updateDirs(){ */ public static Theme theme = new Theme(); + public static UIManager uis = null; public static ExecutorService executor = Executors.newCachedThreadPool(); @@ -127,16 +128,25 @@ public LoggerParams() { } } + /** + * Initialize assuming platform-specific {@link UIManager} was already set earlier.
+ * Meaning {@link App#uis} must be not null when calling this. + */ + public static void init() { + init(null, new LoggerParams()); + } + public static void init(UIManager uiManager) { init(uiManager, new LoggerParams()); } public static void init(UIManager uiManager, LoggerParams loggerParams) { - if (uiManager == null) { + if (uiManager == null && App.uis == null) { throw new NullPointerException("Provided UI factory is null!" + " Make sure to provide an implementation for the platform this app is running in."); } - App.uis = uiManager; + if(uiManager != null) + App.uis = uiManager; try { updateDirs(); Logger.getGlobal().setLevel(Level.SEVERE); diff --git a/src/test/java/com/osiris/desku/simple_app/AppTest.java b/src/test/java/com/osiris/desku/simple_app/AppTest.java index 3e828b4..fae4033 100644 --- a/src/test/java/com/osiris/desku/simple_app/AppTest.java +++ b/src/test/java/com/osiris/desku/simple_app/AppTest.java @@ -10,10 +10,10 @@ class AppTest { public static void main(String[] args) throws Exception { - // Setup details - App.init(new DesktopUIManager()); - App.name = "My-App"; - // before loading the page + // Setup details before init + App.uis = new DesktopUIManager(); + App.name = "My-Example-Desku-App"; + App.init(); // Create routes Route home = new Home();