8263389: IGV: Zooming changes the point that is currently centered
Reviewed-by: rrich, neliasso
This commit is contained in:
parent
371d996a89
commit
164eff8c8a
@ -151,12 +151,9 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
|||||||
@Override
|
@Override
|
||||||
public void zoomOut() {
|
public void zoomOut() {
|
||||||
double zoom = getZoomFactor();
|
double zoom = getZoomFactor();
|
||||||
Point viewPosition = getScrollPane().getViewport().getViewPosition();
|
|
||||||
double newZoom = zoom / DiagramScene.ZOOM_INCREMENT;
|
double newZoom = zoom / DiagramScene.ZOOM_INCREMENT;
|
||||||
if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) {
|
if (newZoom > DiagramScene.ZOOM_MIN_FACTOR) {
|
||||||
setZoomFactor(newZoom);
|
zoom(newZoom);
|
||||||
validate();
|
|
||||||
getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x / DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y / DiagramScene.ZOOM_INCREMENT)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,15 +161,21 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
|||||||
public void zoomIn() {
|
public void zoomIn() {
|
||||||
|
|
||||||
double zoom = getZoomFactor();
|
double zoom = getZoomFactor();
|
||||||
Point viewPosition = getScrollPane().getViewport().getViewPosition();
|
|
||||||
double newZoom = zoom * DiagramScene.ZOOM_INCREMENT;
|
double newZoom = zoom * DiagramScene.ZOOM_INCREMENT;
|
||||||
if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) {
|
if (newZoom < DiagramScene.ZOOM_MAX_FACTOR) {
|
||||||
setZoomFactor(newZoom);
|
zoom(newZoom);
|
||||||
validate();
|
|
||||||
getScrollPane().getViewport().setViewPosition(new Point((int) (viewPosition.x * DiagramScene.ZOOM_INCREMENT), (int) (viewPosition.y * DiagramScene.ZOOM_INCREMENT)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void zoom(double newZoom) {
|
||||||
|
double currentZoom = getZoomFactor();
|
||||||
|
Point viewPosition = getScrollPane().getViewport().getViewPosition();
|
||||||
|
Rectangle viewRect = getScrollPane().getViewport().getViewRect();
|
||||||
|
setZoomFactor(newZoom);
|
||||||
|
validate();
|
||||||
|
getScrollPane().getViewport().validate();
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void centerFigures(List<Figure> list) {
|
public void centerFigures(List<Figure> list) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user