diff --git a/src/main/java/org/dockfx/AbstractDockableNode.java b/src/main/java/org/dockfx/AbstractDockableNode.java
index 4c2d185..ed58f3f 100644
--- a/src/main/java/org/dockfx/AbstractDockableNode.java
+++ b/src/main/java/org/dockfx/AbstractDockableNode.java
@@ -7,6 +7,7 @@ public abstract class AbstractDockableNode implements DockableNode {
protected BooleanProperty closeProperty = new SimpleBooleanProperty(false);
protected DockPane mDockPane;
+ protected DockNode mDockNode;
@Override
public BooleanProperty getCloseProperty() {
@@ -22,4 +23,22 @@ public void setDockPane(DockPane dockPane) {
public DockPane getDockPane() {
return mDockPane;
}
+
+ /**
+ * Owning dock node.
+ *
+ * @param dockNode
+ */
+ @Override
+ public void setDockNode(DockNode dockNode) {
+ mDockNode = dockNode;
+ }
+
+ /**
+ * @return Owning dock node.
+ */
+ @Override
+ public DockNode getDockNode() {
+ return mDockNode;
+ }
}
diff --git a/src/main/java/org/dockfx/BasicFXMLDockPaneAdapter.java b/src/main/java/org/dockfx/BasicFXMLDockPaneAdapter.java
index f9d069d..74b02b7 100644
--- a/src/main/java/org/dockfx/BasicFXMLDockPaneAdapter.java
+++ b/src/main/java/org/dockfx/BasicFXMLDockPaneAdapter.java
@@ -58,7 +58,6 @@ public void setResources(ResourceBundle resourceBundle) {
public DockableNode addDockableFXML(Class extends DockableNode> controllerClass, String FXML) throws IOException {
return addDockableFXML(null, controllerClass, FXML);
}
-
/**
* @param title Title of the Dock. If null
uses {@link DockableNode}.getDockTitle()
.
* @param controllerClass Class of the controller will be used as key for mapping. So every FXML File is singleton.
@@ -66,6 +65,17 @@ public DockableNode addDockableFXML(Class extends DockableNode> controllerClas
* @return the controller object.
* */
public DockableNode addDockableFXML(String title, Class extends DockableNode> controllerClass, String FXML) throws IOException {
+ return addDockableFXML(title, 2, controllerClass, FXML);
+ }
+
+ /**
+ * @param title Title of the Dock. If null
uses {@link DockableNode}.getDockTitle()
.
+ * @param divideRatio The divide ratio of this dock. Should be higher or equal to 2. (Default is 2 means half.)
+ * @param controllerClass Class of the controller will be used as key for mapping. So every FXML File is singleton.
+ * @param FXML FXML path relative to controllerClass. Will be loaded with `controllerClass.getResource`
+ * @return the controller object.
+ * */
+ public DockableNode addDockableFXML(String title, double divideRatio, Class extends DockableNode> controllerClass, String FXML) throws IOException {
FXMLLoader loader = new FXMLLoader(controllerClass.getResource(FXML));
if(resourceBundle != null) {
loader.setResources(resourceBundle);
@@ -80,6 +90,8 @@ public DockableNode addDockableFXML(String title, Class extends DockableNode>
DockNode dockNode = new DockNode(parent, title == null ? controller.getDockTitle() : title, controller.getGraphic());
dockNode.setPrefSize(parent.prefWidth(-1), parent.prefHeight(-1));
+ dockNode.setScreenDivideRatioOnDock(divideRatio);
+ controller.setDockNode(dockNode);
dockNode.closedProperty().addListener(
(observable, oldValue, newValue) -> controller.getCloseProperty().set(newValue)
diff --git a/src/main/java/org/dockfx/DockableNode.java b/src/main/java/org/dockfx/DockableNode.java
index e43f6ae..5990e57 100644
--- a/src/main/java/org/dockfx/DockableNode.java
+++ b/src/main/java/org/dockfx/DockableNode.java
@@ -27,6 +27,16 @@ public interface DockableNode {
DockPos getDocPos();
+ /**
+ * Owning dock node.
+ * */
+ void setDockNode(DockNode dockNode);
+
+ /**
+ * @return Owning dock node.
+ * */
+ DockNode getDockNode();
+
void setDockPane(DockPane dockPane);
DockPane getDockPane();
diff --git a/src/main/java/org/dockfx/demo/controllers/DemoFXML2.java b/src/main/java/org/dockfx/demo/controllers/DemoFXML2.java
index 1bf63e5..d2cb279 100644
--- a/src/main/java/org/dockfx/demo/controllers/DemoFXML2.java
+++ b/src/main/java/org/dockfx/demo/controllers/DemoFXML2.java
@@ -5,6 +5,7 @@
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.AnchorPane;
+import org.dockfx.AbstractDockableNode;
import org.dockfx.DockPane;
import org.dockfx.DockPos;
import org.dockfx.DockableNode;
@@ -12,15 +13,11 @@
import java.net.URL;
import java.util.ResourceBundle;
-public class DemoFXML2 implements DockableNode,Initializable {
+public class DemoFXML2 extends AbstractDockableNode implements Initializable {
@FXML
private AnchorPane mainPane;
- private final BooleanProperty closeProperty = new SimpleBooleanProperty(false);
-
- private DockPane dockPane;
-
/**
* Called to initialize a controller after its root element has been
* completely processed.
@@ -34,14 +31,6 @@ public void initialize(URL location, ResourceBundle resources) {
mainPane.setStyle("-fx-background-color: blue");
}
- /**
- * On dockable closed
- */
- @Override
- public BooleanProperty getCloseProperty() {
- return closeProperty;
- }
-
@Override
public String getDockTitle() {
return "Demo FXML2";
@@ -51,14 +40,4 @@ public String getDockTitle() {
public DockPos getDocPos() {
return DockPos.CENTER;
}
-
- @Override
- public void setDockPane(DockPane dockPane) {
- this.dockPane = dockPane;
- }
-
- @Override
- public DockPane getDockPane() {
- return dockPane;
- }
}
diff --git a/src/main/java/org/dockfx/demo/controllers/DemoMainFXML.java b/src/main/java/org/dockfx/demo/controllers/DemoMainFXML.java
index 01c5496..9bade72 100644
--- a/src/main/java/org/dockfx/demo/controllers/DemoMainFXML.java
+++ b/src/main/java/org/dockfx/demo/controllers/DemoMainFXML.java
@@ -43,7 +43,8 @@ public void initialize(URL location, ResourceBundle resources) {
dockPaneAdapter.wrapInAnchorPane(dockAnchorPane);
try {
dockPaneAdapter.addDockableFXML(DemoFXML2.class, "DemoFXML2.fxml");
- dockPaneAdapter.addDockableFXML("FXML2", DemoFXML2.class, "DemoFXML2.fxml");
+ double customDivideRatio = 5;
+ dockPaneAdapter.addDockableFXML("FXML2", customDivideRatio, DemoFXML2.class, "DemoFXML2.fxml");
dummyBar.setSpacing(3);
dummyBar.getChildren().clear();
dockPaneAdapter.createNodeBar(dummyBar, Button.class, false);
@@ -54,9 +55,8 @@ public void initialize(URL location, ResourceBundle resources) {
List dFxml = dockPaneAdapter.getDockableFXML(DemoFXML.class);
- dFxml.forEach(dockableFXML -> {
- dockableFXML.dockNode.setScreenDivideRatioOnDock(10);
- });
+ // Update divide ratio after dock.
+ dNode.getDockNode().setScreenDivideRatioOnDock(4);
} catch (IOException e) {