Statistics
| Revision:

svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / tools / Behavior / DraggerBehavior.java @ 19509

History | View | Annotate | Download (3.6 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.tools.Behavior;
42

    
43
import java.awt.Graphics;
44
import java.awt.Point;
45
import java.awt.event.MouseEvent;
46
import java.awt.geom.Point2D;
47

    
48
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
49
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent;
50
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener;
51
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener;
52

    
53

    
54
/**
55
 * Behaviour que espera un listener de tipo PanListener.
56
 *
57
 * @author Vicente Caballero Navarro
58
 */
59
public class DraggerBehavior extends Behavior {
60
        private Point2D m_FirstPoint;
61
        private Point2D m_LastPoint;
62
        private Point2D m_PointAnt;
63
        private PanListener listener;
64

    
65
        /**
66
         * Crea un nuevo MoveBehavior.
67
         *
68
         * @param pli listener.
69
         */
70
        public DraggerBehavior(PanListener pli) {
71
                listener = pli;
72
        }
73

    
74
        /**
75
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
76
         */
77
        public void paintComponent(Graphics g) {
78
        }
79

    
80

    
81
        /**
82
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
83
         */
84
        public void mousePressed(MouseEvent e) {
85
                Point pScreen = e.getPoint();
86

    
87
                m_PointAnt = pScreen;
88
                m_FirstPoint = m_PointAnt;
89

    
90
                if (e.getButton() == MouseEvent.BUTTON1) {
91
                        m_PointAnt = pScreen;
92
                        m_FirstPoint = m_PointAnt;
93
                }
94

    
95
                if (listener.cancelDrawing()) {
96
                        getMapControl().cancelDrawing();
97
                }
98
        }
99

    
100
        /**
101
         * Reimplementaci?n del m?todo mouseReleased de Behavior.
102
         *
103
         * @param e MouseEvent
104
         *
105
         * @throws BehaviorException Excepci?n lanzada cuando el Behavior.
106
         */
107
        public void mouseReleased(MouseEvent e) throws BehaviorException {
108
                m_FirstPoint = null;
109
        }
110

    
111
        /**
112
         * Reimplementaci?n del m?todo mouseDragged de Behavior.
113
         *
114
         * @param e MouseEvent
115
         * @throws BehaviorException
116
         */
117
        public void mouseDragged(MouseEvent e) throws BehaviorException {
118
                m_LastPoint = e.getPoint();
119
                MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e);
120
                listener.move(event);
121
                getMapControl().repaint();
122
        }
123

    
124
        /**
125
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
126
         */
127
        public void setListener(ToolListener listener) {
128
                this.listener = (PanListener) listener;
129
        }
130

    
131
        /**
132
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
133
         */
134
        public ToolListener getListener() {
135
                return listener;
136
        }
137
}