Skip to content

Commit

Permalink
Added initial divide ratio support to BasicFXMLDockPaneAdapter. (Robe…
Browse files Browse the repository at this point in the history
…rtBColton#12)

Added support for getDockNode to DockableNode interface which gets updated by BasicFXMLDockPaneAdapter.
  • Loading branch information
TheDoctorOne committed Mar 19, 2022
1 parent 150d172 commit e20ea23
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/dockfx/AbstractDockableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
14 changes: 13 additions & 1 deletion src/main/java/org/dockfx/BasicFXMLDockPaneAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,24 @@ 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 <code>null</code> uses <code>{@link DockableNode}.getDockTitle()</code>.
* @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, Class<? extends DockableNode> controllerClass, String FXML) throws IOException {
return addDockableFXML(title, 2, controllerClass, FXML);
}

/**
* @param title Title of the Dock. If <code>null</code> uses <code>{@link DockableNode}.getDockTitle()</code>.
* @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);
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/dockfx/DockableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
25 changes: 2 additions & 23 deletions src/main/java/org/dockfx/demo/controllers/DemoFXML2.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@
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;

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.
Expand All @@ -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";
Expand All @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/main/java/org/dockfx/demo/controllers/DemoMainFXML.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -54,9 +55,8 @@ public void initialize(URL location, ResourceBundle resources) {

List<BasicFXMLDockPaneAdapter.DockableFXML> dFxml = dockPaneAdapter.getDockableFXML(DemoFXML.class);

dFxml.forEach(dockableFXML -> {
dockableFXML.dockNode.setScreenDivideRatioOnDock(10);
});
// Update divide ratio after dock.
dNode.getDockNode().setScreenDivideRatioOnDock(4);


} catch (IOException e) {
Expand Down

0 comments on commit e20ea23

Please sign in to comment.