From 7f7090f009174ac0ee7df84124f78b075facd923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 22 Feb 2019 00:56:24 +0100 Subject: [PATCH] Improve initialization output --- .../pmd/util/fxdesigner/Designer.java | 44 ++++++++++++++----- .../fxdesigner/app/NodeSelectionSource.java | 2 +- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java index 021ebdd8c6..33bcfcfc25 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/Designer.java @@ -34,23 +34,30 @@ import javafx.stage.Stage; */ public class Designer extends Application { - private boolean parseParameters(Parameters params) { + private boolean isDeveloperMode; + private long initStartTimeMillis; + + public Designer() { + initStartTimeMillis = System.currentTimeMillis(); + } + + private void parseParameters(Parameters params) { List raw = params.getRaw(); - if (!raw.contains("-v") - && !raw.contains("--verbose")) { - // error output is disabled by default - - System.err.close(); - return false; + // error output is disabled by default + if (raw.contains("-v") || raw.contains("--verbose")) { + isDeveloperMode = true; } - return true; } @Override public void start(Stage stage) throws IOException { - boolean isDeveloperMode = parseParameters(getParameters()); + parseParameters(getParameters()); + stage.setTitle("PMD Rule Designer (v " + PMDVersion.VERSION + ')'); + setIcons(stage); + + System.out.print(stage.getTitle() + " initializing... "); FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("designer.fxml")); @@ -66,6 +73,10 @@ public class Designer extends Application { boolean needsRoot = Arrays.stream(type.getConstructors()).anyMatch(it -> ArrayUtils.contains(it.getParameterTypes(), DesignerRoot.class)); if (needsRoot) { + // Controls that need the DesignerRoot can declare a constructor + // with a parameter w/ signature @NamedArg("designerRoot") DesignerRoot + // to be injected with the relevant instance of the app. + // TODO Not everything has been refactored to use this mechanism for now ProxyBuilder builder = new ProxyBuilder<>(type); builder.put("designerRoot", owner); return builder; @@ -99,11 +110,20 @@ public class Designer extends Application { Parent root = loader.load(); Scene scene = new Scene(root); - stage.setTitle("PMD Rule Designer (v " + PMDVersion.VERSION + ')'); - setIcons(stage); - stage.setScene(scene); + + if (owner.isDeveloperMode()) { + // only close after initialization succeeded. + // but before stage.show to reduce unwanted noise + System.err.close(); + } + stage.show(); + + long initTime = System.currentTimeMillis() - initStartTimeMillis; + + System.out.println("done in " + initTime + "ms."); + System.out.println("Run with --verbose parameter to enable error output."); } diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/NodeSelectionSource.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/NodeSelectionSource.java index 1b1b7f4756..f563f0c484 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/NodeSelectionSource.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/app/NodeSelectionSource.java @@ -34,7 +34,7 @@ public interface NodeSelectionSource extends ApplicationComponent { * Initialises this component. Must be called by the component somewhere. * * @param root Instance of the app. Should be the same as {@link #getDesignerRoot()}, - * but a parameter here to make it clear that {@link #getDesignerRoot()} + * but the parameter here is to make it clear that {@link #getDesignerRoot()} * must be initialized before this method is called. * @param mySelectionEvents Stream of nodes that should push an event each * @param alwaysHandleSelection Whether the component should handle selection events that originated from itself.