1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.editor;
19
20 import org.eclipse.draw2d.geometry.Point;
21 import org.eclipse.gef.EditPartViewer;
22 import org.eclipse.gef.MouseWheelHandler;
23 import org.eclipse.gef.editparts.ZoomManager;
24 import org.eclipse.swt.widgets.Event;
25
26
27
28
29
30
31
32 public final class ExtendedMouseWheelScrollHandler implements MouseWheelHandler {
33
34
35
36
37 private static final class SingletonHolder {
38 private static final ExtendedMouseWheelScrollHandler INSTANCE = new ExtendedMouseWheelScrollHandler();
39 }
40
41
42
43
44
45
46 public static ExtendedMouseWheelScrollHandler getInstance(){
47 return SingletonHolder.INSTANCE;
48 }
49
50
51
52
53 private ExtendedMouseWheelScrollHandler() {
54 }
55
56 private static final int SCROLL_MULTIPLIER = 20;
57
58
59
60
61
62
63
64
65
66 public void handleMouseWheel(Event event, EditPartViewer viewer) {
67 ZoomManager zoomMgr = (ZoomManager)viewer
68 .getProperty(ZoomManager.class.toString());
69 if (zoomMgr != null) {
70 Point zoomMgrLocation = zoomMgr.getViewport().getViewLocation();
71
72 int newX = zoomMgrLocation.x - event.count * SCROLL_MULTIPLIER;
73
74 if (newX < zoomMgr.getScalableFigure().getBounds().x) {
75 newX = zoomMgr.getScalableFigure().getBounds().x;
76 } else if (newX >= zoomMgr.getScalableFigure().getBounds().width
77 - zoomMgr.getViewport().getBounds().width) {
78 newX = zoomMgr.getScalableFigure().getBounds().width
79 - zoomMgr.getViewport().getBounds().width - 1;
80 }
81
82 zoomMgrLocation.x = newX;
83 zoomMgr.setViewLocation(zoomMgrLocation);
84
85 event.doit = false;
86
87 }
88
89 }
90
91 }