]> gerrit.simantics Code Review - simantics/district.git/blob
1a4f83d8aaea80ddee799f399d4a0f68084bbbe3
[simantics/district.git] /
1 package org.simantics.district.network.ui;
2
3 import org.simantics.g2d.participant.PanZoomRotateHandler;
4 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseWheelMovedEvent;
5 import org.simantics.scenegraph.g2d.nodes.NavigationNode;
6
7 public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler {
8
9     public DistrictPanZoomRotateHandler() {
10     }
11
12     @Override
13     protected Class<? extends NavigationNode> getNavigationNodeClass() {
14         return DistrictNavigationNode.class;
15     }
16
17     public static class DistrictNavigationNode extends NavigationNode {
18
19         private static final long serialVersionUID = 5452897272925816875L;
20
21         @Override
22         public Double getZoomInLimit() {
23             return super.getZoomInLimit();
24         }
25
26         @Override
27         public Double getZoomOutLimit() {
28             return super.getZoomOutLimit();
29         }
30
31         @Override
32         public boolean mouseWheelMoved(MouseWheelMovedEvent me) {
33             if (navigationEnabled && zoomEnabled) {
34                 double scroll = Math.min(0.9, -me.wheelRotation / 20.0);
35                 double z = 1 - scroll;
36                 double dx = (me.controlPosition.getX() - transform.getTranslateX()) / transform.getScaleX();
37                 double dy = (me.controlPosition.getY() - transform.getTranslateY()) / transform.getScaleY();
38                 dx = dx * (1 - z);
39                 dy = dy * (1 - z);
40                 double limitedScale = limitScaleFactor(z);
41                 if (limitedScale != 1.0) {
42                     translate(dx, dy);
43                     scale(z, z);
44                     transformChanged();
45                     dropQuality();
46                     repaint();
47                 }
48             }
49             return false;
50         }
51
52     }
53 }