Skip to content

Make DragDropStage open at the dropped location and be ownerless #18

@richmeyer7

Description

@richmeyer7

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions