1 package org.catacomb.graph.gui;
2
3
4
5
6
7 final class ClickZoomHandler extends MouseHandler {
8
9 private int xc;
10 private int yc;
11
12 double xfac;
13 double yfac;
14
15
16 final static int NORMAL = 1;
17 final static int IN = 2;
18 final static int OUT = 3;
19 final static int INOUT = 4;
20
21 int actionMode;
22
23 boolean dragging = false;
24
25 public ClickZoomHandler() {
26 xfac = 1.0;
27 yfac = 1.0;
28 }
29
30
31
32 public void activate() {
33 actionMode = NORMAL;
34 super.activate();
35 }
36
37
38
39 public void activateInOut() {
40 activate();
41 actionMode = INOUT;
42 }
43
44
45 public void activateOut() {
46 activate();
47 actionMode = OUT;
48 }
49 public void activateIn() {
50 activate();
51 actionMode = IN;
52 }
53
54
55
56
57
58
59
60 public void init(Mouse m) {
61 dragging = false;
62 xc = m.getX();
63 yc = m.getY();
64
65 double zfac = 1.0;
66 xfac = 1.0;
67 yfac = 1.0;
68
69 if (actionMode == IN) {
70 zfac = 0.7;
71 setClaimIn();
72
73 } else if (actionMode == OUT) {
74 zfac = 1. / 0.7;
75 setClaimIn();
76
77 } else if (actionMode == INOUT) {
78
79 zfac = 1.;
80 if (m.leftButton()) {
81 zfac = 0.7;
82
83 } else if (m.rightButton()) {
84 zfac = 1. / 0.7;
85 }
86 setClaimIn();
87
88
89 } else {
90 if (m.leftButton()) {
91 zfac = 0.7;
92
93 } else if (m.rightButton()) {
94 zfac = 1. / 0.7;
95
96 } else {
97 setClaimOut();
98 }
99 }
100
101
102
103 if (xc > 30) {
104 xfac = zfac;
105 }
106
107 if (yc < m.getCanvasHeight() - 30) {
108 yfac = zfac;
109 }
110
111 }
112
113
114 public void advance(Mouse m) {
115
116 if (actionMode == NORMAL) {
117 int dx = m.getX() - xc;
118 int dy = m.getY() - yc;
119
120 if (dx * dx + dy * dy > 100) {
121
122 setClaimOut();
123 }
124 }
125 }
126
127
128 public void release(Mouse m) {
129 setClaimIn();
130 }
131
132
133
134
135
136 public void applyOnDown(Mouse m) {
137 m.initializeZoom(xc, yc);
138 }
139
140
141 public void applyOnDrag(Mouse m) {
142 int x = m.getX();
143 int y = m.getY();
144
145 double rz = 100.;
146 double zx = Math.exp(-(x - xc) / rz);
147 double zy = Math.exp((y - yc) / rz);
148 if (Math.abs(x - xc) * Math.abs(y - yc) > 5) {
149 dragging = true;
150 }
151
152 m.dragZoom(zx, zy, xc, yc);
153 setFullRepaint();
154 }
155
156
157
158
159
160 public void applyOnRelease(Mouse m) {
161 if (!dragging) {
162 m.zoom(xfac, yfac, xc, yc);
163 }
164 m.restoreAA();
165 }
166
167
168
169
170 }