Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libFMap_mapcontrol / src / org / gvsig / fmap / mapcontrol / tools / Behaibor / PointBehavior.java @ 21203

History | View | Annotate | Download (3.48 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 org.gvsig.fmap.mapcontrol.tools.Behaibor;
42

    
43
import java.awt.event.MouseEvent;
44

    
45
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
46
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
47
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
48
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
49

    
50

    
51

    
52
/**
53
 * <p>Behavior that permits user to select a point with a double click mouse action, on the associated
54
 *  <code>MapControl</code> using a {@link PointListener PointListener}.</p>
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class PointBehavior extends Behavior {
59
        /**
60
         * Tool listener used to work with the <<code>MapControl</code> object.
61
         * 
62
         * @see #getListener()
63
         * @see #setListener(ToolListener)
64
         */
65
        private PointListener listener;
66

    
67
        /**
68
         * Flag that determines a double click user action.
69
         */
70
        private boolean doubleClick=false;
71

    
72
        /**
73
          * <p>Creates a new behavior for selecting a point.</p>
74
          *
75
         * @param l listener used to permit this object to work with the associated <code>MapControl</code>
76
         */
77
        public PointBehavior(PointListener l) {
78
                listener = l;
79
        }
80

    
81
        /*
82
         * (non-Javadoc)
83
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
84
         */
85
        public void mousePressed(MouseEvent e) {
86
                if (listener.cancelDrawing()) {
87
                        getMapControl().cancelDrawing();
88
                }
89
                if (e.getClickCount()==2){
90
                        doubleClick=true;
91
                }
92
        }
93

    
94
        /*
95
         * (non-Javadoc)
96
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
97
         */
98
        public void mouseReleased(MouseEvent e) throws BehaviorException {
99
                PointEvent event = new PointEvent(e.getPoint(), e);
100
                listener.point(event);
101
                if (doubleClick){
102
                        listener.pointDoubleClick(event);
103
                        doubleClick=false;
104
                }
105
        }
106

    
107
        /**
108
         * <p>Sets a tool listener to work with the <code>MapControl</code> using this behavior.</p>
109
         * 
110
         * @param listener a <code>PointListener</code> object for this behavior
111
         */
112
        public void setListener(ToolListener listener) {
113
                this.listener = (PointListener) listener;
114
        }
115

    
116
        /*
117
         * (non-Javadoc)
118
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
119
         */
120
        public ToolListener getListener() {
121
                return listener;
122
        }
123
}