Statistics
| Revision:

root / tags / v10_RC2c / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / dialog / GeoreferencingDialog.java @ 8745

History | View | Annotate | Download (43.6 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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
package org.gvsig.georeferencing.gui.dialog;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Component;
23
import java.awt.Dimension;
24
import java.awt.FlowLayout;
25
import java.awt.event.ActionListener;
26
import java.awt.event.ComponentEvent;
27
import java.awt.event.ComponentListener;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Rectangle2D;
30
import java.beans.PropertyVetoException;
31
import java.io.File;
32

    
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JFileChooser;
36
import javax.swing.JInternalFrame;
37
import javax.swing.JOptionPane;
38
import javax.swing.JPanel;
39
import javax.swing.JToggleButton;
40
import javax.swing.filechooser.FileFilter;
41
import javax.swing.table.DefaultTableModel;
42

    
43
import org.cresques.cts.IProjection;
44
import org.cresques.px.Extent;
45
import org.gvsig.georeferencing.GeoOperations;
46
import org.gvsig.georeferencing.gui.listeners.GeoRasterFrameListener;
47
import org.gvsig.georeferencing.gui.listeners.GeorefMovePointListener;
48
import org.gvsig.georeferencing.gui.listeners.GeorefPanListener;
49
import org.gvsig.georeferencing.gui.listeners.GeorefPointSelectorListener;
50
import org.gvsig.georeferencing.gui.listeners.ZoomGeorefListener;
51
import org.gvsig.georeferencing.gui.panels.ConectorPanel;
52
import org.gvsig.georeferencing.gui.panels.OptionsPanel;
53
import org.gvsig.georeferencing.gui.panels.ZoomControlPanel;
54
import org.gvsig.georeferencing.gui.pointsTable.TablePointsPanel;
55
import org.gvsig.georeferencing.gui.pointsTable.TablePointsPanel.PointTable;
56
import org.gvsig.georeferencing.gui.selectPoints.SelectPointsPanel;
57
import org.gvsig.georeferencing.toc.GeoRasterTocMenuEntry;
58
import org.gvsig.georeferencing.utils.GeoLayerFactory;
59
import org.gvsig.georeferencing.utils.GeoPointPersistence;
60
import org.gvsig.georeferencing.utils.GeoUtils;
61
import org.gvsig.georeferencing.utils.PointManager;
62
import org.gvsig.georeferencing.utils.StackZoom;
63

    
64
import com.iver.andami.PluginServices;
65
import com.iver.cit.gvsig.ProjectExtension;
66
import com.iver.cit.gvsig.fmap.DriverException;
67
import com.iver.cit.gvsig.fmap.MapControl;
68
import com.iver.cit.gvsig.fmap.ViewPort;
69
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
70
import com.iver.cit.gvsig.fmap.layers.FLayers;
71
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
72
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
73
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
74
import com.iver.cit.gvsig.fmap.layers.IGeoUi;
75
import com.iver.cit.gvsig.fmap.layers.RasterFileAdapter;
76
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
77
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
78
import com.iver.cit.gvsig.fmap.tools.Behavior.DraggedBehavior;
79
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior;
80
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior;
81
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
82
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
83
import com.iver.cit.gvsig.gui.View;
84
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
85
import com.iver.cit.gvsig.gui.wizards.WizardListener;
86
import com.iver.cit.gvsig.project.Project;
87

    
88
/**
89
 * Panel que contiene el Wizard de georeferenciaci?n con los tabs
90
 * interiores
91
 *
92
 * @author Nacho Brodin (brodin_ign@gva.es)
93
 */
94
public class GeoreferencingDialog extends JPanel implements IGeoUi, ActionListener, ComponentListener {
95

    
96
        //**********************Vars**********************************
97
        static private IProjection                         proj =  ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject().getProjection();
98
        private JPanel                                                 pBotones = null;  //  @jve:decl-index=0:
99
        private JButton                                         bProcesar = null;  //  @jve:decl-index=0:
100
        private JButton                                         bCancelar = null;  //  @jve:decl-index=0:
101
        private WizardListener                                 wizardListener = new DialogWizardListener();
102
        private GeoRedimBehavior                         rb = null;
103
        private GeoMoveBehavior                         mb = null;
104
        private boolean                                         loadTools = false;
105
        private JInternalFrame                                 frame = null;
106
        /**
107
         * Lista de formatos soportados
108
         */
109
        private String[]                                         fileFilters = {"csv"};
110
        /**
111
         * Recuerda la ?ltima ruta seleccionada por el usuario
112
         */
113
        private String                                                 lastPathLoad = "./";
114
        private String                                                 lastPathSave = "./";
115
        private ConectorPanel                                conectorPanel = null;
116

    
117
        private boolean                                         enlarge = false;
118
        private int                                                 normalWidth = 400;
119
        private int                                                 normalHeight = 273;
120
        private int                                                 enlargeHeight = 448;
121
        private int                                                 tmpWidth = normalWidth;
122

    
123
        private JButton                                         bAceptar = null;
124

    
125
        private FLyrGeoRaster                                 lyrGeoRaster = null;
126
        private TablePointsPanel                         tablePointsPanel = null;
127
        private        PointManager                                pointManager = null;
128
        /**
129
         * True si ha de crearse un fichero de georreferenciaci?n
130
         */
131
        private boolean                                         createWorldFile = false;
132
        /**
133
         * True si los errores han de incluirse en el fichero csv
134
         */
135
        private boolean                                         errorCSV = true;
136
        /**
137
         * Estado de los botones cuando se ejecuta disableAllControls
138
         */
139
        private boolean[]                                         buttonsState = new boolean[7];
140
        /**
141
         * DisableAllControls ha sido ejecutada si est? a true esta variabled
142
         */
143
        private boolean                                         disableAllControls = false;
144
        /**
145
         * Variable que controla si la capa de georreferenciaci?n se ha de desactivar
146
         * despu?s del primer punto.
147
         */
148
        private boolean                                         offLayer = true;
149
        /**
150
         * Variable que controla si la vista ha de centrarse sobre el punto seleccionado
151
         * o no
152
         */
153
        private boolean                                         centerPoint = true;
154
        /**
155
         * Variable que controla si la capa de puntos se ha de desactivar
156
         * despu?s del primer punto.
157
         */
158
        private boolean                                         offPoints = true;
159
        /**
160
         * Panel que contiene los botones de la barra inferior
161
         */
162
        private DialogButtons                                dialogButtons = null;
163
        //**********************End Vars******************************
164

    
165
        //**********************Classes*******************************
166
        /**
167
         * Filtro para selecci?n de ficheros.
168
         * @author Nacho Brodin (brodin_ign@gva.es)
169
         */
170
        class SelectFileFilter extends javax.swing.filechooser.FileFilter {
171

    
172
                private JFileChooser chooser = null;
173
                private String file = null;
174

    
175
                public SelectFileFilter(JFileChooser ch, String file){
176
                        this.chooser = ch;
177
                        this.file = file;
178
                }
179

    
180
            public boolean accept(File f) {
181

    
182
                    return f.isDirectory() || f.getName().toLowerCase().endsWith("."+file);
183
            }
184

    
185
            public String getDescription() {
186
                    return file;
187
            }
188

    
189
        }
190

    
191
        /**
192
         * @author Nacho Brodin (brodin_ign@gva.es)
193
         */
194
        public class DialogWizardListener implements WizardListener {
195

    
196
                /**
197
                 * @see org.gvsig.georeferencing.gui.wms.WizardListener#error(java.lang.Exception)
198
                 */
199
                public void error(Exception e) {
200
                }
201

    
202
                /**
203
                 * @see org.gvsig.georeferencing.gui.wms.WizardListener#wizardStateChanged(boolean)
204
                 */
205
                public void wizardStateChanged(boolean finishable) {
206
                        getBProcess().setEnabled(finishable);
207
                }
208

    
209
        }
210
        //**********************End Classes***************************
211

    
212
        //**********************Methods*******************************
213
    /**
214
     * Constructor.
215
     */
216
    public GeoreferencingDialog(JInternalFrame f, FLyrGeoRaster lyr) {
217
            frame = f;
218
            lyrGeoRaster = lyr;
219

    
220
            frame.addComponentListener(this);
221
            initialize();
222

    
223
            //Creamos el pointManager y lo asignamos a la capa de puntos
224
            pointManager = new PointManager(this, lyrGeoRaster.getFLyrPoints());
225
            this.lyrGeoRaster.getFLyrPoints().setPointManager(pointManager);
226

    
227
            //En estos casos entra cuando la capa se crea al abrir un proyecto
228
            if(lyrGeoRaster.getPersistence() == null){
229
                    lyrGeoRaster.setPersistence(new GeoPointPersistence(lyrGeoRaster.getFLyrPoints()));
230
                    f.addInternalFrameListener(new GeoRasterFrameListener());
231
                    GeoRasterTocMenuEntry.isOpen = true;
232
            }
233
            if(lyrGeoRaster.getStackZoom() == null)
234
                    lyrGeoRaster.setZoom(new StackZoom());
235

    
236
    }
237

    
238
    /**
239
     * En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos
240
     * ls herramientas para manejar las imagenes a georeferenciar.
241
     */
242
    private void initialize() {
243
            //Cargamos las herramientas la primera vez que abrimos la ventana
244
        if(!loadTools){
245
                com.iver.cit.gvsig.gui.View  vista = null;
246
                        try{
247
                                vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveWindow();
248
                        }catch(ClassCastException exc){
249
                                return;
250
                        }
251

    
252
                        MapControl mapCtrl = null;
253
                        if(vista != null)
254
                                mapCtrl = vista.getMapControl();
255

    
256
                if(mapCtrl != null){
257
                        loadTools = true;
258
                                StatusBarListener sbl = new StatusBarListener(mapCtrl);
259

    
260
                                ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
261
                                ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
262
                                rb = new GeoRedimBehavior(zigl);
263
                                mapCtrl.addMapTool("geoZoom", new Behavior[]{rb,
264
                                                        new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
265

    
266
                                GeorefPanListener pl = new GeorefPanListener(mapCtrl);
267
                                mb = new GeoMoveBehavior(pl);
268
                                mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
269

    
270
                                //Seleccion de un punto sobre la vista
271
                        GeorefPointSelectorListener psl = new GeorefPointSelectorListener(this);
272
                        mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
273

    
274
                        GeorefMovePointListener mpl = new GeorefMovePointListener(this);
275
                        mapCtrl.addMapTool("geoMovePoint", new Behavior[]{new DraggedBehavior(mpl), new MouseMovementBehavior(sbl)});
276
                }
277
        }
278

    
279
        this.setLayout(new BorderLayout());
280
        if(!enlarge){
281
                this.setPreferredSize(new java.awt.Dimension(normalWidth, normalHeight));
282
                this.setSize(new java.awt.Dimension(normalWidth, normalHeight));
283
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(false);
284
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(false);
285
        }else{
286
                this.setPreferredSize(new java.awt.Dimension(normalWidth, enlargeHeight));
287
                this.setSize(new java.awt.Dimension(normalWidth, enlargeHeight));
288
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(true);
289
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(true);
290
        }
291
        this.setLocation(new java.awt.Point(0,0));
292

    
293
        this.add(this.getPBotones(), BorderLayout.SOUTH);
294
        this.add(this.getConectorPanel(), BorderLayout.NORTH);
295

    
296
        //A?adimos los listener de los botones de la tabla
297
        //Los botones de borrado los gestiona SelectPointsPanel
298
        //Los botones de cargar y exportar los gestiona GeoreferencigDialog
299
        tablePointsPanel = getConectorPanel().getDataPointsTabPanel().getTablePointsPanel();
300
        tablePointsPanel.getTableControlerPanel().getBClear().addActionListener(this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel());
301
        tablePointsPanel.getTableControlerPanel().getBDelPoint().addActionListener(this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel());
302

    
303
        getDialogButtons().getBExportToCSV().addActionListener(this);
304
        getDialogButtons().getBImportFromCSV().addActionListener(this);
305
        getDialogButtons().getBLoad().addActionListener(this);
306
        getDialogButtons().getBSave().addActionListener(this);
307

    
308
        conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive().addActionListener(this);
309
                getBInsertPointOfTablePoints().addActionListener(conectorPanel.getDataPointsTabPanel().getSelectPointsPanel());
310
                getBNewPointOfTablePoints().addActionListener(conectorPanel.getDataPointsTabPanel().getSelectPointsPanel());
311
    }
312

    
313
        /**
314
         * Comprueba si existe el fichero pasado por par?metro existe solicitando confirmaci?n
315
         * de sobreescritura. Si el usuario acepta devolver? true y si no acepta devuelve false.
316
         * Si se acepta la sobreescritura el fichero es borrado.
317
         * @param file Cadena con el nombre del fichero a comprobar su existencia.
318
         * @return Devuelve true si el fichero existe y va a ser sobreescrito
319
         */
320
        public boolean checkFileExists(String file, boolean delete){
321
                File f = new File(file);
322
                if(f.exists()){
323
                        if (messageBoxYesOrNot("file_exists")){
324
                                if(delete)
325
                                        f.delete();
326
                                return true;
327
                        }else
328
                                return false;
329
                }
330
                return true;
331
        }
332

    
333
        /**
334
         * MessageBox con dos botones (OK y Cancel) que mostrar? el mensaje pasado por
335
         * par?metro
336
         * @param msg Mensaje a mostrar
337
         * @return true si el usuario pulsa Ok y false si pulsa Cancel
338
         */
339
        public boolean messageBoxYesOrNot(String msg){
340
                String string1 = PluginServices.getText(this, "yes");
341
                String string2 = PluginServices.getText(this, "no");
342
                Object[] options = {string1, string2};
343
                int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
344
                                        PluginServices.getText(this, msg),
345
                                        PluginServices.getText(this, "confirmacion"),
346
                                        JOptionPane.YES_NO_OPTION,
347
                                        JOptionPane.QUESTION_MESSAGE,
348
                                        null,
349
                                        options,
350
                                        string1);
351
                if (n == JOptionPane.YES_OPTION)
352
                        return true;
353
                else
354
                        return false;
355
        }
356

    
357
        /**
358
         * Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
359
         * <UL>
360
         * <LI>Cambiamos el nombre a la capa georraster</LI>
361
         * <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
362
         * <LI>Cerramos la ventana</LI>
363
         * </UL>
364
         */
365
        public void actionPerformed(java.awt.event.ActionEvent e) {
366
                com.iver.cit.gvsig.gui.View  theView = null;
367
                try{
368
                        theView = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveWindow();
369
                }catch(ClassCastException exc){
370
                        return;
371
                }
372

    
373
                try{
374
                        //ACEPTAR
375
                        if(e.getSource() == bAceptar)
376
                                accept(theView);
377

    
378
                        //CANCELAR
379
                        if(e.getSource() == bCancelar)
380
                                cancel(theView);
381

    
382
                        //CARGAR PUNTOS
383
                        if(e.getSource() == getDialogButtons().getBLoad())
384
                                loadPoints(theView);
385

    
386
                        //SALVAR PUNTOS
387
                        if(e.getSource() == getDialogButtons().getBSave())
388
                                savePoints();
389

    
390
                        //EXPORTAR A CSV
391
                        if(e.getSource() == getDialogButtons().getBExportToCSV())
392
                                exportToCSV(theView);
393

    
394
                        //IMPORTAR DESDE CSV
395
                        if(e.getSource() == getDialogButtons().getBImportFromCSV())
396
                                importFromCSV(theView);
397

    
398
                        //DESACTIVAR PANELES
399
                        JCheckBox cb = this.conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive();
400
                        if(e.getSource() == cb)
401
                                deactivatePanel(theView, cb);
402

    
403
                        //PROCESAR
404
                        if(e.getSource() == this.getBProcess())
405
                                process(theView);
406
                }catch(Exception exc){
407
                        exc.printStackTrace();
408
                        return;
409
                }
410
        }
411

    
412
        /**
413
         * Cierra el dialogo
414
         */
415
        public void close(){
416
                try{
417
                        frame.setClosed(true);
418
                }catch(PropertyVetoException exc){}
419
        }
420

    
421
        /**
422
         * Funci?n que se ejecuta al pulsar el bot?n procesar. Este procesamiento calcula a partir de
423
         * los puntos de control la georreferenciaci?n de la imagen y la asigna como extent temporal de
424
         * la capa FLyrGeoRaster. Cuando termina actualiza la visualizaci?n.
425
         * @param theView
426
         */
427
        private void process(View theView)throws Exception{
428
                if(getLyrPoints() == null)
429
                        throw new Exception("LyrPoints not loaded.");
430

    
431
                if(this.getLyrPoints().getCountPoints() > 0){
432

    
433
                        //Salvamos los centros
434
                        Point2D[] oldCenter = new Point2D.Double[lyrGeoRaster.getFLyrPoints().getCountPoints()];
435
                        for(int i=0; i<lyrGeoRaster.getFLyrPoints().getCountPoints(); i++)
436
                                oldCenter[i] = lyrGeoRaster.img2World(lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint);
437

    
438
                        //Calculamos las coordenadas de georreferenciaci?n
439
                        GeoOperations go = new GeoOperations(getLyrPoints());
440
                        double[] begin = go.transformPoint(0, 0, go.getAffine());
441
                        double[] end = go.transformPoint((int)lyrGeoRaster.getImageWidth(), (int)lyrGeoRaster.getImageHeight(), go.getAffine());
442
                        Extent ext = new Extent(begin[0], begin[1], end[0], end[1]);
443

    
444
                        //Asignamos el extent temporal a la capa de georreferenciaci?n
445
                        ViewPort vp = theView.getMapControl().getMapContext().getViewPort();
446
                        ((FLyrGeoRaster)theView.getMapControl().getMapContext().getLayers().getLayer(lyrGeoRaster.getName())).setAssignExtent(ext);
447

    
448
                        //Si la capa tiene puntos de control hacemos un update de estos
449
                        //a su posici?n para que se actualicen los controles
450

    
451
                        for(int i=0; i<lyrGeoRaster.getFLyrPoints().getCountPoints(); i++){
452
                                Point2D center = lyrGeoRaster.img2World(lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint);
453
                                lyrGeoRaster.getFLyrPoints().setMiniExtent(        i,
454
                                                                                                                        center,
455
                                                                                                                        GeoUtils.shiftExtent(oldCenter[i], center, getLyrPoints().getMiniExtent(i, false)),
456
                                                                                                                        false);
457
                                if(i == getSelectedPoint())
458
                                        updateData(i + 1, lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint, null, null);
459
                        }
460
                        theView.getMapControl().getMapContext().invalidate();
461
                }
462
        }
463

    
464
        /**
465
         * Funci?n que se ejecuta al pulsar el bot?n aceptar. Este procesamiento calcula a partir de
466
         * los puntos de control la georreferenciaci?n de la imagen, crear el fichero .rmf de georreferenciaci?n
467
         * y descarga la capa del TOC. A continuaci?n vuelve a cargar la capa como FLyrRaster dando
468
         * por finalizada la georreferenciaci?n.
469
         * @param theView
470
         */
471
        private void accept(View theView)throws Exception{
472
                if(getLyrPoints() == null)
473
                        throw new Exception("LyrPoints not loaded.");
474

    
475
                if(this.getLyrPoints().getCountPoints() > 0){
476
                        savePoints();
477

    
478
                        //Creamos el fichero de georreferenciaci?n
479
                        GeoOperations go = new GeoOperations(getLyrPoints());
480
                        go.setCreateWorldFile(this.createWorldFile);
481
                        go.createGeorefFile( (int)getLyrGeoRaster().getImageWidth(),
482
                                                                (int)getLyrGeoRaster().getImageHeight(),
483
                                                                getLyrGeoRaster().getSource().getFiles()[0].getName());
484

    
485
                        FLayers lyrs = this.getLyrGeoRaster().getParentLayer();
486

    
487
                        for(int i = 0; i < lyrs.getLayersCount();i++){
488
                                if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){
489

    
490
                                        //Eliminamos la capa
491
                                        lyrs.removeLayer(i);
492
                                        File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName());
493
                                        try{
494
                                                //Creamos la nueva capa GeoRaster y la a?adimos al TOC.
495
                                                FLyrRaster lyrRaster = GeoLayerFactory.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()),
496
                                                                                                                                                        (RasterDriver)getLyrGeoRaster().getSource().getDriver(),
497
                                                                                                                                                        fich,
498
                                                                                                                                                        getLyrGeoRaster().getProjection());
499
                                                lyrs.addLayer(lyrRaster);
500
                                                theView.getMapControl().getMapContext().invalidate();
501
                                        }catch(DriverException exc){
502

    
503
                                        }
504
                                        break;
505
                                }
506
                        }
507
                }
508
                //Cerramos la ventana
509
                try{
510
                        frame.setClosed(true);
511
                }catch(PropertyVetoException exc){}
512

    
513
        }
514

    
515
        /**
516
         * Funci?n que se ejecuta al pulsar el bot?n cancelar
517
         * @param theView
518
         */
519
        private void cancel(View theView)throws Exception{
520
                if(getLyrPoints() == null)
521
                        throw new Exception("LyrPoints not loaded.");
522

    
523
                //Cerramos la ventana
524
                //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
525
                try{
526
                        frame.setClosed(true);
527
                        theView.getMapControl().getMapContext().invalidate();
528
                }catch(PropertyVetoException exc){}
529
        }
530

    
531
        /**
532
         * Funci?n que se ejecuta al pulsar el bot?n de cargar puntos
533
         * @param theView
534
         */
535
        private void loadPoints(View theView)throws Exception{
536
                if(getLyrPoints() == null)
537
                        throw new Exception("LyrPoints not loaded.");
538

    
539
                if(messageBoxYesOrNot("cargar_puntos")){
540
                        String name = lyrGeoRaster.getName().substring(lyrGeoRaster.getName().indexOf("*") + 1, lyrGeoRaster.getName().lastIndexOf("."));
541
                        String path = ((RasterFileAdapter)lyrGeoRaster.getSource()).getFile().getAbsolutePath();
542
                        String nameRmf = path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".rmf";
543

    
544
                        //Antes de cargar puntos plegamos el cuadro
545
                         getSelectPointsPanel().setEnlarge(true);
546

    
547
                        getLyrPoints().saveState();
548
                        getLyrPoints().XML2PointList(nameRmf);
549

    
550
                        //Esto es por si el panel ha sido estirado cuando cargamos los puntos
551
                        frame.pack();
552
                        frame.show();
553

    
554
                        //Por problemas con repaint e hilos concurrentes tenemos que poner esto explicitamente
555
                        //ya que es posible que se haga un paint de las miniimagenes antes de que cleanCanvas vuelva a valer false
556
                        this.getZoomControlLeft().getCanvas().setCleanCanvas(false);
557
                        this.getZoomControlRight().getCanvas().setCleanCanvas(false);
558

    
559
                        if(getLyrPoints().getCountPoints() > 0)
560
                                setEnableSaveButtons(true);
561
                }
562
        }
563

    
564
        /**
565
         * Funci?n usada para salvar puntos
566
         * @param theView
567
         */
568
        public void savePoints()throws Exception{
569
                if(getLyrPoints() == null)
570
                        throw new Exception("LyrPoints not loaded.");
571
                String name = lyrGeoRaster.getName().substring(lyrGeoRaster.getName().indexOf("*") + 1, lyrGeoRaster.getName().lastIndexOf("."));
572
                String path = ((RasterFileAdapter)lyrGeoRaster.getSource()).getFile().getAbsolutePath();
573
                String nameRmf = path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".rmf";
574

    
575
                File f = new File(nameRmf);
576
                if(f.exists()){
577
                        if (messageBoxYesOrNot("gcps_exist")){
578
                                if(getLyrPoints() != null)
579
                                         getLyrPoints().PointList2XML( path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".grf");
580
                        }
581
                }else
582
                        getLyrPoints().PointList2XML( path.substring(0, path.lastIndexOf(File.separator) + 1) + name + ".grf");
583
        }
584

    
585
        /**
586
         * Funci?n que se ejecuta al pulsar el bot?n de export a ascii
587
         * @param theView
588
         */
589
        private void exportToCSV(View theView)throws Exception{
590
                if(getLyrPoints() == null)
591
                        throw new Exception("LyrPoints not loaded.");
592

    
593
                JFileChooser chooser = new JFileChooser(lastPathSave);
594
                chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
595

    
596
                FileFilter f = null;
597
                for(int i=0; i<this.fileFilters.length;i++){
598
                        f = new SelectFileFilter(chooser, this.fileFilters[i]);
599
                        chooser.addChoosableFileFilter(f);
600
                }
601
                int returnVal = chooser.showOpenDialog(this);
602
                if(returnVal == JFileChooser.APPROVE_OPTION){
603
                         String fName = chooser.getSelectedFile().toString();
604
                         if(!fName.endsWith(".csv"))
605
                                 fName = fName + ".csv";
606
                         lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
607
                         if(checkFileExists(fName, true)){
608
                                 if(getLyrPoints() != null)
609
                                         getLyrPoints().PointList2CSV(fName);
610
                         }
611
                }
612
        }
613

    
614
        /**
615
         * Funci?n que se ejecuta al pulsar el bot?n de importar desde CSV
616
         * @param theView
617
         */
618
        private void importFromCSV(View theView)throws Exception{
619
                if(getLyrPoints() == null)
620
                        throw new Exception("LyrPoints not loaded.");
621

    
622
                JFileChooser chooser = new JFileChooser(lastPathSave);
623
                chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
624

    
625
                FileFilter f = null;
626
                for(int i=0; i<this.fileFilters.length;i++){
627
                        f = new SelectFileFilter(chooser, this.fileFilters[i]);
628
                        chooser.addChoosableFileFilter(f);
629
                }
630
                int returnVal = chooser.showOpenDialog(this);
631
                if(returnVal == JFileChooser.APPROVE_OPTION){
632
                         String fName = chooser.getSelectedFile().toString();
633
                         lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
634
                         getLyrPoints().PointListFromCSV(fName);
635

    
636
                        //Antes de cargar puntos plegamos el cuadro
637
                         getSelectPointsPanel().setEnlarge(true);
638

    
639
                        //Por problemas con repaint e hilos concurrentes tenemos que poner esto explicitamente
640
                        //ya que es posible que se haga un paint de las miniimagenes antes de que cleanCanvas vuelva a valer false
641
                        this.getZoomControlLeft().getCanvas().setCleanCanvas(false);
642
                        this.getZoomControlRight().getCanvas().setCleanCanvas(false);
643

    
644
                         //Si se han cargado puntos desde el CSV se activan los controles
645
                        if(getLyrPoints().getCountPoints() > 0)
646
                                setEnableSaveButtons(true);
647
                }
648
        }
649

    
650
        /**
651
         * Funci?n que se ejecuta al pulsar el bot?n desactivar panel
652
         * @param theView
653
         */
654
        public void deactivatePanel(View theView, JCheckBox cb)throws Exception{
655
                if(getLyrPoints() == null)
656
                        throw new Exception("LyrPoints not loaded.");
657

    
658
                //Sincronizamos con el checkBox de la tabla
659
                tablePointsPanel.getJTable().getTableModel().setValueAt(new Boolean(cb.isSelected()),
660
                                                                                                                                                        tablePointsPanel.getJTable().getTable().getSelectedRow(),
661
                                                                                                                                                        0);
662

    
663
                if(cb.isSelected()){
664
                        this.setEnabled(true);
665
                        getLyrPoints().setPointActive(getSelectedPoint(), true);
666
                }else{
667
                        this.setEnabled(false);
668
                        getLyrPoints().setPointActive(getSelectedPoint(), false);
669
                }
670

    
671
                //Al activar y desactivar tenemos que recalcular errores
672
                this.getPointManager().setErrors(getSelectedPoint());
673

    
674
                theView.getMapControl().getMapContext().invalidate();
675
                getZoomControlLeft().draw();
676
                getZoomControlRight().draw();
677
        }
678

    
679
        /**
680
         * Recalcula el extent de la mini-imagen que corresponde a los puntos en coordenadas
681
         * pixel.Para esto calcula el nuevo centro a partir de la capa y con la distancia entre
682
         * el nuevo centro y el viejo desplaza el extent completo de la mini-imagen.
683
         * @param theView
684
         */
685
        private void calcNewMiniExtent(View theView){
686

    
687
                ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
688
                for(int j = 0; j < getLyrPoints().getCountPoints(); j++){
689
                        //Calculamos el nuevo centro
690
                        Point2D oldCenter = getLyrPoints().getPoint(j).leftCenterPoint;
691
                        Point2D newCenter = new Point2D.Double();
692
                        newCenter.setLocation(        lyrGeoRaster.img2World(getLyrPoints().getPoint(j).pixelPoint));
693

    
694
                        double diffX = oldCenter.getX() - newCenter.getX();
695
                        double diffY = oldCenter.getY() - newCenter.getY();
696

    
697
                        getLyrPoints().getPoint(j).leftCenterPoint = newCenter;
698

    
699
                        ViewPort vpOld = getLyrPoints().getPoint(j).leftViewPort;
700
                        Rectangle2D newExtent = new Rectangle2D.Double(        vpOld.getExtent().getMinX() - diffX,
701
                                                                                                                        vpOld.getExtent().getMinY() - diffY,
702
                                                                                                                        vpOld.getExtent().getWidth(),
703
                                                                                                                        vpOld.getExtent().getHeight() );
704
                        ViewPort vpNew = new ViewPort(vpOld.getProjection());
705
                        vpNew.setExtent(newExtent);
706
                        vpNew.setImageSize(vpOld.getImageSize());
707
                        vpNew.refreshExtent();
708
                        getLyrPoints().getPoint(j).leftViewPort = vpNew;
709
                }
710
        }
711

    
712
        /**
713
         * This method initializes jButton
714
         *
715
         * @return javax.swing.JButton
716
         */
717
        public JButton getBAccept() {
718
                if (bAceptar == null) {
719
                        bAceptar = new JButton();
720
                        bAceptar.setText(PluginServices.getText(this,"aceptar"));
721
                        bAceptar.setToolTipText(PluginServices.getText(this,"accept_tip"));
722
                        bAceptar.addActionListener(this);
723
                }
724
                return bAceptar;
725
        }
726

    
727
        /**
728
         * This method initializes bProcesar
729
         *
730
         * @return javax.swing.JButton
731
         */
732
        public JButton getBProcess() {
733
                if (bProcesar == null) {
734
                        bProcesar = new JButton();
735
                        bProcesar.setText(PluginServices.getText(this,"procesar"));
736
                        bProcesar.setToolTipText(PluginServices.getText(this,"process_tip"));
737
                        bProcesar.setEnabled(true);
738
                        bProcesar.addActionListener(this);
739
                }
740
                return bProcesar;
741
        }
742

    
743
        /**
744
         * El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
745
         * y cierra la ventana.
746
         *
747
         * @return javax.swing.JButton
748
         */
749
        public JButton getBCancel() {
750
                if (bCancelar == null) {
751
                        bCancelar = new JButton();
752
                        bCancelar.setText(PluginServices.getText(this,"cancelar"));
753
                        bCancelar.setToolTipText(PluginServices.getText(this,"cancel_tip"));
754
                        bCancelar.addActionListener(this);
755
                }
756
                return bCancelar;
757
        }
758

    
759
        /**
760
         * Asigna a las textbox el valor de pixel pasado
761
         * @param x        valor x
762
         * @param y        valor y
763
         */
764
        public void setPixelText(double x, double y){
765
                getSelectPointsPanel().getDataPointPanel().getTX().setText(String.valueOf(x));
766
                getSelectPointsPanel().getDataPointPanel().getTY().setText(String.valueOf(y));
767
        }
768

    
769
        /**
770
         * Asigna a las textbox el valor de coordenadas pasado
771
         * @param x        valor x
772
         * @param y        valor y
773
         */
774
        public void setMapCoordText(double x, double y){
775
                getSelectPointsPanel().getDataPointPanel().getLongitud().setText(GeoUtils.tailDecimals(String.valueOf(x), 5));
776
                getSelectPointsPanel().getDataPointPanel().getLatitud().setText(GeoUtils.tailDecimals(String.valueOf(y), 5));
777
        }
778

    
779
        /**
780
         * Esta funci?n resetea los controles del panel de info de un punto.
781
         */
782
        public void resetControls(boolean active){
783
                getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().setSaveToDisk(active);
784
                getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().resetControls(active);
785
                getConectorPanel().getAdjustGeorefPanel().getZoomLeft().clear();
786
                getConectorPanel().getAdjustGeorefPanel().getZoomRight().clear();
787
                setEnabled(active);
788
        }
789

    
790
        /* (non-Javadoc)
791
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
792
         */
793
        public void componentHidden(ComponentEvent arg0) {
794
                // TODO Auto-generated method stub
795

    
796
        }
797
        /* (non-Javadoc)
798
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
799
         */
800
        public void componentMoved(ComponentEvent arg0) {
801
                // TODO Auto-generated method stub
802

    
803
        }
804
        /* (non-Javadoc)
805
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
806
         */
807
        public void componentResized(ComponentEvent ev) {
808

    
809
                if(frame.getWidth() <= this.normalWidth + 10)
810
                        frame.setSize(this.normalWidth, frame.getHeight());
811

    
812
                if(this.getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 1){
813
                        tmpWidth = frame.getWidth();
814
                        this.newFrameSize(frame.getWidth(), frame.getHeight() - 10);
815
                }
816
        }
817
        /* (non-Javadoc)
818
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
819
         */
820
        public void componentShown(ComponentEvent arg0) {
821
                // TODO Auto-generated method stub
822

    
823
        }
824

    
825
    /**
826
     *Inicializa el tama?o del dialogo
827
     */
828
    public void resetSize(){
829
            if(!enlarge){
830
                    frame.setSize(this.normalWidth + 12, this.normalHeight + 10);
831
            }else{
832
                    frame.setSize(this.normalWidth + 12, this.enlargeHeight + 10);
833
            }
834
            newFrameSize((int)Math.round(this.normalWidth / 0.98), this.normalHeight);
835
    }
836

    
837
        /**
838
         * Calculo del nuevo tama?o a partir de un frame redimensionado
839
         * @param w Ancho del frame
840
         * @param h Alto del frame
841
         */
842
        public void newFrameSize(int w, int h){
843
                int newWidth = (int)Math.round(w * 0.98);
844

    
845
        this.setSize(new java.awt.Dimension(newWidth, normalHeight ));
846
        this.setPreferredSize(new java.awt.Dimension(newWidth, normalHeight ));
847
        this.getConectorPanel().newFrameSize(newWidth, h);
848
        }
849

    
850
        /**
851
         * Elimina un punto de la tabla de puntos
852
         * @param pos Posici?n del punto a eliminar
853
         */
854
        public void removeTableValueAt(int pos) throws ArrayIndexOutOfBoundsException{
855
                ((DefaultTableModel)getTable().getTable().getModel()).removeRow(pos);
856
        }
857

    
858
        /**
859
         * A partir de nuevas coordenadas actualiza la vista, minimagen, capa de puntos el
860
         * dialogo y la tabla.
861
         *
862
         */
863
        public void updateData(int nPunto, Point2D pixel, Point2D map, View view){
864
                getPointManager().updateData(nPunto, pixel, map, this, view);
865
        }
866

    
867
        /**
868
         * Esta funci?n deshabilita todos los controles y guarda sus valores
869
         * de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
870
         * se vuelvan a quedar como estaba
871
         */
872
        public void disableAllControls(){
873
                if(!disableAllControls){
874
                        disableAllControls = true;
875

    
876
                        //Salvamos los estados
877
                        buttonsState[0] = getBProcess().isEnabled();
878
                        buttonsState[1] = getBAccept().isEnabled();
879
                        buttonsState[2] = getBCancel().isEnabled();
880
                        buttonsState[3] = getDialogButtons().getBExportToCSV().isEnabled();
881
                        buttonsState[4] = getDialogButtons().getBImportFromCSV().isEnabled();
882
                        buttonsState[5] = getDialogButtons().getBLoad().isEnabled();
883
                        buttonsState[6] = getDialogButtons().getBSave().isEnabled();
884

    
885
                        //Desactivamos controles
886
                        getBProcess().setEnabled(false);
887
                        getBAccept().setEnabled(false);
888
                        getBCancel().setEnabled(false);
889

    
890
                        getDialogButtons().getBExportToCSV().setEnabled(false);
891
                        getDialogButtons().getBImportFromCSV().setEnabled(false);
892
                        getDialogButtons().getBLoad().setEnabled(false);
893
                        getDialogButtons().getBSave().setEnabled(false);
894
                }
895
        }
896

    
897
        /**
898
         * Esta funci?n deja los controles como estaban al ejecutar la funci?n
899
         * disableAllControls
900
         */
901
        public void restoreControlsValue(){
902
                if(disableAllControls){
903
                        disableAllControls = false;
904
                        getBProcess().setEnabled(buttonsState[0]);
905
                        getBAccept().setEnabled(buttonsState[1]);
906
                        getBCancel().setEnabled(buttonsState[2]);
907
                        getDialogButtons().getBExportToCSV().setEnabled(buttonsState[3]);
908
                        getDialogButtons().getBImportFromCSV().setEnabled(buttonsState[4]);
909
                        getDialogButtons().getBLoad().setEnabled(buttonsState[5]);
910
                        getDialogButtons().getBSave().setEnabled(buttonsState[6]);
911
                }
912
        }
913
        //**********************End Methods***************************
914

    
915
        //**********************Setters & Getters*********************
916
        /**
917
         * Obtiene la tabla de puntos
918
         */
919
        public PointTable getTable(){
920
                return this.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getJTable();
921
        }
922

    
923
        /**
924
         * Asigna un valor a una posici?n de la tabla
925
         * @param value Valor a asignar
926
         * @param row        Fila en la que se asigna
927
         * @param col        Columna en la que se asigna
928
         */
929
        public void setTableValueAt(String value, int row, int col)throws ArrayIndexOutOfBoundsException{
930
                ((DefaultTableModel)getTable().getTable().getModel()).setValueAt(value, row, col);
931
        }
932

    
933
        /**
934
         * Asigna un valor del checkBox para una fila de la tabla
935
         * @param row Fila en la que se asigna
936
         */
937
        public void setCheckValueAt(Boolean value, int row)throws ArrayIndexOutOfBoundsException{
938
                ((DefaultTableModel)getTable().getTable().getModel()).setValueAt(value, row, 0);
939
        }
940

    
941
        /**
942
         * Obtiene el n?mero de filas de la tabla
943
         * @return N?mero de filas de la tabla
944
         */
945
        public int getTableRowCount(){
946
                return getTable().getTable().getRowCount();
947
        }
948

    
949
        /**
950
         * A?ade una nueva fila a la tabla de puntos
951
         */
952
        public void addTableNew(){
953
                getTable().getTableModel().addNew();
954
        }
955
        /**
956
         * @return Returns the tmpWidth.
957
         */
958
        public int getTmpWidth() {
959
                return tmpWidth;
960
        }
961
        /**
962
         * @param tmpWidth The tmpWidth to set.
963
         */
964
        public void setTmpWidth(int tmpWidth) {
965
                this.tmpWidth = tmpWidth;
966
        }
967
        /**
968
         * @return Returns the enlargeHeight.
969
         */
970
        public int getEnlargeHeight() {
971
                return enlargeHeight;
972
        }
973
        /**
974
         * @return Returns the normalHeight.
975
         */
976
        public int getNormalHeight() {
977
                return normalHeight;
978
        }
979

    
980
        /**
981
         * @return Returns the normalWidth.
982
         */
983
        public int getNormalWidth() {
984
                return normalWidth;
985
        }
986

    
987
        /**
988
         * Asigna el valor del campo RMS
989
         * @param rms Cadena que representa el RMS
990
         */
991
        public void setRMS(String rms){
992
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTRMS().setText(rms);
993
        }
994

    
995
        /**
996
         * Asigna el valor del campo de residuo en X
997
         * @param rms Cadena que representa el RMS
998
         */
999
        public void setResX(String resX){
1000
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTResX().setText(resX);
1001
        }
1002

    
1003
        /**
1004
         * Asigna el valor del campo de residuo en Y
1005
         * @param rms Cadena que representa el RMS
1006
         */
1007
        public void setResY(String resY){
1008
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTResY().setText(resY);
1009
        }
1010

    
1011
        /**
1012
         * Asigna el valor del campo RMS
1013
         * @param rms Cadena que representa el RMS
1014
         */
1015
        public void setTotal(String total){
1016
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTTotal().setText(total);
1017
        }
1018

    
1019
        /**
1020
         * @return Returns the lyrGeoRaster.
1021
         */
1022
        public FLyrGeoRaster getLyrGeoRaster() {
1023
                return lyrGeoRaster;
1024
        }
1025

    
1026
        /**
1027
         * @return Returns the lyrPoints.
1028
         */
1029
        public FLyrPoints getLyrPoints() {
1030
                try{
1031
                        return lyrGeoRaster.getFLyrPoints();
1032
                }catch(ClassCastException exc){
1033
                        return null;
1034
                }
1035
        }
1036

    
1037
        /**
1038
         * Selecciona un tab del cuadro
1039
         * @param index
1040
         */
1041
        public void setSelectedTab(int index){
1042
                try{
1043
                        this.getConectorPanel().getDataPointsTabPanel().getTbPoints().setSelectedIndex(index);
1044
                }catch(IllegalArgumentException ex){
1045
                        //Si peta al seleccionar un tab, pues nada.
1046
                }
1047
        }
1048

    
1049
        /**
1050
         * @param extended The extended to set.
1051
         */
1052
        public void setEnlarge(boolean enlarge) {
1053
                this.enlarge = enlarge;
1054
                if(!enlarge){
1055
                        frame.setSize(new Dimension(this.normalWidth + 12, this.normalHeight + 10));
1056
                        frame.setPreferredSize(new Dimension(this.normalWidth + 12, this.normalHeight + 10));
1057
                        this.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight));
1058
                        this.setSize(new Dimension(this.normalWidth, this.normalHeight));
1059
                        this.getConectorPanel().setCanvasVisible(false);
1060
                }else{
1061
                        frame.setSize(new Dimension(this.normalWidth + 12, this.enlargeHeight + 10));
1062
                        frame.setPreferredSize(new Dimension(this.normalWidth + 12, this.enlargeHeight + 10));
1063
                        this.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight));
1064
                        this.setSize(new Dimension(this.normalWidth, this.enlargeHeight));
1065
                        this.getConectorPanel().setCanvasVisible(true);
1066
                }
1067
                frame.pack();
1068
        }
1069

    
1070
        /**
1071
         * @return Returns the extended.
1072
         */
1073
        public boolean isEnlarge() {
1074
                return enlarge;
1075
        }
1076

    
1077
        /**
1078
     * Obtiene el panel conector
1079
     * @return
1080
     */
1081
    public ConectorPanel getConectorPanel() {
1082
            if (conectorPanel == null) {
1083
                    conectorPanel = new ConectorPanel(this);
1084
            }
1085

    
1086
            return conectorPanel;
1087
    }
1088

    
1089
        /**
1090
         * This method initializes jPanel
1091
         *
1092
         * @return javax.swing.JPanel
1093
         */
1094
        private JPanel getPBotones() {
1095
                if (pBotones == null) {
1096
                        FlowLayout flowLayout1 = new FlowLayout();
1097
                        pBotones = new JPanel();
1098
                        pBotones.setLayout(flowLayout1);
1099
                        flowLayout1.setHgap(2);
1100
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
1101
                        pBotones.add(getDialogButtons(), null);
1102
                        pBotones.add(getBProcess(), null);
1103
                        pBotones.add(getBAccept(), null);
1104
                        pBotones.add(getBCancel(), null);
1105
                }
1106
                return pBotones;
1107
        }
1108

    
1109
        public static IProjection getLastProjection() {
1110
                return proj;
1111
        }
1112
        public static void setLastProjection(IProjection proj) {
1113
                GeoreferencingDialog.proj = proj;
1114
        }
1115

    
1116
        /**
1117
         * @return Returns the GeoRedimBehavior.
1118
         */
1119
        public GeoRedimBehavior getGeoRedimBehavior() {
1120
                return rb;
1121
        }
1122

    
1123
        /**
1124
         * @param rb The GeoRedimBehavior to set.
1125
         */
1126
        public void setGeoRedimBehavior(GeoRedimBehavior rb) {
1127
                this.rb = rb;
1128
        }
1129

    
1130
        /**
1131
         * @return Returns the GeoMoveBehavior
1132
         */
1133
        public GeoMoveBehavior getGeoMoveBehavior() {
1134
                return mb;
1135
        }
1136

    
1137
        /**
1138
         * @param mb The GeoMoveBehavior to set.
1139
         */
1140
        public void setGeoMoveBehavior(GeoMoveBehavior mb) {
1141
                this.mb = mb;
1142
        }
1143

    
1144

    
1145
        /**
1146
         * Obtiene el punto de la lista que ha sido seleccionado
1147
         * @return
1148
         */
1149
        public int getSelectedPoint(){
1150
                return getConectorPanel().getDataPointsTabPanel().
1151
                        getSelectPointsPanel().getTableControlerPanel().getSelectedIndex();
1152
        }
1153

    
1154
        /**
1155
         * Obtiene el control de la mini imagen que tiene los botones a la izquierda
1156
         * @return ZoomControlPanel
1157
         */
1158
        public ZoomControlPanel getZoomControlLeft(){
1159
                return this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft();
1160
        }
1161

    
1162
        /**
1163
         * Obtiene el control de la mini imagen que tiene los botones a la derecha
1164
         * @return ZoomControlPanel
1165
         */
1166
        public ZoomControlPanel getZoomControlRight(){
1167
                return this.getConectorPanel().getAdjustGeorefPanel().getZoomRight();
1168
        }
1169

    
1170
        /**
1171
         * Obtiene el panel de selecci?n de puntos
1172
         * @return Panel de selecci?n de puntos
1173
         */
1174
        public SelectPointsPanel getSelectPointsPanel(){
1175
                return this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel();
1176
        }
1177

    
1178
        /**
1179
         * Obtiene el panel de opciones
1180
         * @return OptionPanel
1181
         */
1182
        public OptionsPanel getOptionsPanel(){
1183
                return getConectorPanel().getAdjustGeorefPanel().getOptionsPanel();
1184
        }
1185

    
1186
    /**
1187
     * Asigna el frame
1188
     * @param f
1189
     */
1190
    public void setFrame(JInternalFrame f){
1191
            frame = f;
1192
            frame.addComponentListener(this);
1193
    }
1194

    
1195
    /**
1196
     * Obtiene el frame
1197
     * @return frame
1198
     */
1199
    public JInternalFrame getFrame(){
1200
            return frame;
1201
    }
1202

    
1203
    /**
1204
     * Obtiene el gestor de puntos
1205
     * @return PointManager
1206
     */
1207
    public PointManager getPointManager() {
1208
                return pointManager;
1209
        }
1210

    
1211
    /**
1212
     * Activa o desactiva este panel y todos los que lo componen
1213
     * @param enabled variable booleana para la activaci?n y/o desactivaci?n
1214
     */
1215
    public void setEnabled(boolean enabled){
1216
            conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().setEnabled(enabled);
1217
            conectorPanel.getAdjustGeorefPanel().setEnabled(enabled);
1218
    }
1219

    
1220
    /**
1221
         * M?todo para notificar si se desea crear o no el fichero de coordenadas .tfw, .wld .jpgw ,...
1222
         * @param createWorldFile
1223
         */
1224
    public void setCreateWorldFile(boolean createWorldFile) {
1225
                this.createWorldFile = createWorldFile;
1226
        }
1227

    
1228
    /**
1229
     *
1230
     */
1231
    public ViewPort getLeftInitViewport(ViewPort vp, Point2D center, ViewPort initVp, double zoom){
1232
            return getZoomControlLeft().getCanvas().initViewPort(vp, center, initVp, zoom);
1233
    }
1234

    
1235
    /**
1236
         * Consulta si se desea incluir los errores cuando se exporta a fichero .csv
1237
         * @param errorCVS true si se incluyen los errores dentro del fichero y false si no se incluyen
1238
         */
1239
    public boolean isErrorCSV() {
1240
                return errorCSV;
1241
        }
1242

    
1243
    /**
1244
         * M?todo para notificar si se desea incluir los errores cuando se exporta a fichero .csv
1245
         * @param errorCVS true si se incluyen los errores dentro del fichero y false si no se incluyen
1246
         */
1247
        public void setErrorCSV(boolean errorCSV) {
1248
                this.errorCSV = errorCSV;
1249
        }
1250

    
1251
        /**
1252
         * Obtiene los errores en una matriz de Nx3 en la que cada fila es un punto y la
1253
         * columna 0 es el error en X, la columna 1 es el error en Y y la columna 2 es el error RMS.
1254
         * @return matriz de errores
1255
         */
1256
        public double[][] getErrors(){
1257
                return pointManager.getErrors();
1258
        }
1259

    
1260
        /**
1261
         * Pregunta si la capa a georreferenciar se desactiva cuando se introduce el
1262
         * primer punto y devuelve true si lo hace.
1263
         * @return true o false
1264
         */
1265
        public boolean isOffLayer() {
1266
                return offLayer;
1267
        }
1268

    
1269
        /**
1270
         * Asigna el flag que dice si la capa a georreferenciar se desactiva cuando se introduce el
1271
         * primer punto
1272
         * @param offLayer true para desactivar la capa
1273
         */
1274
        public void setOffLayer(boolean offLayer) {
1275
                this.offLayer = offLayer;
1276
        }
1277

    
1278
        /**
1279
         * Consulta si la vista ha de centrarse sobre el punto seleccionado o no.
1280
         * @return true o false
1281
         */
1282
        public boolean isCenterPoint() {
1283
                return centerPoint;
1284
        }
1285

    
1286
        /**
1287
         * Asigna el flag que dice si vista ha centrarse sobre el punto seleccionado o no
1288
         * @param centerPoint true para centrar la vista y false no.
1289
         */
1290
        public void setCenterPoint(boolean centerPoint) {
1291
                this.centerPoint = centerPoint;
1292
        }
1293

    
1294
        /**
1295
         * Pregunta si la capa de puntos se desactiva cuando se introduce el
1296
         * primer punto y devuelve true si lo hace.
1297
         * @return true o false
1298
         */
1299
        public boolean isOffPoints() {
1300
                return offPoints;
1301
        }
1302

    
1303
        /**
1304
         * Asigna el flag que dice si la capa de puntos se desactiva cuando se introduce el
1305
         * primer punto
1306
         * @param offPoints true para desactivar la capa
1307
         */
1308
        public void setOffPoints(boolean offPoints) {
1309
                this.offPoints = offPoints;
1310
        }
1311

    
1312
        /**
1313
         * Obtiene el bot?n de activar/desactivar la inserci?n de punto del panel del control de
1314
         * tabla
1315
         * @return JToggleButton
1316
         */
1317
        public JToggleButton getBInsertPointOfTablePoints(){
1318
                return tablePointsPanel.getPTablePanelButtons().getBInsertPoint();
1319
        }
1320

    
1321
        /**
1322
         * Obtiene el bot?n de activar/desactivar la inserci?n de punto del panel del control de
1323
         * tabla
1324
         * @return JToggleButton
1325
         */
1326
        public JButton getBNewPointOfTablePoints(){
1327
                return tablePointsPanel.getTableControlerPanel().getBNew();
1328
        }
1329

    
1330
        /**
1331
         * This method initializes jPanel
1332
         *
1333
         * @return javax.swing.JPanel
1334
         */
1335
        public DialogButtons getDialogButtons() {
1336
                if (dialogButtons == null) {
1337
                        dialogButtons = new DialogButtons();
1338
                }
1339
                return dialogButtons;
1340
        }
1341

    
1342
        /**
1343
         * Activa/desactiva los botones de la barra correspondientes al salvado
1344
         * de datos a disco.
1345
         * @param active true activa los controles y false los desactiva.
1346
         */
1347
        public void setEnableSaveButtons(boolean active){
1348
                getDialogButtons().getBSave().setEnabled(active);
1349
                getDialogButtons().getBExportToCSV().setEnabled(active);
1350
        }
1351
        //**********************End Setters & Getters*****************
1352

    
1353
 }  //  @jve:decl-index=0:visual-constraint="10,10"
1354
 //  @jve:visual-info  decl-index=0 visual-constraint="10,10"
1355
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"