Statistics
| Revision:

root / trunk / extensions / extTopology / src / com / iver / cit / gvsig / geoprocess / impl / referencing / gui / VectorErrorTable.java @ 23163

History | View | Annotate | Download (22.9 KB)

1
/*
2
 * Created on 10-abr-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id: 
47
 * $Log: 
48
 */
49
package com.iver.cit.gvsig.geoprocess.impl.referencing.gui;
50

    
51
import java.awt.BorderLayout;
52
import java.awt.Dimension;
53
import java.awt.KeyEventDispatcher;
54
import java.awt.Window;
55
import java.awt.event.ActionEvent;
56
import java.awt.event.ActionListener;
57
import java.awt.event.KeyEvent;
58

    
59
import javax.swing.BorderFactory;
60
import javax.swing.JComponent;
61
import javax.swing.JDialog;
62
import javax.swing.JLabel;
63
import javax.swing.JPanel;
64
import javax.swing.JScrollPane;
65
import javax.swing.JTable;
66
import javax.swing.KeyStroke;
67
import javax.swing.ListSelectionModel;
68
import javax.swing.border.EtchedBorder;
69
import javax.swing.table.AbstractTableModel;
70
import javax.vecmath.MismatchedSizeException;
71

    
72
import org.geotools.referencefork.geometry.DirectPosition2D;
73
import org.geotools.referencefork.referencing.operation.builder.MappedPosition;
74
import org.gvsig.exceptions.BaseException;
75
import org.gvsig.fmap.tools.VectorListenerImpl;
76
import org.gvsig.fmap.tools.behavior.VectorBehavior;
77
import org.gvsig.gui.beans.swing.JButton;
78
import org.gvsig.referencing.DisactivableMappedPosition;
79
import org.gvsig.referencing.MappedPositionContainer;
80
import org.gvsig.referencing.ReferencingUtil;
81
import org.gvsig.topology.ui.LayerJComboBox;
82
import org.gvsig.topology.ui.LayerJComboBox.LayerFilter;
83
import org.gvsig.topology.ui.util.BoxLayoutPanel;
84
import org.gvsig.topology.ui.util.GUIUtil;
85
import org.opengis.referencing.FactoryException;
86
import org.opengis.referencing.operation.MathTransform;
87
import org.opengis.referencing.operation.TransformException;
88
import org.opengis.spatialschema.geometry.DirectPosition;
89
import org.opengis.spatialschema.geometry.MismatchedDimensionException;
90
import org.opengis.spatialschema.geometry.MismatchedReferenceSystemException;
91

    
92
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
93
import com.iver.andami.PluginServices;
94
import com.iver.andami.ui.mdiManager.IWindow;
95
import com.iver.andami.ui.mdiManager.WindowInfo;
96
import com.iver.cit.gvsig.drivers.VectorErrorMemoryDriver;
97
import com.iver.cit.gvsig.fmap.MapContext;
98
import com.iver.cit.gvsig.fmap.MapControl;
99
import com.iver.cit.gvsig.fmap.core.FShape;
100
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
101
import com.iver.cit.gvsig.fmap.layers.FLayer;
102
import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial;
103
import com.iver.cit.gvsig.fmap.layers.FLayers;
104
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
105
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
106
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
107
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
108
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent;
109
import com.iver.cit.gvsig.project.documents.view.gui.View;
110
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
111
import com.iver.cit.gvsig.referencing.DisactivableMappedPositionContainerImpl;
112
import com.iver.cit.gvsig.referencing.MappedPositionContainerLayerBased;
113
import com.iver.cit.gvsig.referencing.TransformationsRegistry.TransformationRegistryEntry;
114

    
115
/**
116
 * Component to show digitized vector errors for an spatial adjust in a table.
117
 * 
118
 * @author Alvaro Zabala
119
 * 
120
 */
121
public class VectorErrorTable extends BoxLayoutPanel {
122

    
123
        private static final long serialVersionUID = -6506747314549738246L;
124
        
125
        
126
        private static boolean registeredKeyStrokes = false;
127

    
128
        /**
129
         * Current active view where user could digitize new vectorial errors.
130
         */
131
        MapControl currentView;
132

    
133
        /**
134
         * Provides the digitized vectorial errors to create the transformation
135
         */
136
        MappedPositionContainer verrorContainer;
137

    
138
        /**
139
         * Current transformation provider
140
         */
141
        TransformationRegistryEntry transformBuilderProvider;
142

    
143
        /**
144
         * Current transformation built from control points in vector error
145
         * container with the current transformBuilderProvider
146
         */
147
        MathTransform mathTransform;
148
        /**
149
         * Lyr we are spatially adjusting 
150
         */
151
        FLyrVect adjustingLyr;
152

    
153
        /**
154
         * Table model to show control points and associated errors in a JTable
155
         * 
156
         * @author Alvaro Zabala
157
         * 
158
         */
159
        private final class VErrorTableModel extends AbstractTableModel {
160

    
161
                private static final long serialVersionUID = -3431188780005613099L;
162
                private static final int COLUMN_COUNT = 7;
163

    
164
                private final DirectPosition buffer = new DirectPosition2D();
165

    
166
                public int getColumnCount() {
167
                        return COLUMN_COUNT;
168
                }
169

    
170
                public int getRowCount() {
171
                        return verrorContainer.getCount();
172
                }
173

    
174
                public Class getColumnClass(int c) {
175
                        return getValueAt(0, c).getClass();
176
                }
177

    
178
                public boolean isCellEditable(int row, int col) {
179
                        if (col == 6) {
180
                                return true;
181
                        } else {
182
                                return false;
183
                        }
184
                }
185

    
186
                public void setValueAt(Object value, int row, int col) {
187
                        if (col != 6)
188
                                return;
189
                        DisactivableMappedPosition mappedPosition = (DisactivableMappedPosition) verrorContainer
190
                                        .getMappedPosition(row);
191
                        mappedPosition.setActive(((Boolean) value).booleanValue());
192
                        fireTableCellUpdated(row, col);
193

    
194
                        updateVErrorTable();
195
                        updateRmsText();
196
                }
197

    
198
                public Object getValueAt(int row, int col) {// FIXME USAR NUMBERFORMAT
199
                                                                                                        // PARA LAS COORDENADAS
200
                        Object solution = null;
201
                        MappedPosition mappedPosition = verrorContainer
202
                                        .getMappedPosition(row);
203

    
204
                        DirectPosition position = null;
205
                        switch (col) {
206
                        case 0:// Verror id
207
                                solution = row + "";
208
                                break;
209
                        case 1:// x0
210
                                position = mappedPosition.getSource();
211
                                solution = position.getCoordinates()[0] + "";
212
                                break;
213
                        case 2:// y0
214
                                position = mappedPosition.getSource();
215
                                solution = position.getCoordinates()[1] + "";
216
                                break;
217
                        case 3:// x1
218
                                position = mappedPosition.getTarget();
219
                                solution = position.getCoordinates()[0] + "";
220
                                break;
221
                        case 4:// y1
222
                                position = mappedPosition.getSource();
223
                                solution = position.getCoordinates()[1] + "";
224
                                break;
225
                        case 5:// RMS
226
                                try {
227
                                        if (mathTransform == null) {
228
                                                // mathTransform at begininng will allways be null,
229
                                                // because there arent
230
                                                // enought control points to build a transformation
231
                                                mathTransform = transformBuilderProvider
232
                                                                .createTransformBuilder(
233
                                                                                verrorContainer.getAsList())
234
                                                                .getMathTransform();
235
                                        }
236
                                        solution = mappedPosition.getError(mathTransform, buffer)
237
                                                        + "";
238
                                } catch (TransformException e) {
239
                                        solution = "";
240
                                        getRmsLabel()
241
                                                        .setText(
242
                                                                        PluginServices.getText(this,
243
                                                                                        "Error_computing_RMS"));
244
                                } catch (MismatchedSizeException e) {
245
                                        solution = "";
246
                                        getRmsLabel()
247
                                                        .setText(
248
                                                                        PluginServices
249
                                                                                        .getText(this,
250
                                                                                                        "More_control_points_needed_for_the_current_transform"));
251
                                } catch (MismatchedDimensionException e) {
252
                                        solution = "";
253
                                        getRmsLabel()
254
                                                        .setText(
255
                                                                        PluginServices
256
                                                                                        .getText(
257
                                                                                                        this,
258
                                                                                                        "Control_points_coordinates_dimension_are_insufficient_for_the_current_transform"));
259
                                } catch (MismatchedReferenceSystemException e) {
260
                                        solution = "";
261
                                        getRmsLabel()
262
                                                        .setText(
263
                                                                        PluginServices
264
                                                                                        .getText(this,
265
                                                                                                        "Control_points_have_inconsistent_reference_system"));
266
                                } catch (FactoryException e) {
267
                                        solution = "";
268
                                        getRmsLabel().setText(
269
                                                        PluginServices.getText(this,
270
                                                                        "Error_creating_mathTransform"));
271
                                }
272
                                // catch(RuntimeException e){//FIXME DIFERENCIAR MISMATCHED
273
                                // SIZE, MISMATCHED DIMENSION Y MISMATCHED REFERENCE SYSTEM
274
                                // solution = "";
275
                                // e.printStackTrace();
276
                                // }
277
                                break;
278

    
279
                        case 6:// active or disactive
280
                                if (mappedPosition instanceof DisactivableMappedPosition) {
281
                                        DisactivableMappedPosition pos = (DisactivableMappedPosition) mappedPosition;
282
                                        solution = new Boolean(pos.isActive());
283
                                } else {
284
                                        solution = new Boolean(true);
285
                                }
286
                                break;
287
                        }
288
                        return solution;
289
                }
290
        }// TableModel
291

    
292
        private JTable verrorTable;
293

    
294
        private VErrorTableModel verrorTableModel;
295

    
296
        private JLabel totalRmsLabel;
297

    
298
        private JButton deleteLinkBtn;
299

    
300
        private JButton addLinkBtn;
301

    
302
        private JButton loadLinksBtn;
303
        
304
        /**
305
         * Listener for mouse events in MapControl
306
         */
307
        private ExtendedVectorListener vl;
308
        /**
309
         * Behavior to digitize vector errors
310
         */
311
        private VectorBehavior vb;
312
        
313
        /**
314
         * Constructor.
315
         * @param currentView
316
         * @param adjustingLyr
317
         * @param transformBuilderProvider
318
         */
319
        public VectorErrorTable(MapControl currentView,
320
                                                        FLyrVect adjustingLyr,
321
                        TransformationRegistryEntry transformBuilderProvider) {
322
                this.currentView = currentView;
323
                this.verrorContainer = new DisactivableMappedPositionContainerImpl();
324
                this.transformBuilderProvider = transformBuilderProvider;
325
                this.adjustingLyr = adjustingLyr;
326
                try {
327
                        this.mathTransform = transformBuilderProvider
328
                                        .createTransformBuilder(verrorContainer.getAsList())
329
                                        .getMathTransform();
330
                } catch (Exception e) {
331
                        e.printStackTrace();
332
                }
333
                initialize();
334
                
335
                ReferencingUtil.getInstance().incrementAdjustSessions();
336
        }
337

    
338
        public void updateVErrorTable() {
339
                getVErrorTable().revalidate();
340
                updateRmsText();
341
                this.repaint();
342
        }
343

    
344
        private void initialize() {
345
                this.addRow(new JComponent[] { new JLabel(PluginServices.getText(this,
346
                                "VERROR_TITLE")) });
347

    
348
                JScrollPane scrollPane = new JScrollPane();
349
                scrollPane.setViewportView(getVErrorTable());
350
                scrollPane.setBorder(BorderFactory
351
                                .createEtchedBorder(EtchedBorder.RAISED));
352
                // scrollPane.setPreferredSize(new Dimension(600, 160));
353
                // scrollPane.setMinimumSize(new Dimension(600, 120));
354
                scrollPane
355
                                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
356
                scrollPane
357
                                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
358

    
359
                this.addRow(new JComponent[] { scrollPane }, 600, 300);
360

    
361
                this.addRow(new JComponent[] { getAddVErrorButton(),
362
                                getDeleteVErrorButton(), getLoadLinksButton() }, 600,
363
                                DEFAULT_HEIGHT);
364

    
365
                this.addRow(new JComponent[] { getRmsLabel() });
366
                
367
                initializeKeyEventsListening();
368

    
369
        }
370
        
371
        private void initializeKeyEventsListening(){
372
                if(! registeredKeyStrokes){
373
                KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
374
                
375
                PluginServices.registerKeyStroke(key, new KeyEventDispatcher(){
376
                        public boolean dispatchKeyEvent(KeyEvent e) {
377
                                if (e.getID() != KeyEvent.KEY_RELEASED)
378
                                        return false;
379
                                
380
                                IWindow v = PluginServices.getMDIManager().getActiveWindow();
381
                                if (!(v instanceof View))
382
                                        return false;
383

    
384
                                View view = (View)v;
385
                                MapControl mapControl = view.getMapControl();
386
                                if(mapControl.getCurrentTool().equals("digitizeVectorError")){
387
                                        if (e.getKeyCode() == KeyEvent.VK_ESCAPE){
388
                                                vl.showContainer();
389
                                                return true;
390
                                        }
391
                                }
392
                                return false;
393
                        }});
394
                
395
//                KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
396
//                kfm.addKeyEventPostProcessor(new KeyEventPostProcessor(){
397
//                        public boolean postProcessKeyEvent(KeyEvent arg0) {
398
//                                return false;
399
//                        }});
400
                registeredKeyStrokes = true;
401
                }
402

    
403
        }
404

    
405
        private JTable getVErrorTable() {
406
                if (verrorTable == null) {
407
                        verrorTable = new JTable();
408
                        verrorTableModel = new VErrorTableModel();
409
                        verrorTable.setModel(verrorTableModel);
410
                        verrorTable.getColumnModel().getColumn(0).setHeaderValue(
411
                                        PluginServices.getText(this, "VError_ID"));
412

    
413
                        verrorTable.getColumnModel().getColumn(1).setHeaderValue(
414
                                        PluginServices.getText(this, "Source_x"));
415

    
416
                        verrorTable.getColumnModel().getColumn(2).setHeaderValue(
417
                                        PluginServices.getText(this, "Source_y"));
418

    
419
                        verrorTable.getColumnModel().getColumn(3).setHeaderValue(
420
                                        PluginServices.getText(this, "Target_x"));
421

    
422
                        verrorTable.getColumnModel().getColumn(4).setHeaderValue(
423
                                        PluginServices.getText(this, "Target_y"));
424

    
425
                        verrorTable.getColumnModel().getColumn(5).setHeaderValue(
426
                                        PluginServices.getText(this, "RMS"));
427

    
428
                        verrorTable.getColumnModel().getColumn(6).setHeaderValue(
429
                                        PluginServices.getText(this, "Active"));
430

    
431
                        verrorTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
432
                }
433
                return verrorTable;
434

    
435
        }
436

    
437
        private JButton getDeleteVErrorButton() {
438
                if (deleteLinkBtn == null) {
439
                        deleteLinkBtn = new JButton(PluginServices.getText(this,
440
                                        "Delete_VError"));
441
                        deleteLinkBtn.addActionListener(new ActionListener() {
442
                                public void actionPerformed(ActionEvent arg0) {
443
                                        deleteLink();
444
                                }
445
                        });
446
                }
447
                return deleteLinkBtn;
448
        }
449

    
450
        private JButton getAddVErrorButton() {
451
                if (addLinkBtn == null) {
452
                        addLinkBtn = new JButton(PluginServices.getText(this, "Add_VError"));
453
                        addLinkBtn.addActionListener(new ActionListener() {
454
                                public void actionPerformed(ActionEvent arg0) {
455
                                        addLink();
456
                                }
457
                        });
458
                }
459
                return addLinkBtn;
460
        }
461

    
462
        private JButton getLoadLinksButton() {
463
                if (loadLinksBtn == null) {
464
                        loadLinksBtn = new JButton(PluginServices.getText(this,
465
                                        "Load_links"));
466
                        loadLinksBtn.addActionListener(new ActionListener() {
467
                                public void actionPerformed(ActionEvent arg0) {
468
                                        loadLinks();
469
                                }
470
                        });
471
                }
472
                return loadLinksBtn;
473
        }
474

    
475
        private JLabel getRmsLabel() {
476
                if (totalRmsLabel == null) {
477
                        totalRmsLabel = new JLabel();
478
                        updateRmsText();
479
                }
480
                return totalRmsLabel;
481
        }
482

    
483
        private void updateRmsText() {
484
                try {
485
                        getRmsLabel().setText(
486
                                        PluginServices.getText(this, "RMS")
487
                                                        + " : "
488
                                                        + transformBuilderProvider.createTransformBuilder(
489
                                                                        verrorContainer.getAsList())
490
                                                                        .getErrorStatistics().rms());
491
                } catch (FactoryException e) {
492
                        getRmsLabel().setText(
493
                                        PluginServices.getText(this, "Error_al_calcular_RMS"));
494
                } catch (RuntimeException re) {
495
                        getRmsLabel().setText("");
496
                }
497

    
498
                // MismatchedSizeException, MismatchedDimensionException,
499
                // MismatchedReferenceSystemException
500
        }
501
        
502
        class ExtendedVectorListener extends VectorListenerImpl{
503
                JComponent container;
504
                
505
                public ExtendedVectorListener(MapControl mapCtrl, 
506
                                                                          MappedPositionContainer linksList,
507
                                                                          JComponent container) {
508
                        super(mapCtrl, linksList);
509
                        this.container = container;
510
                }
511
                
512
                public void hideContainer(){
513
                        if (container != null) {
514
                                GUIUtil.getInstance().getParentOfType(container,
515
                                                JDialog.class).setVisible(false);
516
                        }
517
                }
518
                
519
                public void showContainer(){
520
                        if (container != null) {
521
                                if (!GUIUtil.getInstance().getParentOfType(container, JDialog.class).isVisible()) {
522
                                        GUIUtil.getInstance().getParentOfType(container, JDialog.class).setVisible(true);
523
                                }//if
524
                        }// thisContainer
525
                }
526
                
527
                public void vector(MoveEvent event) throws BehaviorException {
528
                        super.vector(event);
529
                        if(isZooming)
530
                                return;
531
                        mapCtrl.setPrevTool();
532

    
533
                        if (!verrorContainer.existsLinksLyr()) {
534
                                FLyrVect linkLyr = verrorContainer
535
                                                .getLinkLyr(currentView.getProjection());
536
                                MapContext mapContext = currentView.getMapContext();
537
                                
538
                                //each time we create a new link layer, we are creating a new spatial adjusting session
539
                                FLayers solution = new FLayers();
540
                                solution.setMapContext(mapContext);
541
                                solution.setParentLayer(mapContext.getLayers());
542
                                solution.setName(PluginServices.getText(this, "SPATIAL_ADJUST_SESSION")+" "+ReferencingUtil.getInstance().getNumberOfSpatialAdjustSessions());
543
                                solution.addLayer(linkLyr);
544
                                mapContext.beginAtomicEvent();
545
                                mapContext.getLayers().addLayer(solution);
546
                                mapContext.endAtomicEvent();
547
                        }
548
                        mapCtrl.commandRepaint();
549

    
550
                        updateVErrorTable();
551
                        updateRmsText();
552

    
553
                        showContainer();
554
                }
555
        }//class ExtendedVectorListener
556

    
557
        private void addLink() {
558
                final MapControl mapCtrl = currentView;
559
                if (mapCtrl != null) {
560
                        String sTool = "digitizeVectorError";
561
                        
562
                        if(vb == null){
563
                                JComponent container = (JComponent) GUIUtil.getInstance()
564
                                .getParentOfType(this, IWindow.class);
565
                
566
                                vl = new ExtendedVectorListener(mapCtrl,
567
                                                                                        verrorContainer, 
568
                                                                                                container);
569
                                vb = new VectorBehavior(vl, this.adjustingLyr);
570
                                
571
                                StatusBarListener sbl = new StatusBarListener(mapCtrl);
572
                                mapCtrl.addMapTool(sTool, 
573
                                                new Behavior[] { vb, 
574
                                                new MouseMovementBehavior(sbl) });
575
                        }//if vl == null
576
                        
577
                        mapCtrl.setTool(sTool);
578

    
579
                        vl.hideContainer();
580
                }// if mapCtrl != null
581
        }
582

    
583
        
584
        private void deleteLink() {
585
                int toDelete = getVErrorTable().getSelectedRow();
586
                this.verrorContainer.delete(toDelete);
587
                updateVErrorTable();
588
                updateRmsText();
589
        }
590

    
591
        /**
592
         * Creates de MappedPositionContainer from one of the TOC's layer
593
         */
594
        private void loadLinks() {
595
                LayerJComboBox lyrComboBox = new LayerJComboBox(currentView
596
                                .getMapContext().getLayers(), new LayerFilter() {
597
                        public boolean filter(FLayer layer) {
598
                                if (layer instanceof FLyrVect) {
599
                                        FLyrVect aux = (FLyrVect) layer;
600
                                        try {
601
                                                if (aux.getShapeType() == FShape.LINE)
602
                                                        return true;
603
                                        } catch (ReadDriverException e) {
604
                                                e.printStackTrace();
605
                                        }
606
                                }
607
                                return false;
608
                        }
609
                });
610

    
611
                class LayerComboPanel extends JPanel implements IWindow {
612

    
613
                        private boolean okPressed = false;
614

    
615
                        public WindowInfo getWindowInfo() {
616
                                WindowInfo solution = new WindowInfo(WindowInfo.MODALDIALOG
617
                                                | WindowInfo.PALETTE | WindowInfo.ICONIFIABLE
618
                                                | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
619
                                solution.setTitle(PluginServices.getText(this,
620
                                                "Link_layer_Selection"));
621
                                solution.setWidth(300);
622
                                solution.setHeight(50);
623
                                return solution;
624
                        }
625

    
626
                        public void setOkPressed(boolean okPressed) {
627
                                this.okPressed = okPressed;
628
                        }
629

    
630
                        public boolean isOkPressed() {
631
                                return this.okPressed;
632
                        }
633
                }// class
634

    
635
                final LayerComboPanel panel = new LayerComboPanel();
636
                panel.setLayout(new BorderLayout());
637

    
638
                JPanel centerPanel = new JPanel();
639
                centerPanel.setLayout(new BorderLayout());
640
                JPanel caux = new JPanel();
641
                caux.add(new JLabel(PluginServices.getText(this, "Select_link_layer")),
642
                                BorderLayout.WEST);
643
                caux.add(lyrComboBox, BorderLayout.EAST);
644
                centerPanel.add(caux, BorderLayout.EAST);
645
                panel.add(centerPanel, BorderLayout.CENTER);
646

    
647
                JPanel southPanel = new JPanel();
648
                JButton okButton = new JButton(PluginServices.getText(this, "OK"));
649

    
650
                okButton.addActionListener(new ActionListener() {
651
                        public void actionPerformed(ActionEvent arg0) {
652
                                Window parentWindow = GUIUtil.getInstance().getParentWindow(
653
                                                panel);
654
                                parentWindow.setVisible(false);
655
                                parentWindow.dispose();
656
                                panel.setOkPressed(true);
657
                        }
658
                });
659

    
660
                southPanel.setLayout(new BorderLayout());
661
                JPanel aux = new JPanel();
662
                aux.add(okButton, BorderLayout.EAST);
663
                southPanel.add(aux, BorderLayout.EAST);
664
                panel.add(southPanel, BorderLayout.SOUTH);
665

    
666
                panel.setSize(new Dimension(300, 50));
667
                PluginServices.getMDIManager().addWindow(panel);
668

    
669
                // Now we check if user presssed ok
670
                FLyrVect selectedLyr = null;
671
                if (panel.isOkPressed()) {
672
                        selectedLyr = (FLyrVect) lyrComboBox.getSelectedLayer();
673
                        MappedPositionContainer auxContainer = null;
674
                        if (selectedLyr instanceof FLayerGenericVectorial) {
675
                                FLayerGenericVectorial genericLyr = (FLayerGenericVectorial) selectedLyr;
676
                                VectorialDriver driver = genericLyr.getDriver();
677
                                if (driver instanceof VectorErrorMemoryDriver) {
678
                                        VectorErrorMemoryDriver errorDriver = (VectorErrorMemoryDriver) driver;
679
                                        auxContainer = errorDriver.getMappedPositionContainer();
680
                                }
681
                        } else {
682
                                try {
683
                                        auxContainer = new MappedPositionContainerLayerBased(
684
                                                        selectedLyr);
685
                                } catch (BaseException e) {
686
                                        e.printStackTrace();
687
                                        GUIUtil.getInstance().messageBox(
688
                                                        PluginServices
689
                                                                        .getText(this, "Error_cargando_links"),
690
                                                        PluginServices
691
                                                                        .getText(this, "Error_cargando_links"));
692
                                        return;
693
                                }
694
                        }
695
                        boolean overwriteCurrentLinks = true;
696
                        if (this.verrorContainer.getCount() > 0) {
697
                                overwriteCurrentLinks = GUIUtil.getInstance().optionMessage(
698
                                                PluginServices.getText(this,
699
                                                                "overwrite_current_vector_error"),
700
                                                PluginServices.getText(this, "spatial_adjust_warning"));
701

    
702
                        }
703
                        if (overwriteCurrentLinks) {
704
                                this.verrorContainer = auxContainer;
705
                                updateVErrorTable();
706
                                String folderName = PluginServices.getText(this,
707
                                                                                "SPATIAL_ADJUST_SESSION")
708
                                                                                                + " "
709
                                                                                                + ReferencingUtil.getInstance()
710
                                                                                                .getNumberOfSpatialAdjustSessions();
711
                                FLayers rootLyrs = currentView.getMapContext().getLayers();
712
                                FLayers adjustSessionLyrs = (FLayers) rootLyrs.getLayer(folderName);
713
                                if(adjustSessionLyrs == null){
714
                                        adjustSessionLyrs = new FLayers();
715
                                        adjustSessionLyrs.setMapContext(currentView.getMapContext());
716
                                        adjustSessionLyrs.setParentLayer(rootLyrs);
717
                                        adjustSessionLyrs.setName(folderName);
718
                                        rootLyrs.addLayer(adjustSessionLyrs);
719
                                }//if
720
                                rootLyrs.removeLayer(selectedLyr);
721
                                adjustSessionLyrs.addLayer(selectedLyr);
722
                                
723
                                
724
                        }
725
                }//if ok pressed
726
        }
727

    
728
        public TransformationRegistryEntry getTransformBuilderProvider() {
729
                return transformBuilderProvider;
730
        }
731

    
732
        public void setTransformBuilderProvider(
733
                        TransformationRegistryEntry transformBuilderProvider)
734
                        throws FactoryException {
735
                this.transformBuilderProvider = transformBuilderProvider;
736
                this.mathTransform = transformBuilderProvider.createTransformBuilder(
737
                                verrorContainer.getAsList()).getMathTransform();
738
                updateVErrorTable();
739
                updateRmsText();
740
        }
741

    
742
        public MappedPositionContainer getVerrorContainer() {
743
                return verrorContainer;
744
        }
745

    
746
        public void setVerrorContainer(MappedPositionContainer verrorContainer) {
747
                this.verrorContainer = verrorContainer;
748
        }
749

    
750
        public FLyrVect getAdjustingLyr() {
751
                return adjustingLyr;
752
        }
753

    
754
        public void setAdjustingLyr(FLyrVect adjustingLyr) {
755
                this.adjustingLyr = adjustingLyr;
756
                if(vb != null)
757
                        vb.setSnappingLyr(adjustingLyr);
758
        }
759

    
760
}