Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
#42 Tweak the 'demo with all files'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoghuman committed Mar 7, 2019
1 parent dcd553c commit 7fb86bf
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 98 deletions.
2 changes: 1 addition & 1 deletion release/Release_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand Down Expand Up @@ -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.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DemoWithAllFilesController> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -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() : "<not-defined>"); // NOI18N
this.resources = (resources != null ? resources.getBaseBundleName() : "<not-defined>"); // NOI18N
this.keyHelloLibFXML = (resources != null ? resources.getString("key.hello.libfxml") : "<not-defined>"); // 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();
}

}
Original file line number Diff line number Diff line change
@@ -1,86 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: LIGHTGREEN;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
<children>
<Label text="ResourceBundle">
<TextArea fx:id="taDemoInfos" wrapText="true" VBox.vgrow="ALWAYS">
<font>
<Font size="14.0" />
</font>
</Label>
<HBox>
<children>
<GridPane maxWidth="1.7976931348623157E308" prefHeight="50.0" HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="128.0" minWidth="128.0" prefWidth="128.0" />
<ColumnConstraints hgrow="NEVER" maxWidth="7.0" minWidth="7.0" prefWidth="7.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="445.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text=" - URL Location" />
<Label text=" - ResourceBundle" GridPane.rowIndex="1" />
<Label text=" - key.hello.libfxml" GridPane.rowIndex="2" />
<Label text=":" GridPane.columnIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="lLocation" text="&lt;text&gt;" GridPane.columnIndex="2" />
<Label fx:id="lResourceBundle" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label fx:id="lHelloLibFXML" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</HBox>
<Label text="FXMLModel">
<font>
<Font size="14.0" />
</font>
<padding>
<Insets top="14.0" />
</padding>
</Label>
<HBox>
<children>
<GridPane maxWidth="1.7976931348623157E308" prefHeight="50.0" HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="128.0" minWidth="128.0" prefWidth="128.0" />
<ColumnConstraints hgrow="NEVER" maxWidth="7.0" minWidth="7.0" prefWidth="7.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="445.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text=" - my.int" />
<Label text=" - my.double" GridPane.rowIndex="1" />
<Label text=" - my.string" GridPane.rowIndex="2" />
<Label text=":" GridPane.columnIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="lMyInt" text="&lt;text&gt;" GridPane.columnIndex="2" />
<Label fx:id="lMyDouble" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label fx:id="lMyString" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</HBox>
<Font name="Monospaced Regular" size="12.0" />
</font></TextArea>
</children>
</VBox>
</children>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
/*
Created on : 19.12.2018, 10:33:35
Author : Naoghuman
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: LIGHTGREEN;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
<children>
<Label text="ResourceBundle">
<font>
<Font size="14.0" />
</font>
</Label>
<HBox>
<children>
<GridPane maxWidth="1.7976931348623157E308" prefHeight="50.0" HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="128.0" minWidth="128.0" prefWidth="128.0" />
<ColumnConstraints hgrow="NEVER" maxWidth="7.0" minWidth="7.0" prefWidth="7.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="445.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text=" - URL Location" />
<Label text=" - ResourceBundle" GridPane.rowIndex="1" />
<Label text=" - key.hello.libfxml" GridPane.rowIndex="2" />
<Label text=":" GridPane.columnIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="lLocation" text="&lt;text&gt;" GridPane.columnIndex="2" />
<Label fx:id="lResourceBundle" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label fx:id="lHelloLibFXML" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</HBox>
<Label text="FXMLModel">
<font>
<Font size="14.0" />
</font>
<padding>
<Insets top="14.0" />
</padding>
</Label>
<HBox>
<children>
<GridPane maxWidth="1.7976931348623157E308" prefHeight="50.0" HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="128.0" minWidth="128.0" prefWidth="128.0" />
<ColumnConstraints hgrow="NEVER" maxWidth="7.0" minWidth="7.0" prefWidth="7.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="445.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text=" - my.int" />
<Label text=" - my.double" GridPane.rowIndex="1" />
<Label text=" - my.string" GridPane.rowIndex="2" />
<Label text=":" GridPane.columnIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text=":" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="lMyInt" text="&lt;text&gt;" GridPane.columnIndex="2" />
<Label fx:id="lMyDouble" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label fx:id="lMyString" text="&lt;text&gt;" GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>

0 comments on commit 7fb86bf

Please sign in to comment.