-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #562 from jensonwe/560_test_jigsaw_modules
560 test jigsaw modules
- Loading branch information
Showing
28 changed files
with
686 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# MvvmFX JigSaw Example | ||
|
||
This is a simple application to demonstrate that the mvvmFX framework can be used in applications based on a Java version | ||
above Java 8 and using the jigsaw module system. | ||
|
||
### The use-case | ||
|
||
The application consists on a main view, which contains two separate sub views to calculate the areas of a circle | ||
respectively a rectangle. | ||
The circle view is included via `fx:include`, the rectangle view is loaded via FluentViewLoader when initializing the | ||
main view. | ||
|
||
### Important difference to the other examples in the MvvmFX project | ||
|
||
The application is not involved in the build process of the main project because the main project is compiled with Java 8 | ||
and the jigsaw-example is compiled with Java 11. Because of differences on the project structures, otherwise building | ||
the main project would fail. | ||
|
||
### Configuration to run with Java 11 | ||
|
||
* set JAVA_HOME to an installed jdk-11 | ||
* set IDE's runconfiguration to JRE 11 | ||
* set properties tag in pom.xml to | ||
```xml | ||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
|
||
<java.version>11</java.version> | ||
<mvvmfx.version>1.8.0-SNAPSHOT</mvvmfx.version> | ||
</properties> | ||
``` | ||
* set the release tag in the maven compiler plugin to | ||
```xml | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<release>11</release> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
``` | ||
|
||
### Interesting parts | ||
|
||
#### JavaFX | ||
|
||
Since Java 11, JavaFX is no longer part of the JDK. Therefore the packages for javafx-controls, javafx-graphics, | ||
javafx-base and javafx-fxml from org.openjfx must be added as maven `<dependency>`to the main pom.xml. | ||
|
||
#### Modules | ||
|
||
Since Java 9, java applications need a `module-info.java` file in the top-level-package of every module. | ||
This module descriptor contains informations on which other packages are required or must be exported respectively opened for | ||
other packages. | ||
|
||
```Java | ||
module de.saxsys.mvvmfx.examples.jigsaw.app{ | ||
|
||
requires de.saxsys.mvvmfx.examples.jigsaw.circle; | ||
requires de.saxsys.mvvmfx.examples.jigsaw.rectangle; | ||
requires javafx.base; | ||
requires javafx.fxml; | ||
requires javafx.controls; | ||
requires javafx.graphics; | ||
requires mvvmfx; | ||
|
||
exports de.saxsys.mvvmfx.examples.jigsaw.app to javafx.graphics; | ||
|
||
opens de.saxsys.mvvmfx.examples.jigsaw.app to mvvmfx, javafx.fxml; | ||
} | ||
``` | ||
##### Instructions | ||
|
||
- `requires <name of the module>` - indicates from which other modules the current module depends | ||
- `exports <name of the package>` - indicates which packages from the current module are exported outside the module | ||
- `opens <name of the package>` - provides a package for deep reflection at runtime | ||
|
||
##### Further Informations | ||
|
||
[More information about the the Java Platform Module System](https://dzone.com/articles/java-9-modules-introduction-part-1) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>de.saxsys.mvvmfx.jigsaw-example</groupId> | ||
<artifactId>jigsaw-example</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jigsaw-example-app</artifactId> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/de.saxsys/mvvmfx --> | ||
<dependency> | ||
<groupId>de.saxsys</groupId> | ||
<artifactId>mvvmfx</artifactId> | ||
<version>${mvvmfx.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>de.saxsys.mvvmfx.jigsaw-example</groupId> | ||
<artifactId>jigsaw-example-circle</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>de.saxsys.mvvmfx.jigsaw-example</groupId> | ||
<artifactId>jigsaw-example-rectangle</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core --> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.11.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
examples/jigsaw-example/app/src/main/java/de/saxsys/mvvmfx/examples/jigsaw/app/AppView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.saxsys.mvvmfx.examples.jigsaw.app; | ||
|
||
import de.saxsys.mvvmfx.FluentViewLoader; | ||
import de.saxsys.mvvmfx.FxmlView; | ||
import de.saxsys.mvvmfx.InjectViewModel; | ||
import de.saxsys.mvvmfx.ViewTuple; | ||
import de.saxsys.mvvmfx.examples.jigsaw.rectangle.RectangleView; | ||
import de.saxsys.mvvmfx.examples.jigsaw.rectangle.RectangleViewModel; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.layout.VBox; | ||
import java.util.ResourceBundle; | ||
|
||
public class AppView implements FxmlView<AppViewModel> { | ||
|
||
@FXML | ||
VBox appMainBox; | ||
|
||
@FXML | ||
VBox circle; | ||
|
||
@InjectViewModel | ||
private AppViewModel appViewModel; | ||
|
||
public void initialize() { | ||
loadRectangleView(); | ||
} | ||
|
||
private void loadRectangleView() { | ||
ResourceBundle rectangleBundle = ResourceBundle.getBundle("rectangle"); | ||
|
||
ViewTuple<RectangleView, RectangleViewModel> viewTuple = FluentViewLoader.fxmlView( | ||
RectangleView.class).resourceBundle(rectangleBundle).load(); | ||
|
||
appMainBox.getChildren().add(viewTuple.getView()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...s/jigsaw-example/app/src/main/java/de/saxsys/mvvmfx/examples/jigsaw/app/AppViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.saxsys.mvvmfx.examples.jigsaw.app; | ||
|
||
import de.saxsys.mvvmfx.ViewModel; | ||
|
||
public class AppViewModel implements ViewModel {} |
28 changes: 28 additions & 0 deletions
28
examples/jigsaw-example/app/src/main/java/de/saxsys/mvvmfx/examples/jigsaw/app/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.saxsys.mvvmfx.examples.jigsaw.app; | ||
|
||
import de.saxsys.mvvmfx.FluentViewLoader; | ||
import de.saxsys.mvvmfx.ViewTuple; | ||
import javafx.application.Application; | ||
import javafx.scene.Parent; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
|
||
import java.util.ResourceBundle; | ||
|
||
public class Main extends Application { | ||
|
||
public static void main(String... args) { | ||
Application.launch(args); | ||
} | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
ResourceBundle resourceBundle = ResourceBundle.getBundle("app"); | ||
stage.setTitle(resourceBundle.getString("app.stage.title")); | ||
|
||
ViewTuple<AppView, AppViewModel> viewTuple = FluentViewLoader.fxmlView(AppView.class).load(); | ||
Parent root = viewTuple.getView(); | ||
stage.setScene(new Scene(root)); | ||
stage.show(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/jigsaw-example/app/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
module de.saxsys.mvvmfx.examples.jigsaw.app{ | ||
|
||
requires de.saxsys.mvvmfx.examples.jigsaw.circle; | ||
requires de.saxsys.mvvmfx.examples.jigsaw.rectangle; | ||
requires javafx.base; | ||
requires javafx.fxml; | ||
requires javafx.controls; | ||
requires javafx.graphics; | ||
requires mvvmfx; | ||
|
||
exports de.saxsys.mvvmfx.examples.jigsaw.app to javafx.graphics; | ||
|
||
opens de.saxsys.mvvmfx.examples.jigsaw.app to mvvmfx, javafx.fxml; | ||
} |
1 change: 1 addition & 0 deletions
1
examples/jigsaw-example/app/src/main/resources/app_de_DE.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
app.stage.title=Jigsaw Testanwendung |
1 change: 1 addition & 0 deletions
1
examples/jigsaw-example/app/src/main/resources/app_en.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
app.stage.title=Jigsaw test application |
11 changes: 11 additions & 0 deletions
11
...s/jigsaw-example/app/src/main/resources/de/saxsys/mvvmfx/examples/jigsaw/app/AppView.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.layout.VBox?> | ||
<VBox xmlns="http://javafx.com/javafx" | ||
fx:id="appMainBox" | ||
xmlns:fx="http://javafx.com/fxml" | ||
fx:controller="de.saxsys.mvvmfx.examples.jigsaw.app.AppView" | ||
prefHeight="400.0" prefWidth="600.0"> | ||
<fx:include | ||
source="../../../../../../../../../circle/src/main/resources/de/saxsys/mvvmfx/examples/jigsaw/circle/CircleView.fxml" resources="circle" /> | ||
</VBox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>de.saxsys.mvvmfx.jigsaw-example</groupId> | ||
<artifactId>jigsaw-example</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jigsaw-example-circle</artifactId> | ||
|
||
</project> |
46 changes: 46 additions & 0 deletions
46
...gsaw-example/circle/src/main/java/de/saxsys/mvvmfx/examples/jigsaw/circle/CircleView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package de.saxsys.mvvmfx.examples.jigsaw.circle; | ||
|
||
import de.saxsys.mvvmfx.FxmlView; | ||
import de.saxsys.mvvmfx.InjectViewModel; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.control.TextFormatter; | ||
import javafx.util.converter.DoubleStringConverter; | ||
|
||
public class CircleView implements FxmlView<CircleViewModel> { | ||
|
||
@FXML | ||
private TextField radiusTextField; | ||
|
||
@FXML | ||
private Label circleAreaLabel; | ||
|
||
@InjectViewModel | ||
private CircleViewModel circleViewModel; | ||
|
||
|
||
public void initialize() { | ||
setupValidation(); | ||
bindViewValues(); | ||
} | ||
|
||
private void setupValidation() { | ||
TextFormatter<Double> textFormatter = new TextFormatter<>(new DoubleStringConverter(), 0.0, | ||
change -> { | ||
String newText = change.getControlNewText(); | ||
if (circleViewModel.validateDouble(newText)) { | ||
return change; | ||
} else { | ||
return null; | ||
} | ||
}); | ||
|
||
radiusTextField.setTextFormatter(textFormatter); | ||
} | ||
|
||
private void bindViewValues() { | ||
radiusTextField.textProperty().bindBidirectional(circleViewModel.radiusProperty()); | ||
circleAreaLabel.textProperty().bind(circleViewModel.circularAreaProperty()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...example/circle/src/main/java/de/saxsys/mvvmfx/examples/jigsaw/circle/CircleViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.saxsys.mvvmfx.examples.jigsaw.circle; | ||
|
||
import de.saxsys.mvvmfx.ViewModel; | ||
import javafx.beans.property.ReadOnlyStringWrapper; | ||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
import java.util.regex.Pattern; | ||
|
||
public class CircleViewModel implements ViewModel { | ||
|
||
private static final Pattern VALID_DOUBLE_PATTERN = Pattern.compile("((\\d*)|(\\d+\\.\\d*))"); | ||
|
||
private final StringProperty radius = new SimpleStringProperty(); | ||
private final ReadOnlyStringWrapper circularArea = new ReadOnlyStringWrapper(""); | ||
|
||
|
||
public void initialize() { | ||
radius.addListener(observable -> calculateCircleArea()); | ||
} | ||
|
||
private void calculateCircleArea() { | ||
if (radius.get() != null && !radius.get().isEmpty()) { | ||
double radiusAsDouble = Double.valueOf(radius.get()); | ||
double roundedResult = Math.round(Math.pow(radiusAsDouble, 2) * Math.PI); | ||
circularArea.set(Double.toString(roundedResult)); | ||
} else { | ||
circularArea.set(""); | ||
} | ||
} | ||
|
||
boolean validateDouble(String newText) { | ||
return VALID_DOUBLE_PATTERN.matcher(newText).matches(); | ||
} | ||
|
||
StringProperty radiusProperty() { | ||
return radius; | ||
} | ||
|
||
ReadOnlyStringWrapper circularAreaProperty() { | ||
return circularArea; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/jigsaw-example/circle/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
module de.saxsys.mvvmfx.examples.jigsaw.circle { | ||
|
||
requires javafx.base; | ||
requires javafx.fxml; | ||
requires javafx.controls; | ||
requires javafx.graphics; | ||
requires mvvmfx; | ||
|
||
exports de.saxsys.mvvmfx.examples.jigsaw.circle to javafx.graphics, de.saxsys.mvvmfx.examples.jigsaw.app; | ||
|
||
opens de.saxsys.mvvmfx.examples.jigsaw.circle to mvvmfx, javafx.fxml; | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/jigsaw-example/circle/src/main/resources/circle_de.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
circle.label.circlearea=Kreisfläche: | ||
circle.label.radius=Radius | ||
circle.label.title=Berechnen einer Kreisfläche |
4 changes: 4 additions & 0 deletions
4
examples/jigsaw-example/circle/src/main/resources/circle_en.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
circle.label.circlearea=Circle area:\ | ||
|
||
circle.label.radius=Radius | ||
circle.label.title=Calculate a circular area |
Oops, something went wrong.