Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / tools / Behavior / DraggerBehavior.java @ 45680

History | View | Annotate | Download (3.7 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40559 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5 40435 jjdelcerro
 *
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 40559 jjdelcerro
 * as published by the Free Software Foundation; either version 3
9 40435 jjdelcerro
 * 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 40559 jjdelcerro
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20 40435 jjdelcerro
 *
21 40559 jjdelcerro
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23 40435 jjdelcerro
 */
24
package org.gvsig.fmap.mapcontrol.tools.Behavior;
25
26
import java.awt.event.MouseEvent;
27
import java.awt.geom.Point2D;
28
29
import org.gvsig.fmap.mapcontrol.MapControlDrawer;
30
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
31
import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent;
32
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener;
33
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
34
35
36
37
/**
38
 * <p>Behavior that permits user to drag the image of the associated
39
 *  <code>MapControl</code> using a {@link PanListener PanListener}.</p>
40
 *
41
 * @author Vicente Caballero Navarro
42
  * @author Pablo Piqueras Bartolom?
43
 */
44
public class DraggerBehavior extends Behavior {
45
        /**
46
         * First point of the path in image coordinates.
47
         */
48
        private Point2D m_FirstPoint;
49
50
        /**
51
         * Tool listener used to work with the <code>MapControl</code> object.
52
         *
53
         * @see #getListener()
54
         * @see #setListener(ToolListener)
55
         */
56
        private PanListener listener;
57
58
        /**
59
          * <p>Creates a new behavior for dragging the mouse.</p>
60
          *
61
         * @param pli listener used to permit this object to work with the associated <code>MapControl</code>
62
         */
63
        public DraggerBehavior(PanListener pli) {
64
                listener = pli;
65
        }
66
67
        /*
68
         * (non-Javadoc)
69
         * @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(org.gvsig.fmap.mapcontrol.MapControlDrawer)
70
         */
71
        public void paintComponent(MapControlDrawer mapControlDrawer) {
72
        }
73
74
        /*
75
         * (non-Javadoc)
76
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
77
         */
78
        public void mousePressed(MouseEvent e) {
79
                if (e.getButton() == MouseEvent.BUTTON1) {
80
                        m_FirstPoint = e.getPoint();
81
                }
82
83
                if (listener.cancelDrawing()) {
84
                        getMapControl().cancelDrawing();
85
                }
86
        }
87
88
        /*
89
         * (non-Javadoc)
90
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
91
         */
92
        public void mouseReleased(MouseEvent e) throws BehaviorException {
93
                m_FirstPoint = null;
94
        }
95
96
        /*
97
         * (non-Javadoc)
98
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent)
99
         */
100
        public void mouseDragged(MouseEvent e) throws BehaviorException {
101
                MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e);
102
                listener.move(event);
103
                getMapControl().repaint();
104
        }
105
106
        /**
107
         * <p>Sets a tool listener to work with the <code>MapControl</code> using this behavior.</p>
108
         *
109
         * @param listener a <code>PanListener</code> object for this behavior
110
         */
111
        public void setListener(ToolListener listener) {
112
                this.listener = (PanListener) listener;
113
        }
114
115
        /*
116
         * (non-Javadoc)
117
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
118
         */
119
        public ToolListener getListener() {
120
                return listener;
121
        }
122
}