Skip to content

Commit 164eff8

Browse files
jtfuller111TobiHartmann
authored andcommittedJul 5, 2021
8263389: IGV: Zooming changes the point that is currently centered
Reviewed-by: rrich, neliasso
1 parent 371d996 commit 164eff8

File tree

1 file changed

+11
-8
lines changed
  • src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view

1 file changed

+11
-8
lines changed
 

‎src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -151,28 +151,31 @@ private static boolean intersects(Set<? extends Object> s1, Set<? extends Object
151151
@Override
152152
public void zoomOut() {
153153
double zoom = getZoomFactor();
154-
Point viewPosition = getScrollPane().getViewport().getViewPosition();
155154
double newZoom = zoom / DiagramScene.ZOOM_INCREMENT;
156155
if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) {
157-
setZoomFactor(newZoom);
158-
validate();
159-
getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT)));
156+
zoom(newZoom);
160157
}
161158
}
162159

163160
@Override
164161
public void zoomIn() {
165162

166163
double zoom = getZoomFactor();
167-
Point viewPosition = getScrollPane().getViewport().getViewPosition();
168164
double newZoom = zoom * DiagramScene.ZOOM_INCREMENT;
169165
if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) {
170-
setZoomFactor(newZoom);
171-
validate();
172-
getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT)));
166+
zoom(newZoom);
173167
}
174168
}
175169

170+
private void zoom(double newZoom) {
171+
double currentZoom = getZoomFactor();
172+
Point viewPosition = getScrollPane().getViewport().getViewPosition();
173+
Rectangle viewRect = getScrollPane().getViewport().getViewRect();
174+
setZoomFactor(newZoom);
175+
validate();
176+
getScrollPane().getViewport().validate();
177+
getScrollPane().getViewport().setViewPosition(new Point((int) ((viewPosition.x + viewRect.width / 2) * newZoom / currentZoom - viewRect.width / 2), (int) ((viewPosition.y + viewRect.height / 2) * newZoom / currentZoom - viewRect.height / 2)));
178+
}
176179

177180
@Override
178181
public void centerFigures(List<Figure> list) {

0 commit comments

Comments
 (0)
Please sign in to comment.