Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / listeners / GeorefPointSelectorListener.java @ 5491

History | View | Annotate | Download (5.33 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.georeferencing.gui.listeners;
42

    
43
import java.awt.Component;
44
import java.awt.geom.Point2D;
45

    
46
import javax.swing.JOptionPane;
47

    
48
import org.gvsig.georeferencing.GeoreferencingToolsModule;
49
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog;
50

    
51
import com.iver.andami.PluginServices;
52
import com.iver.cit.gvsig.fmap.ViewPort;
53
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
54
import com.iver.cit.gvsig.fmap.tools.GeorefPointerListenerImpl;
55
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
56
import com.iver.cit.gvsig.gui.View;
57

    
58

    
59
/**
60
 * <p>Extensi?n de la clase GeorefPointerListenerImpl de FMap para poder llamar a m?todos de
61
 * andami o de gvSIG.</p>
62
 * <p>Este listener salva puntos clickeados desde una vista sobre una capa de puntos.</p>
63
 * 
64
 * @author Nacho Brodin (brodin_ign@gva.es)
65
 */
66
public class GeorefPointSelectorListener extends GeorefPointerListenerImpl {
67
        
68
        //**********************Vars**********************************
69
        private GeoreferencingDialog         dialog = null;
70
        private View                                         theView = null;
71
                        
72
   /**
73
        * true si se va a seleccionar el primer punto y false si se selecciona el segundo.
74
        */
75
        public static boolean                         firstPoint = true;
76
        
77
        /**
78
         * Posici?n del punto a ser seleccionado. 
79
         */
80
        public static int                                 posPoint = -1;
81
        //**********************End Vars******************************
82
        
83
        //**********************Methods*******************************
84
        /**
85
         * Constructor
86
         *
87
         * @param mapCtrl
88
         */
89
        public GeorefPointSelectorListener(GeoreferencingDialog dialog) {
90
                super();
91
                this.dialog = dialog;
92
        }
93

    
94
        /**
95
         * Captura de puntos sobre una capa FlyrPoint
96
         *
97
         * @param event Evento de un punto sobre la vista
98
         *
99
         * @throws BehaviorException
100
         */
101
        public void point(PointEvent event) throws BehaviorException {
102
                super.point(event);
103
                        
104
                try{
105
                        theView = (View)PluginServices.getMDIManager().getActiveView();
106
                }catch(ClassCastException exc){
107
                        return;
108
                }
109
                //Obtenemos la capa de puntos y la capa de georaster
110
                                
111
                if(dialog.getLyrPoints() == null || dialog.getLyrGeoRaster() == null){
112
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
113
                                        PluginServices.getText(this, "error_capa_puntos"));
114
                        return;
115
                }
116
                
117
                ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
118
                Point2D wcPoint = viewPort.toMapPoint(event.getPoint());
119
                                        
120
                if(firstPoint){        
121
                        if(dialog.getLyrPoints() != null){
122
                                dialog.getPointManager().restoreControlsValue();
123
                                
124
                                //Obtenemos el punto seleccionado en coordenadas de la vista
125
                                Point2D pixelImg = dialog.getLyrGeoRaster().world2Img(wcPoint);
126
                                if(pixelImg == null){
127
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
128
                                                        PluginServices.getText(this, "fuera_de_extent"));
129
                                        return;
130
                                }                        
131
                                
132
                                //Obtenemos del dialogo el n? de pto seleccionado y lo actualizamos en la capa de ptos 
133
                                int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue();
134
                                dialog.getPointManager().updateData(n, pixelImg, null, dialog, theView);
135
                                dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(false);
136
                                dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setEnabled(true);
137
                                
138
                                dialog.getPointManager().disableAllControls();
139
                                firstPoint = false;
140
                        }
141
                }else{
142
                        //Deseleccionamos la herramienta de marcado de puntos
143
                        theView.getMapControl().setTool(dialog.getLyrPoints().getLastTool());
144
                        
145
                        //Volvemos a dejar los controles con su valor habitual
146
                        dialog.getPointManager().restoreControlsValue();
147
                        
148
                        //Obtenemos del dialogo el n? de pto seleccionado y lo actualizamos en la capa de ptos
149
                        int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue();
150
                        dialog.getPointManager().updateData(n, null, wcPoint, dialog, theView);
151
                        dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
152
                        dialog.getConectorPanel().getAdjustGeorefPanel().setEnabled(true);
153
                        dialog.getPointManager().setErrors(n - 1);
154
                        
155
                        firstPoint = true;
156
                }
157
                //theView.getMapControl().drawMap(false);
158
        }
159
        
160
        //**********************End Methods*******************************
161
}