package org.simantics.district.network.ui; import org.simantics.g2d.participant.PanZoomRotateHandler; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseWheelMovedEvent; import org.simantics.scenegraph.g2d.nodes.NavigationNode; public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler { public DistrictPanZoomRotateHandler() { } @Override protected Class getNavigationNodeClass() { return DistrictNavigationNode.class; } public static class DistrictNavigationNode extends NavigationNode { private static final long serialVersionUID = 5452897272925816875L; @Override public Double getZoomInLimit() { return super.getZoomInLimit(); } @Override public Double getZoomOutLimit() { return super.getZoomOutLimit(); } @Override public boolean mouseWheelMoved(MouseWheelMovedEvent me) { if (navigationEnabled && zoomEnabled) { double scroll = Math.min(0.9, -me.wheelRotation / 20.0); double z = 1 - scroll; double dx = (me.controlPosition.getX() - transform.getTranslateX()) / transform.getScaleX(); double dy = (me.controlPosition.getY() - transform.getTranslateY()) / transform.getScaleY(); dx = dx * (1 - z); dy = dy * (1 - z); double limitedScale = limitScaleFactor(z); if (limitedScale != 1.0) { translate(dx, dy); scale(z, z); transformChanged(); dropQuality(); repaint(); } } return false; } } }