Statistics
| Revision:

root / trunk / extensions / extTopology / src / org / gvsig / fmap / tools / VectorListenerImpl.java @ 23163

History | View | Annotate | Download (5.15 KB)

1 22893 azabala
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id:
47
* $Log:
48
*/
49
package org.gvsig.fmap.tools;
50
51
import java.awt.Cursor;
52 23053 azabala
import java.awt.event.MouseEvent;
53 22893 azabala
import java.awt.geom.Point2D;
54 23053 azabala
import java.awt.geom.Rectangle2D;
55 22893 azabala
56
import org.gvsig.fmap.tools.listeners.VectorListener;
57
import org.gvsig.referencing.DisactivableMappedPosition;
58
import org.gvsig.referencing.MappedPositionContainer;
59
import org.gvsig.referencing.ReferencingUtil;
60
import org.opengis.spatialschema.geometry.DirectPosition;
61
62
import com.iver.cit.gvsig.fmap.MapControl;
63
import com.iver.cit.gvsig.fmap.ViewPort;
64
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
65
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent;
66
67
/**
68
 * Vector listener impl that creates vector errors to compute vectorial layers
69
 * transformations.
70
 *
71
 * For each digitized vector error in screen, it creates a geotools MappedPosition
72
 * instance.
73
 * */
74
public class VectorListenerImpl implements VectorListener {
75
76
//        private final Image img = new ImageIcon(MapControl.class.
77
//                                                                                                getResource("images/PointSelectCursor.gif")).
78
//                                                                                                getImage();
79
80
//        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
81
//                                                                                                        new Point(16, 16), "");
82
83
        private Cursor cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
84
85
        /**
86
         * MapControl creator of digitizing events.
87
         */
88
        protected MapControl mapCtrl;
89
90
        /**
91
         * Collection of existing digitized links, to add new vector error.
92
         */
93
        MappedPositionContainer linksList;
94
95 23053 azabala
        protected boolean isZooming = false;
96 22893 azabala
97 23053 azabala
98 22893 azabala
        public VectorListenerImpl(MapControl mapCtrl, MappedPositionContainer linksList) {
99
                super();
100
                this.mapCtrl = mapCtrl;
101
                this.linksList = linksList;
102
        }
103
104
        public void vector(MoveEvent event) throws BehaviorException {
105
                ViewPort vp = mapCtrl.getMapContext().getViewPort();
106 23053 azabala
                int modifiers = event.getEvent().getModifiers();
107
                int modifiersEx = event.getEvent().getModifiersEx();
108 22893 azabala
109 23053 azabala
                int ctrlDownMask = modifiersEx & MouseEvent.CTRL_DOWN_MASK;
110
                int button1Mask = modifiers & MouseEvent.BUTTON1_MASK;
111
                int button2Mask = modifiers & MouseEvent.BUTTON3_MASK;
112
113
                if(ctrlDownMask == MouseEvent.CTRL_DOWN_MASK && vp.getExtent()!=null){
114
                        isZooming = true;
115
                        Rectangle2D.Double r = new Rectangle2D.Double();
116
                        Rectangle2D rect = vp.getExtent();
117
                        double factor = 1;
118
                        if(button1Mask == MouseEvent.BUTTON1_MASK){
119
                                //zoom +
120
                                factor = 1/1.5d;
121
                        }else if(button2Mask == MouseEvent.BUTTON3_MASK){
122
                                //zoom -
123
                                factor = 1*1.5d;
124
                        }else{
125
                                System.err.println("Tecla ctrl pulsada, pero pulsacion de boton sin boton izquierdo o derecho");
126
                                return;
127
                        }
128
129
                        double nuevoX = rect.getMaxX() -
130
                                ((vp.getExtent().getWidth() * factor) / 2.0);
131
                        double nuevoY = rect.getMaxY() -
132
                                ((vp.getExtent().getHeight() * factor) / 2.0);
133
                        r.x = nuevoX;
134
                        r.y = nuevoY;
135
                        r.width = vp.getExtent().getWidth() * factor;
136
                        r.height = vp.getExtent().getHeight() * factor;
137
                        vp.setExtent(r);
138
                        mapCtrl.getMapContext().clearAllCachingImageDrawnLayers();
139
140
                }else{
141
                        isZooming = false;
142
//                        Point2D from = vp.toMapPoint(event.getFrom());
143
//                        Point2D to = vp.toMapPoint(event.getTo());
144
145
                        Point2D from = event.getFrom();
146
                        Point2D to = event.getTo();
147
148
                        ReferencingUtil referencing = ReferencingUtil.getInstance();
149
150
                        //TODO Ver como pasar a GeoAPI la proyeccion del mapControl (libJCRS)
151
                        //de momento estamos pasando null
152
                        DirectPosition source =
153
                                referencing.create(new double[]{from.getX(), from.getY()}, null);
154
155
                        DirectPosition destination =
156
                                referencing.create(new double[]{to.getX(), to.getY()}, null);
157
158
                        DisactivableMappedPosition mappedPosition
159
                                = new DisactivableMappedPosition(source, destination);
160
161
                        this.linksList.addMappedPosition(mappedPosition);
162
                }
163 22893 azabala
164
165
166
        }
167
168
        public boolean cancelDrawing() {
169
                return false;
170
        }
171
172
        public Cursor getCursor() {
173
                return cur;
174
        }
175
176
}