Skip to content

Commit 5840c29

Browse files
Werner RandelshoferWerner Randelshofer
authored andcommitted
InteractiveDrawingRenderer should not call requestLayout in the repaint() method, but should rather repaint on every the JavaFX pulse event.
1 parent c2751c5 commit 5840c29

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/render/InteractiveDrawingRenderer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javafx.scene.Group;
2020
import javafx.scene.Node;
2121
import javafx.scene.Parent;
22+
import javafx.scene.Scene;
2223
import javafx.scene.transform.NonInvertibleTransformException;
2324
import javafx.scene.transform.Transform;
2425
import org.jhotdraw8.base.event.Listener;
@@ -89,12 +90,27 @@ protected void layoutChildren() {
8990
private final ObjectProperty<DrawingEditor> editor = new SimpleObjectProperty<>(this, DrawingView.EDITOR_PROPERTY, null);
9091
private final Listener<TreeModelEvent<Figure>> treeModelListener = this::onTreeModelEvent;
9192
private final NodeFinder nodeFinder = new NodeFinder();
93+
private final Runnable pulseListener = this::onPulse;
9294

9395
public InteractiveDrawingRenderer() {
9496
drawingPane.setManaged(true);
9597
model.addListener(this::onDrawingModelChanged);
9698
clipBounds.addListener(this::onClipBoundsChanged);
9799
zoomFactorProperty().addListener(this::onClipBoundsChanged);
100+
drawingPane.sceneProperty().addListener(this::onSceneChanged);
101+
}
102+
103+
private void onSceneChanged(Observable observable, @Nullable Scene oldScene, @Nullable Scene newScene) {
104+
if (oldScene != null) {
105+
oldScene.removePreLayoutPulseListener(pulseListener);
106+
}
107+
if (newScene != null) {
108+
newScene.addPreLayoutPulseListener(pulseListener);
109+
}
110+
}
111+
112+
private void onPulse() {
113+
paintImmediately();
98114
}
99115

100116
public ObjectProperty<Bounds> clipBoundsProperty() {
@@ -627,7 +643,7 @@ private void removeNode(Figure f) {
627643
}
628644

629645
public void repaint() {
630-
drawingPane.requestLayout();
646+
// This is a no-op, we repaint on every pulse
631647
}
632648

633649
/**

0 commit comments

Comments
 (0)