Statistics
| Revision:

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

History | View | Annotate | Download (4.58 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.Color;
44
import java.awt.Graphics;
45
import java.awt.Point;
46
import java.awt.event.MouseEvent;
47
import java.awt.geom.Point2D;
48

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

    
54

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

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

    
76
        /**
77
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
78
         */
79
        public void paintComponent(Graphics g) {
80
            Color theBackColor = getMapControl().getMapContext().getViewPort().getBackColor();
81
            if (theBackColor == null)
82
                g.setColor(Color.WHITE);
83
            else
84
                g.setColor(theBackColor);
85

    
86
                g.setColor(getMapControl().getMapContext().getViewPort().getBackColor());
87
                g.fillRect(0, 0, getMapControl().getWidth(), getMapControl().getHeight());
88

    
89
                if (getMapControl().getImage() != null) {
90
                        if ((m_FirstPoint != null) && (m_LastPoint != null)) {
91
                                if ((m_LastPoint == null) && (m_PointAnt == null)) {
92
                                        m_LastPoint = new Point();
93
                                        m_PointAnt = new Point();
94
                                }
95

    
96
                                g.drawImage(getMapControl().getImage(),
97
                                        (int) (m_LastPoint.getX() - m_PointAnt.getX()),
98
                                        (int) (m_LastPoint.getY() - m_PointAnt.getY()), null);
99
                        } else {
100
                                super.paintComponent(g);
101
                        }
102
                }
103
        }
104

    
105
        /**
106
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
107
         */
108
        public void mousePressed(MouseEvent e) {
109
                Point pScreen = e.getPoint();
110

    
111
                m_PointAnt = pScreen;
112
                m_FirstPoint = m_PointAnt;
113
                if (e.getButton() == MouseEvent.BUTTON1) {
114
                        isButton1=true;
115
                        m_PointAnt = pScreen;
116

    
117
                }else{
118
                        isButton1=false;
119
                }
120

    
121
                if (listener.cancelDrawing()) {
122
                        getMapControl().cancelDrawing();
123
                }
124
        }
125

    
126
        /**
127
         * Reimplementaci?n del m?todo mouseReleased de Behavior.
128
         *
129
         * @param e MouseEvent
130
         *
131
         * @throws BehaviorException Excepci?n lanzada cuando el Behavior.
132
         */
133
        public void mouseReleased(MouseEvent e) throws BehaviorException {
134
                if (e.getButton() == MouseEvent.BUTTON1 && m_FirstPoint!=null) {
135
                        MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e);
136
                        listener.move(event);
137

    
138
                        // System.out.println("mouseReleased");
139
                        getMapControl().drawMap(true);
140
                }
141

    
142
                m_FirstPoint = null;
143
        }
144

    
145
        /**
146
         * Reimplementaci?n del m?todo mouseDragged de Behavior.
147
         *
148
         * @param e MouseEvent
149
         */
150
        public void mouseDragged(MouseEvent e) {
151
                if (isButton1){
152
                        m_LastPoint = e.getPoint();
153
                        getMapControl().repaint();
154
                }
155
        }
156

    
157
        /**
158
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
159
         */
160
        public void setListener(ToolListener listener) {
161
                this.listener = (PanListener) listener;
162
        }
163

    
164
        /**
165
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
166
         */
167
        public ToolListener getListener() {
168
                return listener;
169
        }
170
}