Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extDerivedGeometries / src / es / iver / derivedGeom / gui / DerivedGeometryControlPanel.java @ 37422

History | View | Annotate | Download (62.8 KB)

1
package es.iver.derivedGeom.gui;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

    
25
import java.awt.BorderLayout;
26
import java.awt.Color;
27
import java.awt.Component;
28
import java.awt.Container;
29
import java.awt.Dimension;
30
import java.awt.Graphics;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.ComponentAdapter;
34
import java.awt.event.ComponentEvent;
35
import java.awt.event.ComponentListener;
36

    
37
import javax.swing.BorderFactory;
38
import javax.swing.ImageIcon;
39
import javax.swing.JButton;
40
import javax.swing.JInternalFrame;
41
import javax.swing.JLabel;
42
import javax.swing.JOptionPane;
43
import javax.swing.JPanel;
44
import javax.swing.JScrollPane;
45
import javax.swing.JSplitPane;
46
import javax.swing.JTable;
47
import javax.swing.ListSelectionModel;
48
import javax.swing.UIManager;
49
import javax.swing.event.ListSelectionEvent;
50
import javax.swing.event.ListSelectionListener;
51
import javax.swing.table.DefaultTableModel;
52
import javax.swing.table.TableCellRenderer;
53
import javax.swing.table.TableModel;
54

    
55
import org.apache.log4j.Logger;
56
import org.gvsig.gui.beans.AcceptCancelPanel;
57
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
58
import org.gvsig.gui.beans.progresspanel.ProgressPanel;
59
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP;
60

    
61
import com.iver.andami.PluginServices;
62
import com.iver.andami.messages.NotificationManager;
63
import com.iver.andami.ui.mdiManager.IWindow;
64
import com.iver.andami.ui.mdiManager.WindowInfo;
65
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
66
import com.iver.cit.gvsig.fmap.layers.CancelationException;
67
import com.iver.cit.gvsig.fmap.layers.FBitSet;
68
import com.iver.cit.gvsig.fmap.layers.FLayers;
69
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
70
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
71
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
72
import com.iver.cit.gvsig.fmap.layers.LayerEvent;
73
import com.iver.cit.gvsig.fmap.layers.LayerListener;
74
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
75
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
76
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
77
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
78
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
79
import com.iver.cit.gvsig.project.documents.view.gui.View;
80

    
81
import es.iver.derivedGeom.process.AddDerivedGeometrySHPProcess;
82
import es.iver.derivedGeom.process.DerivedGeometryProcessParameters;
83

    
84
/**
85
 *
86
 *
87
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
88
 */
89
public class DerivedGeometryControlPanel extends JPanel implements IWindow, LayerListener {
90
        private static final long serialVersionUID = 79868642843290024L;
91

    
92
        protected WindowInfo viewInfo = null;
93
    protected final short Window_Width = 400;
94
    protected final short Window_Height = 466;
95
        protected DerivedGeometryProcessParameters parameters;
96
        protected JPanel summaryPanel = null;
97
        protected JPanel featuresPanel = null;
98
        protected JPanel newFeatureSelectionPanel = null;
99
        protected JPanel motionButtonsPanel = null;
100
        protected JPanel centerPanel = null;
101
        protected JSplitPane horizontalSplitPane = null;
102
//        protected JButton snappingCBox = null;
103
        protected JScrollPane allFeaturesScrollPane = null;
104
        protected JScrollPane selectedFeaturesScrollPane = null;
105
        protected JLabel sourceLayerNameLabel = null;
106
        protected JTextFieldWithSCP sourceLayerNameTextField = null;
107
        protected JLabel destLayerNameLabel = null;
108
        protected JTextFieldWithSCP destLayerNameTextField = null;
109
        protected JTable allFeaturesTable = null;
110
        protected TableModel allFeaturesTableModel = null;
111
        protected JTable selectedFeaturesTable = null;
112
        protected TableModel selectedFeaturesTableModel = null;
113
        protected AdaptedAcceptCancelPanel acceptCancelPanel = null;
114
        protected Color bgIDColor = new Color(204, 204, 204);
115
        protected boolean isShown = false;
116
        protected LayerCollectionListener layerCollectionListener = null;
117
        protected Behavior combinedTool = null;
118
        protected boolean mustRestoreWindow = false;
119
        protected ComponentListener viewListener = null;
120
        protected LayerCollectionListener newLayerCollectionListener = null;
121
//        protected SnappingTool sTool = null;
122
        
123
        protected final short TABLE_COLUMN_PREF_WIDTH = 80;
124
        
125
//        protected static final byte ADD_ALL_FEATURES = 0;
126
//        protected static final byte REMOVE_ALL_FEATURES = 1;
127
//        protected static final byte ADD_SELECTED_FEATURES = 2;
128
//        protected static final byte REMOVE_SELECTED_FEATURES = 3;
129
        
130

    
131
        public DerivedGeometryControlPanel(DerivedGeometryProcessParameters parameters) {
132
                super();
133

    
134
                mustRestoreWindow = false;
135
                this.parameters = parameters;
136
                
137
                registerListeners();
138
                
139
                // Registers the snapping tool
140
//                registerSnappingTool();
141

    
142
                initialize();
143

    
144
                isShown = true;
145
        }
146

    
147
        protected void registerListeners() {
148
                /* Replaces any previous control panel with the new one */
149
                FLyrVect sourceLayer = parameters.getSourceLayer();
150
                   LayerListener[] listeners = sourceLayer.getLayerListeners();
151

    
152
                // Calls to unregister any previous "DerivativeGeometryControlPanel" associated to the same source layer
153
                for (int i = listeners.length-1; i >= 0; i--) {
154
                        if (listeners[i] instanceof DerivedGeometryControlPanel) {
155
                                ((DerivedGeometryControlPanel)listeners[i]).doUnregistration();
156
                                ((DerivedGeometryControlPanel)listeners[i]).closeWindow();
157
                        }
158
                }
159

    
160
                /* Registers the new listeners */
161
                parameters.getSourceLayer().addLayerListener(this);
162
        parameters.getMapControl().getMapContext().getLayers().addLayerCollectionListener(getAssociatedLayerCollectionListener());
163

    
164
        /* Combined tool -> Simple geometry selection by point */
165
//        parameters.getMapControl().addCombinedTool(getCombinedTool());
166

    
167
        /* View listener */
168
        registerViewListener();
169
        }
170
        
171
        /**
172
         */
173
        protected void initialize() {
174
                setLayout(new BorderLayout());
175
                add(getSummaryPanel(), BorderLayout.PAGE_START);
176
                add(getCenterPanel(), BorderLayout.CENTER);
177
                add(getAdaptedAcceptCancelPanel(), BorderLayout.PAGE_END);
178
                
179
                refreshGeometries();
180
                updateOkButtons();
181
        }
182
        
183
        protected JPanel getSummaryPanel() {
184
                if (summaryPanel == null) {
185
                        summaryPanel = new JPanel();
186
                        summaryPanel.setLayout(new BorderLayout());
187
                        summaryPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "Layers")));
188
                        summaryPanel.setPreferredSize(new Dimension(390, 80));
189

    
190
                        JPanel pageStartPanel = new JPanel();
191
                        pageStartPanel.setLayout(new BorderLayout());
192
                        pageStartPanel.setPreferredSize(new Dimension(380, 22));
193
                        pageStartPanel.add(getSourceLayerNameLabel(), BorderLayout.LINE_START);
194
                        pageStartPanel.add(getSourceLayerNameTextField(), BorderLayout.LINE_END);
195
                        summaryPanel.add(pageStartPanel, BorderLayout.PAGE_START);
196
                        
197
                        JPanel pageEndPanel = new JPanel();
198
                        pageEndPanel.setLayout(new BorderLayout());
199
                        pageEndPanel.setPreferredSize(new Dimension(380, 22));
200
                        pageEndPanel.add(getOutputLayerNameLabel(), BorderLayout.LINE_START);
201
                        pageEndPanel.add(getOutputLayerNameTextField(), BorderLayout.LINE_END);
202
                        summaryPanel.add(pageEndPanel, BorderLayout.PAGE_END);
203
                }
204

    
205
                return summaryPanel;
206
        }
207
        
208
        protected JPanel getCenterPanel() {
209
                if (centerPanel == null) {
210
                        centerPanel = new JPanel();
211
                        centerPanel.setLayout(new BorderLayout());
212
                        centerPanel.setPreferredSize(new Dimension(390, 340));
213
                        centerPanel.add(getHorizontalSplitPane(), BorderLayout.CENTER);
214
//                        centerPanel.add(getFeaturesPanel(), BorderLayout.CENTER);
215
//                        centerPanel.add(getNewFeaturePanel(), BorderLayout.PAGE_END);
216
                }
217
                
218
                return centerPanel;
219
        }
220
        
221
        protected JSplitPane getHorizontalSplitPane() {
222
                if (horizontalSplitPane == null) {
223
                        horizontalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
224
                        horizontalSplitPane.setPreferredSize(new Dimension(390, 340));
225
//                        horizontalSplitPane.setMinimumSize(new Dimension(390, 340));
226
                        horizontalSplitPane.setOneTouchExpandable(true);
227

    
228
                        horizontalSplitPane.setTopComponent(getFeaturesPanel());
229
                        horizontalSplitPane.setBottomComponent(getNewFeaturePanel());
230
                        
231
                        // Sets the split pane's divider to the 50 %
232
                        horizontalSplitPane.setDividerLocation((int)(horizontalSplitPane.getPreferredSize().getHeight() * 0.50));
233
                }
234

    
235
                return horizontalSplitPane;
236
        }
237
        
238
        protected JLabel getSourceLayerNameLabel() {
239
                if (sourceLayerNameLabel == null) {
240
                        sourceLayerNameLabel = new JLabel(PluginServices.getText(null, "Source_layer"));
241
                        sourceLayerNameLabel.setToolTipText(PluginServices.getText(null, "Source_layer"));
242
                        sourceLayerNameLabel.setPreferredSize(new Dimension(100, 20));
243
                }
244
                
245
                return sourceLayerNameLabel;
246
        }
247
        
248
        protected JTextFieldWithSCP getSourceLayerNameTextField() {
249
                if (sourceLayerNameTextField == null) {
250
                        sourceLayerNameTextField = new JTextFieldWithSCP(parameters.getSourceLayer().getName());
251
                        sourceLayerNameTextField.setToolTipText(parameters.getSourceLayer().getName());
252
                        sourceLayerNameTextField.setPreferredSize(new Dimension(270, 20));
253
                        sourceLayerNameTextField.setEnabled(false);
254
                }
255
                
256
                return sourceLayerNameTextField;
257
        }
258
        
259
        
260
        protected JLabel getOutputLayerNameLabel() {
261
                if (destLayerNameLabel == null) {
262
                        destLayerNameLabel = new JLabel(PluginServices.getText(null, "Output_layer"));
263
                        destLayerNameLabel.setToolTipText(PluginServices.getText(null, "Output_layer"));
264
                        destLayerNameLabel.setPreferredSize(new Dimension(100, 20));
265
                }
266
                
267
                return destLayerNameLabel;
268
        }
269
        
270
        protected JTextFieldWithSCP getOutputLayerNameTextField() {
271
                if (destLayerNameTextField == null) {
272
                        destLayerNameTextField = new JTextFieldWithSCP(parameters.getDestinationLayerName());
273
                        destLayerNameTextField.setToolTipText(parameters.getDestinationLayerName());
274
                        destLayerNameTextField.setPreferredSize(new Dimension(270, 20));
275
                        destLayerNameTextField.setEnabled(false);
276
                }
277
                
278
                return destLayerNameTextField;
279
        }        
280
        
281
        protected JPanel getFeaturesPanel() {
282
                if (featuresPanel == null) {
283
                        featuresPanel = new JPanel();
284
                        featuresPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "Features")));
285
                        featuresPanel.setLayout(new BorderLayout());
286
                        featuresPanel.setPreferredSize(new Dimension(380, 130));
287
                        featuresPanel.add(getAllFeaturesScrollPane(), BorderLayout.CENTER);
288
                }
289
                
290
                return featuresPanel;
291
        }
292

    
293

    
294
        protected JPanel getNewFeaturePanel() {
295
                if (newFeatureSelectionPanel == null) {
296
                        newFeatureSelectionPanel = new JPanel();
297
                        newFeatureSelectionPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "New_features")));
298
                        newFeatureSelectionPanel.setPreferredSize(new Dimension(390, 200));
299
                        newFeatureSelectionPanel.setLayout(new BorderLayout());
300
                        
301
                        // Icons
302
                        ImageIcon removeAllIcon = PluginServices.getIconTheme().get("remove-all-icon");
303
                        ImageIcon removeIcon = PluginServices.getIconTheme().get("remove-icon");
304
                        ImageIcon addAllIcon = PluginServices.getIconTheme().get("add-all-icon");
305
                        ImageIcon addIcon = PluginServices.getIconTheme().get("add_v2-icon");
306

    
307
                        // Add all button 
308
                     JButton addAllIconButton = new JButton(addAllIcon);
309
                     addAllIconButton.setToolTipText(PluginServices.getText(this, "add_all_button_TOOLTIP_HTML_explanation"));
310
                     addAllIconButton.setPreferredSize(new Dimension(40, 40));
311
                     addAllIconButton.addActionListener(new ActionListener() {
312
                             /*
313
                              * (non-Javadoc)
314
                              * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
315
                              */
316
                                public void actionPerformed(ActionEvent e) {
317
                                    try {
318
                                            // Adds the new columns and rows
319

    
320
                                            // Columns (only if weren't added)
321
                                            TableModel sourceTableModel = getAllFeaturesTableModel();
322
                                            TableModel destTableModel = getSelectedFeaturesTableModel();
323
                                            
324
                                            if (getSelectedFeaturesTable().getColumnCount() == 0) {
325
                                                    // Order column
326
                                                    ((DefaultTableModel)destTableModel).addColumn(PluginServices.getText(null, "Order"), new JLabel[] {} );
327
                                                    
328
                                                    // ID column:
329
                                                    ((DefaultTableModel)destTableModel).addColumn(PluginServices.getText(null, "ID"), new JLabel[] {} );
330

    
331
                                                    // The other columns:                                                    
332
                                                    for (int i = 0; i < sourceTableModel.getColumnCount(); i++) {
333
                                                            ((DefaultTableModel)destTableModel).addColumn(sourceTableModel.getColumnName(i), new Object[] {} );
334
                                                    }
335

    
336
                                                    // Define the renderer (a JLabel) for the first table's column
337
                                                getSelectedFeaturesTable().getColumnModel().getColumn(0).setCellRenderer(new JTableColumnLabelRenderer());
338

    
339
                                                // Define the renderer (a JLabel) for the second table's column
340
                                                getSelectedFeaturesTable().getColumnModel().getColumn(1).setCellRenderer(new JTableColumnLabelRenderer());
341
                                                    
342
                                                    // Sets the least column width to all table's columns
343
                                                    for (int cIndex = 0; cIndex < getSelectedFeaturesTable().getColumnModel().getColumnCount(); cIndex++) {
344
                                                            getSelectedFeaturesTable().getColumnModel().getColumn(cIndex).setPreferredWidth(TABLE_COLUMN_PREF_WIDTH);
345
                                                            getSelectedFeaturesTable().getColumnModel().getColumn(cIndex).setMinWidth(TABLE_COLUMN_PREF_WIDTH);
346
                                                    }
347
                                            }
348

    
349
                                                // Rows
350
                                            Object[] rowValues = new Object[sourceTableModel.getColumnCount() + 2];
351
                                            JTable sourceTable = getAllFeaturesTable();
352
                                            int base = getSelectedFeaturesTable().getRowCount() + 1; // + 1 -> the counter starts in 1
353

    
354
                                            for (int i = 0; i < sourceTable.getRowCount(); i++) {
355
                                                    // Order column:
356
                                                    rowValues[0] = new JLabel(Integer.toString(base + i));
357
                                                    
358
                                                    // ID column:
359
                                                    rowValues[1] = new JLabel(Integer.toString(i));
360
                                                    
361
                                                    // The other columns:
362
                                                    for (int j = 0; j < sourceTableModel.getColumnCount(); j++) {
363
                                                            rowValues[j + 2] = sourceTable.getValueAt(i, j).toString();
364
                                                    }
365

    
366
                                                    ((DefaultTableModel)destTableModel).addRow(rowValues);
367
                                            }
368

    
369
                                            updateOkButtons();
370
                                            
371
                                            // Clears the selection
372
                                            getAllFeaturesTable().clearSelection();
373
                                    }
374
                                    catch (Exception ex) {
375
                                            NotificationManager.showMessageError(PluginServices.getText(null, "Failed_updating_features"), ex);
376

    
377
                                            // Forces to remove all columns and rows of the table
378
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
379
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setColumnCount(0);
380
                                            updateOkButtons();
381
                                    }
382
                                }
383
                     });
384

    
385
                     // Remove all button 
386
                     JButton removeAllIconButton = new JButton(removeAllIcon);
387
                     removeAllIconButton.setToolTipText(PluginServices.getText(this, "remove_all_button_TOOLTIP_HTML_explanation"));
388
                     removeAllIconButton.setPreferredSize(new Dimension(40, 40));
389
                     removeAllIconButton.addActionListener(new ActionListener() {
390
                             /*
391
                              * (non-Javadoc)
392
                              * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
393
                              */
394
                                public void actionPerformed(ActionEvent e) {
395
                                        try {
396
                                            // Removes all rows of the table
397
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
398
                                            //((DefaultTableModel)getSelectedFeaturesTable().getModel()).setColumnCount(0);
399
                                            
400
                                            updateOkButtons();
401
                                        }
402
                                    catch (Exception ex) {
403
                                            NotificationManager.showMessageError(PluginServices.getText(null, "Failed_updating_features"), ex);
404
                                            
405
                                            updateOkButtons();
406
                                    }                                        
407
                                }
408
                     });
409

    
410
                        // Left panel
411
                        JPanel leftPanel = new JPanel();
412
                        //leftPanel.setLayout(new BorderLayout());
413
                        leftPanel.setPreferredSize(new Dimension(110, 44));
414
//                     leftPanel.add(addAllIconButton, BorderLayout.CENTER);
415
//                     leftPanel.add(removeAllIconButton, BorderLayout.CENTER);
416
//                     newFeatureSelectionPanel.add(leftPanel, BorderLayout.LINE_START);
417
                     leftPanel.add(addAllIconButton);
418
                     leftPanel.add(removeAllIconButton);
419
             //        newFeatureSelectionPanel.add(leftPanel, BorderLayout.LINE_START);
420
                     
421
                     // Center-top panel
422
//                     JPanel centerTopPanel = new JPanel();
423
//                     centerTopPanel.setPreferredSize(new Dimension(130, 44));
424
//                     centerTopPanel.add(getSnappingCBox());
425
                     //newFeatureSelectionPanel.add(centerTopPanel, BorderLayout.CENTER);
426

    
427
                        // Add button 
428
                     JButton addIconButton = new JButton(addIcon);
429
                     addIconButton.setToolTipText(PluginServices.getText(this, "add_selected_button_TOOLTIP_HTML_explanation"));
430
                     addIconButton.setPreferredSize(new Dimension(40, 40));
431
                     addIconButton.addActionListener(new ActionListener() {
432
                             /*
433
                              * (non-Javadoc)
434
                              * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
435
                              */
436
                                public void actionPerformed(ActionEvent e) {
437
                                    try {
438
                                            // Adds the new columns and rows
439

    
440
                                            // Columns (only if weren't added)
441
                                            TableModel sourceTableModel = getAllFeaturesTableModel();
442
                                            TableModel destTableModel = getSelectedFeaturesTableModel();
443
                                            
444
                                            if (getSelectedFeaturesTable().getColumnCount() == 0) {
445
                                                    // Order column
446
                                                    ((DefaultTableModel)destTableModel).addColumn(PluginServices.getText(null, "Order"), new JLabel[] {} );
447
                                                    
448
                                                    // ID column:
449
                                                    ((DefaultTableModel)destTableModel).addColumn(PluginServices.getText(null, "ID"), new JLabel[] {} );
450

    
451
                                                    // The other columns:                                                    
452
                                                    for (int i = 0; i < sourceTableModel.getColumnCount(); i++) {
453
                                                            ((DefaultTableModel)destTableModel).addColumn(sourceTableModel.getColumnName(i), new Object[] {} );
454
                                                    }
455

    
456
                                                    // Define the renderer (a JLabel) for the first table's column
457
                                                getSelectedFeaturesTable().getColumnModel().getColumn(0).setCellRenderer(new JTableColumnLabelRenderer());
458

    
459
                                                // Define the renderer (a JLabel) for the second table's column
460
                                                getSelectedFeaturesTable().getColumnModel().getColumn(1).setCellRenderer(new JTableColumnLabelRenderer());
461

    
462
                                                    // Sets the least column width to all table's columns
463
                                                    for (int cIndex = 0; cIndex < getSelectedFeaturesTable().getColumnModel().getColumnCount(); cIndex++) {
464
                                                            getSelectedFeaturesTable().getColumnModel().getColumn(cIndex).setPreferredWidth(TABLE_COLUMN_PREF_WIDTH);
465
                                                            getSelectedFeaturesTable().getColumnModel().getColumn(cIndex).setMinWidth(TABLE_COLUMN_PREF_WIDTH);
466
                                                    }
467
                                            }
468
                                            
469
                                                // Rows
470
                                            Object[] rowValues = new Object[sourceTableModel.getColumnCount() + 2];
471
                                            JTable sourceTable = getAllFeaturesTable();
472
                                            int base = getSelectedFeaturesTable().getRowCount() + 1; // + 1 -> the counter starts in 1
473
                                            int[] sRows = getAllFeaturesTable().getSelectedRows();
474

    
475
                                            for (int i = 0; i < sRows.length; i++) {
476
                                                    // Order column:
477
                                                    rowValues[0] = new JLabel(Integer.toString(base + i));
478
                                                    
479
                                                    // ID column:
480
                                                    rowValues[1] = new JLabel(Integer.toString(sRows[i]));
481
                                                    
482
                                                    // The other columns:
483
                                                    for (int j = 0; j < sourceTableModel.getColumnCount(); j++) {
484
                                                            rowValues[j + 2] = sourceTable.getValueAt(sRows[i], j).toString();
485
                                                    }
486

    
487
                                                    ((DefaultTableModel)destTableModel).addRow(rowValues);
488
                                            }
489
                                            
490
                                            updateOkButtons();
491

    
492
                                            // Clears the selection
493
                                            getAllFeaturesTable().clearSelection();
494
                                    }
495
                                    catch (Exception ex) {
496
                                            NotificationManager.showMessageError(PluginServices.getText(null, "Failed_updating_features"), ex);
497

    
498
                                            // Forces to remove all columns and rows of the table
499
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
500
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setColumnCount(0);
501
                                            
502
                                            updateOkButtons();
503
                                    }
504
                                }
505
                     });
506

    
507
                        // Remove button 
508
                     JButton removeIconButton = new JButton(removeIcon);
509
                     removeIconButton.setToolTipText(PluginServices.getText(this, "remove_selected_button_TOOLTIP_HTML_explanation"));
510
                     removeIconButton.setPreferredSize(new Dimension(40, 40));
511
                     removeIconButton.addActionListener(new ActionListener() {
512
                             /*
513
                              * (non-Javadoc)
514
                              * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
515
                              */
516
                                public void actionPerformed(ActionEvent e) {
517
                                    try {
518
                                            // Removes the selected rows
519

    
520
                                                // Rows
521
                                            TableModel model = getSelectedFeaturesTableModel();
522
                                            int[] sRows = getSelectedFeaturesTable().getSelectedRows();
523

    
524
                                            for (int i = (sRows.length - 1); i >= 0; i--) {
525
                                                    ((DefaultTableModel)model).removeRow(sRows[i]);
526
                                            }
527
                                            
528
                                            // Updates the order
529
                                            for (int i = 0; i < model.getRowCount(); i++) {
530
                                                    model.setValueAt(new JLabel(Integer.toString(i + 1)), i, 0);
531
                                            }
532
                                            
533
                                            updateOkButtons();
534
                                    }
535
                                    catch (Exception ex) {
536
                                            NotificationManager.showMessageError(PluginServices.getText(null, "Failed_updating_features"), ex);
537

    
538
                                            // Forces to remove all columns and rows of the table
539
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
540
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setColumnCount(0);
541
                                            
542
                                            updateOkButtons();
543
                                    }
544
                                }
545
                     });
546

    
547
                        // Right panel
548
                        JPanel rightPanel = new JPanel();
549
                        //rightPanel.setLayout(new BorderLayout());
550
                        rightPanel.setPreferredSize(new Dimension(110, 44));
551
//                        rightPanel.add(addIconButton, BorderLayout.CENTER);
552
//                     rightPanel.add(removeIconButton, BorderLayout.CENTER);
553
//                     newFeatureSelectionPanel.add(rightPanel, BorderLayout.LINE_END);
554
                        rightPanel.add(addIconButton);
555
                     rightPanel.add(removeIconButton);
556

    
557
                     // North panel
558
                     JPanel northPanel = new JPanel();
559
                     northPanel.setLayout(new BorderLayout());
560
                     northPanel.setPreferredSize(new Dimension(390, 50));
561
                     northPanel.add(leftPanel, BorderLayout.LINE_START);
562
//                     northPanel.add(centerTopPanel, BorderLayout.CENTER);
563
                     northPanel.add(rightPanel, BorderLayout.LINE_END);
564
                     newFeatureSelectionPanel.add(northPanel, BorderLayout.PAGE_START);
565

    
566
                     // South panel
567
                     JPanel southPanel = new JPanel();
568
                     southPanel.setLayout(new BorderLayout());
569
                     southPanel.setPreferredSize(new Dimension(390, 125));
570

    
571
                     // Selected features table
572
//                     JPanel southLeftPanel = new JPanel();
573
//                     southLeftPanel.setLayout(new BorderLayout());
574
//                     southLeftPanel.setPreferredSize(new Dimension(320, 120));
575
//                     southLeftPanel.add(getSelectedFeaturesScrollPane(), BorderLayout.CENTER);
576
//
577
//                     southPanel.add(southLeftPanel, BorderLayout.LINE_START);
578
//                     southPanel.add(getMotionButtonsPanel(), BorderLayout.LINE_END);
579
                     
580
                     southPanel.add(getSelectedFeaturesScrollPane(), BorderLayout.CENTER);
581
                     southPanel.add(getMotionButtonsPanel(), BorderLayout.LINE_END);
582
                     
583
                     newFeatureSelectionPanel.add(southPanel, BorderLayout.CENTER);        
584
                }
585

    
586
                return newFeatureSelectionPanel;
587
        }
588
        
589
        /**
590
         * 
591
         * 
592
     * @see TableCellRenderer
593
     * 
594
     * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
595
     */
596
    protected class JTableColumnLabelRenderer implements TableCellRenderer {
597
            /*
598
             * (non-Javadoc)
599
             * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
600
             */
601
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
602
                        JLabel renderer = (JLabel)value;
603
                        
604
                        // Enable the change of the foreground and background color
605
                        renderer.setOpaque(true);
606
                        
607
                        if (isSelected) {
608
                                renderer.setForeground(UIManager.getColor( "Table.selectionForeground" ));
609
                                renderer.setBackground(UIManager.getColor( "Table.selectionBackground" ));
610
                        }
611
                        else
612
                                renderer.setBackground(bgIDColor);
613

    
614
                    return renderer;
615
                }
616
    }
617
        
618
        protected JScrollPane getAllFeaturesScrollPane() {
619
                if (allFeaturesScrollPane == null) {
620
                        allFeaturesScrollPane = new JScrollPane();
621
                        allFeaturesScrollPane.setPreferredSize(new Dimension(370, 120));
622
                        allFeaturesScrollPane.setViewportView(getAllFeaturesTable());
623
                        allFeaturesScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
624
                }
625
                
626
                return allFeaturesScrollPane;
627
        }
628
        
629
        protected JTable getAllFeaturesTable() {
630
                if (allFeaturesTable == null) {
631
                        allFeaturesTable = new JTable(getAllFeaturesTableModel()) {
632
                                /*
633
                                 * (non-Javadoc)
634
                                 * @see javax.swing.JTable#isCellEditable(int, int)
635
                                 */
636
                                public boolean isCellEditable(int row, int column) {
637
                                        return false;
638
                                }
639
                        };
640

    
641
                        allFeaturesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
642
                        allFeaturesTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
643

    
644
                        allFeaturesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
645

    
646
                                public void valueChanged(ListSelectionEvent e) {
647
                                        try {
648
                                                SelectableDataSource sds = parameters.getSourceLayer().getRecordset();
649
                                                FBitSet newSelection = (FBitSet) sds.getSelection().clone();
650
                                                newSelection.clear();
651
                                                
652
                                                int[] sRows = getAllFeaturesTable().getSelectedRows();
653

    
654
                                                for (int i = 0; i < sRows.length; i++) {
655
                                                        newSelection.set( sRows[i] );
656
                                                }
657

    
658
                                                sds.setSelection(newSelection);
659
                                        }
660
                                        catch (Exception ex) {
661
                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_selecting_geometries_in_layer"), ex);
662
                                        }
663
                                }
664
                        });
665

    
666
                }
667

    
668
                return allFeaturesTable;
669
        }
670

    
671
        protected JScrollPane getSelectedFeaturesScrollPane() {
672
                if (selectedFeaturesScrollPane == null) {
673
                        selectedFeaturesScrollPane = new JScrollPane();
674
                        selectedFeaturesScrollPane.setPreferredSize(new Dimension(320, 120));
675
                        selectedFeaturesScrollPane.setViewportView(getSelectedFeaturesTable());
676
                        selectedFeaturesScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
677
                }
678
                
679
                return selectedFeaturesScrollPane;
680
        }
681
        
682
        protected JTable getSelectedFeaturesTable() {
683
                if (selectedFeaturesTable == null) {
684
                        selectedFeaturesTable = new JTable(getSelectedFeaturesTableModel()) {
685
                                /*
686
                                 * (non-Javadoc)
687
                                 * @see javax.swing.JTable#isCellEditable(int, int)
688
                                 */
689
                                public boolean isCellEditable(int row, int column) {
690
                                        return false;
691
                                }
692
                        };
693

    
694
                        selectedFeaturesTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
695
                        selectedFeaturesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
696

    
697
                        selectedFeaturesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
698

    
699
                                public void valueChanged(ListSelectionEvent e) {
700
                                        try {
701
                                                SelectableDataSource sds = parameters.getSourceLayer().getRecordset();
702
                                                FBitSet newSelection = (FBitSet) sds.getSelection().clone();
703
                                                newSelection.clear();
704
                                                
705
                                                int[] sRows = getSelectedFeaturesTable().getSelectedRows();
706

    
707
                                                for (int i = 0; i < sRows.length; i++) {
708
                                                        newSelection.set( Integer.parseInt(((JLabel)getSelectedFeaturesTable().getValueAt(sRows[i], 1)).getText()) );
709
                                                }
710

    
711
                                                sds.setSelection(newSelection);
712
                                        }
713
                                        catch (Exception ex) {
714
                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_selecting_geometries_in_layer"), ex);
715
                                        }
716
                                }
717
                        });
718
                }
719
                
720
                return selectedFeaturesTable;
721
        }
722
        
723
        protected JPanel getMotionButtonsPanel() {
724
                if (motionButtonsPanel == null) {
725
                        motionButtonsPanel = new JPanel();
726
                        motionButtonsPanel.setLayout(new BorderLayout());
727
                        motionButtonsPanel.setPreferredSize(new Dimension(50, 120));
728
                        
729
                        // Icons
730
                        ImageIcon moveUpIcon = PluginServices.getIconTheme().get("up-arrow-icon");
731
                        ImageIcon moveDownIcon = PluginServices.getIconTheme().get("down-arrow-icon");
732
                        
733
                        // Move up button
734
                     JButton moveUp = new JButton(moveUpIcon);
735
                     moveUp.setToolTipText(PluginServices.getText(this, "move_up_button_TOOLTIP_HTML_explanation"));
736
                     moveUp.setPreferredSize(new Dimension(40, 40));
737
                     moveUp.addActionListener(new ActionListener() {
738
                             /*
739
                              * (non-Javadoc)
740
                              * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
741
                              */
742
                                public void actionPerformed(ActionEvent e) {
743
                                    try {
744
                                            // Moves up the selected rows
745

    
746
                                            TableModel model = getSelectedFeaturesTableModel();
747
                                            int[] sRows = getSelectedFeaturesTable().getSelectedRows();
748

    
749
                                            for (int i = 0; i < sRows.length; i++) {
750
                                                    if (sRows[i] > 0)
751
                                                            ((DefaultTableModel)model).moveRow(sRows[i], sRows[i], sRows[i] - 1);
752
                                            }
753
                                            
754
                                            // Updates the order
755
                                            for (int i = 0; i < model.getRowCount(); i++) {
756
                                                    model.setValueAt(new JLabel(Integer.toString(i + 1)), i, 0);
757
                                            }
758
                                    }
759
                                    catch (Exception ex) {
760
                                            NotificationManager.showMessageError(PluginServices.getText(null, "Failed_updating_features"), ex);
761

    
762
                                            // Forces to remove all columns and rows of the table
763
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
764
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setColumnCount(0);
765
                                    }
766
                                }
767
                     });
768

    
769
                     JPanel upPanel = new JPanel();
770
//                     upPanel.setLayout(new BorderLayout());
771
                     upPanel.setPreferredSize(new Dimension(44, 50));
772
                     upPanel.add(moveUp);
773
                        motionButtonsPanel.add(upPanel, BorderLayout.PAGE_START);
774
                        
775
                        // Move down button
776
                     JButton moveDown = new JButton(moveDownIcon);
777
                     moveDown.setToolTipText(PluginServices.getText(this, "move_down_button_TOOLTIP_HTML_explanation"));
778
                     moveDown.setPreferredSize(new Dimension(40, 40));
779
                     moveDown.addActionListener(new ActionListener() {
780
                             /*
781
                              * (non-Javadoc)
782
                              * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
783
                              */
784
                                public void actionPerformed(ActionEvent e) {
785
                                    try {
786
                                            // Moves up the selected rows
787

    
788
                                            TableModel model = getSelectedFeaturesTableModel();
789
                                            int[] sRows = getSelectedFeaturesTable().getSelectedRows();
790

    
791
                                            for (int i = sRows.length - 1; i >= 0; i--) {
792
                                                    if (sRows[i] < getSelectedFeaturesTable().getRowCount() - 1)
793
                                                            ((DefaultTableModel)model).moveRow(sRows[i], sRows[i], sRows[i] + 1);
794
                                            }
795
                                            
796
                                            // Updates the order
797
                                            for (int i = 0; i < model.getRowCount(); i++) {
798
                                                    model.setValueAt(new JLabel(Integer.toString(i + 1)), i, 0);
799
                                            }
800
                                    }
801
                                    catch (Exception ex) {
802
                                            NotificationManager.showMessageError(PluginServices.getText(null, "Failed_updating_features"), ex);
803

    
804
                                            // Forces to remove all columns and rows of the table
805
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
806
                                            ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setColumnCount(0);
807
                                    }
808
                                }
809
                     });
810

    
811

    
812
                     JPanel downPanel = new JPanel();
813
                     downPanel.setPreferredSize(new Dimension(44, 50));
814
//                     downPanel.setLayout(new BorderLayout());
815
                     downPanel.add(moveDown);
816
                        motionButtonsPanel.add(downPanel, BorderLayout.PAGE_END);
817
                }
818
                
819
                return motionButtonsPanel;
820
        }
821
        
822
//        protected JButton getSnappingCBox() {
823
//                if (snappingCBox == null) {
824
//                        snappingCBox = new JButton(PluginServices.getText(null, "Snapping"));
825
//                        snappingCBox.setToolTipText(PluginServices.getText(null, "Start_snapping_tool"));
826
//                        snappingCBox.setPreferredSize(new Dimension(100, 40));
827
//                        snappingCBox.addActionListener(new ActionListener() {
828
//                                /*
829
//                                 * (non-Javadoc)
830
//                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
831
//                                 */
832
//                                public void actionPerformed(ActionEvent e) {
833
//                                        // Sets the snapping tool as current tool
834
//                                        //parameters.getMapControl().setTool(AddDerivativeGeometrySHPExtension.ToolID);
835
//                                        
836
////                                        // Sets as CAD tool the "simple selection tool"
837
////                                        CADTool[] cadTools = CADExtension.getCADTools();
838
////                                        
839
////                                        boolean found = false;
840
////                                        
841
////                                        for (int i = 0; i < cadTools.length; i++) {
842
////                                                if (cadTools[i].getName().equals("_selection")) {
843
////                                                        found = true;
844
////                                                        break;
845
////                                                }
846
////                                        }
847
////                                        
848
////                                        if (! found)
849
////                                                CADExtension.setCADTool("_selection",false);
850
//
851
////                                        try {
852
////                                                parameters.getSourceLayer().setEditing(true);
853
////                                        } catch (Exception e1) {
854
////                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_starting_edition_of_layer"), e1);
855
////                                                return;
856
////                                        }
857
//
858
////                                        parameters.getMapControl().setTool("cadtooladapter");
859
////                                        ((CADExtension)cadExtension).getCADToolAdapter().get
860
//                                        
861
//                                        CADTool cadTool = sTool.getCADTool("_nonEditedLayerSelection");
862
//
863
//                                        if (cadTool == null) {
864
//                                                cadTool = new NonEditedLayerSelectionCADTool(parameters.getSourceLayer());
865
//                                                SnappingTool.addCADTool("_nonEditedLayerSelection", cadTool);
866
//                                        }
867
//                                        else {
868
//                                                ((NonEditedLayerSelectionCADTool)cadTool).setAssociatedLayer(parameters.getSourceLayer());
869
//                                        }
870
//
871
//                                        sTool.setMapControl(parameters.getMapControl());
872
//                                        sTool.setSnappedLayer(parameters.getSourceLayer());
873
//                                        sTool.setCadTool(cadTool);
874
//                                        
875
////                                        CADExtension.setCADTool("_nonEditedLayerSelection", false);
876
//                                        parameters.getMapControl().setTool(SnappingTool.TOOL_ID);
877
//
878
//                                        // Force to repaint the layer
879
//                                        parameters.getSourceLayer().setSpatialCacheEnabled(true);
880
//                                        parameters.getSourceLayer().setDirty(true);
881
//                                        parameters.getMapControl().rePaintDirtyLayers();
882
//                                        
883
//                                        
884
////                                        try {
885
////                                                parameters.getSourceLayer().setEditing(true);
886
////                                        } catch (EditionException e1) {
887
////                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_starting_edition_of_layer"), e1);
888
////                                                return;
889
////                                        }
890
//                                        
891
//                                        sTool.initializeFlatness();
892
//                                        sTool.initializeGrid();
893
//                                        sTool.setCadTool(cadTool);
894
//                                        cadTool.init();
895
//                                }
896
//                        });
897
//                }
898
//                
899
//                return snappingCBox;
900
//        }
901
//        
902
//        public boolean isEnabledSnapping() {
903
//                return getSnappingCBox().isSelected();
904
//        }
905
        
906
    /**
907
     * <p>This method initializes acceptCancelPanel.</p>        
908
     * 
909
     * @return an adapted {@link AcceptCancelPanel AcceptCancelPanel}
910
     */
911
    protected AdaptedAcceptCancelPanel getAdaptedAcceptCancelPanel() {
912
            if (acceptCancelPanel == null) {
913
                    acceptCancelPanel = new AdaptedAcceptCancelPanel();
914
            }
915
            
916
            return acceptCancelPanel;
917
    }
918

    
919
        /*
920
         * (non-Javadoc)
921
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
922
         */
923
        public WindowInfo getWindowInfo() {
924
                if (viewInfo == null) {
925
                        viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE | WindowInfo.ICONIFIABLE);
926
                        viewInfo.setTitle(parameters.getProcessName());
927
                        viewInfo.setWidth(Window_Width);
928
                        viewInfo.setHeight(Window_Height);
929
                }
930

    
931
                return viewInfo;
932
        }
933
        
934

    
935
    /**
936
     * <p>Adapts {@link AcceptCancelPanel AcceptCancelPanel} to be used as a component of the <code>QInfoDataSelectionPanel</code> panel.</p>
937
     * 
938
     * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
939
     */
940
    protected class AdaptedAcceptCancelPanel extends JPanel {
941
            private JButton btnOk = null;
942
            private JButton btnCancel = null;
943
            private JButton btnOk2 = null;
944
            
945
            protected final static String BUTTON_OK_ACTION = "OK";
946
            protected final static String BUTTON_OK2_ACTION = "OK2";
947
            protected final static String BUTTON_CANCEL_ACTION = "CANCEL";
948

    
949
                public AdaptedAcceptCancelPanel () {
950
                                super();
951
                                initialize();
952
                }
953
                
954
                protected void initialize() {
955
                this.setLayout(new BorderLayout());
956
                JPanel aux = new JPanel();
957
                        
958
                    if (parameters.getProcessID() == DerivedGeometryProcessParameters.POINTS_TO_LINE_OR_POLYGON_ID) {
959
                            aux.add(getBtnOk(getOKAction()), java.awt.BorderLayout.LINE_END);
960
                            aux.add(getBtn2Ok(getOKAction()), java.awt.BorderLayout.LINE_END);
961
                            aux.add(getCancelButton(getCancelAction()), java.awt.BorderLayout.EAST);
962
                            getOkButton().setText(PluginServices.getText(null, "Generate_line")); // Changes the text associated to the OK button
963
                            getOkButton2().setText(PluginServices.getText(null, "Generate_polygon")); // Changes the text associated to the OK button
964
                    }
965
                    else {
966
                            aux.add(getBtnOk(getOKAction()), java.awt.BorderLayout.LINE_END);
967
                            aux.add(getCancelButton(getCancelAction()), java.awt.BorderLayout.LINE_END);
968
                            getOkButton().setText(PluginServices.getText(null, "Generate")); // Changes the text associated to the OK button
969
                    }
970
                    
971
                this.add(aux, java.awt.BorderLayout.LINE_END);
972
                    setPreferredSize(new Dimension(390, 28));                            
973
            }
974
                
975
                /**
976
                 * This method initializes btnOk
977
                 *
978
                 * @return javax.swing.JButton
979
                 */
980
                protected JButton getBtnOk(ActionListener okAction) {
981
                        if (btnOk == null) {
982
                                btnOk = new JButton();
983
                                btnOk.setText(PluginServices.getText(null, "ok"));
984
                                btnOk.setActionCommand(BUTTON_OK_ACTION);
985
                                if (okAction != null)
986
                                        btnOk.addActionListener(okAction);
987
                        }
988
                        return btnOk;
989
                }
990

    
991
                /**
992
                 * This method initializes btnOk
993
                 *
994
                 * @return javax.swing.JButton
995
                 */
996
                protected JButton getBtn2Ok(ActionListener okAction) {
997
                        if (btnOk2 == null) {
998
                                btnOk2 = new JButton();
999
                                btnOk2.setActionCommand(BUTTON_OK2_ACTION);
1000
                                if (okAction != null)
1001
                                        btnOk2.addActionListener(okAction);
1002
                        }
1003
                        return btnOk2;
1004
                }
1005

    
1006
                /**
1007
                 * This method initializes btnCancel
1008
                 *
1009
                 * @return javax.swing.JButton
1010
                 */
1011
                protected JButton getCancelButton(ActionListener cancelAction) {
1012
                        if (btnCancel == null) {
1013
                                btnCancel = new JButton();
1014
                                btnCancel.setText(PluginServices.getText(null, "cancel"));
1015
                                btnCancel.setActionCommand(BUTTON_CANCEL_ACTION);
1016
                                if (cancelAction != null)
1017
                                        btnCancel.addActionListener(cancelAction);
1018
                        }
1019
                        return btnCancel;
1020
                }
1021

    
1022
                /**
1023
                 * Sets the ActionListener to the <b>OK</b> button removing any other previous one.
1024
                 * @param l
1025
                 */
1026
                public void setOkButtonActionListener(ActionListener l) {
1027
                        ActionListener[] listeners = btnOk.getActionListeners();
1028
                        for (int i = 0; i < listeners.length; i++) {
1029
                                btnOk.removeActionListener(listeners[i]);
1030
                        }
1031
                        btnOk.addActionListener(l);
1032
                }
1033

    
1034

    
1035
                /**
1036
                 * Sets the ActionListener to the second <b>OK</b> button removing any other previous one.
1037
                 * @param l
1038
                 */
1039
                public void setOkButton2ActionListener(ActionListener l) {
1040
                        ActionListener[] listeners = btnOk2.getActionListeners();
1041
                        for (int i = 0; i < listeners.length; i++) {
1042
                                btnOk2.removeActionListener(listeners[i]);
1043
                        }
1044
                        btnOk2.addActionListener(l);
1045
                }
1046

    
1047
                
1048
                /**
1049
                 * Sets the ActionListener to the <b>cancel</b> button removing any other previous one.
1050
                 * @param l
1051
                 */
1052
                public void setCancelButtonActionListener(ActionListener l) {
1053
                        ActionListener[] listeners = btnCancel.getActionListeners();
1054
                        for (int i = 0; i < listeners.length; i++) {
1055
                                btnCancel.removeActionListener(listeners[i]);
1056
                        }
1057
                        btnCancel.addActionListener(l);
1058
                }
1059

    
1060
                /**
1061
                 * Returns the ok button contained by this panel since resizing issues should be
1062
                 * automatically handled by the layout manager. The use of this method is discouraged,
1063
                 * it is kept only for compatibility issues. Try using specific button properties
1064
                 * access methods contained by this class instead.
1065
                 * @return the Ok button
1066
                 * @deprecated
1067
                 */
1068
                public JButton getOkButton() {
1069
                        return btnOk;
1070
                }
1071
                
1072
                /**
1073
                 * Returns the second ok button contained by this panel since resizing issues should be
1074
                 * automatically handled by the layout manager. The use of this method is discouraged,
1075
                 * it is kept only for compatibility issues. Try using specific button properties
1076
                 * access methods contained by this class instead.
1077
                 * @return the second Ok button
1078
                 * @deprecated
1079
                 */
1080
                public JButton getOkButton2() {
1081
                        return btnOk2;
1082
                }
1083
                
1084
                /**
1085
                 * Returns the cancel button contained by this panel since resizing issues should be
1086
                 * automatically handled by the layout manager. The use of this method is discouraged,
1087
                 * it is kept only for compatibility issues. Try using specific button properties
1088
                 * access methods contained by this class instead.
1089
                 * @return the cancel button
1090
                 * @deprecated
1091
                 */
1092
                public JButton getCancelButton() {
1093
                        return btnCancel;
1094
                }
1095

    
1096
                public boolean isOkButtonEnabled() {
1097
                        return btnOk.isEnabled();
1098
                }
1099
                
1100
                public boolean isOkButton2Enabled() {
1101
                        return btnOk2.isEnabled();
1102
                }
1103

    
1104
                public boolean isCancelButtonEnabled() {
1105
                        return btnCancel.isEnabled();
1106
                }
1107

    
1108
                public void setOkButtonEnabled(boolean b) {
1109
                        btnOk.setEnabled(b);
1110
                }
1111

    
1112
                public void setOkButton2Enabled(boolean b) {
1113
                        if (btnOk2 != null)
1114
                                btnOk2.setEnabled(b);
1115
                }
1116

    
1117
                public void setCancelButtonEnabled(boolean b) {
1118
                        btnCancel.setEnabled(b);
1119
                }
1120

    
1121
                /**
1122
                 * Adds an ActionListener to the <b>OK</b> button.
1123
                 * @param l
1124
                 */
1125
                public void addOkButtonActionListener(ActionListener l) {
1126
                        btnOk.addActionListener(l);
1127
                }
1128

    
1129
                /**
1130
                 * Adds an ActionListener to the second <b>OK</b> button.
1131
                 * @param l
1132
                 */
1133
                public void addOkButton2ActionListener(ActionListener l) {
1134
                        btnOk2.addActionListener(l);
1135
                }
1136

    
1137
                /**
1138
                 * Adds an ActionListener to the <b>cancel</b> button.
1139
                 * @param l
1140
                 */
1141
                public void addCancelButtonActionListener(ActionListener l) {
1142
                        btnCancel.addActionListener(l);
1143
                }
1144
                
1145
            /**
1146
              * <p>Create the action that will be executed when user pressed the <i>ok</i> button.</p>
1147
             * 
1148
             * @return action that will be executed when user pressed the <i>cancel</i> button
1149
             */
1150
            protected ActionListener getOKAction() {
1151
                    // OK button action
1152
                    return new ActionListener() {
1153
                            /*
1154
                             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1155
                             */
1156
                                public void actionPerformed(ActionEvent e) {
1157
                                        boolean restoreProcessMultiple = false;
1158
                                        /* Tests */
1159
                                        /*File newFilePath = new File("/home/pablo/Pruebas crear SHP de geometr?as derivadas/prueba/prueba.shp");
1160

1161
                                        long geomIndexes[][] = {{1, 2, 3}, {2, 3, 5, 6, 8}, {12, 14, 15, 16}, {2, 4, 5}, {1}, {10, 11}, {4, 6, 7, 9}}; // Points to Lines
1162
                                        long geomIndexes[][] = {{1, 2, 3}, {2, 3, 5, 6, 8}, {12, 14, 15, 16}, {2, 4, 5}, {1}, {10, 11}, {4, 6, 7, 9}}; // Points to Polygons
1163
                                        long geomIndexes[][] = {{1, 2, 3, 5, 7, 8, 9, 10}}; // Lines to Polygons
1164

1165
                                        FLyrVect sourceLayer = (FLyrVect)((View)view).getMapControl().getMapContext().getLayers().getLayer(0);
1166
                                        
1167
                                        //                                        parameters.setGeometryIndexes(new long[][]{{1, 2, 3}, {2, 3, 5, 6, 8}, {12, 14, 15, 16}, {2, 4, 5}, {1}, {10, 11}, {4, 6, 7, 9}});
1168
                                        
1169
                                        DerivativeGeometryProcessParameters parameters = new DerivativeGeometryProcessParameters (
1170
                                                        sourceLayer, // A cambiar
1171
                                                        newFilePath, // A cambiar
1172
                                                        "Copy of " + ((View)view).getMapControl().getMapContext().getLayers().getLayer(0).getName(), // A cambiar
1173
                                                        geomIndexes,
1174
                                                        //FShape.LINE, // A l?nea
1175
                                                        (short)FShape.POLYGON, // A pol?gono
1176
                                                        (View)view
1177
                                                        );
1178
                                         */
1179
                                        
1180
                                        if (parameters.getProcessID() == DerivedGeometryProcessParameters.POINTS_TO_LINE_OR_POLYGON_ID) {
1181
                                                restoreProcessMultiple = true;
1182

    
1183
                                                if (e.getActionCommand().equals(BUTTON_OK_ACTION)) {
1184
                                                        parameters.setProcessID(DerivedGeometryProcessParameters.POINTS_TO_LINE_PROCESS_ID);
1185
                                                }
1186
                                                else {
1187
                                                        parameters.setProcessID(DerivedGeometryProcessParameters.POINTS_TO_POLYGON_PROCESS_ID);
1188
                                                }
1189
                                        }
1190

    
1191
                                        // Sets the feature indexes
1192
                                        try {
1193
                                                if (parameters.getProcessID() == DerivedGeometryProcessParameters.CLOSE_MULTILINE_PROCESS_ID) {
1194
                                                        long[][] indexes = new long[1][getSelectedFeaturesTable().getRowCount()];
1195
        
1196
                                                        for (int i = 0; i < getSelectedFeaturesTable().getRowCount(); i++) {
1197
                                                                indexes[0][i] = Long.parseLong(((JLabel)getSelectedFeaturesTable().getValueAt(i, 1)).getText());
1198
                                                        }
1199

    
1200
                                                        parameters.setGeometryIndexes(indexes);
1201
                                                }
1202
                                                else {
1203
                                                        // It's prepared to define multiple sets of points, but in isn't used in that way because I don't have enought time
1204
                                                        long[][] indexes = new long[1][getSelectedFeaturesTable().getRowCount()];
1205

    
1206
                                                        for (int i = 0; i < getSelectedFeaturesTable().getRowCount(); i++) {
1207
                                                                indexes[0][i] = Long.parseLong(((JLabel)getSelectedFeaturesTable().getValueAt(i, 1)).getText());
1208
                                                        }
1209
        
1210
                                                        parameters.setGeometryIndexes(indexes);
1211
                                                }
1212
                                        }
1213
                                        catch(Exception ex) {
1214
                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_getting_the_features_indexes"), ex);
1215
                                                return;
1216
                                        }
1217

    
1218
                                        // Hides this panel and sets the focus to the associated view
1219
//                                        removeCombinedTool(); 
1220
                                        closeWindow();
1221
                                        PluginServices.getMDIManager().addWindow(parameters.getView());
1222
                                        
1223
                                        // Removes the geometries selected
1224
                                        ((DefaultTableModel)getSelectedFeaturesTable().getModel()).setRowCount(0);
1225
                                        updateOkButtons();
1226

    
1227
                                        AddDerivedGeometrySHPProcess iprocess = new AddDerivedGeometrySHPProcess(
1228
                                                        PluginServices.getText(null, "Creation_derivative_geometry_layer_process"),
1229
                                                        PluginServices.getText(this, "Ongoing_process_please_wait"),
1230
                                                        parameters);
1231

    
1232
                                        IncrementableTask iTask = new IncrementableTask(iprocess, new ProgressPanel(false));
1233
                                        iTask.addIncrementableListener(iprocess);
1234
                                        iprocess.setIncrementableTask(iTask);
1235
                                        final AddDerivedGeometrySHPProcess f_iprocess = iprocess;
1236
                                        final View f_view = (View)parameters.getView();
1237
                                        final boolean f_restoreProcessMultiple = restoreProcessMultiple;
1238
                                        final boolean f_layer_was_created = (parameters.getDestLayer() != null);
1239
                                        final IncrementableTask f_iTask = iTask;
1240
                                        
1241
                                        iTask.getProgressPanel().addComponentListener(new ComponentAdapter() {
1242
                                                /*
1243
                                                 * (non-Javadoc)
1244
                                                 * @see java.awt.event.ComponentAdapter#componentHidden(java.awt.event.ComponentEvent)
1245
                                                 */
1246
                                                public void componentHidden(ComponentEvent e) {
1247
                                                        /* Forces to refresh the TOC */
1248
                                                        f_view.getTOC().getComponent().setVisible(false);
1249
                                                    f_view.getTOC().getComponent().setVisible(true);
1250
                                                        f_iTask.getProgressPanel().dispose();
1251
                                                        
1252
                                                        /* Adds listener to be notified by a layer removing */
1253
                                                        if (! f_layer_was_created) {
1254
                                                                if (parameters.getDestLayer() != null) {
1255
                                                                        parameters.getMapControl().getMapContext().getLayers().addLayerCollectionListener(getNewLayerCollectionListener());
1256
                                                                }
1257
                                                        }
1258
                                                        
1259
                                                        if (f_restoreProcessMultiple == true) {
1260
                                                                parameters.setProcessID(DerivedGeometryProcessParameters.POINTS_TO_LINE_OR_POLYGON_ID);
1261
                                                        }
1262
                                                        
1263
                                                        showWindow();
1264
//                                                        parameters.getMapControl().addCombinedTool(getCombinedTool());
1265

    
1266
                                                        /* Writes in the gvSIG log the results of the process */
1267
                                                        String text = "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" +
1268
                                                                PluginServices.getText(this, "Summary_of_the_new_shape_with_derivative_geometries_process") + ":\n" +
1269
                                                                f_iprocess.getLog() +
1270
                                                                "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
1271
                                                        Logger.getLogger(getClass().getName()).debug(text);
1272
                                                }
1273
                                        });
1274

    
1275
                                        /* Starts the process */
1276
                                        iprocess.start();
1277
                                        iTask.start();
1278
                                }
1279
                    };
1280
            }
1281

    
1282
            /**
1283
             * <p>Create the action that will be executed when user pressed the <i>cancel</i> button.</p>
1284
             * 
1285
             * @return action that will be executed when user pressed the <i>cancel</i> button
1286
             */
1287
            protected ActionListener getCancelAction() {
1288
                    // Cancel button action
1289
                    return new ActionListener() {
1290
                            /*
1291
                             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1292
                             */
1293
                                public void actionPerformed(ActionEvent e) {
1294
                                        doUnregistration();
1295
                                        closeWindow();
1296
                                }
1297
                    };
1298
            }
1299
    }
1300
    
1301
    protected void refreshGeometries() {
1302
            try {
1303
                    // Removes the previous table model
1304
                    ((DefaultTableModel)getAllFeaturesTable().getModel()).setRowCount(0);
1305
                    ((DefaultTableModel)getAllFeaturesTable().getModel()).setColumnCount(0);
1306

    
1307
                    // Adds the new columns and rows
1308
                    SelectableDataSource sds = parameters.getSourceLayer().getRecordset();
1309

    
1310
                    // Columns
1311
                    FieldDescription[] fields = sds.getFieldsDescription();
1312
                    TableModel tableModel = getAllFeaturesTableModel();
1313
                    
1314
                    for (int i = 0; i < fields.length; i++) {
1315
                            ((DefaultTableModel)tableModel).addColumn(fields[i].getFieldName(), new Object[] {} );
1316

    
1317
//                            switch(fields[i].getFieldType()) {
1318
//                                    case Types.VARCHAR:
1319
//                                            break;
1320
//                                    case Types.DOUBLE:
1321
//                                            break;
1322
//                                    case Types.INTEGER:
1323
//                                            break;
1324
//                                    case Types.BOOLEAN:
1325
//                                            getAllFeaturesTable().getColumnModel().getColumn(i).setMaxWidth(12);
1326
//                                            break;
1327
//                                    case Types.DATE:
1328
//                                            break;
1329
//                            }
1330
                    }
1331
                    
1332
                    // Sets the least column width to all table's columns
1333
                    for (int cIndex = 0; cIndex < getAllFeaturesTable().getColumnModel().getColumnCount(); cIndex++) {
1334
                            getAllFeaturesTable().getColumnModel().getColumn(cIndex).setPreferredWidth(TABLE_COLUMN_PREF_WIDTH);
1335
                            getAllFeaturesTable().getColumnModel().getColumn(cIndex).setMinWidth(TABLE_COLUMN_PREF_WIDTH);
1336
                    }
1337

    
1338
                        // Rows
1339
                    com.hardcode.gdbms.engine.values.Value values[];
1340
                    String[] rowValues; 
1341

    
1342
                    for (long i = 0; i < sds.getRowCount(); i++) {
1343
                            values = sds.getRow(i);
1344
                            rowValues = new String[fields.length];
1345

    
1346
                            for (int j = 0; j < rowValues.length; j++) {
1347
                                    rowValues[j] = values[j].toString();
1348
                            }
1349

    
1350
                            ((DefaultTableModel)tableModel).addRow(rowValues);
1351
                    }
1352
            }
1353
            catch (Exception ex) {
1354
                    NotificationManager.showMessageError(PluginServices.getText(null, "Failed_loading_features"), ex);
1355
                    
1356
                    // Forces to remove all columns and rows of the table
1357
                    ((DefaultTableModel)getAllFeaturesTable().getModel()).setRowCount(0);
1358
                    ((DefaultTableModel)getAllFeaturesTable().getModel()).setColumnCount(0);
1359
            }
1360
    }
1361
    
1362
    protected TableModel getAllFeaturesTableModel() {
1363
            if (allFeaturesTableModel == null) {
1364
                    allFeaturesTableModel = new ViewsTableModel();
1365
            }
1366
            
1367
            return allFeaturesTableModel;
1368
    }
1369

    
1370
    protected TableModel getSelectedFeaturesTableModel() {
1371
            if (selectedFeaturesTableModel == null) {
1372
                    selectedFeaturesTableModel = new ViewsTableModel();
1373
            }
1374
            
1375
            return selectedFeaturesTableModel;
1376
    }
1377

    
1378
    /**
1379
     * <p>Inherits from {@link DefaultTableModel DefaultTableModel} adding support for having different
1380
     *  column renderers.</p>
1381
     * 
1382
     * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
1383
     */
1384
    protected class ViewsTableModel extends DefaultTableModel {
1385

    
1386
                /**
1387
             * <p>Instances <code>LayerTypesTableModel</code>.</p>
1388
             */
1389
            public ViewsTableModel() {
1390
                    super();
1391
            }
1392
            
1393
        /*
1394
         * <p>JTable uses this method to determine the default renderer/
1395
         * editor for each cell.  If we didn't implement this method,
1396
         * then the last column would contain text ("true"/"false"),
1397
         * rather than a check box.</p>
1398
         */
1399
        public Class getColumnClass(int c) {
1400
            return getValueAt(0, c).getClass();
1401
        }
1402

    
1403
    }
1404

    
1405
    /**
1406
     * <p>Closes this window.</p>
1407
     */
1408
        public void closeWindow() {
1409
                PluginServices.getMDIManager().closeWindow(this);
1410
                isShown = false;
1411
        }
1412
        
1413
        protected void showWindow() {
1414
                PluginServices.getMDIManager().addWindow(this);
1415
                isShown = true;
1416
        }
1417

    
1418
        protected void updateOkButtons() {
1419
                if (getSelectedFeaturesTableModel().getRowCount() == 0) {
1420
                        getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
1421
                        getAdaptedAcceptCancelPanel().setOkButton2Enabled(false);
1422
                }
1423
                else {
1424
                        getAdaptedAcceptCancelPanel().setOkButtonEnabled(true);
1425
                        getAdaptedAcceptCancelPanel().setOkButton2Enabled(true);
1426
                }
1427
        }
1428

    
1429
        public void activationChanged(LayerEvent e) {
1430
                if ((e.getSource().isVisible()) && (e.getSource().isActive()) && (! e.getSource().isEditing())) {
1431
                        if (! isShown) {
1432
//                                parameters.getMapControl().addCombinedTool(getCombinedTool());
1433
                                showWindow();
1434
                                refreshSelectedGeometries();
1435
                                updateViewListener(); // If wasn't registered -> registers, otherwise no
1436
                        }
1437
                } else {
1438
                        if (isShown) {
1439
//                                removeCombinedTool();
1440
                                unregisterSnappingTool();
1441
                                closeWindow();
1442
                        }
1443
                }
1444
        }
1445

    
1446
        public void editionChanged(LayerEvent e) {
1447
                if ((e.getSource().isVisible()) && (e.getSource().isActive()) && (! e.getSource().isEditing())) {
1448
                        if (! isShown) {
1449
                                // The compound behavior must invoke the paintComponent of the new combined tool
1450
//                                CompoundBehavior cBehavior = new CompoundBehavior(new Behavior[0]);
1451
//                                cBehavior.addMapBehavior(getCombinedTool(), true);
1452

    
1453
//                                parameters.getMapControl().addCombinedTool(getCombinedTool());
1454
                                showWindow();
1455
                                refreshSelectedGeometries();
1456
                                updateViewListener(); // If wasn't registered -> registers, otherwise no
1457
                        }
1458
                } else {
1459
                        if (isShown) {
1460
//                                removeCombinedTool();
1461
                                unregisterSnappingTool();
1462
                                closeWindow();
1463
                        }
1464
                }
1465
        }
1466

    
1467
        public void nameChanged(LayerEvent e) {
1468
        }
1469

    
1470
        public void visibilityChanged(LayerEvent e) {
1471
                if ((e.getSource().isVisible()) && (e.getSource().isActive()) && (! e.getSource().isEditing())) {
1472
                        if (! isShown) {
1473
                                // The compound behavior must invoke the paintComponent of the new combined tool
1474
//                                CompoundBehavior cBehavior = new CompoundBehavior(new Behavior[0]);
1475
//                                cBehavior.addMapBehavior(getCombinedTool(), true);
1476

    
1477
//                                parameters.getMapControl().addCombinedTool(getCombinedTool());
1478
                                showWindow();
1479
                                refreshSelectedGeometries();
1480
                                updateViewListener(); // If wasn't registered -> registers, otherwise no
1481
                        }
1482
                } else {
1483
                        if (isShown) {
1484
//                                removeCombinedTool();
1485
                                unregisterSnappingTool();
1486
                                closeWindow();
1487
                        }
1488
                }
1489
        }
1490
        
1491
        public LayerCollectionListener getAssociatedLayerCollectionListener() {
1492
                if (layerCollectionListener == null) {
1493
                        layerCollectionListener = new LayerCollectionListener() {
1494

    
1495
                                public void layerAdded(LayerCollectionEvent e) {
1496
                                }
1497

    
1498
                                public void layerAdding(LayerCollectionEvent e)        throws CancelationException {
1499
                                }
1500

    
1501
                                public void layerMoved(LayerPositionEvent e) {
1502
                                }
1503

    
1504
                                public void layerMoving(LayerPositionEvent e) throws CancelationException {
1505
                                }
1506

    
1507
                                public void layerRemoved(LayerCollectionEvent e) {
1508
                                }
1509

    
1510
                                public void layerRemoving(LayerCollectionEvent e) throws CancelationException {
1511
                                        // Removes all registered listeners when layer has been removed
1512
                                        if (e.getAffectedLayer() == parameters.getSourceLayer()) {
1513
                                                // Asks user to remove this control panel
1514
                                                // (this avoids removed the panel when the layer is removed updating the TOC)
1515
                                                //if (JOptionPane.showConfirmDialog(parameters.getView(), PluginServices.getText(null, "Really_want_to_remove_the_control_panel_of_the_layer") + " " + parameters.getSourceLayer().getName(), PluginServices.getText(null, "Confirmation"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
1516
                                                        doUnregistration();
1517
                                                        closeWindow();
1518
                                                //}
1519
                                        }
1520
                                }
1521

    
1522
                                public void visibilityChanged(LayerCollectionEvent e) throws CancelationException {
1523
                                }
1524
                };
1525
                }
1526
                
1527
                return layerCollectionListener;
1528
        }
1529
        
1530
        public boolean doUnregistration() {
1531
                try {
1532
                        FLyrVect sourceLayer = parameters.getSourceLayer();
1533
                        FLayers layers = parameters.getMapControl().getMapContext().getLayers();
1534

    
1535
                        // Removes the associated source layer collection listener
1536
                        layers.removeLayerCollectionListener(getAssociatedLayerCollectionListener());
1537
                        
1538
                        // Removes the associated destination layer collection listener
1539
                        if (parameters.getDestLayer() != null)
1540
                                layers.removeLayerCollectionListener(getNewLayerCollectionListener());
1541
        
1542
                        // Removes the source layer listener
1543
                        sourceLayer.removeLayerListener(this);
1544

    
1545
                        // Removes the combined tool
1546
//                        removeCombinedTool();
1547

    
1548
                        // Unregisters the snapping tool
1549
                        unregisterSnappingTool();
1550
                        
1551
                        // Removes the associate View's listener
1552
                        unregisterViewListener();
1553

    
1554
                        PluginServices.getLogger().debug(PluginServices.getText(this, "Derivative_geometries_control_panel_listener_removed"));
1555
                }
1556
                catch(Exception ex) {
1557
                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_unregistering_derivative_geometry_control_panel_listener"), ex);
1558
                        
1559
                        return false;
1560
                }
1561

    
1562
                return true;
1563
        }
1564

    
1565
        protected void unregisterSnappingTool() {
1566
//                // Changes to the default tool -> zoom
1567
//                if (parameters.getMapControl().getCurrentTool().equals(SnappingTool.TOOL_ID)) {
1568
//                        // Restores to the default tool: zoom in
1569
//                        parameters.getMapControl().setTool("zoomIn");
1570
//                        PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
1571
//
1572
//                        parameters.getMapControl().drawMap(false);
1573
//                }
1574
        }
1575
        
1576
//        protected Behavior getCombinedTool() {
1577
//                if (combinedTool == null) {
1578
//                        combinedTool = new AdaptedPointBehavior(new AddDerivativeGeometriesListener(this));
1579
//                }
1580
//
1581
//                return combinedTool;
1582
//        }
1583

    
1584
        public DerivedGeometryProcessParameters getParameters() {
1585
                return parameters;
1586
        }
1587

    
1588
        public void selectGeometry(int geometryIndex) {
1589
                // Selects in the table with all geometries
1590
                getAllFeaturesTable().getSelectionModel().addSelectionInterval(geometryIndex, geometryIndex);
1591
        }
1592
        
1593
//        protected void removeCombinedTool() {
1594
//                Behavior cTool = (Behavior) parameters.getMapControl().getCombinedTool();
1595
//
1596
//                if (cTool == null)
1597
//                        return;
1598
//
1599
//                if (cTool instanceof CompoundBehavior)
1600
//                        ((CompoundBehavior)cTool).removeMapBehavior(getCombinedTool());
1601
//                else {
1602
//                        if (cTool.equals(getCombinedTool()))
1603
//                                parameters.getMapControl().removeCombinedTool();
1604
//                }
1605
                
1606
//                parameters.getMapControl().removeCombinedTool(getCombinedTool());
1607
//        }
1608

    
1609
        protected void refreshSelectedGeometries() {
1610
                try {
1611
                        SelectableDataSource sds = parameters.getSourceLayer().getRecordset();
1612
                        FBitSet newSelection = (FBitSet) sds.getSelection().clone();
1613
                        newSelection.clear();
1614
                        
1615
                        int[] sRows = getAllFeaturesTable().getSelectedRows();
1616

    
1617
                        for (int i = 0; i < sRows.length; i++) {
1618
                                newSelection.set( sRows[i] );
1619
                        }
1620

    
1621
                        sds.setSelection(newSelection);
1622
                }
1623
                catch (Exception ex) {
1624
                        NotificationManager.showMessageError(PluginServices.getText(null, "Failed_selecting_geometries_in_layer"), ex);
1625
                }
1626
        }
1627

    
1628
        protected void registerViewListener() {
1629
        /* Window listener -> hides this control panel when the view looses the window is closed */
1630
        Container container = parameters.getView();
1631
        
1632
        if (container == null)
1633
                return;
1634
        
1635
        while (! (container instanceof JInternalFrame) ) {
1636
                container = container.getParent();
1637
                
1638
                if (container == null)
1639
                        return;
1640
        }
1641

    
1642
        container.addComponentListener(getViewListener());
1643
        }
1644
        
1645
        protected void unregisterViewListener() {
1646
        /* Window listener -> hides this control panel when the view looses the window is closed */
1647
        Container container = parameters.getView();
1648

    
1649
        if (container == null)
1650
                return;
1651
        
1652
        while (! (container instanceof JInternalFrame) ) {
1653
                container = container.getParent();
1654
                
1655
                if (container == null)
1656
                        return;
1657
        }
1658

    
1659
        container.removeComponentListener(getViewListener());
1660
        }
1661
        
1662
        protected void updateViewListener() {
1663
                // Forces to set the view listener to the associated view
1664
                // (When a view is closed, next time is opened, the container (JInternalFrame) is another object)
1665
                unregisterViewListener();
1666
                registerViewListener();
1667
        }
1668

    
1669
        protected ComponentListener getViewListener() {
1670
                if (viewListener == null) {
1671
                        viewListener = new ComponentAdapter() {
1672
                                /*
1673
                                 * (non-Javadoc)
1674
                                 * @see java.awt.event.ComponentAdapter#componentHidden(java.awt.event.ComponentEvent)
1675
                                 */
1676
                                public void componentHidden(ComponentEvent e) {
1677
                                        mustRestoreWindow = true;
1678

    
1679
                                        // Hides the control panel
1680
                                        closeWindow();
1681
                                        
1682
                                        isShown = false;
1683
                                }
1684
                };
1685
                }
1686

    
1687
                return viewListener;
1688
        }
1689

    
1690
        protected LayerCollectionListener getNewLayerCollectionListener() {
1691
                if (newLayerCollectionListener == null) {
1692
                        newLayerCollectionListener = new LayerCollectionListener() {
1693

    
1694
                                public void layerAdded(LayerCollectionEvent e) {
1695
                                }
1696

    
1697
                                public void layerAdding(LayerCollectionEvent e)
1698
                                                throws CancelationException {
1699
                                        
1700
                                }
1701

    
1702
                                public void layerMoved(LayerPositionEvent e) {
1703
                                        
1704
                                }
1705

    
1706
                                public void layerMoving(LayerPositionEvent e)
1707
                                                throws CancelationException {
1708
                                        
1709
                                }
1710

    
1711
                                public void layerRemoved(LayerCollectionEvent e) {
1712
                                        
1713
                                }
1714

    
1715
                                public void layerRemoving(LayerCollectionEvent e) throws CancelationException {
1716
                                        // Asks user to confirm removing the destination layer (that will also remove this control panel)
1717
                                        //if ((parameters.getDestLayer() != null) && (e.getAffectedLayer() == parameters.getDestLayer()) && (JOptionPane.showConfirmDialog(parameters.getView(), PluginServices.getText(null, "Really_want_remove_to_the_layer") + " " + parameters.getDestLayer().getName(), PluginServices.getText(null, "Confirmation"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) {
1718
                                        try {
1719
                                                doUnregistration();
1720
                                                closeWindow();
1721
                                                JOptionPane.showMessageDialog(parameters.getMapControl(), PluginServices.getText(null, "Finished_the_derivative_geometries_tool_in_layers") + ": " + parameters.getSourceLayer().getName() + ", " + e.getAffectedLayer().getName(), PluginServices.getText(null, "Information"), JOptionPane.INFORMATION_MESSAGE);
1722
                                        }
1723
                                        catch(Exception ex)  {
1724
                                                NotificationManager.showMessageError(PluginServices.getText(null, "Failed_finishing_the_derivative_geometries_tool_in_layer") + ": " + e.getAffectedLayer().getName(), ex);
1725
                                        }
1726
                                        //}
1727
                                }
1728

    
1729
                                public void visibilityChanged(LayerCollectionEvent e)
1730
                                                throws CancelationException {
1731
                                        
1732
                                }
1733
                        };
1734
                }
1735
                
1736
                return newLayerCollectionListener;
1737
        }
1738

    
1739
//        public ComponentListener getViewListener() {
1740
//                if (viewListener == null) {
1741
//                        viewListener = new ComponentAdapter() {
1742
//
1743
//                                public void componentHidden(ComponentEvent e) {
1744
//                                        mustRestoreWindow = true;
1745
//                                        closeWindow();
1746
//                                }
1747
//
1748
//                                public void componentMoved(ComponentEvent e) {
1749
//                                }
1750
//
1751
//                                public void componentResized(ComponentEvent e) {
1752
//                                }
1753
//
1754
//                                public void componentShown(ComponentEvent e) {
1755
//                                        if (mustRestoreWindow) {
1756
//                                                showWindow();
1757
//                                                mustRestoreWindow = false;
1758
//                                        }
1759
//                                }
1760
//                };
1761
//                }
1762
//                
1763
//                return viewListener;
1764
//        }
1765
        
1766
    
1767
    /**
1768
     * As combined tool, in a CompoundBehavior its "paintComponent" method is always called. The idea is painting nothing to
1769
     * accelerate the MapControl painting process.
1770
     * 
1771
     * @see PointBehavior
1772
     * 
1773
         * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
1774
     */
1775
    protected class AdaptedPointBehavior extends PointBehavior {
1776
            /**
1777
             * @see PointBehavior#PointBehavior(PointListener)
1778
             */
1779
                public AdaptedPointBehavior(PointListener mli) {
1780
                        super(mli);
1781
                }
1782
            
1783
                /*
1784
                 * (non-Javadoc)
1785
                 * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
1786
                 */
1787
                public void paintComponent(Graphics g) {
1788
                        //super.paintComponent(g);
1789
                }
1790
    }
1791

    
1792
        public Object getWindowProfile() {
1793
                return WindowInfo.DIALOG_PROFILE;
1794
        }
1795

    
1796
        public void drawValueChanged(LayerEvent e) {
1797
        }
1798
}