From 7445784e1667964e69899e1fdb36a0ecbcbff411 Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Mon, 2 Nov 2026 12:05:36 +0000 Subject: [PATCH] Fix drag and drop functionality in editor Bug was introduced when changing the background of the scroll pane to stop flickering scroll bars. The fix brings back the sizing listener to set the min width/ height of the widget_pane so that the background is correctly drawn to that size. Drag and drop also did not work if you changed the model width/height to a value larger than the current viewport and tried to drag on to the new area. I have also fixed that by updating the min width/height when the model size is changed. --- .../javafx/JFXRepresentation.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/JFXRepresentation.java b/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/JFXRepresentation.java index 79b5041d4a..db81045b18 100644 --- a/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/JFXRepresentation.java +++ b/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/JFXRepresentation.java @@ -225,6 +225,12 @@ final public ScrollPane createModelRoot() model_root = new ScrollPane(scroll_body); model_root.setId(MODEL_ROOT_ID); + if (isEditMode()) { + final InvalidationListener resized = prop -> handleEditorViewportChanges(); + model_root.widthProperty().addListener(resized); + model_root.heightProperty().addListener(resized); + } + // Update background of parent when it changes or, for example, // becomes not null final InvalidationListener background = prop -> { @@ -650,6 +656,37 @@ public ToolkitRepresentation openNewWindow(final DisplayModel mode throw new IllegalStateException("Not implemented"); } + /** Handle changes in on-screen size of the editor */ + private void handleEditorViewportChanges() + { + final int view_width = (int) model_root.getWidth(); + final int view_height = (int) model_root.getHeight(); + + final int model_width, model_height; + final DisplayModel copy = model; + if (copy == null) + model_width = model_height = 0; + else + { + model_width = copy.propWidth().getValue(); + model_height = copy.propHeight().getValue(); + } + + // If on-screen viewport is larger than model, + // grow the widget_pane so it fills the area. + // If the viewport is smaller, use the model's size + // to get appropriate scrollbars. + final int show_x = view_width >= model_width + ? view_width-SCROLLBAR_ADJUST + : model_width; + final int show_y = view_height >= model_height + ? view_height-SCROLLBAR_ADJUST + : model_height; + + // Does not consider zooming. + widget_pane.setMinSize(show_x, show_y); + } + /** Update lines that indicate model's size in edit mode */ private void updateModelSizeIndicators() { @@ -671,6 +708,10 @@ private void updateModelSizeIndicators() vert_bound.setStartX(width); vert_bound.setEndY(height); vert_bound.setEndX(width); + + // Update the widget_pane size based on the + // new model size + handleEditorViewportChanges(); } @Override