From 7fb86bfdf6902aba56e8e5a283bcb4a3aad871c2 Mon Sep 17 00:00:00 2001 From: Naoghuman Date: Thu, 7 Mar 2019 19:07:27 +0100 Subject: [PATCH] #42 Tweak the 'demo with all files'. --- ...ease_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md | 2 +- .../lib/fxml/core/DemoWithAllFiles.java | 12 ++- .../fxml/core/DemoWithAllFilesController.java | 90 ++++++++++++++----- .../lib/fxml/core/demowithallfiles.fxml | 76 +--------------- .../fxml/core/demowithoutpropertiesfile.css | 21 +++++ .../fxml/core/demowithoutpropertiesfile.fxml | 87 ++++++++++++++++++ 6 files changed, 190 insertions(+), 98 deletions(-) create mode 100644 src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.css create mode 100644 src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.fxml diff --git a/release/Release_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md b/release/Release_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md index a40d853..880dd09 100644 --- a/release/Release_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md +++ b/release/Release_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md @@ -21,6 +21,7 @@ and connect them to a controller (called the presenter). #48 [test] Enhance the method DefaultFXMLValidator.requireEndsWith(...). #47 [api] Create 'FXMLModel.EMPTY' instance in the class FXMLModel. #45 [api] Create new interface FXMLModelable. +#42 [test] Rename the demo applications to fit the necessities from the api. @@ -52,7 +53,6 @@ Naoghuman [//]: # (Issues which will be integrated in this release) -#42 [test] Rename the demo applications to fit the necessities from the api. diff --git a/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFiles.java b/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFiles.java index f358284..8e21450 100644 --- a/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFiles.java +++ b/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFiles.java @@ -16,6 +16,7 @@ */ package com.github.naoghuman.lib.fxml.core; +import java.util.Optional; import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; @@ -34,17 +35,20 @@ public static void main(String[] args) { @Override public void start(Stage primaryStage) throws Exception { - primaryStage.setTitle("Demo with all Files: Lib-FXML v0.3.0-PRERELEASE"); + primaryStage.setTitle("Lib-FXML Demo with all files"); final FXMLModel model = new FXMLModel(); model.put("my.int", 12345); model.put("my.double", 3.145d); model.put("my.string", "Hello Lib-FXML from demo with all files!"); - FXMLView view = FXMLView.create(DemoWithAllFilesController.class, model); - System.out.println(view.toString()); + final FXMLView view = FXMLView.create(DemoWithAllFilesController.class, model); + final Optional optional = view.getController(DemoWithAllFilesController.class); + optional.ifPresent(controller -> { + controller.onActionShowFXMLViewInfos(view.toString()); + }); - final Scene scene = new Scene(view.getRoot().get(), 960, 360); + final Scene scene = new Scene(view.getRoot().get(), 1280, 720); primaryStage.setScene(scene); primaryStage.show(); diff --git a/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFilesController.java b/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFilesController.java index f060b1b..c320712 100644 --- a/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFilesController.java +++ b/src/test/java/com/github/naoghuman/lib/fxml/core/DemoWithAllFilesController.java @@ -21,7 +21,7 @@ import java.util.ResourceBundle; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.Label; +import javafx.scene.control.TextArea; /** * @@ -31,39 +31,87 @@ */ public class DemoWithAllFilesController extends FXMLController implements Initializable { - @FXML private Label lHelloLibFXML; - @FXML private Label lLocation; - @FXML private Label lResourceBundle; + @FXML private TextArea taDemoInfos; - @FXML private Label lMyDouble; - @FXML private Label lMyInt; - @FXML private Label lMyString; + private String keyHelloLibFXML; + private String resources; + private String location; @Override - public void initialize(URL location, ResourceBundle resources) { + public void initialize(final URL location, final ResourceBundle resources) { + DefaultFXMLValidator.requireNonNull(location); + DefaultFXMLValidator.requireNonNull(resources); - lLocation.setText( (location == null ? "NULL" : location.toString())); - lResourceBundle.setText((resources == null ? "NULL" : resources.getBaseBundleName())); - lHelloLibFXML.setText( (resources == null ? "NULL" : resources.getString("key.hello.libfxml"))); + this.location = (location != null ? location.toString() : ""); // NOI18N + this.resources = (resources != null ? resources.getBaseBundleName() : ""); // NOI18N + this.keyHelloLibFXML = (resources != null ? resources.getString("key.hello.libfxml") : ""); // NOI18N + + taDemoInfos.appendText(this.initializeDemoInfos()); + } + + private String initializeDemoInfos() { + final StringBuilder sb = new StringBuilder(); + sb.append("================================================================================\n\n"); // NOI18N + sb.append("This demo shows how to load the following files with the library 'Lib-FXML' in v0.3.0-PRERELEASE.\n"); // NOI18N + sb.append(" - The factory FXMLView.create (class FXMLController>, FXMLModel extended)\n"); // NOI18N + sb.append(" loads an instance of the controller class DemoWithAllFilesController,\n"); // NOI18N + sb.append(" automatically configuring thereby the passed FXMLModel.\n"); // NOI18N + sb.append(" - The optional files '.css' and '.properties' are automatically loaded\n"); // NOI18N + sb.append(" with the 'conventional name' (controller name in lower case without the suffix controller).\n\n"); // NOI18N + + sb.append("================================================================================\n\n"); // NOI18N + sb.append("Demo files:\n"); // NOI18N + sb.append(" - DemoWithAllFiles.java\n"); // NOI18N + sb.append(" - DemoWithAllFilesController.java\n"); // NOI18N + sb.append(" - demowithallfiles.css\n"); // NOI18N + sb.append(" - demowithallfiles.fxml\n"); // NOI18N + sb.append(" - demowithallfiles.properties\n\n"); // NOI18N + + sb.append("================================================================================\n\n"); // NOI18N + sb.append("Details:\n"); // NOI18N + + return sb.toString(); } @Override - public void configure(FXMLModel model) { + public void configure(final FXMLModel model) { DefaultFXMLValidator.requireNonNull(model); super.configure(model); - model.get(Integer.class, "my.int").ifPresent((myInt) -> { - lMyInt.setText(String.valueOf(myInt)); - }); + taDemoInfos.appendText(model.toString()); + taDemoInfos.appendText("\n\n"); // NOI18N + taDemoInfos.appendText(this.toString()); + taDemoInfos.appendText("\n\n"); // NOI18N + } + + /** + * + * @param fxmlViewInfos + * @since 0.3.0-PRERELEASE + * @version 0.3.0-PRERELEASE + * @author Naoghuman + */ + public void onActionShowFXMLViewInfos(final String fxmlViewInfos) { + DefaultFXMLValidator.requireNonNullAndNotEmpty(fxmlViewInfos); + + taDemoInfos.appendText(fxmlViewInfos); + taDemoInfos.appendText("\n\n"); // NOI18N + taDemoInfos.appendText("================================================================================\n"); // NOI18N + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("DemoWithAllFilesController [\n"); // NOI18N + + sb.append(" urlLocation = ").append(location ).append(",\n"); // NOI18N + sb.append(" resourceBundle = ").append(resources ).append(",\n"); // NOI18N + sb.append(" key.hello.libfxml = ").append(keyHelloLibFXML).append("\n"); // NOI18N - model.get(Double.class, "my.double").ifPresent((myDouble) -> { - lMyDouble.setText(String.valueOf(myDouble)); - }); + sb.append("]"); // NOI18N - model.get(String.class, "my.string").ifPresent((myString) -> { - lMyString.setText(myString); - }); + return sb.toString(); } } diff --git a/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithallfiles.fxml b/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithallfiles.fxml index 6e16bdd..9a89215 100644 --- a/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithallfiles.fxml +++ b/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithallfiles.fxml @@ -1,12 +1,7 @@ - - + - - - - @@ -14,73 +9,10 @@ - diff --git a/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.css b/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.css new file mode 100644 index 0000000..b7e4aa7 --- /dev/null +++ b/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.css @@ -0,0 +1,21 @@ +/* +Copyright (C) 2018 - 2019 Naoghuman's dream + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +/* + Created on : 19.12.2018, 10:33:35 + Author : Naoghuman +*/ + diff --git a/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.fxml b/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.fxml new file mode 100644 index 0000000..6e16bdd --- /dev/null +++ b/src/test/resources/com/github/naoghuman/lib/fxml/core/demowithoutpropertiesfile.fxml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +