When a user drag-drop gesture creates a DragDropStage, it opens centered on the sourceStage (I think) and owned by the sourceStage.
In our application's usage, we prefer the new DragDropStage to open where dropped, and be ownerless so that it is not "always in front" of the sourceStage.
One way to accomplish this is to configure a custom StageBuilding on the Bento instance; for example (Kotlin):
/**
* A [StageBuilding] whose [initializeFromSource]
* initializes the new [Stage] without an owner
* and positions it at the current mouse position.
*/
class StageBuildingOwnerlessAtMousePosition(
bento: Bento,
) : StageBuilding(bento) {
override fun initializeFromSource(
sourceScene: Scene,
newScene: Scene,
sourceStage: Stage?,
newStage: DragDropStage,
sourceIsOwner: Boolean,
) {
super.initializeFromSource(
sourceScene,
newScene,
sourceStage,
newStage,
// Do not make the source Stage the owner of the
// new Stage. Thus, the new Stage is not "always in front"
// of the source Stage, and doesn't minimize with it.
false,
)
// Apply mouse position to the new stage before it is shown.
val robot = Robot()
val mousePos: Point2D = robot.mousePosition
newStage.x = mousePos.x
newStage.y = mousePos.y
}
}
Request as an improvement a way to initialize and configure the new DragDropStage without a custom StageBuilding.
The following change could suffice:
- Add a property
Consumer<DragDropStage> configureDragDropStageBeforeShowing (with a default no-op) to Bento, and change setOnDragDone(...) inside method Header.withDragDrop() to pass the new DragDropStage to bento.configureDragDropStageBeforeShowing before calling stage.show(). The client application could, for example, then implement configureDragDropStageBeforeShowing to call newStage.initOwner(null) (to counteract StageBuilding's call to newStage.initOwner(sourceStage);) and set the newStage position as desired.
When a user drag-drop gesture creates a
DragDropStage, it opens centered on thesourceStage(I think) and owned by thesourceStage.In our application's usage, we prefer the new
DragDropStageto open where dropped, and be ownerless so that it is not "always in front" of thesourceStage.One way to accomplish this is to configure a custom
StageBuildingon theBentoinstance; for example (Kotlin):Request as an improvement a way to initialize and configure the new
DragDropStagewithout a customStageBuilding.The following change could suffice:
Consumer<DragDropStage> configureDragDropStageBeforeShowing(with a default no-op) toBento, and changesetOnDragDone(...)inside methodHeader.withDragDrop()to pass the newDragDropStagetobento.configureDragDropStageBeforeShowingbefore callingstage.show(). The client application could, for example, then implementconfigureDragDropStageBeforeShowingto callnewStage.initOwner(null)(to counteractStageBuilding's call tonewStage.initOwner(sourceStage);) and set thenewStageposition as desired.