Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / dialogs / GeoreferencingDialog.java @ 4840

History | View | Annotate | Download (30.3 KB)

1
package com.iver.cit.gvsig.gui.dialogs;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Component;
5
import java.awt.Dimension;
6
import java.awt.FlowLayout;
7
import java.awt.event.ActionListener;
8
import java.awt.event.ComponentEvent;
9
import java.awt.event.ComponentListener;
10
import java.awt.geom.Point2D;
11
import java.awt.geom.Rectangle2D;
12
import java.beans.PropertyVetoException;
13
import java.io.File;
14

    
15
import javax.swing.JButton;
16
import javax.swing.JCheckBox;
17
import javax.swing.JFileChooser;
18
import javax.swing.JInternalFrame;
19
import javax.swing.JOptionPane;
20
import javax.swing.JPanel;
21
import javax.swing.filechooser.FileFilter;
22
import javax.swing.table.DefaultTableModel;
23

    
24
import org.cresques.cts.IProjection;
25

    
26
import com.iver.andami.PluginServices;
27
import com.iver.cit.gvsig.GeoOperations;
28
import com.iver.cit.gvsig.fmap.DriverException;
29
import com.iver.cit.gvsig.fmap.MapControl;
30
import com.iver.cit.gvsig.fmap.ViewPort;
31
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
32
import com.iver.cit.gvsig.fmap.layers.FLayers;
33
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
34
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
35
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
36
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
37
import com.iver.cit.gvsig.fmap.tools.Behavior.DraggedBehavior;
38
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior;
39
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior;
40
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
41
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
42
import com.iver.cit.gvsig.gui.View;
43
import com.iver.cit.gvsig.gui.listeners.GeorefMovePointListener;
44
import com.iver.cit.gvsig.gui.listeners.GeorefPanListener;
45
import com.iver.cit.gvsig.gui.listeners.GeorefPointSelectorListener;
46
import com.iver.cit.gvsig.gui.listeners.ZoomGeorefListener;
47
import com.iver.cit.gvsig.gui.panels.ConectorPanel;
48
import com.iver.cit.gvsig.gui.panels.OptionsPanel;
49
import com.iver.cit.gvsig.gui.panels.ZoomControlPanel;
50
import com.iver.cit.gvsig.gui.pointsTable.TablePointsPanel;
51
import com.iver.cit.gvsig.gui.pointsTable.TablePointsPanel.PointTable;
52
import com.iver.cit.gvsig.gui.selectPoints.SelectPointsPanel;
53
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
54
import com.iver.cit.gvsig.gui.wizards.WizardListener;
55
import com.iver.cit.gvsig.project.Project;
56
import com.iver.cit.gvsig.utils.MathUtils;
57
import com.iver.cit.gvsig.utils.PointManager;
58

    
59
/**
60
 * Panel que contiene el Wizard de georeferenciaci?n con los tabs
61
 * interiores
62
 *
63
 * @author Nacho Brodin (brodin_ign@gva.es)
64
 */
65
public class GeoreferencingDialog extends JPanel implements ActionListener, ComponentListener {
66
        
67
        //**********************Vars**********************************
68
        static private IProjection                         proj = Project.getProjection();
69
        private JPanel                                                 pBotones = null;  //  @jve:decl-index=0:
70
        private JButton                                         bProcesar = null;  //  @jve:decl-index=0:
71
        private JButton                                         bCancelar = null;  //  @jve:decl-index=0:
72
        private WizardListener                                 wizardListener = new DialogWizardListener();
73
        private JButton                                         bLoadPoints = null;  //  @jve:decl-index=0:
74
        private GeoRedimBehavior                         rb = null;
75
        private GeoMoveBehavior                         mb = null;
76
        private boolean                                         loadTools = false;
77
        private JInternalFrame                                 frame = null;
78
        /**
79
         * Lista de formatos soportados
80
         */
81
        private String[]                                         fileFilters = {"grf"};
82
        /**
83
         * Recuerda la ?ltima ruta seleccionada por el usuario
84
         */
85
        private String                                                 lastPathLoad = "./";
86
        private String                                                 lastPathSave = "./";
87
        private ConectorPanel                                conectorPanel = null;
88
        
89
        private boolean                                         enlarge = false;
90
        private int                                                 normalWidth = 400;
91
        private int                                                 normalHeight = 273;
92
        private int                                                 enlargeHeight = 438;
93
        private int                                                 tmpWidth = normalWidth;
94
        
95
        private JButton                                         bAceptar = null;
96
        
97
        private JButton                                         bSavePoints = null;
98
        private FLyrGeoRaster                                 lyrGeoRaster = null;
99
        private TablePointsPanel                         tablePointsPanel = null;
100
        private        PointManager                                pointManager = null;
101
        //**********************End Vars******************************        
102
        
103
        //**********************Classes*******************************
104
        /**
105
         * Filtro para selecci?n de ficheros.
106
         * @author Nacho Brodin (brodin_ign@gva.es)
107
         */
108
        class SelectFileFilter extends javax.swing.filechooser.FileFilter {
109
                
110
                private JFileChooser chooser = null;
111
                private String file = null;
112
                
113
                public SelectFileFilter(JFileChooser ch, String file){
114
                        this.chooser = ch;
115
                        this.file = file;
116
                }
117
                
118
            public boolean accept(File f) {
119

    
120
                    return f.isDirectory() || f.getName().toLowerCase().endsWith("."+file);
121
            }
122
            
123
            public String getDescription() {
124
                    return file;
125
            }
126
            
127
        }
128
        
129
        /**
130
         * @author Nacho Brodin (brodin_ign@gva.es)
131
         */
132
        public class DialogWizardListener implements WizardListener {
133

    
134
                /**
135
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#error(java.lang.Exception)
136
                 */
137
                public void error(Exception e) {
138
                }
139

    
140
                /**
141
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#wizardStateChanged(boolean)
142
                 */
143
                public void wizardStateChanged(boolean finishable) {
144
                        getBProcesar().setEnabled(finishable);
145
                }
146
                
147
        }
148
        //**********************End Classes***************************
149
        
150
        //**********************Methods*******************************
151
    /**
152
     * Constructor.
153
     */
154
    public GeoreferencingDialog(JInternalFrame f, FLyrGeoRaster lyr) {
155
            frame = f;
156
            lyrGeoRaster = lyr;
157
            
158
            frame.addComponentListener(this);
159
            initialize();
160
            
161
            //Creamos el pointManager y lo asignamos a la capa de puntos
162
            pointManager = new PointManager(this, lyrGeoRaster.getFLyrPoints());
163
            this.lyrGeoRaster.getFLyrPoints().setPointManager(pointManager);
164
    }
165
      
166
    /**
167
     * En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos 
168
     * ls herramientas para manejar las imagenes a georeferenciar.
169
     */
170
    private void initialize() {
171
            //Cargamos las herramientas la primera vez que abrimos la ventana
172
        if(!loadTools){
173
                loadTools = true;
174
                com.iver.cit.gvsig.gui.View  vista = null;
175
                        try{
176
                                vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
177
                        }catch(ClassCastException exc){
178
                                return;
179
                        }
180
                MapControl mapCtrl = vista.getMapControl();
181

    
182
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
183
                        
184
                        ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
185
                        ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
186
                        rb = new GeoRedimBehavior(zigl, this);
187
                        mapCtrl.addMapTool("geoZoom", new Behavior[]{rb,
188
                                                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
189
                                                        
190
                        GeorefPanListener pl = new GeorefPanListener(mapCtrl);
191
                        mb = new GeoMoveBehavior(pl, this);
192
                        mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
193
                        
194
                        //Seleccion de un punto sobre la vista
195
                GeorefPointSelectorListener psl = new GeorefPointSelectorListener(this);
196
                mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
197
                
198
                GeorefMovePointListener mpl = new GeorefMovePointListener(this);
199
                mapCtrl.addMapTool("geoMovePoint", new Behavior[]{new DraggedBehavior(mpl), new MouseMovementBehavior(sbl)});
200
                
201
        }
202
        
203
        this.setLayout(new BorderLayout());
204
        if(!enlarge){
205
                this.setPreferredSize(new java.awt.Dimension(normalWidth, normalHeight));
206
                this.setSize(new java.awt.Dimension(400,273));
207
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(false);
208
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(false);
209
        }else{
210
                this.setPreferredSize(new java.awt.Dimension(normalWidth, enlargeHeight));
211
                this.setSize(new java.awt.Dimension(normalWidth, enlargeHeight));
212
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(true);
213
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(true);
214
        }
215
        this.setLocation(new java.awt.Point(0,0));
216
        
217
        this.add(this.getPBotones(), BorderLayout.SOUTH);
218
        this.add(this.getConectorPanel(), BorderLayout.NORTH);    
219
        
220
        //A?adimos los listener de los botones de la tabla
221
        //Los botones de borrado los gestiona SelectPointsPanel
222
        //Los botones de cargar y exportar los gestiona GeoreferencigDialog
223
        tablePointsPanel = getConectorPanel().getDataPointsTabPanel().getTablePointsPanel(); 
224
        tablePointsPanel.getTableControlerPanel().getBClear().addActionListener(this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel());
225
        tablePointsPanel.getTableControlerPanel().getBDelPoint().addActionListener(this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel());
226
        tablePointsPanel.getPButtonsExportImportPanel().getBLoad().addActionListener(this);
227
        tablePointsPanel.getPButtonsExportImportPanel().getBSave().addActionListener(this);
228
        tablePointsPanel.getPButtonsExportImportPanel().getBExportToAscii().addActionListener(this);
229
        conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive().addActionListener(this);
230
    }
231
            
232
        /**
233
         * This method initializes jButton        
234
         *         
235
         * @return javax.swing.JButton        
236
         */    
237
        private JButton getBAceptar() {
238
                if (bAceptar == null) {
239
                        bAceptar = new JButton();
240
                        bAceptar.setText(PluginServices.getText(this,"aceptar"));
241
                        bAceptar.addActionListener(this);
242
                }
243
                return bAceptar;
244
        }
245
        
246
        /**
247
         * Comprueba si existe el fichero pasado por par?metro existe solicitando confirmaci?n
248
         * de sobreescritura. Si el usuario acepta devolver? true y si no acepta devuelve false.
249
         * Si se acepta la sobreescritura el fichero es borrado. 
250
         * @param file Cadena con el nombre del fichero a comprobar su existencia.
251
         * @return Devuelve true si el fichero existe y va a ser sobreescrito
252
         */
253
        private boolean checkFileExists(String file){
254
                File f = new File(file);
255
                if(f.exists()){
256
                        String string1 = PluginServices.getText(this, "yes");
257
                        String string2 = PluginServices.getText(this, "no");
258
                        Object[] options = {string1, string2};
259
                        int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
260
                                        PluginServices.getText(this, "file_exists"),
261
                                        PluginServices.getText(this, "confirmacion"),
262
                                        JOptionPane.YES_NO_OPTION,
263
                                        JOptionPane.QUESTION_MESSAGE,
264
                                        null,     
265
                                        options,  
266
                                        string1); 
267
                        if (n == JOptionPane.YES_OPTION){ 
268
                                f.delete();
269
                                return true;
270
                        }else
271
                                return false;
272
                }
273
                return true;
274
        }
275
        
276
        /**
277
         * Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
278
         * <UL>
279
         * <LI>Cambiamos el nombre a la capa georraster</LI>
280
         * <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
281
         * <LI>Cerramos la ventana</LI>
282
         * </UL>
283
         */
284
        public void actionPerformed(java.awt.event.ActionEvent e) {
285
                com.iver.cit.gvsig.gui.View  theView = null;
286
                try{
287
                        theView = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
288
                }catch(ClassCastException exc){
289
                        return;
290
                }
291

    
292
                try{
293
                        //ACEPTAR 
294
                        if(e.getSource() == bAceptar){
295
                                accept(theView);        
296
                        }
297
                        
298
                        //CANCELAR
299
                        if(e.getSource() == bCancelar){
300
                                cancel(theView);
301
                        }
302
                }catch(Exception exc){
303
                        return; 
304
                }
305
                
306
                //CARGAR PUNTOS
307
                if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBLoad()){
308
                        JFileChooser chooser = new JFileChooser(lastPathLoad);
309
                        chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
310
                        FileFilter f = null;
311
                        for(int i=0; i<this.fileFilters.length;i++){
312
                                f = new SelectFileFilter(chooser, this.fileFilters[i]);
313
                                chooser.addChoosableFileFilter(f);
314
                        }
315
                        int returnVal = chooser.showOpenDialog(this);
316
                        if(returnVal == JFileChooser.APPROVE_OPTION){
317
                                 String fName = chooser.getSelectedFile().toString();
318
                                 FileFilter filter = chooser.getFileFilter();
319
                                 lastPathLoad = chooser.getCurrentDirectory().getAbsolutePath();
320
                        
321
                                 if(getLyrPoints() == null)
322
                                         return;
323

    
324
                                 lyrGeoRaster.getFLyrPoints().saveState();
325
                                 getLyrPoints().XML2PointList(fName);
326
                        }
327
                }
328
                
329
                //SALVAR PUNTOS
330
                if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBSave()){
331
                        JFileChooser chooser = new JFileChooser(lastPathSave);
332
                        chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
333
                        
334
                        FileFilter f = null;
335
                        for(int i=0; i<this.fileFilters.length;i++){
336
                                f = new SelectFileFilter(chooser, this.fileFilters[i]);
337
                                chooser.addChoosableFileFilter(f);
338
                        }
339
                        int returnVal = chooser.showOpenDialog(this);
340
                        if(returnVal == JFileChooser.APPROVE_OPTION){
341
                                 String fName = chooser.getSelectedFile().toString();                         
342
                                 lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
343
                                 if(!fName.endsWith(".grf"))
344
                                         fName = fName + ".grf";
345
                                 if(this.checkFileExists(fName)){
346
                                         if(getLyrPoints() != null)
347
                                                 getLyrPoints().PointList2XML(fName);
348
                                 }
349
                        }
350
                        
351
                }
352
                
353
                //EXPORTAR A ASCII
354
                if(e.getSource() == tablePointsPanel.getPButtonsExportImportPanel().getBExportToAscii()){
355
                        JFileChooser chooser = new JFileChooser(lastPathSave);
356
                        chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
357
                        
358
                        FileFilter f = null;
359
                        for(int i=0; i<this.fileFilters.length;i++){
360
                                f = new SelectFileFilter(chooser, this.fileFilters[i]);
361
                                chooser.addChoosableFileFilter(f);
362
                        }
363
                        int returnVal = chooser.showOpenDialog(this);
364
                        if(returnVal == JFileChooser.APPROVE_OPTION){
365
                                 String fName = chooser.getSelectedFile().toString();
366
                                 lastPathSave = chooser.getCurrentDirectory().getAbsolutePath();
367
                                 if(this.checkFileExists(fName)){
368
                                         if(getLyrPoints() != null)
369
                                                 getLyrPoints().PointList2Ascii(fName);
370
                                 }
371
                        }
372
                        
373
                }
374
                
375
                //DESACTIVAR PANELES
376
                JCheckBox cb = this.conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel().getCbActive();
377
                if(e.getSource() == cb){
378
                        if(cb.isSelected()){
379
                                this.setEnabled(true);
380
                                getLyrPoints().setPointActive(getSelectedPoint(), true);
381
                        }else{
382
                                this.setEnabled(false);
383
                                getLyrPoints().setPointActive(getSelectedPoint(), false);
384
                        }
385
                        theView.getMapControl().getMapContext().invalidate();
386
                        getZoomControlLeft().draw();
387
                        getZoomControlRight().draw();
388
                }        
389
                
390
                //PROCESAR
391
                if(e.getSource() == this.getBProcesar()){
392
                        if(this.getLyrPoints().getCountPoints() > 0){
393
                                        
394
                                //Creamos el fichero de georreferenciaci?n
395
                                GeoOperations go = new GeoOperations(getLyrPoints());
396
                                go.createWorldFile( (int)getLyrGeoRaster().getWidth(), 
397
                                                                        (int)getLyrGeoRaster().getHeight(),
398
                                                                        getLyrGeoRaster().getSource().getFiles()[0].getName());
399
                                
400
                                FLayers lyrs = this.getLyrGeoRaster().getParentLayer(); 
401
                                for(int i = 0; i < lyrs.getLayersCount();i++){
402
                                        if(this.getLyrGeoRaster().getName().equals(lyrs.getLayer(i).getName())){
403
                                                
404
                                                //Eliminamos la capa
405
                                                lyrs.removeLayer(i);
406
                                                File fich = new File(getLyrGeoRaster().getSource().getFiles()[0].getName());
407
                                                try{
408
                                                        //Creamos la nueva capa GeoRaster y la a?adimos al TOC. 
409
                                                        FLyrGeoRaster lyrGeoRaster = 
410
                                                                FLyrGeoRaster.createLayer(getLyrGeoRaster().getName().substring(1, getLyrGeoRaster().getName().length()), 
411
                                                                                                                (RasterDriver)getLyrGeoRaster().getSource().getDriver(), 
412
                                                                                                                fich,
413
                                                                                                                getLyrGeoRaster().getProjection(),
414
                                                                                                                getLyrGeoRaster().getImageWidth(),
415
                                                                                                                getLyrGeoRaster().getImageHeight());
416
                                                        getLyrPoints().setVisible(false);
417
                                                        this.getLyrPoints().setLyrGeoRaster(lyrGeoRaster);
418
                                                        lyrGeoRaster.setFLyrPoints(this.getLyrPoints());
419
                                                        lyrGeoRaster.setGeoDialog(this);
420
                                                        this.lyrGeoRaster = lyrGeoRaster;
421
                                                        calcNewMiniExtent(theView);
422
                                                        lyrs.addLayer(lyrGeoRaster);
423
                                                                                                                
424
                                                        lyrGeoRaster.setActive(false);
425
                                                        theView.getMapControl().getMapContext().invalidate();
426
                                                                                                                
427
                                                        try{
428
                                                                frame.setClosed(true);
429
                                                        }catch(PropertyVetoException exc){}
430
                                                                                                                                                                        
431
                                                }catch(DriverException exc){
432
                                                        
433
                                                }
434
                                                break;
435
                                        }
436
                                }
437
                        
438
                        }
439
                }                
440
        }
441
        
442
        /**
443
         * Funci?n que se ejecuta al pulsar el bot?n aceptar
444
         * @param theView
445
         */
446
        private void accept(View theView)throws Exception{
447
                if(getLyrPoints() == null)
448
                        throw new Exception("LyrPoints not loaded.");
449
                                        
450
                if(lyrGeoRaster != null){
451
                        getLyrPoints().setVisible(false);
452
                        lyrGeoRaster.setName(lyrGeoRaster.getName().substring(1, lyrGeoRaster.getName().length()));
453
                        lyrGeoRaster.setActive(false);
454
                        theView.getMapControl().getMapContext().invalidate();
455
                }
456
                
457
                try{
458
                        frame.setClosed(true);
459
                }catch(PropertyVetoException exc){}
460
        }
461
        
462
        /**
463
         * Funci?n que se ejecuta al pulsar el bot?n cancelar
464
         * @param theView
465
         */
466
        private void cancel(View theView)throws Exception{
467
                if(getLyrPoints() == null)
468
                        throw new Exception("LyrPoints not loaded.");
469
                                        
470
                //Cerramos la ventana 
471
                //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
472
                try{
473
                        frame.setClosed(true);
474
                        theView.getMapControl().getMapContext().invalidate();
475
                }catch(PropertyVetoException exc){}
476
        }
477
        
478
        
479
        /**
480
         * Recalcula el extent de la mini-imagen que corresponde a los puntos en coordenadas
481
         * pixel.Para esto calcula el nuevo centro a partir de la capa y con la distancia entre
482
         * el nuevo centro y el viejo desplaza el extent completo de la mini-imagen.
483
         * @param theView
484
         */
485
        private void calcNewMiniExtent(View theView){
486

    
487
                ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort();
488
                for(int j = 0; j < getLyrPoints().getCountPoints(); j++){
489
                        //Calculamos el nuevo centro
490
                        Point2D oldCenter = getLyrPoints().getPoint(j).leftCenterPoint;
491
                        Point2D newCenter = new Point2D.Double();
492
                        newCenter.setLocation(        lyrGeoRaster.img2World(getLyrPoints().getPoint(j).pixelPoint));
493
                        
494
                        double diffX = oldCenter.getX() - newCenter.getX();
495
                        double diffY = oldCenter.getY() - newCenter.getY();
496
                        
497
                        getLyrPoints().getPoint(j).leftCenterPoint = newCenter;        
498
                                                
499
                        ViewPort vpOld = getLyrPoints().getPoint(j).leftViewPort;                        
500
                        Rectangle2D newExtent = new Rectangle2D.Double(        vpOld.getExtent().getMinX() - diffX, 
501
                                                                                                                        vpOld.getExtent().getMinY() - diffY, 
502
                                                                                                                        vpOld.getExtent().getWidth(), 
503
                                                                                                                        vpOld.getExtent().getHeight() );
504
                        ViewPort vpNew = new ViewPort(vpOld.getProjection());
505
                        vpNew.setExtent(newExtent);
506
                        vpNew.setImageSize(vpOld.getImageSize());
507
                        vpNew.setScale();
508
                        getLyrPoints().getPoint(j).leftViewPort = vpNew;
509
                }
510
        }
511
        
512
        /**
513
         * This method initializes bProcesar        
514
         *         
515
         * @return javax.swing.JButton        
516
         */    
517
        private JButton getBProcesar() {
518
                if (bProcesar == null) {
519
                        bProcesar = new JButton();
520
                        bProcesar.setText(PluginServices.getText(this,"procesar"));
521
                        bProcesar.setEnabled(true);
522
                        bProcesar.addActionListener(this);
523
                }
524
                return bProcesar;
525
        }
526
        
527
        /**
528
         * El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
529
         * y cierra la ventana.         
530
         *         
531
         * @return javax.swing.JButton        
532
         */    
533
        private JButton getBCancelar() {
534
                if (bCancelar == null) {
535
                        bCancelar = new JButton();
536
                        bCancelar.setText(PluginServices.getText(this,"cancelar"));
537
                        bCancelar.addActionListener(this);
538
                }
539
                return bCancelar;
540
        }
541
                
542
        /**
543
         * This method initializes jButton        
544
         *         
545
         * @return javax.swing.JButton        
546
         */
547
        private JButton getBLoadPoints() {
548
                if (bLoadPoints == null) {
549
                        bLoadPoints = new JButton();
550
                        bLoadPoints.setText(PluginServices.getText(this,"cargar"));
551
                        bLoadPoints.setEnabled(true);
552
                        bLoadPoints.addActionListener(this);
553
                }
554
                return bLoadPoints;
555
        }
556

    
557
        /**
558
         * Asigna a las textbox el valor de pixel pasado
559
         * @param x        valor x
560
         * @param y        valor y
561
         */
562
        public void setPixelText(double x, double y){
563
                getSelectPointsPanel().getDataPointPanel().getTX().setText(String.valueOf(x));
564
                getSelectPointsPanel().getDataPointPanel().getTY().setText(String.valueOf(y));
565
        }
566
        
567
        /**
568
         * Asigna a las textbox el valor de coordenadas pasado
569
         * @param x        valor x
570
         * @param y        valor y
571
         */
572
        public void setMapCoordText(double x, double y){
573
                getSelectPointsPanel().getDataPointPanel().getLongitud().setText(MathUtils.tailDecimals(String.valueOf(x), 5));
574
                getSelectPointsPanel().getDataPointPanel().getLatitud().setText(MathUtils.tailDecimals(String.valueOf(y), 5));
575
        }
576
        
577
        /**
578
         * Esta funci?n resetea los controles del panel de info de un punto.
579
         */
580
        public void resetControls(boolean active){
581
                getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().setSaveToDisk(active);
582
                getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().resetControls(active);                
583
                getConectorPanel().getAdjustGeorefPanel().getZoomLeft().clear();
584
                setEnabled(active);
585
        }
586
        
587
        /* (non-Javadoc)
588
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
589
         */
590
        public void componentHidden(ComponentEvent arg0) {
591
                // TODO Auto-generated method stub
592

    
593
        }
594
        /* (non-Javadoc)
595
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
596
         */
597
        public void componentMoved(ComponentEvent arg0) {
598
                // TODO Auto-generated method stub
599

    
600
        }
601
        /* (non-Javadoc)
602
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
603
         */
604
        public void componentResized(ComponentEvent ev) {
605
                
606
                if(frame.getWidth() <= this.normalWidth + 10)
607
                        frame.setSize(this.normalWidth, frame.getHeight());
608
                
609
                if(this.getConectorPanel().getDataPointsTabPanel().getTbPoints().getSelectedIndex() == 1){
610
                        tmpWidth = frame.getWidth();
611
                        this.newFrameSize(frame.getWidth(), frame.getHeight() - 10);
612
                }
613
        }
614
        /* (non-Javadoc)
615
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
616
         */
617
        public void componentShown(ComponentEvent arg0) {
618
                // TODO Auto-generated method stub
619

    
620
        }
621
        
622
    /**
623
     *Inicializa el tama?o del dialogo
624
     */
625
    public void resetSize(){
626
            if(!enlarge){
627
                    frame.setSize(this.normalWidth + 12, this.normalHeight + 10);
628
            }else{
629
                    frame.setSize(this.normalWidth + 12, this.enlargeHeight + 10);
630
            }
631
            newFrameSize((int)Math.round(this.normalWidth / 0.98), this.normalHeight);
632
    }
633
        
634
        /**
635
         * Calculo del nuevo tama?o a partir de un frame redimensionado
636
         * @param w Ancho del frame
637
         * @param h Alto del frame
638
         */
639
        public void newFrameSize(int w, int h){
640
                int newWidth = (int)Math.round(w * 0.98);
641
                                
642
        this.setSize(new java.awt.Dimension(newWidth, normalHeight ));
643
        this.setPreferredSize(new java.awt.Dimension(newWidth, normalHeight ));
644
        this.getConectorPanel().newFrameSize(newWidth, h);    
645
        }
646
        
647
        /**
648
         * Elimina un punto de la tabla de puntos
649
         * @param pos Posici?n del punto a eliminar
650
         */
651
        public void removeTableValueAt(int pos) throws ArrayIndexOutOfBoundsException{
652
                ((DefaultTableModel)this.getTable().getTable().getModel()).removeRow(pos);
653
        }
654
        
655

    
656
        //**********************End Methods***************************
657
        
658
        //**********************Setters & Getters*********************
659
        /**
660
         * Obtiene la tabla de puntos
661
         */
662
        public PointTable getTable(){
663
                return this.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getJTable();
664
        }
665
                
666
        /**
667
         * Asigna un valor a una posici?n de la tabla
668
         * @param value Valor a asignar
669
         * @param row        Fila en la que se asigna
670
         * @param col        Columna en la que se asigna
671
         */
672
        public void setTableValueAt(String value, int row, int col)throws ArrayIndexOutOfBoundsException{
673
                ((DefaultTableModel)this.getTable().getTable().getModel()).setValueAt(value, row, col);
674
        }
675
        
676
        /**
677
         * Obtiene el n?mero de filas de la tabla
678
         * @return N?mero de filas de la tabla
679
         */
680
        public int getTableRowCount(){
681
                return this.getTable().getTable().getRowCount();
682
        }
683
        
684
        /**
685
         * A?ade una nueva fila a la tabla de puntos
686
         */
687
        public void addTableNew(){
688
                this.getTable().getTableModel().addNew();
689
        }
690
        /**
691
         * @return Returns the tmpWidth.
692
         */
693
        public int getTmpWidth() {
694
                return tmpWidth;
695
        }
696
        /**
697
         * @param tmpWidth The tmpWidth to set.
698
         */
699
        public void setTmpWidth(int tmpWidth) {
700
                this.tmpWidth = tmpWidth;
701
        }
702
        /**
703
         * @return Returns the enlargeHeight.
704
         */
705
        public int getEnlargeHeight() {
706
                return enlargeHeight;
707
        }
708
        /**
709
         * @return Returns the normalHeight.
710
         */
711
        public int getNormalHeight() {
712
                return normalHeight;
713
        }
714

    
715
        /**
716
         * @return Returns the normalWidth.
717
         */
718
        public int getNormalWidth() {
719
                return normalWidth;
720
        }
721
        
722
        /**
723
         * This method initializes jButton        
724
         *         
725
         * @return javax.swing.JButton        
726
         */    
727
        private JButton getBSavePoints() {
728
                if (bSavePoints == null) {
729
                        bSavePoints = new JButton();
730
                        bSavePoints.setText(PluginServices.getText(this,"salvar"));
731
                        //bSavePoints.setPreferredSize(new java.awt.Dimension(41,25));
732
                        bSavePoints.addActionListener(this);
733
                }
734
                return bSavePoints;
735
        }
736
        
737
        /**
738
         * Asigna el valor del campo RMS
739
         * @param rms Cadena que representa el RMS
740
         */
741
        public void setRMS(String rms){
742
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTRMS().setText(rms);
743
        }
744
        
745
        /**
746
         * Asigna el valor del campo de residuo en X
747
         * @param rms Cadena que representa el RMS
748
         */
749
        public void setResX(String resX){
750
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTResX().setText(resX);
751
        }
752
        
753
        /**
754
         * Asigna el valor del campo de residuo en Y
755
         * @param rms Cadena que representa el RMS
756
         */
757
        public void setResY(String resY){
758
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTResY().setText(resY);
759
        }
760
        
761
        /**
762
         * Asigna el valor del campo RMS
763
         * @param rms Cadena que representa el RMS
764
         */
765
        public void setTotal(String total){
766
                this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getErrorPointPanel().getTTotal().setText(total);
767
        }
768
        
769
        /**
770
         * @return Returns the lyrGeoRaster.
771
         */
772
        public FLyrGeoRaster getLyrGeoRaster() {
773
                return lyrGeoRaster;
774
        }
775

    
776
        /**
777
         * @return Returns the lyrPoints.
778
         */
779
        public FLyrPoints getLyrPoints() {
780
                try{
781
                        return lyrGeoRaster.getFLyrPoints();                                                
782
                }catch(ClassCastException exc){
783
                        return null;
784
                }
785
        }
786
        
787
        /**
788
         * Selecciona un tab del cuadro
789
         * @param index
790
         */
791
        public void setSelectedTab(int index){
792
                this.getConectorPanel().getDataPointsTabPanel().getTbPoints().setSelectedIndex(index);
793
        }
794
        
795
        /**
796
         * @param extended The extended to set.
797
         */
798
        public void setEnlarge(boolean enlarge) {
799
                this.enlarge = enlarge;
800
                if(!enlarge){
801
                        frame.setSize(new Dimension(this.normalWidth + 12, this.normalHeight + 10));
802
                        frame.setPreferredSize(new Dimension(this.normalWidth + 12, this.normalHeight + 10));
803
                        this.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight));
804
                        this.setSize(new Dimension(this.normalWidth, this.normalHeight));
805
                        this.getConectorPanel().setCanvasVisible(false);
806
                }else{
807
                        frame.setSize(new Dimension(this.normalWidth + 12, this.enlargeHeight + 10));
808
                        frame.setPreferredSize(new Dimension(this.normalWidth + 12, this.enlargeHeight + 10));
809
                        this.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight));
810
                        this.setSize(new Dimension(this.normalWidth, this.enlargeHeight));
811
                        this.getConectorPanel().setCanvasVisible(true);                                
812
                }
813
                frame.pack();
814
        }
815
                
816
        /**
817
         * @return Returns the extended.
818
         */
819
        public boolean isEnlarge() {
820
                return enlarge;
821
        }
822
        
823
        /**
824
     * Obtiene el panel conector
825
     * @return
826
     */
827
    public ConectorPanel getConectorPanel() {
828
            if (conectorPanel == null) {                            
829
                    conectorPanel = new ConectorPanel(this);
830
            }
831
        
832
            return conectorPanel;
833
    }
834
                 
835
        /**
836
         * This method initializes jPanel        
837
         *         
838
         * @return javax.swing.JPanel        
839
         */    
840
        private JPanel getPBotones() {
841
                if (pBotones == null) {
842
                        FlowLayout flowLayout1 = new FlowLayout();
843
                        pBotones = new JPanel();
844
                        pBotones.setLayout(flowLayout1);
845
                        flowLayout1.setHgap(10);
846
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
847
                        pBotones.add(getBProcesar(), null);
848
                        pBotones.add(getBAceptar(), null);
849
                        pBotones.add(getBCancelar(), null);
850
                }
851
                return pBotones;
852
        }
853
        
854
        public static IProjection getLastProjection() {
855
                return proj;
856
        }
857
        public static void setLastProjection(IProjection proj) {
858
                GeoreferencingDialog.proj = proj;
859
        }
860

    
861
        /**
862
         * @return Returns the GeoRedimBehavior.
863
         */
864
        public GeoRedimBehavior getGeoRedimBehavior() {
865
                return rb;
866
        }
867

    
868
        /**
869
         * @param rb The GeoRedimBehavior to set.
870
         */
871
        public void setGeoRedimBehavior(GeoRedimBehavior rb) {
872
                this.rb = rb;
873
        }
874
        
875
        /**
876
         * @return Returns the GeoMoveBehavior
877
         */
878
        public GeoMoveBehavior getGeoMoveBehavior() {
879
                return mb;
880
        }
881

    
882
        /**
883
         * @param mb The GeoMoveBehavior to set.
884
         */
885
        public void setGeoMoveBehavior(GeoMoveBehavior mb) {
886
                this.mb = mb;
887
        }
888
        
889

    
890
        /**
891
         * Obtiene el punto de la lista que ha sido seleccionado
892
         * @return
893
         */
894
        public int getSelectedPoint(){
895
                return getConectorPanel().getDataPointsTabPanel().
896
                        getSelectPointsPanel().getTableControlerPanel().getSelectedIndex();
897
        }
898
        
899
        /**
900
         * Obtiene el control de la mini imagen que tiene los botones a la izquierda
901
         * @return ZoomControlPanel
902
         */
903
        public ZoomControlPanel getZoomControlLeft(){
904
                return this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft();
905
        }
906
        
907
        /**
908
         * Obtiene el control de la mini imagen que tiene los botones a la derecha
909
         * @return ZoomControlPanel
910
         */
911
        public ZoomControlPanel getZoomControlRight(){
912
                return this.getConectorPanel().getAdjustGeorefPanel().getZoomRight();
913
        }
914
        
915
        /**
916
         * Obtiene el panel de selecci?n de puntos
917
         * @return Panel de selecci?n de puntos
918
         */
919
        public SelectPointsPanel getSelectPointsPanel(){
920
                return this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel();
921
        }
922
        
923
        /**
924
         * Obtiene el panel de opciones
925
         * @return OptionPanel
926
         */
927
        public OptionsPanel getOptionsPanel(){
928
                return getConectorPanel().getAdjustGeorefPanel().getOptionsPanel();
929
        }
930
          
931
    /**
932
     * Asigna el frame
933
     * @param f
934
     */
935
    public void setFrame(JInternalFrame f){
936
            frame = f;
937
            frame.addComponentListener(this);
938
    }
939
    
940
    /**
941
     * Obtiene el frame
942
     * @return frame
943
     */
944
    public JInternalFrame getFrame(){
945
            return frame;
946
    }
947
    
948
    /**
949
     * Obtiene el gestor de puntos
950
     * @return PointManager
951
     */
952
    public PointManager getPointManager() {
953
                return pointManager;
954
        }
955
    
956
    /**
957
     * Activa o desactiva este panel y todos los que lo componen
958
     * @param enabled variable booleana para la activaci?n y/o desactivaci?n
959
     */
960
    public void setEnabled(boolean enabled){
961
            this.conectorPanel.getDataPointsTabPanel().getSelectPointsPanel().setEnabled(enabled);
962
            this.conectorPanel.getAdjustGeorefPanel().setEnabled(enabled);
963
    }
964
        //**********************End Setters & Getters*****************
965
                
966
 }  //  @jve:decl-index=0:visual-constraint="10,10"
967
 //  @jve:visual-info  decl-index=0 visual-constraint="10,10"
968
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"