Skip to content

Commit

Permalink
[core] ♻️ StageResizer: by default do not allow resize if the Stage i…
Browse files Browse the repository at this point in the history
…s not resizable

Signed-off-by: palexdev <[email protected]>
  • Loading branch information
palexdev committed Dec 29, 2024
1 parent 7215bc4 commit e466289
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,33 @@
* (given that the root of the content is a {@link Region}).
*/
public class StageResizer extends RegionDragResizer {
//================================================================================
// Properties
//================================================================================
private Stage stage;

//================================================================================
// Constructors
//================================================================================
public StageResizer(Region node, Stage stage) {
super(node);
this.stage = stage;
setResizeHandler((n, x, y, w, h) -> resizeStage(stage, w, h));
}

//================================================================================
// Methods
//================================================================================
protected void resizeStage(Stage stage, double w, double h) {
if (!canResize()) return;
stage.setWidth(w);
stage.setHeight(h);
}

protected boolean canResize() {
return stage.isResizable();
}

//================================================================================
// Overridden Methods
//================================================================================
Expand All @@ -65,4 +75,19 @@ protected void handleDragged(MouseEvent event) {
if (node.getCursor() == Cursor.MOVE) return;
super.handleDragged(event);
}

@Override
protected void handleMoved(MouseEvent event) {
if (!canResize()) {
node.setCursor(Cursor.DEFAULT);
return;
}
super.handleMoved(event);
}

@Override
public void dispose() {
stage = null;
super.dispose();
}
}

0 comments on commit e466289

Please sign in to comment.