Skip to content

Commit

Permalink
Use property
Browse files Browse the repository at this point in the history
  • Loading branch information
GameplayJDK committed Jun 10, 2017
1 parent b9fcb94 commit 23e2203
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public class MyMain extends Application {

```

Notice that it's possible to use bindings and other JavaFx features on the `main` property of `BaseController` since v1.1.

### Some more details please!

Ok, so there is some hidden magic with the name of the fxml file.
Expand Down
14 changes: 10 additions & 4 deletions src/de/gameplayjdk/simplefx/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package de.gameplayjdk.simplefx;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXML;
import javafx.scene.Parent;

Expand All @@ -33,7 +35,7 @@
*/
public class BaseController<V extends Parent, M> extends Controller<V> {

private M main;
private ObjectProperty<M> main;

public BaseController() {
super();
Expand All @@ -46,7 +48,7 @@ public BaseController(M main) {
public BaseController(M main, String name) {
super(name);

this.main = main;
this.main = new SimpleObjectProperty<M>(main);

super.setReady();
}
Expand All @@ -57,14 +59,18 @@ protected void initialize() {
}

public M getMain() {
if (this.main == null) {
if (this.main.get() == null) {
throw new NullPointerException("Main is null. Please set it manually in your " + this.getClass().getSimpleName() + " controller");
}

return this.main.get();
}

public ObjectProperty<M> mainProperty() {
return this.main;
}

public void setMain(M main) {
this.main = main;
this.main.set(main);
}
}

0 comments on commit 23e2203

Please sign in to comment.