Skip to content

Commit

Permalink
Refactor PowerPane for direct content binding
Browse files Browse the repository at this point in the history
The code refactors the PowerPane class by introducing a HiddenSidesPane that directly binds to the content property. This allows for easier manipulation of content. The previous implementation had individual properties for positioning (top, bottom, left, right, and center), which have now been simplified and removed. Additionally, a new constructor has been added, allowing a Node content to be directly passed, enhancing flexibility.
  • Loading branch information
dlemmermann committed Mar 22, 2024
1 parent 1e1f79b commit 4a13584
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 150 deletions.
56 changes: 49 additions & 7 deletions gemsfx-demo/src/main/java/com/dlsc/gemsfx/demo/PowerPaneApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Side;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
Expand All @@ -24,6 +25,7 @@
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.util.StringConverter;
import org.controlsfx.control.HiddenSidesPane;

import java.time.ZonedDateTime;
import java.util.List;
Expand All @@ -35,15 +37,28 @@ public class PowerPaneApp extends Application {

private DialogPane dialogPane;
private InfoCenterPane infoCenterPane;
private HiddenSidesPane hiddenSidesPane;

@Override
public void start(Stage stage) {
PowerPane powerPane = new PowerPane();
powerPane.setLeft(new RegionView("Left"));
powerPane.setRight(new RegionView("Right"));
powerPane.setCenter(new RegionView("Center"));
powerPane.setTop(new RegionView("Top"));
powerPane.setBottom(new RegionView("Bottom"));
Button testMe = new Button("Test Me");
PowerPane powerPane = new PowerPane(testMe);

RegionView leftHiddenSide = new RegionView("Left Hidden");
RegionView rightHiddenSide = new RegionView("Right Hidden");
RegionView topHiddenSide = new RegionView("Top Hidden");
RegionView bottomHiddenSide = new RegionView("Bottom Hidden");

hiddenSidesPane = powerPane.getHiddenSidesPane();
hiddenSidesPane.setLeft(leftHiddenSide);
hiddenSidesPane.setRight(rightHiddenSide);
hiddenSidesPane.setTop(topHiddenSide);
hiddenSidesPane.setBottom(bottomHiddenSide);

testMe.setOnAction(evt -> {
System.out.println("button pressed");
powerPane.getDialogPane().showInformation("Info", "Button pressed!");
});

dialogPane = powerPane.getDialogPane();
infoCenterPane = powerPane.getInfoCenterPane();
Expand All @@ -67,7 +82,10 @@ public void start(Stage stage) {
new Label("Dialogs"),
createDialogControls(),
new Label("Info Center"),
createInfoCenterPaneControls());
createInfoCenterPaneControls(),
new Label("Hidden Sides"),
createHiddenSidesPaneControls()
);

controls.setStyle("-fx-background-color: aliceblue;");
controls.setPadding(new Insets(20));
Expand Down Expand Up @@ -279,6 +297,30 @@ public String getAddress() {
}
}

private Node createHiddenSidesPaneControls() {
Button unpin = new Button("Unpin");
unpin.setOnAction(evt -> hiddenSidesPane.setPinnedSide(null));
unpin.setMaxWidth(Double.MAX_VALUE);

Button pinLeft = new Button("Pin Left");
pinLeft.setOnAction(evt -> hiddenSidesPane.setPinnedSide(Side.LEFT));
pinLeft.setMaxWidth(Double.MAX_VALUE);

Button pinRight = new Button("Pin Right");
pinRight.setOnAction(evt -> hiddenSidesPane.setPinnedSide(Side.RIGHT));
pinRight.setMaxWidth(Double.MAX_VALUE);

Button pinTop = new Button("Pin Top");
pinTop.setOnAction(evt -> hiddenSidesPane.setPinnedSide(Side.TOP));
pinTop.setMaxWidth(Double.MAX_VALUE);

Button pinBottom = new Button("Pin Bottom");
pinBottom.setOnAction(evt -> hiddenSidesPane.setPinnedSide(Side.BOTTOM));
pinBottom.setMaxWidth(Double.MAX_VALUE);

return new VBox(10, unpin, pinLeft, pinRight, pinTop, pinBottom);
}

private final NotificationGroup<Mail, MailNotification> mailGroup = new NotificationGroup<>("Mail");
private final NotificationGroup<Object, SlackNotification> slackGroup = new NotificationGroup<>("Slack");
private final NotificationGroup<Object, CalendarNotification> calendarGroup = new NotificationGroup<>("Calendar");
Expand Down
169 changes: 26 additions & 143 deletions gemsfx/src/main/java/com/dlsc/gemsfx/PowerPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,37 @@ public PowerPane() {
drawerStackPane = createDrawerStackPane();
hiddenSidesPane = createHiddenSidesPane();

BorderPane borderPane = new BorderPane();
borderPane.topProperty().bind(topProperty());
borderPane.bottomProperty().bind(bottomProperty());
borderPane.leftProperty().bind(leftProperty());
borderPane.rightProperty().bind(rightProperty());
borderPane.centerProperty().bind(centerProperty());

InfoCenterPane infoCenterPane = getInfoCenterPane();
infoCenterPane.setContent(new StackPane(borderPane, getHiddenSidesPane(), getDrawerStackPane(), getDialogPane()));

hiddenSidesPane.contentProperty().bind(contentProperty());

DrawerStackPane drawerStackPane = getDrawerStackPane();
drawerStackPane.getChildren().add(hiddenSidesPane);

infoCenterPane.setContent(new StackPane(drawerStackPane, getDialogPane()));

getChildren().add(infoCenterPane);
}

public PowerPane(Node content) {
this();
setContent(content);
}

private final ObjectProperty<Node> content = new SimpleObjectProperty<>(this, "content");

public final Node getContent() {
return content.get();
}

public final ObjectProperty<Node> contentProperty() {
return content;
}

public final void setContent(Node content) {
this.content.set(content);
}

protected InfoCenterPane createInfoCenterPane() {
return new InfoCenterPane();
}
Expand Down Expand Up @@ -67,139 +85,4 @@ public DrawerStackPane getDrawerStackPane() {
public HiddenSidesPane getHiddenSidesPane() {
return hiddenSidesPane;
}

/**
* The node placed in the center of this pane.
* If resizable, it will be resized fill the center of the border pane
* between the top, bottom, left, and right nodes. If the node cannot be
* resized to fill the center space (it's not resizable or its max size prevents
* it) then it will be center aligned unless the child's alignment constraint
* has been set.
*
* @return the node placed in the center of this pane
*/
public final ObjectProperty<Node> centerProperty() {
if (center == null) {
center = new SimpleObjectProperty<>(this, "center");
}
return center;
}

private ObjectProperty<Node> center;

public final void setCenter(Node value) {
centerProperty().set(value);
}

public final Node getCenter() {
return center == null ? null : center.get();
}

/**
* The node placed on the top edge of this pane.
* If resizable, it will be resized to its preferred height and it's width
* will span the width of the border pane. If the node cannot be
* resized to fill the top space (it's not resizable or its max size prevents
* it) then it will be aligned top-left within the space unless the child's
* alignment constraint has been set.
*
* @return the node placed on the top edge of this pane
*/
public final ObjectProperty<Node> topProperty() {
if (top == null) {
top = new SimpleObjectProperty<>(this, "top");
}
return top;
}

private ObjectProperty<Node> top;

public final void setTop(Node value) {
topProperty().set(value);
}

public final Node getTop() {
return top == null ? null : top.get();
}

/**
* The node placed on the bottom edge of this pane.
* If resizable, it will be resized to its preferred height and it's width
* will span the width of the border pane. If the node cannot be
* resized to fill the bottom space (it's not resizable or its max size prevents
* it) then it will be aligned bottom-left within the space unless the child's
* alignment constraint has been set.
*
* @return the node placed on the bottom edge of this pane
*/
public final ObjectProperty<Node> bottomProperty() {
if (bottom == null) {
bottom = new SimpleObjectProperty<>(this, "bottom");
}
return bottom;
}

private ObjectProperty<Node> bottom;

public final void setBottom(Node value) {
bottomProperty().set(value);
}

public final Node getBottom() {
return bottom == null ? null : bottom.get();
}

/**
* The node placed on the left edge of this pane.
* If resizable, it will be resized to its preferred width and it's height
* will span the height of the border pane between the top and bottom nodes.
* If the node cannot be resized to fill the left space (it's not resizable
* or its max size prevents it) then it will be aligned top-left within the space
* unless the child's alignment constraint has been set.
*
* @return the node placed on the left edge of this pane
*/
public final ObjectProperty<Node> leftProperty() {
if (left == null) {
left = new SimpleObjectProperty<>(this, "left");
}
return left;
}

private ObjectProperty<Node> left;

public final void setLeft(Node value) {
leftProperty().set(value);
}

public final Node getLeft() {
return left == null ? null : left.get();
}

/**
* The node placed on the right edge of this pane.
* If resizable, it will be resized to its preferred width and it's height
* will span the height of the border pane between the top and bottom nodes.
* If the node cannot be resized to fill the right space (it's not resizable
* or its max size prevents it) then it will be aligned top-right within the space
* unless the child's alignment constraint has been set.
*
* @return the node placed on the right edge of this pane
*/
public final ObjectProperty<Node> rightProperty() {
if (right == null) {
right = new SimpleObjectProperty<>(this, "right");
}
return right;
}

private ObjectProperty<Node> right;

public final void setRight(Node value) {
rightProperty().set(value);
}

public final Node getRight() {
return right == null ? null : right.get();
}
}

0 comments on commit 4a13584

Please sign in to comment.