root / tags / v2_0_0_Build_2038 / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / tools / Behavior / MouseWheelBehavior.java @ 37103
History | View | Annotate | Download (3.42 KB)
1 | 36722 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program 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
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.fmap.mapcontrol.tools.Behavior; |
||
23 | |||
24 | import java.awt.event.MouseWheelEvent; |
||
25 | |||
26 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
27 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
28 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
29 | import org.gvsig.fmap.geom.primitive.Point; |
||
30 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
31 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
32 | 36750 | fdiaz | import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
33 | 36722 | cordinyana | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
34 | import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
||
35 | |||
36 | /**
|
||
37 | * @author gvSIG Team
|
||
38 | * @version $Id$
|
||
39 | *
|
||
40 | */
|
||
41 | public class MouseWheelBehavior extends Behavior { |
||
42 | |||
43 | /**
|
||
44 | * Constructor.
|
||
45 | */
|
||
46 | public MouseWheelBehavior() {
|
||
47 | } |
||
48 | |||
49 | @Override
|
||
50 | public ToolListener getListener() {
|
||
51 | return null; |
||
52 | } |
||
53 | |||
54 | @Override
|
||
55 | public void mouseWheelMoved(MouseWheelEvent event) throws BehaviorException { |
||
56 | MapControl control = getMapControl(); |
||
57 | control.cancelDrawing(); |
||
58 | super.mouseWheelMoved(event);
|
||
59 | ViewPort viewPort = control.getViewPort(); |
||
60 | Envelope envelope = viewPort.getEnvelope(); |
||
61 | if (envelope != null) { |
||
62 | double factor = event.getWheelRotation() < 0 ? 0.9d : 1.2d; |
||
63 | Point mousePosition = viewPort.convertToMapPoint(event.getPoint());
|
||
64 | Point envelopPoint1 = envelope.getLowerCorner();
|
||
65 | Point envelopPoint2 = envelope.getUpperCorner();
|
||
66 | |||
67 | double width1 = mousePosition.getX() - envelopPoint1.getX();
|
||
68 | double heigth1 = mousePosition.getY() - envelopPoint1.getY();
|
||
69 | double width2 = envelopPoint2.getX() - mousePosition.getX();
|
||
70 | double heigth2 = envelopPoint2.getY() - mousePosition.getY();
|
||
71 | |||
72 | double xmin = mousePosition.getX() - width1 * factor;
|
||
73 | double ymin = mousePosition.getY() - heigth1 * factor;
|
||
74 | double xmax = mousePosition.getX() + width2 * factor;
|
||
75 | double ymax = mousePosition.getY() + heigth2 * factor;
|
||
76 | |||
77 | try {
|
||
78 | viewPort.setEnvelope(geomManager.createEnvelope(xmin, ymin, |
||
79 | xmax, ymax, SUBTYPES.GEOM2D)); |
||
80 | } catch (CreateEnvelopeException e) {
|
||
81 | throw new BehaviorException( |
||
82 | "Error changing the viewport envelope to (" + xmin + "," |
||
83 | + ymin + "),(" + xmax + "," + ymax + ")", e); |
||
84 | } |
||
85 | getMapControl().drawMap(true);
|
||
86 | } |
||
87 | event.consume(); |
||
88 | } |
||
89 | 36750 | fdiaz | |
90 | @Override
|
||
91 | public void paintComponent(MapControlDrawer mapControlDrawer) { |
||
92 | // Do nothing
|
||
93 | } |
||
94 | 36722 | cordinyana | } |