01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.tools.internal;
18:
19: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
20: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseWheelEvent;
21: import net.refractions.udig.project.ui.tool.AbstractTool;
22:
23: /**
24: * A tool that enables zooming using the mouse wheel and simulates the mouse
25: * wheel zoom when the alt key is held down and the mouse is moved horizontally
26: * This tool is always "on"
27: *
28: * @author Jesse Eichar
29: * @version $Revision: 1.9 $
30: */
31: public class ScrollZoom extends AbstractTool {
32:
33: private static final int INTERVAL = 50;
34: private int distance = 0;
35:
36: private int start;
37:
38: boolean in = true;
39:
40: /**
41: * Creates an new instance of ScrollZoom
42: */
43: public ScrollZoom() {
44: super (MOUSE | MOTION | WHEEL);
45: }
46:
47: /**
48: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseWheelMoved(net.refractions.udig.project.render.displayAdapter.MapMouseWheelEvent)
49: */
50: public void mouseWheelMoved(MapMouseWheelEvent e) {
51: if (e.modifiersDown())
52: return;
53: UpdateThread.getUpdater().zoom(e.clickCount * 3, getContext());
54: }
55:
56: /**
57: * @see net.refractions.udig.project.ui.tool.AbstractTool#mousePressed(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
58: */
59: public void mousePressed(MapMouseEvent e) {
60: if (e.modifiers == MapMouseEvent.ALT_DOWN_MASK
61: && e.buttons == MapMouseEvent.BUTTON1) {
62: start = e.x;
63: }
64: }
65:
66: /**
67: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseDragged(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
68: */
69: public void mouseDragged(MapMouseEvent e) {
70: if (e.modifiers == MapMouseEvent.ALT_DOWN_MASK
71: && e.buttons == MapMouseEvent.BUTTON1) {
72: distance += (start - e.x);
73:
74: if ((distance >= INTERVAL) || (distance <= -INTERVAL)) {
75: UpdateThread.getUpdater().zoom(
76: 10 * (distance > 0 ? 1 : -1), getContext());
77: distance = 0;
78: start = e.x;
79: }
80: }
81: }
82:
83: /**
84: * @see net.refractions.udig.project.ui.tool.AbstractTool#mouseReleased(net.refractions.udig.project.render.displayAdapter.MapMouseEvent)
85: */
86: public void mouseReleased(MapMouseEvent e) {
87: distance = 0;
88: }
89:
90: }
|