Skip to content

Commit

Permalink
Enhance ResizingBehaviour to Allow Direction Control and Improve Reso…
Browse files Browse the repository at this point in the history
…urce Management.
  • Loading branch information
leewyatt committed Apr 29, 2024
1 parent 2db0b87 commit a6c08ff
Show file tree
Hide file tree
Showing 2 changed files with 397 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
import com.dlsc.gemsfx.util.ResizingBehaviour;
import fr.brouillard.oss.cssfx.CSSFX;
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.StringConverter;
import org.controlsfx.control.CheckComboBox;

public class ResizingBehaviourApp extends Application {

private ResizingBehaviour resizingSupport;

@Override
public void start(Stage stage) {
Label content = new Label("Content");
content.setMouseTransparent(false);
content.setStyle("-fx-background-color: orange;");
content.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
content.setAlignment(Pos.CENTER);
Expand All @@ -27,14 +37,37 @@ public void start(Stage stage) {
stackPane.setPrefSize(250, 250);
stackPane.setMaxSize(950, 850);

ResizingBehaviour resizingSupport = ResizingBehaviour.install(stackPane);
resizingSupport = ResizingBehaviour.install(stackPane);
resizingSupport.setResizable(true);
resizingSupport.setOnResize((width, height) -> System.out.println("width: " + width + ", height: " + height));
Label installLabel = new Label("ResizingBehaviour already installed.");

CheckComboBox<ResizingBehaviour.Operation> supportedOperationsBox = createOperationCheckComboBox();

CheckBox resizeableBox = new CheckBox("Resizable");
resizeableBox.selectedProperty().bindBidirectional(resizingSupport.resizableProperty());

Spinner<Double> offsetSpinner = new Spinner<>(5, 20, 5, 5);
resizingSupport.offsetProperty().bind(offsetSpinner.valueProperty());

Button uninstallButton = new Button("Uninstall");
uninstallButton.setOnAction(e -> {
if (resizingSupport.isInstalled()) {
resizingSupport.uninstall();
installLabel.setText("Tips: ResizingBehaviour already uninstalled.");
}
});

HBox controlsBox = new HBox(10, uninstallButton, supportedOperationsBox, resizeableBox, new Label("Edge Offset:"), offsetSpinner);
controlsBox.setAlignment(Pos.CENTER_LEFT);
VBox controlsContainer = new VBox(10, controlsBox, installLabel);
controlsContainer.setAlignment(Pos.CENTER_LEFT);
controlsContainer.setPadding(new Insets(10));

Group group = new Group(stackPane);

StackPane container = new StackPane(group);
container.setAlignment(Pos.CENTER);
BorderPane container = new BorderPane(group);
container.setBottom(controlsContainer);

Scene scene = new Scene(container);
CSSFX.start(scene);
Expand All @@ -47,6 +80,43 @@ public void start(Stage stage) {
stage.show();
}

private CheckComboBox<ResizingBehaviour.Operation> createOperationCheckComboBox() {
CheckComboBox<ResizingBehaviour.Operation> supportedOperationsBox = new CheckComboBox<>();
supportedOperationsBox.getItems().addAll(ResizingBehaviour.Operation.values());
supportedOperationsBox.setConverter(createOperationStringConverter());
supportedOperationsBox.getCheckModel().checkAll();
supportedOperationsBox.getCheckModel().getCheckedItems().addListener((InvalidationListener) (c) -> {
resizingSupport.setSupportedOperations(supportedOperationsBox.getCheckModel().getCheckedItems());
});
return supportedOperationsBox;
}

private StringConverter<ResizingBehaviour.Operation> createOperationStringConverter() {
return new StringConverter<>() {
@Override
public String toString(ResizingBehaviour.Operation operation) {
if (operation == null) {
return "";
}
return switch (operation) {
case RESIZE_E -> "Right";
case RESIZE_W -> "Left";
case RESIZE_N -> "Top";
case RESIZE_NE -> "Top Right";
case RESIZE_NW -> "Top Left";
case RESIZE_S -> "Bottom";
case RESIZE_SE -> "Bottom Right";
case RESIZE_SW -> "Bottom Left";
};
}

@Override
public ResizingBehaviour.Operation fromString(String string) {
return null;
}
};
}

public static void main(String[] args) {
launch();
}
Expand Down
Loading

0 comments on commit a6c08ff

Please sign in to comment.