/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Pan.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Pan.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (hide annotations)
Fri Jan 29 08:37:34 2010 UTC (15 years, 1 month ago) by alfonx
File MIME type: text/plain
File size: 4003 byte(s)
Created XMapPaneAction_Pan 
1 alfonx 651 /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3     *
4     * This file is part of the SCHMITZM library - a collection of utility
5     * classes based on Java 1.6, focusing (not only) on Java Swing
6     * and the Geotools library.
7     *
8     * The SCHMITZM project is hosted at:
9     * http://wald.intevation.org/projects/schmitzm/
10     *
11     * This program is free software; you can redistribute it and/or
12     * modify it under the terms of the GNU Lesser General Public License
13     * as published by the Free Software Foundation; either version 3
14     * of the License, or (at your option) any later version.
15     *
16     * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     * GNU General Public License for more details.
20     *
21     * You should have received a copy of the GNU Lesser General Public License (license.txt)
22     * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24     * or try this link: http://www.gnu.org/licenses/lgpl.html
25     *
26     * Contributors:
27     * Martin O. J. Schmitz - initial API and implementation
28     * Stefan A. Krüger - additional utility classes
29     ******************************************************************************/
30     package skrueger.geotools;
31    
32     import java.awt.Cursor;
33     import java.awt.Point;
34     import java.awt.Rectangle;
35     import java.awt.event.MouseEvent;
36     import java.awt.event.MouseWheelEvent;
37    
38     import org.opengis.geometry.DirectPosition;
39    
40     import schmitzm.swing.SwingUtil;
41    
42     import com.vividsolutions.jts.geom.Envelope;
43    
44     public class XMapPaneAction_Pan implements XMapPaneAction {
45    
46     /**
47     * This variable can be used to backup the active cursor of the mapPane, if
48     * the actions changes the cursor during dragging
49     */
50     public Cursor backupCursor = null;
51    
52     /**
53     * Performs a pan action. During panning, the displacement is
54     * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
55     * reset the offset and call {@link #setMapArea(Envelope)}.
56     */
57     @Override
58     public void performDragged(XMapPane mapPane, MouseEvent ev,
59     Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
60     DirectPosition endCoord) {
61    
62     final Rectangle winBounds = mapPane.getVisibleRect();
63    
64     Point imageOrigin = mapPane.getImageOrigin();
65    
66     winBounds.translate(-imageOrigin.x, -imageOrigin.y);
67     final Envelope newMapArea = mapPane.tranformWindowToGeo(winBounds.x,
68     winBounds.y, winBounds.x + winBounds.width, winBounds.y
69     + winBounds.height);
70    
71     imageOrigin.x = 0;
72     imageOrigin.y = 0;
73    
74     if (!mapPane.setMapArea(newMapArea)) {
75     /**
76     * If setMapArea returns true, the finalImage is updated anyways.
77     * This if-case exists to ensure that we repaint a correct image
78     * even if the new panning area has been denied.
79     */
80     mapPane.updateFinalImage();
81     mapPane.repaint();
82     }
83    
84     if (mapPane.getCursor() == SwingUtil.PANNING_CURSOR) {
85     mapPane.setCursor(backupCursor);
86     }
87     }
88    
89     /**
90     * TODO: Stop dragging if the expected map area would not be valid.
91     */
92     @Override
93     public void performDragging(XMapPane mapPane, MouseEvent ev,
94     Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
95     DirectPosition endCoord) {
96    
97     if (mapPane.getCursor() != SwingUtil.PANNING_CURSOR) {
98     backupCursor = mapPane.getCursor();
99     mapPane.setCursor(SwingUtil.PANNING_CURSOR);
100     }
101    
102     int dX;
103     int dY;
104    
105     if (dragLastPos == null) {
106     dX = ev.getPoint().x - dragStartPos.x;
107     dY = ev.getPoint().y - dragStartPos.y;
108     } else {
109     dX = ev.getPoint().x - dragLastPos.x;
110     dY = ev.getPoint().y - dragLastPos.y;
111     }
112    
113     if (dX != 0 && dY != 0)
114     mapPane.pan(dX, dY);
115    
116     }
117    
118     @Override
119     public void performWheel(XMapPane mapPane, MouseWheelEvent ev,
120     DirectPosition coord) {
121     }
122    
123     @Override
124     public void performClick(XMapPane mapPane, MouseEvent ev,
125     DirectPosition coord) {
126     }
127    
128    
129     }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26