@@ -151,28 +151,31 @@ private static boolean intersects(Set<? extends Object> s1, Set<? extends Object
151
151
@ Override
152
152
public void zoomOut () {
153
153
double zoom = getZoomFactor ();
154
- Point viewPosition = getScrollPane ().getViewport ().getViewPosition ();
155
154
double newZoom = zoom / DiagramScene .ZOOM_INCREMENT ;
156
155
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 );
160
157
}
161
158
}
162
159
163
160
@ Override
164
161
public void zoomIn () {
165
162
166
163
double zoom = getZoomFactor ();
167
- Point viewPosition = getScrollPane ().getViewport ().getViewPosition ();
168
164
double newZoom = zoom * DiagramScene .ZOOM_INCREMENT ;
169
165
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 );
173
167
}
174
168
}
175
169
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
+ }
176
179
177
180
@ Override
178
181
public void centerFigures (List <Figure > list ) {
0 commit comments