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 / PointBehavior.java @ 41964

History | View | Annotate | Download (3.53 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontrol.tools.Behavior;
25

    
26
import java.awt.event.MouseEvent;
27

    
28
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
29
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
30
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
31
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
32

    
33

    
34

    
35
/**
36
 * <p>Behavior that permits user to select a point with a double click mouse action, on the associated
37
 *  <code>MapControl</code> using a {@link PointListener PointListener}.</p>
38
 *
39
 * @author Vicente Caballero Navarro
40
 */
41
public class PointBehavior extends Behavior {
42
        /**
43
         * Tool listener used to work with the <<code>MapControl</code> object.
44
         *
45
         * @see #getListener()
46
         * @see #setListener(ToolListener)
47
         */
48
        private PointListener listener;
49

    
50
        /**
51
         * Flag that determines a double click user action.
52
         */
53
        private boolean doubleClick=false;
54

    
55
        /**
56
          * <p>Creates a new behavior for selecting a point.</p>
57
          *
58
         * @param l listener used to permit this object to work with the associated <code>MapControl</code>
59
         */
60
        public PointBehavior(PointListener l, int mouseButton) {
61
            super(mouseButton);
62
            listener = l;
63
        }
64

    
65
        public PointBehavior(PointListener l) {
66
            this(l,LEFT);
67
        }
68

    
69
        /*
70
         * (non-Javadoc)
71
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent)
72
         */
73
        public void mousePressed(MouseEvent e) {
74
                if( !isMyButton(e) ) {
75
                    return;
76
                }
77
                if (listener.cancelDrawing()) {
78
                        getMapControl().cancelDrawing();
79
                }
80
                if (e.getClickCount()==2){
81
                        doubleClick=true;
82
                }
83
        }
84

    
85
        /*
86
         * (non-Javadoc)
87
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent)
88
         */
89
        public void mouseReleased(MouseEvent e) throws BehaviorException {
90
                if( !isMyButton(e) ) {
91
                    return;
92
                }
93
                PointEvent event = new PointEvent(e.getPoint(), e, this.getMapControl());
94
                listener.point(event);
95
                if (doubleClick){
96
                        listener.pointDoubleClick(event);
97
                        doubleClick=false;
98
                }
99
        }
100

    
101
        /**
102
         * <p>Sets a tool listener to work with the <code>MapControl</code> using this behavior.</p>
103
         *
104
         * @param listener a <code>PointListener</code> object for this behavior
105
         */
106
        public void setListener(ToolListener listener) {
107
                this.listener = (PointListener) listener;
108
        }
109

    
110
        /*
111
         * (non-Javadoc)
112
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
113
         */
114
        public ToolListener getListener() {
115
                return listener;
116
        }
117
}