Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSAreaPanel.java @ 10341

History | View | Annotate | Download (93.7 KB)

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

    
3
import java.awt.Color;
4
import java.awt.Dimension;
5
import java.awt.GridBagLayout;
6
import java.awt.Point;
7
import java.awt.Rectangle;
8
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionListener;
10
import java.awt.event.FocusAdapter;
11
import java.awt.event.FocusEvent;
12
import java.awt.event.FocusListener;
13
import java.awt.event.ItemEvent;
14
import java.awt.event.ItemListener;
15
import java.awt.event.MouseAdapter;
16
import java.awt.event.MouseEvent;
17
import java.awt.event.MouseListener;
18
import java.awt.event.MouseMotionListener;
19
import java.awt.event.MouseWheelListener;
20
import java.awt.geom.Rectangle2D;
21
import java.io.Serializable;
22

    
23
import javax.swing.ImageIcon;
24
import javax.swing.JComboBox;
25
import javax.swing.JLabel;
26
import javax.swing.JOptionPane;
27
import javax.swing.JPanel;
28
import javax.swing.JRadioButton;
29
import javax.swing.JTextField;
30
import javax.swing.JToggleButton;
31
import javax.swing.SwingConstants;
32

    
33
import com.iver.andami.PluginServices;
34
import com.iver.andami.messages.NotificationManager;
35
import com.iver.cit.gvsig.fmap.ColorEvent;
36
import com.iver.cit.gvsig.fmap.DriverException;
37
import com.iver.cit.gvsig.fmap.ExtentEvent;
38
import com.iver.cit.gvsig.fmap.MapContext;
39
import com.iver.cit.gvsig.fmap.MapControl;
40
import com.iver.cit.gvsig.fmap.ProjectionEvent;
41
import com.iver.cit.gvsig.fmap.ViewPort;
42
import com.iver.cit.gvsig.fmap.ViewPortListener;
43
import com.iver.cit.gvsig.fmap.layers.XMLException;
44
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
45
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
46
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
47
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior;
48
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
49
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior;
50
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior;
51
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
52
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
53
//import com.iver.cit.gvsig.project.documents.ProjectDocument;
54
import com.iver.cit.gvsig.project.documents.view.gui.View;
55
import com.iver.cit.gvsig.project.documents.view.toolListeners.AreaListener;
56
import com.iver.cit.gvsig.project.documents.view.toolListeners.MeasureListener;
57
import com.iver.cit.gvsig.project.documents.view.toolListeners.PanListener;
58
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
59
import com.iver.cit.gvsig.project.documents.view.toolListeners.ZoomInListener;
60
import com.iver.cit.gvsig.project.documents.view.toolListeners.ZoomOutListener;
61
import com.iver.utiles.stringNumberUtilities.StringNumberUtilities;
62

    
63
import javax.swing.JButton;
64

    
65
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.ImageIconItemInfo;
66
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.JComboBoxWithImageIconItems;
67
import org.gvsig.gui.beans.swing.jTextFieldWithSpecificCaretPosition.JTextFieldWithSpecificCaretPosition;
68

    
69

    
70

    
71
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
72
 *
73
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
74
 *
75
 * This program is free software; you can redistribute it and/or
76
 * modify it under the terms of the GNU General Public License
77
 * as published by the Free Software Foundation; either version 2
78
 * of the License, or (at your option) any later version.
79
 *
80
 * This program is distributed in the hope that it will be useful,
81
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
83
 * GNU General Public License for more details.
84
 *
85
 * You should have received a copy of the GNU General Public License
86
 * along with this program; if not, write to the Free Software
87
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
88
 *
89
 * For more information, contact:
90
 *
91
 *  Generalitat Valenciana
92
 *   Conselleria d'Infraestructures i Transport
93
 *   Av. Blasco Ib??ez, 50
94
 *   46010 VALENCIA
95
 *   SPAIN
96
 *
97
 *      +34 963862235
98
 *   gvsig@gva.es
99
 *      www.gvsig.gva.es
100
 *
101
 *    or
102
 *
103
 *   IVER T.I. S.A
104
 *   Salamanca 50
105
 *   46005 Valencia
106
 *   Spain
107
 *
108
 *   +34 963163400
109
 *   dac@iver.es
110
 */
111
/* CVS MESSAGES:
112
 *
113
 * $Id: WFSAreaPanel.java 10341 2007-02-15 11:36:57Z ppiqueras $
114
 * $Log$
115
 * Revision 1.15  2007-02-15 11:36:57  ppiqueras
116
 * Mejorada la interfaz: nuevas herramientas, mejoradas las de coordenadas absolutas. Y corregido alg?n bug de interacci?n con otros paneles.
117
 *
118
 * Revision 1.14  2007/02/12 11:29:37  ppiqueras
119
 * Mejoras de la interfaz y uso de las herramientas
120
 *
121
 * Revision 1.13  2007/02/09 14:22:07  ppiqueras
122
 * Mejoras de funcionalidad
123
 *
124
 * Revision 1.12  2007/02/09 13:56:56  ppiqueras
125
 * Mejorada la funcionalidad de la interfaz: ya hay varias herramientas que se pueden usar.
126
 *
127
 * Revision 1.11  2007/02/08 14:18:57  ppiqueras
128
 * Carga de la vista actual.
129
 *
130
 * Revision 1.10  2007/02/05 13:49:26  ppiqueras
131
 * Mejorada la interfaz y a?adidos componentes de tipo lista desplegable con iconos como ?tems.
132
 *
133
 * Revision 1.9  2007/02/02 12:22:03  ppiqueras
134
 * Mejorada la interfaz.
135
 *
136
 * Revision 1.8  2007/01/26 14:23:56  ppiqueras
137
 * Mejorada la interfaz
138
 *
139
 * Revision 1.7  2007/01/25 14:37:16  ppiqueras
140
 * Utiliza JTextFieldWithSpecificCaretPosition
141
 *
142
 * Revision 1.6  2007/01/25 09:31:09  ppiqueras
143
 * Mejorada la interfaz.
144
 *
145
 * Revision 1.5  2007/01/19 14:24:30  ppiqueras
146
 * + Avanzada.
147
 *
148
 * Revision 1.4  2007/01/12 13:09:41  jorpiell
149
 * added searches by area
150
 *
151
 * Revision 1.3  2007/01/10 09:01:25  jorpiell
152
 * The coordinates panel is opened with the view coordinates
153
 *
154
 * Revision 1.2  2006/12/22 11:45:53  jorpiell
155
 * Actualizado el driver del WFS
156
 *
157
 * Revision 1.1  2006/10/10 12:55:06  jorpiell
158
 * Se ha a?adido el soporte de features complejas
159
 *
160
 *
161
 */
162

    
163
/**
164
 * This panel allows user to select the area he/she wants to get in the view.
165
 * There are two options to do this:
166
 *  - Indicating the coordinates of the top-left and down-right corners
167
 *  - Selecting the area with the mouse
168
 * 
169
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
170
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
171
 */
172
public class WFSAreaPanel extends JPanel {
173
        private final Rectangle DEFAULT_BOUNDS = new Rectangle(10, 5, 490, 380);
174
        private final Rectangle DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE = new Rectangle(8, 20, 481, 60);
175
        private final Rectangle DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE = new Rectangle(8, 115, 481, 265);
176

    
177
//        private final Rectangle DEFAULT_COORDINATES_CHECKBOX_RECTANGLE = new Rectangle(6, 19, 445, 20);
178
        private final Rectangle DEFAULT_UNDO_ICON_BUTTON_RECTANGLE = new Rectangle (250, 85, 25, 25);
179
        private final Rectangle DEFAULT_REDO_ICON_BUTTON_RECTANGLE = new Rectangle (277, 85, 25, 25);
180
        private final Rectangle DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (304, 85, 25, 25);
181
        private final Rectangle DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (331, 85, 25, 25);
182
        private final Rectangle DEFAULT_PAN_ICON_BUTTON_RECTANGLE = new Rectangle(250, 85, 25, 25);
183
        private final Rectangle DEFAULT_TOOL_JCOMBOBOX_RECTANGLE = new Rectangle(10, 87, 230, 21);
184
        private final Rectangle DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE = new Rectangle(277, 85, 47, 25);
185
//        private final Rectangle DEFAULT_ZOOMIN_ICON_BUTTON_RECTANGLE = new Rectangle(297,100,25,25);
186
//        private final Rectangle DEFAULT_ZOOMOUT_ICON_BUTTON_RECTANGLE = new Rectangle(324,100,25,25);
187
//        private final Rectangle DEFAULT_ZOOMRECTANGLESELECTION_ICON_BUTTON_RECTANGLE = new Rectangle(326, 85, 25, 25);
188
        private final Rectangle DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE = new Rectangle(326, 85, 25, 25);
189
        private final Rectangle DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE = new Rectangle(353, 85, 25, 25);
190
        private final Rectangle DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE = new Rectangle(380, 85, 47, 25);
191
        private final Rectangle DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE = new Rectangle(429, 85, 47, 25);
192
        //        private final Rectangle DEFAULT_ZOOMINVIEWCENTERED_ICON_BUTTON_RECTANGLE = new Rectangle(378,100,25,25);
193
//        private final Rectangle DEFAULT_ZOOMOUTVIEWCENTERED_ICON_BUTTON_RECTANGLE = new Rectangle(405,100,25,25);
194
//        private final Rectangle DEFAULT_INFO_ICON_BUTTON_RECTANGLE_V1 = new Rectangle(277, 85, 25, 25);
195
//        private final Rectangle DEFAULT_INFO_ICON_BUTTON_RECTANGLE_V2 = new Rectangle(429, 85, 25, 25);
196
//        private final Rectangle DEFAULT_TOOLS_ICON_BUTTON_RECTANGLE = new Rectangle(459,100,25,25);
197
        
198
        private final int DISABLED_OPERATION = 0;
199
        private final int SELECTION_BY_COORDINATES_OPERATION = 1;
200
        private final int SELECTION_BY_AREA_OPERATION = 2;
201
        
202
        private WFSWizardData data = null;
203
        private WFSParamsPanel parent = null;
204
        private AreaCoordinatesPanel coordinatesPanel = null;
205
        private SelectableMapControlAreaPanel selectableMapAreaPanel = null;
206
        private JComboBox jComboBoxToolSelection = null;
207
        private JButton jButtonUndo = null;
208
        private JButton jButtonRedo = null;
209
        private JToggleButton jToggleButtonMove = null;
210
        private JToggleButton jToggleButtonScaling = null;
211
        private JButton jButtonPan = null;
212
//        private JButton jButtonZoomIn = null;
213
//        private JButton jButtonZoomOut = null;
214
//        private JButton jButtonZoomRectangleSelection = null;
215
        private JButton jButtonZoomPrevious = null;
216
        private JButton jButtonZoomComplete = null;
217
//        private JButton jButtonZoomInViewCentered = null;
218
//        private JButton jButtonZoomOutViewCentered = null;
219
//        private JButton jButtonInfo = null;
220
//        private JButton jButtonTools = null;
221
        private JComboBoxWithImageIconItems jComboBoxZoomInAndOut = null;
222
        private JComboBoxWithImageIconItems jComboBoxZoomInAndOutViewCentered = null;
223
        private JComboBoxWithImageIconItems jComboBoxOtherTools = null;
224
        
225
//        private Point last_V1;
226
//        private Point last_V2;
227
        
228
        /* Tool identifier constants */
229
        private final String PAN_TOOL = "HAND";
230
//        private final String ERASER_TOOL = "ERASER";
231
        private final String ZOOM_IN_TOOL = "zoomIn"; // This constant must be 'zoomIn' for a correct operation of the tools 'Zoom In' and 'Zoom In Map Centered'
232
        private final String ZOOM_OUT_TOOL = "zoomOut"; // This constant must be 'zoomOut' for a correct operation of the tools 'Zoom Out' and 'Zoom Out Map Centered'
233
//        private final String ZOOM_RECTANGLE_SELECTION_TOOL = "ZOOM_RECTANGLE_SELECTION";
234
//        private final String ZOOM_PREVIOUS_TOOL = "ZOOM_PREVIOUS";
235
//        private final String ZOOM_COMPLETE_TOOL = "ZOOM_COMPLETE";
236
        private final String ZOOM_IN_VIEW_CENTERED_TOOL = "ZOOM_IN_VIEW_CENTERED";
237
        private final String ZOOM_OUT_VIEW_CENTERED_TOOL = "ZOOM_OUT_VIEW_CENTERED";
238
//        private final String INFO_TOOL = "INFO_TOOL";
239
        private final String MEASURE_DISTANCES_TOOL = "MEASURE_DISTANCES";
240
        private final String MEASURE_AREA_TOOL = "MEASURE_AREA";
241
        /* End tool identifier constants */
242
        
243
        
244
        /**
245
         * This method initializes
246
         */
247
        public WFSAreaPanel(WFSParamsPanel parent) {
248
                super();
249
                this.parent = parent;
250
                initialize();
251
        }
252

    
253
        /**
254
         * This method initializes this
255
         */
256
        private void initialize() {
257
                this.setLayout(null);
258
                this.setBounds(DEFAULT_BOUNDS);
259
                this.setBorder(javax.swing.BorderFactory.createTitledBorder(
260
                                null, PluginServices.getText(this, "select_by_area"),
261
                                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
262
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
263
                
264
                // Adds JPanel with the coordinates
265
                this.add(getCoordinatesPanel(), null);
266
                
267
                // Adds JComboBox to select a part of the graphical interface 
268
                this.add(getJComboBoxToolSelection(), null);
269
                this.getJComboBoxToolSelection().setSelectedIndex(0); // By default select first element
270

    
271
                // Adds Icons
272
//                this.add(getJButtonPan(), null);
273
////                this.add(getJButtonZoomIn(), null);
274
////                this.add(getJButtonZoomOut(), null);
275
//                this.add(getJComboBoxZoomInAndOut(), null);
276
//                this.add(getJButtonZoomRectangleSelection(), null);
277
//                this.add(getJButtonZoomPrevious(), null);
278
//                this.add(getJButtonZoomComplete(), null);
279
//                this.add(getJComboBoxZoomInAndOutViewCentered(), null);
280
//                this.add(getJButtonInfo(), null);
281
                
282
                // Adds Jpanel with the view
283
                this.add(getSelectableMapAreaPanel(), null);
284
//                this.add(get, null);
285
                
286
                initCoordinates();
287
                
288
                // DE PRUEBA
289
//                getJComboBoxToolSelection().setSelectedIndex(2);
290
        }        
291

    
292
        /**
293
         * Write the view coordinates into the coordinates panel
294
         */
295
        private void initCoordinates(){
296
                View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
297
//                Rectangle2D r2d= activeView.getMapControl().getViewPort().getAdjustedExtent();
298
                Rectangle2D r2d = activeView.getMapControl().getViewPort().getExtent();
299
                if (r2d != null){
300
//                        getCoordinatesPanel().setExtent(r2d);
301
                        getCoordinatesPanel().getJTextFieldVertex1X().setText(Double.toString(r2d.getMaxX()));
302
                        getCoordinatesPanel().getJTextFieldVertex1Y().setText(Double.toString(r2d.getMaxY()));
303
                        getCoordinatesPanel().getJTextFieldVertex2X().setText(Double.toString(r2d.getMinX()));
304
                        getCoordinatesPanel().getJTextFieldVertex2Y().setText(Double.toString(r2d.getMinY()));
305
                }
306
        }
307
        
308
        /**
309
         * This method initializes coordinatesPanel        
310
         *         
311
         * @return javax.swing.JPanel        
312
         */
313
        private AreaCoordinatesPanel getCoordinatesPanel() {
314
                if (coordinatesPanel == null) {
315
                        coordinatesPanel = new AreaCoordinatesPanel();
316
                }
317
                return coordinatesPanel;
318
        }
319

    
320
        /**
321
         * This method initializes jComboBoxToolSelection
322
         * 
323
         * @return  javax.swing.JComboBox
324
         */
325
        private JComboBox getJComboBoxToolSelection() {
326
                if (jComboBoxToolSelection == null) {
327
                        jComboBoxToolSelection = new JComboBox();
328
                        jComboBoxToolSelection.setBounds(DEFAULT_TOOL_JCOMBOBOX_RECTANGLE);
329
                        jComboBoxToolSelection.setToolTipText(PluginServices.getText(this, "select_a_tool"));
330
                        jComboBoxToolSelection.setEditable(false);
331
                        jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "disabled"), this.DISABLED_OPERATION));
332
                        jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "define_absolute_coordinates"), this.SELECTION_BY_COORDINATES_OPERATION));
333
                        jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "define_coordinates_using_view"), this.SELECTION_BY_AREA_OPERATION));
334
                        
335
                        jComboBoxToolSelection.addActionListener(new ActionListener() {
336
                                /*
337
                                 * (non-Javadoc)
338
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
339
                                 */
340
                                public void actionPerformed(ActionEvent e) {
341
                                         JComboBox cb = (JComboBox)e.getSource();
342
                                         switch(((ItemOperation)cb.getSelectedItem()).getOperation()) {
343
                                                 case DISABLED_OPERATION:
344
                                                         disableCoorderatesRegionOperation();
345
                                                         disableAreaRegionOperation();
346
                                                         break;
347
                                                 case SELECTION_BY_COORDINATES_OPERATION:
348
                                                         disableAreaRegionOperation();
349
                                                         enableCoorderatesRegionOperation();
350
                                                         break;
351
                                                 case SELECTION_BY_AREA_OPERATION:
352
                                                         // Only enable the area operation if there is data loaded in this MapControl
353
                                                         if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) {
354
                                                                 disableCoorderatesRegionOperation();
355
                                                                 enableAreaRegionOperation();
356
                                                         }
357
                                                         else {
358
                                                                 JOptionPane.showMessageDialog(jComboBoxToolSelection, PluginServices.getText(null, "there_is_no_layer_loaded_in_the_active_view"), PluginServices.getText(null, "information"), JOptionPane.INFORMATION_MESSAGE);
359
                                                                 
360
                                                                 // Select: no tools
361
                                                                 jComboBoxToolSelection.setSelectedIndex(0);
362
                                                         }
363

    
364
                                                         break;
365
                                                 }
366
                                }                                
367
                        });
368
                }
369
                return jComboBoxToolSelection;
370
        }
371

    
372
        /**
373
         * Enables the components associated to the selection of area by coordinates
374
         */
375
        private void enableCoorderatesRegionOperation() {
376
                // Adds associated icons
377
                this.add(getJButtonUndo(), null);
378
                this.add(getJButtonRedo(), null);
379
                this.add(getJToggleButtonMove(), null);
380
                this.add(getJToggleButtonScaling(), null);
381
//                this.add(getJButtonInfo(), null);
382
                
383
                getCoordinatesPanel().setAllTextFieldsEnabled(true);
384
                getCoordinatesPanel().getJRadioButtonPreviewArea().setEnabled(true);
385
                
386
                // Force update this panel
387
//                this.invalidate();
388
        }
389

    
390
        /**
391
         * Enables the components associated to the selection of area by view
392
         */
393
        private void enableAreaRegionOperation() {
394
                // Adds associated icons
395
                this.add(getJButtonPan(), null);
396
//                this.add(getJButtonZoomIn(), null);
397
//                this.add(getJButtonZoomOut(), null);
398
                this.add(getJComboBoxZoomInAndOut(), null);
399
                getJComboBoxZoomInAndOut().revalidate(); // Force update this component
400
//                this.add(getJButtonZoomRectangleSelection(), null);
401
                this.add(getJButtonZoomPrevious(), null);
402
                this.add(getJButtonZoomComplete(), null);
403
                this.add(getJComboBoxZoomInAndOutViewCentered(), null);
404
                getJComboBoxZoomInAndOutViewCentered().revalidate(); // Force update this component
405
                this.add(getJComboBoxOtherTools(), null);
406
                getJComboBoxOtherTools().revalidate(); // Force update this component
407
//                this.add(getJButtonInfo(), null);        
408
                
409
                // Enables the icons
410
//                getJButtonPan().setEnabled(true);
411
//                getJComboBoxZoomInAndOut().setEnabled(true);
412
//                getJButtonZoomRectangleSelection().setEnabled(true);
413
//                getJButtonZoomPrevious().setEnabled(true);
414
//                getJButtonZoomComplete().setEnabled(true);
415
//                getJComboBoxZoomInAndOutViewCentered().setEnabled(true);
416
                
417
                // Enables the MapControl area
418
                getSelectableMapAreaPanel().setEnabled(true);
419
//                getSelectableMapAreaPanel().enableAllMouseListeners();
420

    
421
                // Force update this panel
422
//                this.invalidate();
423
        }
424

    
425
        /**
426
         * Disables the components associated to the selection of area by coordinates
427
         */
428
        private void disableCoorderatesRegionOperation() {
429
                // Removes associated icons
430
                this.remove(getJButtonUndo());
431
                this.remove(getJButtonRedo());
432
                this.remove(getJToggleButtonMove());                
433
                this.remove(getJToggleButtonScaling());                
434
//                if (jButtonInfo != null)
435
//                        this.remove(jButtonInfo);        
436

    
437
                getCoordinatesPanel().setAllTextFieldsEnabled(false);
438
                getCoordinatesPanel().getJRadioButtonPreviewArea().setEnabled(false);
439
                
440
                // Force update this panel
441
//                this.invalidate();
442
        }
443

    
444
        /**
445
         * Disables the components associated to the selection of area by view
446
         */
447
        private void disableAreaRegionOperation() {
448
                // Removes associated icons
449
                this.remove(getJButtonPan());
450
//                this.add(getJButtonZoomIn(), null);
451
//                this.add(getJButtonZoomOut(), null);
452
                this.remove(getJComboBoxZoomInAndOut());
453
//                this.remove(getJButtonZoomRectangleSelection());
454
                this.remove(getJButtonZoomPrevious());
455
                this.remove(getJButtonZoomComplete());
456
                this.remove(getJComboBoxZoomInAndOutViewCentered());
457
                this.remove(getJComboBoxOtherTools());
458
                
459
//                if (jButtonInfo != null)
460
//                        this.remove(jButtonInfo);        
461

    
462
                
463
                // Disables the icons
464
//                getJButtonPan().setEnabled(false);
465
//                getJComboBoxZoomInAndOut().setEnabled(false);
466
//                getJButtonZoomRectangleSelection().setEnabled(false);
467
//                getJButtonZoomPrevious().setEnabled(false);
468
//                getJButtonZoomComplete().setEnabled(false);
469
//                getJComboBoxZoomInAndOutViewCentered().setEnabled(false);
470
                
471
                // Disables the MapControl area
472
//                getSelectableMapAreaPanel().disableAllMouseListeners();
473
                getSelectableMapAreaPanel().setEnabled(false);
474

    
475
                // Force update this panel
476
//                this.invalidate();
477
        }
478

    
479
        /**
480
         * This method initializes areaMapControlPanel
481
         * 
482
         * @return A reference to an object of SelectableMapControlAreaPanel
483
         */
484
        private SelectableMapControlAreaPanel getSelectableMapAreaPanel() {
485
                if (selectableMapAreaPanel == null) {
486
                        selectableMapAreaPanel = new SelectableMapControlAreaPanel();
487
                }
488

    
489
                return selectableMapAreaPanel;
490
        }
491

    
492
        /**
493
         * This method initializes jButtonUndo
494
         * 
495
         * @return javax.swing.JButton
496
         */
497
        private JButton getJButtonUndo() {
498
                if (jButtonUndo == null) {
499
                        jButtonUndo = new JButton();
500
                        jButtonUndo.setBounds(DEFAULT_UNDO_ICON_BUTTON_RECTANGLE);
501
                        jButtonUndo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/edit-undo.png")));
502
                        jButtonUndo.setToolTipText(PluginServices.getText(this, "previous_area"));
503
                        jButtonUndo.addMouseListener(new MouseAdapter() {
504
                                /*
505
                                 * (non-Javadoc)
506
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
507
                                 */
508
                                public void mouseClicked(MouseEvent e) {
509
                                        goToPreviousZoom();
510
                                }
511
                        });
512
                }
513
                
514
                return jButtonUndo;
515
        }
516
        
517
        /**
518
         * This method initializes jButtonUndo
519
         * 
520
         * @return javax.swing.JButton
521
         */
522
        private JButton getJButtonRedo() {
523
                if (jButtonRedo == null) {
524
                        jButtonRedo = new JButton();
525
                        jButtonRedo.setBounds(DEFAULT_REDO_ICON_BUTTON_RECTANGLE);
526
                        jButtonRedo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/edit-redo.png")));
527
                        jButtonRedo.setToolTipText(PluginServices.getText(this, "following_area"));
528
                }
529
                
530
                return jButtonRedo;
531
        }
532
        
533
        /**
534
         * This method initializes jToggleButtonMove
535
         * 
536
         * @return javax.swing.JButton
537
         */
538
        private JToggleButton getJToggleButtonMove() {
539
                if (jToggleButtonMove == null) {
540
                        jToggleButtonMove = new JToggleButton();
541
                        jToggleButtonMove.setBounds(DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE);
542
                        jToggleButtonMove.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/move.png")));
543
                        jToggleButtonMove.setToolTipText(PluginServices.getText(this, "move"));
544
                        jToggleButtonMove.addItemListener(new ItemListener() {
545
                                /*
546
                                 *  (non-Javadoc)
547
                                 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
548
                                 */
549
                                public void itemStateChanged(ItemEvent e) {
550
                                        // Isn't allowed that the two JToggleButton would be selected (can't move and scale)
551
                                        if (jToggleButtonMove.isSelected())
552
                                                jToggleButtonScaling.setSelected(false);
553
                                }
554
                        });
555
                }
556
                
557
                return jToggleButtonMove;
558
        }
559
        
560
        /**
561
         * This method initializes jToggleButtonScaling
562
         * 
563
         * @return javax.swing.JButton
564
         */
565
        private JToggleButton getJToggleButtonScaling() {
566
                if (jToggleButtonScaling == null) {
567
                        jToggleButtonScaling = new JToggleButton();
568
                        jToggleButtonScaling.setBounds(DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE);
569
                        jToggleButtonScaling.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/scaling.png")));
570
                        jToggleButtonScaling.setToolTipText(PluginServices.getText(this, "scaling"));
571
                        jToggleButtonScaling.addItemListener(new ItemListener() {
572
                                /*
573
                                 *  (non-Javadoc)
574
                                 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
575
                                 */
576
                                public void itemStateChanged(ItemEvent e) {
577
                                        // Isn't allowed that the two JToggleButton would be selected (can't move and scale)
578
                                        if (jToggleButtonScaling.isSelected())
579
                                                jToggleButtonMove.setSelected(false);
580
                                }
581
                        });
582
                }
583
                
584
                return jToggleButtonScaling;
585
        }
586
        /**
587
         * This method initializes jButtonPan        
588
         *         
589
         * @return javax.swing.JButton        
590
         */
591
        private JButton getJButtonPan() {
592
                if (jButtonPan == null) {
593
                        jButtonPan = new JButton();
594
                        jButtonPan.setBounds(DEFAULT_PAN_ICON_BUTTON_RECTANGLE);
595
                        jButtonPan.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/Pan.png")));
596
                        jButtonPan.setToolTipText(PluginServices.getText(this, "Desplazamiento"));
597
                        jButtonPan.addMouseListener(new MouseAdapter() {
598
                                /*
599
                                 * (non-Javadoc)
600
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
601
                                 */
602
                                public void mouseClicked(MouseEvent e) {
603
                                        getSelectableMapAreaPanel().setTool(PAN_TOOL);
604
                                }
605
                        });
606
                }
607
                return jButtonPan;
608
        }
609

    
610
        /**
611
         * This method initializes jComboBoxZoomInAndOut        
612
         *         
613
         * @return         
614
         */
615
        private JComboBoxWithImageIconItems getJComboBoxZoomInAndOut() {
616
                if (jComboBoxZoomInAndOut == null) {
617
                        jComboBoxZoomInAndOut = new JComboBoxWithImageIconItems();
618
                        jComboBoxZoomInAndOut.setBounds(DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE);
619
                        jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo("images/ZoomIn.png", new ImageIcon(getClass().getClassLoader().getResource("images/ZoomIn.png")), PluginServices.getText(this, "Zoom_Mas"), ZOOM_IN_TOOL));
620
                        jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo("images/ZoomOut.png", new ImageIcon(getClass().getClassLoader().getResource("images/ZoomOut.png")), PluginServices.getText(this, "Zoom_Menos"), ZOOM_OUT_TOOL));
621
                        jComboBoxZoomInAndOut.addActionListener(new ActionListener() {
622
                                /*
623
                                 *  (non-Javadoc)
624
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
625
                                 */
626
                                public void actionPerformed(ActionEvent e) {
627
                                        JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
628
                                        ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
629
                                        getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
630
                                }
631
                });
632
                }
633

    
634
                return jComboBoxZoomInAndOut;
635
        }
636
        
637
//        /**
638
//         * This method initializes jButtonZoomOut        
639
//         *         
640
//         * @return javax.swing.JButton        
641
//         */
642
//        private JButton getJButtonZoomOut() {
643
//                if (jButtonZoomOut == null) {
644
//                        jButtonZoomOut = new JButton();
645
//                        jButtonZoomOut.setBounds(DEFAULT_ZOOMOUT_ICON_BUTTON_RECTANGLE);
646
//                        jButtonZoomOut.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/ZoomOut.png")));
647
//                }
648
//                return jButtonZoomOut;
649
//        }
650
//
651
//        /**
652
//         * This method initializes jButtonZoomIn        
653
//         *         
654
//         * @return javax.swing.JButton        
655
//         */
656
//        private JButton getJButtonZoomIn() {
657
//                if (jButtonZoomIn == null) {
658
//                        jButtonZoomIn = new JButton();
659
//                        jButtonZoomIn.setBounds(DEFAULT_ZOOMIN_ICON_BUTTON_RECTANGLE);
660
//                        jButtonZoomIn.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/ZoomIn.png")));
661
//                }
662
//                return jButtonZoomIn;
663
//        }
664

    
665
//        /**
666
//         * This method initializes jButtonZoomRectangleSelection        
667
//         *         
668
//         * @return javax.swing.JButton        
669
//         */
670
//        private JButton getJButtonZoomRectangleSelection() {
671
//                if (jButtonZoomRectangleSelection == null) {
672
//                        jButtonZoomRectangleSelection = new JButton();
673
//                        jButtonZoomRectangleSelection.setBounds(DEFAULT_ZOOMRECTANGLESELECTION_ICON_BUTTON_RECTANGLE);
674
//                        jButtonZoomRectangleSelection.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/ZoomSeleccion.png")));
675
//                        jButtonZoomRectangleSelection.setToolTipText(PluginServices.getText(this, "seleccionar_por_rectangulo"));
676
//                        jButtonZoomRectangleSelection.addMouseListener(new MouseAdapter() {
677
//                                /*
678
//                                 * (non-Javadoc)
679
//                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
680
//                                 */
681
//                                public void mouseClicked(MouseEvent e) {
682
//                                        getSelectableMapAreaPanel().setTool(ZOOM_RECTANGLE_SELECTION_TOOL);
683
//                                }
684
//                        });
685
//                }
686
//                return jButtonZoomRectangleSelection;
687
//        }
688

    
689
        /**
690
         * This method initializes jButtonZoomPrevious        
691
         *         
692
         * @return javax.swing.JButton        
693
         */
694
        private JButton getJButtonZoomPrevious() {
695
                if (jButtonZoomPrevious == null) {
696
                        jButtonZoomPrevious = new JButton();
697
                        jButtonZoomPrevious.setBounds(DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE);
698
                        jButtonZoomPrevious.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/ZoomPrevio.png")));
699
                        jButtonZoomPrevious.setToolTipText(PluginServices.getText(this, "Zoom_Previo"));
700
                        
701
                        // By default this JButton is disabled
702
//                        jButtonZoomPrevious.setEnabled(false);
703
                        
704
                        
705
                        jButtonZoomPrevious.addMouseListener(new MouseAdapter() {
706
                                /*
707
                                 * (non-Javadoc)
708
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
709
                                 */
710
                                public void mouseClicked(MouseEvent e) {
711
                                        //getSelectableMapAreaPanel().setTool(ZOOM_PREVIOUS_TOOL);
712
                                        
713
//                                        View vista = (View) PluginServices.getMDIManager().getActiveWindow();
714
//                                        ViewPort vp = vista.getModel().getMapContext().getViewPort();
715
//                                        vp.setPreviousExtent();
716
//                                        ((ProjectDocument)vista.getModel()).setModified(true);
717
                                        
718
//                                        if (vista.)
719
                                        goToPreviousZoom();
720

    
721
//                                        else {
722
//                                                // Disables Previous JButton if there isn't any previous zoom view 
723
//                                                jButtonZoomPrevious.setEnabled(false);
724
//                                        }
725
                                }
726
                        });
727
                }
728
                return jButtonZoomPrevious;
729
        }
730

    
731
        /**
732
         * This method initializes jButtonZoomComplete        
733
         *         
734
         * @return javax.swing.JButton        
735
         */
736
        private JButton getJButtonZoomComplete() {
737
                if (jButtonZoomComplete == null) {
738
                        jButtonZoomComplete = new JButton();
739
                        jButtonZoomComplete.setBounds(DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE);
740
                        jButtonZoomComplete.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/MapContents.png")));
741
                        jButtonZoomComplete.setToolTipText(PluginServices.getText(this, "Zoom_Completo"));
742
                        jButtonZoomComplete.addMouseListener(new MouseAdapter() {
743
                                /*
744
                                 * (non-Javadoc)
745
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
746
                                 */
747
                                public void mouseClicked(MouseEvent e) {
748
//                                        getSelectableMapAreaPanel().setTool(ZOOM_COMPLETE_TOOL);
749
                                        try {
750
                                            // mapa.beginAtomicEvent();
751
                                                getSelectableMapAreaPanel().getViewPort().setExtent(getSelectableMapAreaPanel().getMapContext().getLayers().getFullExtent());
752
                                                View view =((View)PluginServices.getMDIManager().getActiveWindow());
753
                                                view.repaintMap();
754
                                                //((ProjectDocument)view.getModel()).setModified(true);
755
                                                // mapa.endAtomicEvent();
756
                                        } catch (DriverException de) {
757
                                                NotificationManager.addError("Error obteniendo el full extent",        de);
758
                                        }
759
                                }
760
                        });
761
                }
762
                return jButtonZoomComplete;
763
        }
764

    
765
//        /**
766
//         * This method initializes jButtonZoomInViewCentered        
767
//         *         
768
//         * @return javax.swing.JButton        
769
//         */
770
//        private JButton getJButtonZoomInViewCentered() {
771
//                if (jButtonZoomInViewCentered == null) {
772
//                        jButtonZoomInViewCentered = new JButton();
773
//                        jButtonZoomInViewCentered.setBounds(DEFAULT_ZOOMINVIEWCENTERED_ICON_BUTTON_RECTANGLE);
774
//                        jButtonZoomInViewCentered.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/zoommas.png")));
775
//                }
776
//                return jButtonZoomInViewCentered;
777
//        }
778
//
779
//        /**
780
//         * This method initializes jButtonZoomOutViewCentered
781
//         *         
782
//         * @return javax.swing.JButton        
783
//         */
784
//        private JButton getJButtonZoomOutViewCentered() {
785
//                if (jButtonZoomOutViewCentered == null) {
786
//                        jButtonZoomOutViewCentered = new JButton();
787
//                        jButtonZoomOutViewCentered.setBounds(DEFAULT_ZOOMOUTVIEWCENTERED_ICON_BUTTON_RECTANGLE);
788
//                        jButtonZoomOutViewCentered.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/zoommenos.png")));
789
//                }
790
//                return jButtonZoomOutViewCentered;
791
//        }
792

    
793
        /**
794
         * This method initializes jComboBoxZoomInAndOut        
795
         *         
796
         * @return         
797
         */
798
        private JComboBoxWithImageIconItems getJComboBoxZoomInAndOutViewCentered() {
799
                if (jComboBoxZoomInAndOutViewCentered == null) {
800
                        jComboBoxZoomInAndOutViewCentered = new JComboBoxWithImageIconItems();
801
                        jComboBoxZoomInAndOutViewCentered.setBounds(DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE);
802
                        jComboBoxZoomInAndOutViewCentered.addImageIconItem(new ImageIconItemInfo("images/zoommas.png", new ImageIcon(getClass().getClassLoader().getResource("images/zoommas.png")), PluginServices.getText(this, "Zoom_Acercar"), ZOOM_IN_VIEW_CENTERED_TOOL));
803
                        jComboBoxZoomInAndOutViewCentered.addImageIconItem(new ImageIconItemInfo("images/ZoomOut.png", new ImageIcon(getClass().getClassLoader().getResource("images/zoommenos.png")), PluginServices.getText(this, "Zoom_Alejar"), ZOOM_OUT_VIEW_CENTERED_TOOL));
804
                        jComboBoxZoomInAndOutViewCentered.addActionListener(new ActionListener() {
805
                                /*
806
                                 *  (non-Javadoc)
807
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
808
                                 */
809
                                public void actionPerformed(ActionEvent e) {
810
                                        JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
811
                                        ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
812
                        
813
                                        if (((String)iiii.getItemValue()).compareTo(ZOOM_IN_VIEW_CENTERED_TOOL) == 0) {
814
                                                getSelectableMapAreaPanel().zoomIn();
815
                                                //((ProjectDocument)((View)PluginServices.getMDIManager().getActiveWindow()).getModel()).setModified(tre);
816
                                        }
817
                                        else {
818
                                                getSelectableMapAreaPanel().zoomOut();
819
//                                                ((ProjectDocument)vista.getModel()).setModified(true);                                                
820
                                        }
821
                                        
822
                                //        ((ProjectDocument)((View)PluginServices.getMDIManager().getActiveWindow()).getModel()).setModified(true);
823
                                        
824
//                                                getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
825
                                }
826
                });
827
                }
828
                return jComboBoxZoomInAndOutViewCentered;
829
        }
830
        
831
        /**
832
         * This method initializes jComboBoxOtherTools        
833
         *         
834
         * @return         
835
         */
836
        private JComboBoxWithImageIconItems getJComboBoxOtherTools() {
837
                if (jComboBoxOtherTools == null) {
838
                        jComboBoxOtherTools = new JComboBoxWithImageIconItems();
839
                        jComboBoxOtherTools.setBounds(DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE);
840
                        jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Distancia.png", new ImageIcon(getClass().getClassLoader().getResource("images/Distancia.png")), PluginServices.getText(this, "medir_distancias"), MEASURE_DISTANCES_TOOL));
841
                        jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Poligono16.png", new ImageIcon(getClass().getClassLoader().getResource("images/Poligono16.png")), PluginServices.getText(this, "medir_area"), MEASURE_AREA_TOOL));
842
//                        jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Identify.png", new ImageIcon(getClass().getClassLoader().getResource("images/Identify.png")), PluginServices.getText(this, "informacion"), INFO_TOOL));
843
                        jComboBoxOtherTools.addActionListener(new ActionListener() {
844
                                /*
845
                                 *  (non-Javadoc)
846
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
847
                                 */
848
                                public void actionPerformed(ActionEvent e) {
849
                                        JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
850
                                        ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
851
                                        getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
852
                        
853
//                                        if (((String)iiii.getItemValue()).compareTo(ZOOM_IN_VIEW_CENTERED_TOOL) == 0) {
854
//                                                getSelectableMapAreaPanel().zoomIn();
855
//                                                //((ProjectDocument)((View)PluginServices.getMDIManager().getActiveWindow()).getModel()).setModified(tre);
856
//                                        }
857
//                                        else {
858
//                                                getSelectableMapAreaPanel().zoomOut();
859
////                                                ((ProjectDocument)vista.getModel()).setModified(true);                                                
860
//                                        }
861
//                                        
862
//                                        ((ProjectDocument)((View)PluginServices.getMDIManager().getActiveWindow()).getModel()).setModified(true);
863
                                        
864
//                                                getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
865
                                }
866
                });
867
                }
868
                
869
                return jComboBoxOtherTools;
870
        }
871

    
872
//        /**
873
//         * This method initializes jButtonInfo        
874
//         *         
875
//         * @return javax.swing.JButton        
876
//         */
877
//        private JButton getJButtonInfo() {
878
//                switch (((ItemOperation)getJComboBoxToolSelection().getSelectedItem()).getOperation()) {
879
//                        case SELECTION_BY_COORDINATES_OPERATION:
880
//                                jButtonInfo = new JButton();
881
//                                jButtonInfo.setBounds(DEFAULT_INFO_ICON_BUTTON_RECTANGLE_V1);
882
//                                jButtonInfo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/Identify.png")));
883
//                                jButtonInfo.setToolTipText(PluginServices.getText(this, "informacion"));
884
//                                break;
885
////                        case SELECTION_BY_AREA_OPERATION:
886
////                                jButtonInfo = new JButton();
887
////                                jButtonInfo.setBounds(DEFAULT_INFO_ICON_BUTTON_RECTANGLE_V2);
888
////                                jButtonInfo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/Identify.png")));
889
////                                jButtonInfo.setToolTipText(PluginServices.getText(this, "informacion"));
890
////                                break;
891
//                        case DISABLED_OPERATION: // Do nothing
892
//                                break;                                        
893
//                }
894
//
895
//                return jButtonInfo;
896
//        }
897

    
898
//        /**
899
//         * This method initializes jButtonTools        
900
//         *         
901
//         * @return javax.swing.JButton        
902
//         */
903
//        private JButton getJButtonTools() {
904
//                if (jButtonTools == null) {
905
//                        jButtonTools = new JButton();
906
//                        jButtonTools.setBounds(DEFAULT_TOOLS_ICON_BUTTON_RECTANGLE);
907
//                        jButtonTools.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/ZoomOut.png")));
908
//                }
909
//                return jButtonTools;
910
//        }
911
        
912
        /**
913
         * Refresh map control with the new map context of the active view
914
         */
915
        public void refreshMapControlWithTheActiveView() {
916
                getSelectableMapAreaPanel().refreshWithTheActiveView();
917
        }
918
        
919
        /**
920
         * Goes to previous zoom
921
         */
922
        private void goToPreviousZoom() {
923
                // Gets the view port and sets its previous extent
924
                ViewPort vp = getSelectableMapAreaPanel().getMapContext().getViewPort();
925

    
926
                if (vp.getExtents().hasPrevious()) {
927
                        vp.setPreviousExtent();
928
        //                ((ProjectDocument)((View) PluginServices.getMDIManager().getActiveWindow()).getModel()).setModified(true);
929
                }
930
        }
931
        
932
        /**
933
         * Represents an object that stores the necessary information for know each operation of the 'jComboBoxToolSelection'
934
         * 
935
         * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
936
         */
937
        private class ItemOperation {
938
                String _name;
939
                int _operation;
940
                
941
                /**
942
                 * Default constructor with two parameters
943
                 * 
944
                 * @param name Name of the operation
945
                 * @param operation A code that identifies the operation
946
                 */
947
                public ItemOperation(String name, int operation) {
948
                        _name = new String(name);
949
                        _operation = operation;
950
                }
951
                
952
                /**
953
                 * Returns the name of the operation
954
                 * 
955
                 * @return An String
956
                 */
957
                public String getName() {
958
                        return _name;
959
                }
960
                
961
                /**
962
                 * Returns the code that identifies the operation
963
                 * 
964
                 * @return An integer value
965
                 */
966
                public int getOperation() {
967
                        return _operation;
968
                }
969
                
970
                /**
971
                 * The name of the operation that will use JComboBox
972
                 */
973
                public String toString() {
974
                        return _name;
975
                }
976
        }
977
        
978
        /**
979
         * This class is a panel width four fields for indicate the coordinates of two points:
980
         *   One for the ritgh-up point and another for the left-down point of a rectangle area
981
         * 
982
         * @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
983
         * @author Jorge Piera Llodr? (piera_jor@gva.es) 
984
         */
985
        private class AreaCoordinatesPanel extends JPanel implements Serializable {
986
                private final Rectangle DEFAULT_JRADIOBUTTON_GO_TO_AREA_RECTANGLE = new Rectangle(412, 5, 67, 50);  //  @jve:decl-index=0:
987
                private final int DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT = 20;
988
                private final int DEFAULT_COORDIANTE_LABEL_WIDTH = 20;
989
                private final int DEFAULT_TEXT_FIELDS_WIDTH = 132;
990
                private final int DEFAULT_X_LOCATION = 8;
991
                private final int DEFAULT_Y_LEFT_UP_CORNER_LOCATION = 6;
992
                private final int DEFAULT_COORDINATE_WIDTH = DEFAULT_COORDIANTE_LABEL_WIDTH + DEFAULT_TEXT_FIELDS_WIDTH + 10;
993
                private final int DEFAULT_COORDINATE_HEIGHT = 25;
994
                private final Dimension DEFAULT_JLABEL_VERTEX_DIMENSION = new Dimension(60, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT);  //  @jve:decl-index=0:
995
                private final int DEFAULT_XY_COORDINATES_WIDTH = 2 * DEFAULT_COORDINATE_WIDTH + DEFAULT_JLABEL_VERTEX_DIMENSION.width + 10 ;
996
                
997
                private final String JTEXTFIELD_V1X_NAME = "V1X";
998
                private final String JTEXTFIELD_V1Y_NAME = "V1Y";
999
                private final String JTEXTFIELD_V2X_NAME = "V2X";
1000
                private final String JTEXTFIELD_V2Y_NAME = "V2Y";
1001

    
1002
                private JPanel jPanelVertex1 = null;
1003
                private JPanel jPanelVertex2 = null;
1004
                private JPanel jPanelVertex1X = null;
1005
                private JPanel jPanelVertex1Y = null;
1006
                private JPanel jPanelVertex2X = null;
1007
                private JPanel jPanelVertex2Y = null;
1008
                
1009
                private JLabel jLabelVertex1 = null;
1010
                private JLabel jLabelVertex2 = null;
1011
                private JLabel jLabelVertex1X = null;
1012
                private JLabel jLabelVertex1Y = null;
1013
                private JLabel jLabelVertex2X = null;
1014
                private JLabel jLabelVertex2Y = null;
1015
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex1X = null;
1016
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex1Y = null;
1017
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex2X = null;
1018
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex2Y = null;
1019
                private JRadioButton jRadioButtonPreviewArea = null;
1020
                private String last_Coordinates[];
1021
                private boolean hasChanged_v1X;
1022
                private boolean hasChanged_v1Y;
1023
                private boolean hasChanged_v2X;
1024
                private boolean hasChanged_v2Y;
1025

    
1026
                private FocusListener focusListenerForCoordinateValidation = null;
1027

    
1028
                /**
1029
                 * This is the default constructor
1030
                 */
1031
                public AreaCoordinatesPanel() {
1032
                        super();
1033
                        initialize();
1034
                }
1035

    
1036
                /**
1037
                 * This method initializes this
1038
                 * 
1039
                 * @return void
1040
                 */
1041
                private void initialize() {
1042
                        this.setLayout(null);
1043
                        this.setBounds(DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE);
1044
                        this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
1045
                        this.setToolTipText(PluginServices.getText(this, "select_by_vertexes_coordinates"));
1046
//                        this.setBorder(javax.swing.BorderFactory.createTitledBorder(
1047
//                        null, PluginServices.getText(this, "select_by_vertexes_coordinates"),
1048
//                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
1049
//                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
1050

    
1051
                        this.last_Coordinates = new String[4];
1052
                        this.last_Coordinates[0] = "";
1053
                        this.last_Coordinates[1] = "";
1054
                        this.last_Coordinates[2] = "";
1055
                        this.last_Coordinates[3] = "";
1056

    
1057
                        // By default no coordinates have changed
1058
                        this.resetCoordinatesFlags();
1059

    
1060
                        this.add(getJPanelVertex1());
1061
                        this.add(getJPanelVertex2());
1062
                        this.add(getJRadioButtonPreviewArea());
1063
                }
1064
                
1065
                /**
1066
                 * Returns the default width of this component
1067
                 * 
1068
                 * @return The default width
1069
                 */
1070
                public int getDefaultWidth() {
1071
                        return DEFAULT_COORDINATE_WIDTH * 2;
1072
                }
1073
                
1074
                /**
1075
                 * Returns the default height of this component
1076
                 * 
1077
                 * @return The default height
1078
                 */
1079
                public int getDefaultHeight() {
1080
                        return DEFAULT_COORDINATE_HEIGHT * 2;
1081
                }
1082

    
1083
                /**
1084
                 * Sets all flags about if a coordinate has change to false (haven't changed)
1085
                 */
1086
                private void resetCoordinatesFlags() {
1087
                        hasChanged_v1X = false;
1088
                        hasChanged_v1Y = false;
1089
                        hasChanged_v2X = false;
1090
                        hasChanged_v2Y = false;
1091
                }
1092
                
1093
//                /**
1094
//                 *  This method initializes last_V1
1095
//                 * 
1096
//                 * @return java.awt.Point
1097
//                 */
1098
//                private Point get_Last_V1() {
1099
//                        if (last_V1 == null) {
1100
//                                last_V1 = new Point();
1101
//                        }
1102
//                        
1103
//                        return last_V1;
1104
//                }
1105
//
1106
//                /**
1107
//                 *  This method initializes last_V2
1108
//                 * 
1109
//                 * @return java.awt.Point
1110
//                 */
1111
//                private Point get_Last_V2() {
1112
//                        if (last_V2 == null) {
1113
//                                last_V2 = new Point();
1114
//                        }
1115
//                        
1116
//                        return last_V2;
1117
//                }
1118
                
1119
                /**
1120
                 * This method initializes jPanelVertex1
1121
                 * 
1122
                 * @return javax.swing.JPanel
1123
                 */
1124
                private JPanel getJPanelVertex1() {
1125
                        if (jPanelVertex1 == null) {
1126
                                jPanelVertex1 = new JPanel();
1127
                                jPanelVertex1.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT);
1128
                                jPanelVertex1.setLayout(new GridBagLayout());
1129
                                jPanelVertex1.add(getJLabelVertex1(), null);
1130
                                jPanelVertex1.add(getJPanelVertex1X(), null);
1131
                                jPanelVertex1.add(getJPanelVertex1Y(), null);
1132
                        }
1133
                        
1134
                        return jPanelVertex1;
1135
                }
1136
                
1137
                /**
1138
                 * This method initializes jPanelVertex2
1139
                 * 
1140
                 * @return javax.swing.JPanel
1141
                 */
1142
                private JPanel getJPanelVertex2() {
1143
                        if (jPanelVertex2 == null) {
1144
                                jPanelVertex2 = new JPanel();
1145
                                jPanelVertex2.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION + DEFAULT_COORDINATE_HEIGHT, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT);
1146
                                jPanelVertex2.setLayout(new GridBagLayout());
1147
                                jPanelVertex2.add(getJLabelVertex2(), null);
1148
                                jPanelVertex2.add(getJPanelVertex2X(), null);
1149
                                jPanelVertex2.add(getJPanelVertex2Y(), null);
1150
                        }
1151
                        
1152
                        return jPanelVertex2;
1153
                }
1154
                
1155
                /**
1156
                 * This method initializes jLabelVertex1
1157
                 * 
1158
                 * @return javax.swing.JPanel
1159
                 */
1160
                private JLabel getJLabelVertex1() {
1161
                        if (jLabelVertex1 == null) {
1162
                                jLabelVertex1 = new JLabel();
1163
                                jLabelVertex1.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION);
1164
                                jLabelVertex1.setToolTipText(PluginServices.getText(this, "coordinates_from_area_right_up_vertex"));
1165
                                jLabelVertex1.setText(PluginServices.getText(this, "vertex") + " 1:");
1166
                                jLabelVertex1.setHorizontalAlignment(SwingConstants.LEFT);
1167
                                jLabelVertex1.setVerticalAlignment(SwingConstants.CENTER);
1168
                                jLabelVertex1.setForeground(new Color(0, 0, 255)); // Blue color for text
1169
                        }
1170
                        return jLabelVertex1;
1171
                }
1172

    
1173
                /**
1174
                 * This method initializes jLabelVertex2
1175
                 * 
1176
                 * @return javax.swing.JPanel
1177
                 */
1178
                private JLabel getJLabelVertex2() {
1179
                        if (jLabelVertex2 == null) {
1180
                                jLabelVertex2 = new JLabel();
1181
                                jLabelVertex2.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION);
1182
                                jLabelVertex2.setToolTipText(PluginServices.getText(this, "coordinates_from_area_left_bottom_vertex"));
1183
                                jLabelVertex2.setText(PluginServices.getText(this, "vertex") + " 2:");
1184
                                jLabelVertex2.setHorizontalAlignment(SwingConstants.LEFT);
1185
                                jLabelVertex2.setVerticalAlignment(SwingConstants.CENTER);
1186
                                jLabelVertex2.setForeground(new Color(128, 64, 0)); // Brown color for text
1187
                        }
1188
                        return jLabelVertex2;
1189
                }
1190

    
1191
                /**
1192
                 * This method initializes jPanelVertex1X
1193
                 * 
1194
                 * @return javax.swing.JPanel
1195
                 */
1196
                private JPanel getJPanelVertex1X() {
1197
                        if (jPanelVertex1X == null) {
1198
                                jPanelVertex1X = new JPanel();
1199
                                jPanelVertex1X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1200
                                jPanelVertex1X.setLayout(new GridBagLayout());
1201
                                jPanelVertex1X.add(getJLabelVertex1X(), null);
1202
                                jPanelVertex1X.add(getJTextFieldVertex1X(), null);
1203
                        }
1204
                        
1205
                        return jPanelVertex1X;
1206
                }
1207

    
1208
                /**
1209
                 * This method initializes jPanelVertex1Y
1210
                 * 
1211
                 * @return javax.swing.JPanel
1212
                 */
1213
                private JPanel getJPanelVertex1Y() {
1214
                        if (jPanelVertex1Y == null) {
1215
                                jPanelVertex1Y = new JPanel();
1216
                                jPanelVertex1Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1217
                                jPanelVertex1Y.setLayout(new GridBagLayout());
1218
                                jPanelVertex1Y.add(getJLabelVertex1Y(), null);
1219
                                jPanelVertex1Y.add(getJTextFieldVertex1Y(), null);
1220
                        }
1221
                        
1222
                        return jPanelVertex1Y;
1223
                }
1224

    
1225
                /**
1226
                 * This method initializes jPanelVertex2X
1227
                 * 
1228
                 * @return javax.swing.JPanel
1229
                 */
1230
                private JPanel getJPanelVertex2X() {
1231
                        if (jPanelVertex2X == null) {
1232
                                jPanelVertex2X = new JPanel();
1233
                                jPanelVertex2X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1234
                                jPanelVertex2X.setLayout(new GridBagLayout());
1235
                                jPanelVertex2X.add(getJLabelVertex2X(), null);
1236
                                jPanelVertex2X.add(getJTextFieldVertex2X(), null);
1237
                        }
1238
                        
1239
                        return jPanelVertex2X;
1240
                }
1241
                
1242
                /**
1243
                 * This method initializes jPanelVertex2Y
1244
                 * 
1245
                 * @return javax.swing.JPanel
1246
                 */
1247
                private JPanel getJPanelVertex2Y() {
1248
                        if (jPanelVertex2Y == null) {
1249
                                jPanelVertex2Y = new JPanel();
1250
                                jPanelVertex2Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1251
                                jPanelVertex2Y.setLayout(new GridBagLayout());
1252
                                jPanelVertex2Y.add(getJLabelVertex2Y(), null);
1253
                                jPanelVertex2Y.add(getJTextFieldVertex2Y(), null);
1254
                        }
1255
                        
1256
                        return jPanelVertex2Y;
1257
                }
1258

    
1259
                /**
1260
                 * This method initializes jLabelVertex1X
1261
                 * 
1262
                 * @return  javax.swing.JLabel
1263
                 */
1264
                private JLabel getJLabelVertex1X() {
1265
                        if (jLabelVertex1X == null) {
1266
                                jLabelVertex1X = new JLabel();
1267
                                jLabelVertex1X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1268
                                jLabelVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1269
                                jLabelVertex1X.setText(PluginServices.getText(this, "x") + ":");
1270
                                jLabelVertex1X.setHorizontalAlignment(SwingConstants.CENTER);
1271
                                jLabelVertex1X.setVerticalAlignment(SwingConstants.CENTER);
1272
                                jLabelVertex1X.setForeground(new Color(0, 0, 255)); // Blue color for text
1273
                        }
1274
                        
1275
                        return jLabelVertex1X;
1276
                }
1277
                
1278
                /**
1279
                 * This method initializes jLabelVertex2X
1280
                 * 
1281
                 * @return  javax.swing.JLabel
1282
                 */
1283
                private JLabel getJLabelVertex2X() {
1284
                        if (jLabelVertex2X == null) {
1285
                                jLabelVertex2X = new JLabel();
1286
                                jLabelVertex2X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1287
                                jLabelVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1288
                                jLabelVertex2X.setText(PluginServices.getText(this, "x") + ":");
1289
                                jLabelVertex2X.setHorizontalAlignment(SwingConstants.CENTER);
1290
                                jLabelVertex2X.setVerticalAlignment(SwingConstants.CENTER);
1291
                                jLabelVertex2X.setForeground(new Color(128, 64, 0)); // Brown color for text
1292
                        }
1293
                        
1294
                        return jLabelVertex2X;
1295
                }
1296
                
1297
                /**
1298
                 * This method initializes jLabelVertex1Y
1299
                 * 
1300
                 * @return  javax.swing.JLabel
1301
                 */
1302
                private JLabel getJLabelVertex1Y() {
1303
                        if (jLabelVertex1Y == null) {
1304
                                jLabelVertex1Y = new JLabel();
1305
                                jLabelVertex1Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1306
                                jLabelVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1307
                                jLabelVertex1Y.setText(PluginServices.getText(this, "y") + ":");
1308
                                jLabelVertex1Y.setHorizontalAlignment(SwingConstants.CENTER);
1309
                                jLabelVertex1Y.setVerticalAlignment(SwingConstants.CENTER);
1310
                                jLabelVertex1Y.setForeground(new Color(0, 0, 255)); // Blue color for text
1311
                        }
1312
                        
1313
                        return jLabelVertex1Y;
1314
                }
1315
                
1316
                /**
1317
                 * This method initializes jLabelVertex2Y
1318
                 * 
1319
                 * @return  javax.swing.JLabel
1320
                 */
1321
                private JLabel getJLabelVertex2Y() {
1322
                        if (jLabelVertex2Y == null) {
1323
                                jLabelVertex2Y = new JLabel();                        
1324
                                jLabelVertex2Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1325
                                jLabelVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1326
                                jLabelVertex2Y.setText(PluginServices.getText(this, "y") + ":");
1327
                                jLabelVertex2Y.setHorizontalAlignment(SwingConstants.CENTER);
1328
                                jLabelVertex2Y.setVerticalAlignment(SwingConstants.CENTER);
1329
                                jLabelVertex2Y.setForeground(new Color(128, 64, 0)); // Brown color for text
1330
                        }
1331
                        
1332
                        return jLabelVertex2Y;
1333
                }
1334
//                
1335
//                /**
1336
//                 * This method initializes a FocusAdapter event adapter, it's 'focusLost()' method for set the caret position of
1337
//                 *   the JTextField (source which generates the event of focusLost), to the first position.
1338
//                 * This adapter is done for use only with the JTextFields of the coordinates
1339
//                 * 
1340
//                 * @return java.awt.event.FocusAdapter
1341
//                 */
1342
//                private FocusAdapter getJFocusAdapterForJTextFields() {
1343
//                        if (focusAdapterForJTextFields == null) {
1344
//                                focusAdapterForJTextFields = new FocusAdapter() {
1345
//                                        /*
1346
//                                         *  (non-Javadoc)
1347
//                                         * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
1348
//                                         */
1349
//                                        public void focusLost(FocusEvent e) {
1350
//                                                ((JTextField)e.getSource()).setCaretPosition(0);
1351
//                                        }                                        
1352
//                                };
1353
//                        }
1354
//                        return focusAdapterForJTextFields;
1355
//                }
1356
                
1357
                /**
1358
                 * Returns a focus listener for validate the text of a JTextField when that component loses its focus
1359
                 * 
1360
                 * @return java.awt.event.FocusListener
1361
                 */
1362
                private FocusListener getFocusListenerForCoordinateValidation() {
1363
                        if (focusListenerForCoordinateValidation == null) {
1364
                                focusListenerForCoordinateValidation = new FocusListener() {
1365
                                        /*
1366
                                         *  (non-Javadoc)
1367
                                         * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
1368
                                         */
1369
                                        public void focusLost(FocusEvent e) {
1370
                                                JTextField jTF = (JTextField)e.getSource();
1371

    
1372
                                                // If a coordinate has lost focus, is valid and has changed -> store the new value and set its related 'hasChanged' flag to true
1373
                                                if (validateCoordinate(jTF)) {
1374
                                                        String text = jTF.getText();
1375

    
1376
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1377
                                                                if (text.compareTo(last_Coordinates[0]) != 0) {
1378
                                                                        hasChanged_v1X = true;
1379
                                                                }
1380
                                                                
1381
                                                                return;
1382
                                                        }
1383
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1384
                                                                if (text.compareTo(last_Coordinates[1]) != 0) {
1385
                                                                        hasChanged_v1Y = true;
1386
                                                                }
1387
                                                                
1388
                                                                return;
1389
                                                        }
1390
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1391
                                                                if (text.compareTo(last_Coordinates[2]) != 0) {
1392
                                                                        hasChanged_v2X = true;
1393
                                                                }
1394
                                                                
1395
                                                                return;
1396
                                                        }
1397
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1398
                                                                if (text.compareTo(last_Coordinates[3]) != 0) {
1399
                                                                        hasChanged_v2Y = true;
1400
                                                                }
1401
                                                                
1402
                                                                return;
1403
                                                        }
1404
                                                }
1405
                                        }
1406

    
1407
                                        /*
1408
                                         *  (non-Javadoc)
1409
                                         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
1410
                                         */
1411
                                        public void focusGained(FocusEvent e) {
1412
                                                JTextField jTF = (JTextField)e.getSource();
1413

    
1414
                                                // If a coordinate has lost focus, is valid and has changed -> store the new value and set its related 'hasChanged' flag to true
1415
                                                if (validateCoordinate(jTF)) {
1416
                                                        String text = jTF.getText();
1417

    
1418
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1419
                                                                last_Coordinates[0] = text;
1420
                                                                
1421
                                                                return;
1422
                                                        }
1423
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1424
                                                                last_Coordinates[1] = text;
1425
                                                                
1426
                                                                return;
1427
                                                        }
1428
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1429
                                                                last_Coordinates[2] = text;
1430
                                                                
1431
                                                                return;
1432
                                                        }
1433
                                                        if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1434
                                                                last_Coordinates[3] = text;
1435
                                                                
1436
                                                                return;
1437
                                                        }
1438
                                                }                                                
1439
                                        }                                        
1440
                                };
1441
                        }
1442
                        
1443
                        return focusListenerForCoordinateValidation;
1444
                }
1445

    
1446
                /**
1447
                 * This method initializes jTextFieldVertex1X        
1448
                 *         
1449
                 * @return JTextFieldWithSpecificCaretPosition
1450
                 */
1451
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex1X() {
1452
                        if (jTextFieldVertex1X == null) {
1453
                                jTextFieldVertex1X = new JTextFieldWithSpecificCaretPosition();
1454
                                jTextFieldVertex1X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1455
                                jTextFieldVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1456
                                jTextFieldVertex1X.addFocusListener(getFocusListenerForCoordinateValidation());
1457
                                jTextFieldVertex1X.setName(JTEXTFIELD_V1X_NAME);
1458
                        }
1459
                        return jTextFieldVertex1X;
1460
                }
1461

    
1462
                /**
1463
                 * This method initializes jTextFieldVertex1Y        
1464
                 *         
1465
                 * @return JTextFieldWithSpecificCaretPosition
1466
                 */
1467
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex1Y() {
1468
                        if (jTextFieldVertex1Y == null) {
1469
                                jTextFieldVertex1Y = new JTextFieldWithSpecificCaretPosition();
1470
                                jTextFieldVertex1Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1471
                                jTextFieldVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1472
                                jTextFieldVertex1Y.addFocusListener(getFocusListenerForCoordinateValidation());
1473
                                jTextFieldVertex1Y.setName(JTEXTFIELD_V1Y_NAME);
1474
                        }
1475
                        return jTextFieldVertex1Y;
1476
                }
1477

    
1478
                /**
1479
                 * This method initializes jTextFieldVertex2X        
1480
                 *         
1481
                 * @return JTextFieldWithSpecificCaretPosition        
1482
                 */
1483
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex2X() {
1484
                        if (jTextFieldVertex2X == null) {
1485
                                jTextFieldVertex2X = new JTextFieldWithSpecificCaretPosition();
1486
                                jTextFieldVertex2X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1487
                                jTextFieldVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1488
                                jTextFieldVertex2X.addFocusListener(getFocusListenerForCoordinateValidation());
1489
                                jTextFieldVertex2X.setName(JTEXTFIELD_V2X_NAME);
1490
                        }
1491
                        return jTextFieldVertex2X;
1492
                }
1493

    
1494
                /**
1495
                 * This method initializes jTextFieldVertex2Y        
1496
                 *         
1497
                 * @return JTextFieldWithSpecificCaretPosition
1498
                 */
1499
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex2Y() {
1500
                        if (jTextFieldVertex2Y == null) {
1501
                                jTextFieldVertex2Y = new JTextFieldWithSpecificCaretPosition();
1502
                                jTextFieldVertex2Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));                        
1503
                                jTextFieldVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1504
                                jTextFieldVertex2Y.addFocusListener(getFocusListenerForCoordinateValidation());
1505
                                jTextFieldVertex2Y.setName(JTEXTFIELD_V2Y_NAME);
1506
                        }
1507
                        return jTextFieldVertex2Y;
1508
                }
1509
                
1510
                /**
1511
                 * Validates the coordinate of a JTextField
1512
                 * 
1513
                 * @param coordinate javax.swing.JTextField
1514
                 * @return If it's valid or not
1515
                 */
1516
                private boolean validateCoordinate(JTextField coordinate) {
1517
                        if (coordinate != null) {
1518
                                // If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text 
1519
                                if ((coordinate.getText().compareTo("") != 0) &&(! StringNumberUtilities.isExponentialRealNumber(coordinate.getText()))) {
1520
                                        JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1521
                                        coordinate.setText(""); // Reset text
1522
                                        return false;
1523
                                }
1524
                        }
1525

    
1526
                        return true;
1527
                }
1528

    
1529
                /**
1530
                 * This method initializes jRadioButtonPreviewArea
1531
                 * 
1532
                 * @return javax.swing.JRadioButton
1533
                 */
1534
                private JRadioButton getJRadioButtonPreviewArea() {
1535
                        if (jRadioButtonPreviewArea == null) {
1536
                                jRadioButtonPreviewArea = new JRadioButton();
1537
                                jRadioButtonPreviewArea.setBounds(DEFAULT_JRADIOBUTTON_GO_TO_AREA_RECTANGLE);
1538
                                jRadioButtonPreviewArea.setToolTipText(PluginServices.getText(this, "to_previsualize"));
1539
                                jRadioButtonPreviewArea.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/to_previsualize_area.png")));
1540
//                                jRadioButtonPreviewArea.addActionListener(new ActionListener() {
1541
//                                        /*
1542
//                                         *  (non-Javadoc)
1543
//                                         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
1544
//                                         */
1545
//                                        public void actionPerformed(ActionEvent e) {
1546
//                                                System.out.println("Action performed");
1547
//                                        }
1548
//                                });
1549
                                
1550
                                jRadioButtonPreviewArea.addMouseListener(new MouseAdapter() {
1551
                                        /*
1552
                                         *  (non-Javadoc)
1553
                                         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
1554
                                         */
1555
                                        public void mouseClicked(MouseEvent e) {
1556
//                                                System.out.println("Mouse clicked");
1557
                                                if ((validateCoordinate(getJTextFieldVertex1X())) && (validateCoordinate(getJTextFieldVertex1Y())) && (validateCoordinate(getJTextFieldVertex2X())) && (validateCoordinate(getJTextFieldVertex2Y()))) {
1558
//                                                        ViewPort vP = getSelectableMapAreaPanel().getViewPort();
1559
//                                                        if (vP != null) {
1560
//                                                                if (vP.getExtent() != null) {
1561
//                                                                        vP.setExtent(new Rectangle2D.Double(new Double(getJTextFieldVertex1X().getText()).doubleValue(),
1562
//                                                                                new Double(getJTextFieldVertex1Y().getText()).doubleValue(),
1563
//                                                                                new Double(getJTextFieldVertex2X().getText()).doubleValue(),
1564
//                                                                                new Double(getJTextFieldVertex2Y().getText()).doubleValue()));
1565
//                                                                        a
1566
//                                                                        // Refresh the extent
1567
////                                                                        getSelectableMapAreaPanel().getMapContext().
1568
//                                                                }
1569
//                                                        }
1570
                                                        
1571
//                                                        View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
1572
//                                                        Rectangle2D r2d= activeView.getMapControl().getViewPort().getAdjustedExtent();
1573
//                                                        Rectangle2D r2d = getViewPort().getExtent();
1574

    
1575
                                                        ViewPort vP = getSelectableMapAreaPanel().getViewPort();
1576
                                                        if (vP != null) {
1577
                                                                // If has to scale the area
1578
                                                                if (getJToggleButtonScaling().isSelected()) {
1579
                                                                        // Scale Vertex 1
1580
                                                                        if ((hasChanged_v1X) || (hasChanged_v1Y)) {
1581
                                                                                double cx = Double.parseDouble(getJTextFieldVertex1X().getText());
1582
                                                                                double cy = Double.parseDouble(getJTextFieldVertex1Y().getText());
1583
                                                                                double sx, sy, aux;
1584
                                                                                
1585
                                                                                if (hasChanged_v1X) {
1586
                                                                                        aux = Double.parseDouble(last_Coordinates[0]);
1587
                                                                                        if (aux == 0.0)
1588
                                                                                                sx = 1.0; // Don't scale if new coordenate is zero
1589
                                                                                        else
1590
                                                                                                sx = cx / aux;
1591
                                                                                }
1592
                                                                                else
1593
                                                                                        sx = 1.0;
1594
                                                                                
1595
                                                                                if (hasChanged_v1Y) {
1596
                                                                                        aux = Double.parseDouble(last_Coordinates[1]);
1597
                                                                                        if (aux == 0.0)
1598
                                                                                                sy = 1.0; // Don't scale if new coordenate is zero
1599
                                                                                        else
1600
                                                                                                sy = cy / aux;
1601
                                                                                }
1602
                                                                                else
1603
                                                                                        sy = 1.0;
1604
                                                                                
1605
                                                                                if (sx == 1.0) {
1606
                                                                                        // It's supposed that sy != 1.0
1607
                                                                                        cx *= sy;
1608
                                                                                        
1609
                                                                                        if (cx < Double.parseDouble(getJTextFieldVertex2X().getText())) {
1610
                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v1x") + " < " + PluginServices.getText(jRadioButtonPreviewArea, "v2x"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1611
                                                                                                getJTextFieldVertex1Y().setText(last_Coordinates[1]); // Restore to the last value
1612
                                                                                                return;
1613
                                                                                        }
1614
                                                                                        
1615
                                                                                        getJTextFieldVertex1X().setText(Double.toString(cx));
1616
                                                                                }
1617
                                                                                else {
1618
                                                                                        if (sy == 1.0) {
1619
                                                                                                // It's supposed that sx != 1.0
1620
                                                                                                cy *= sx;
1621
                                                                                                
1622
                                                                                                if (cy < Double.parseDouble(getJTextFieldVertex2Y().getText())) {
1623
                                                                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v1y") + " < " + PluginServices.getText(jRadioButtonPreviewArea, "v2y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1624
                                                                                                        getJTextFieldVertex1X().setText(last_Coordinates[0]); // Restore to the last value
1625
                                                                                                        return;
1626
                                                                                                }
1627
                                                                                                
1628
                                                                                                getJTextFieldVertex1Y().setText(Double.toString(cy));
1629
                                                                                        }
1630
                                                                                        else {
1631
                                                                                                // If there has been an error -> can't move different distances in X the two vertexes
1632
                                                                                                if (sx != sy) {
1633
                                                                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "different_scale_factors"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1634
                                                                                                        return;
1635
                                                                                                }
1636
                                                                                        }
1637
                                                                                }
1638
                                                                                
1639
                                                                                hasChanged_v1X = false;
1640
                                                                                hasChanged_v1Y = false;
1641
                                                                        }
1642
                                                                        
1643
                                                                        // Scale Vertex2
1644
                                                                        if ((hasChanged_v2X) || (hasChanged_v2Y)) {
1645
                                                                                double cx = Double.parseDouble(getJTextFieldVertex2X().getText());
1646
                                                                                double cy = Double.parseDouble(getJTextFieldVertex2Y().getText());
1647
                                                                                double sx, sy, aux;
1648
                                                                                
1649
                                                                                if (hasChanged_v2X) {
1650
                                                                                        aux = Double.parseDouble(last_Coordinates[2]);
1651
                                                                                        if (aux == 0.0)
1652
                                                                                                sx = 1.0; // Don't scale if new coordenate is zero
1653
                                                                                        else
1654
                                                                                                sx = cx / aux;
1655
                                                                                }
1656
                                                                                else
1657
                                                                                        sx = 1.0;
1658
                                                                                
1659
                                                                                if (hasChanged_v2Y) {
1660
                                                                                        aux = Double.parseDouble(last_Coordinates[3]);
1661
                                                                                        if (aux == 0.0)
1662
                                                                                                sy = 1.0; // Don't scale if new coordenate is zero
1663
                                                                                        else
1664
                                                                                                sy = cy / aux;
1665
                                                                                }
1666
                                                                                else
1667
                                                                                        sy = 1.0;
1668
                                                                                
1669
                                                                                if (sx == 1.0) {
1670
                                                                                        // It's supposed that sy != 1.0
1671
                                                                                        cx *= sy;
1672
                                                                                        
1673
                                                                                        if (cx > Double.parseDouble(getJTextFieldVertex1X().getText())) {
1674
                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v2x") + " > " + PluginServices.getText(jRadioButtonPreviewArea, "v1x"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1675
                                                                                                getJTextFieldVertex2Y().setText(last_Coordinates[3]); // Restore to the last value
1676
                                                                                                return;
1677
                                                                                        }
1678

    
1679
                                                                                        getJTextFieldVertex2X().setText(Double.toString(cx));
1680
                                                                                }
1681
                                                                                else {
1682
                                                                                        if (sy == 1.0) {
1683
                                                                                                // It's supposed that sx != 1.0
1684
                                                                                                cy *= sx;
1685
                                                                                                
1686
                                                                                                if (cy > Double.parseDouble(getJTextFieldVertex1Y().getText())) {
1687
                                                                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v2y") + " > " + PluginServices.getText(jRadioButtonPreviewArea, "v1y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1688
                                                                                                        getJTextFieldVertex2X().setText(last_Coordinates[2]); // Restore to the last value
1689
                                                                                                        return;
1690
                                                                                                }
1691

    
1692
                                                                                                getJTextFieldVertex2Y().setText(Double.toString(cy));
1693
                                                                                        }
1694
                                                                                        else {
1695
                                                                                                // If there has been an error -> can't move different distances in X the two vertexes
1696
                                                                                                if (sx != sy) {
1697
                                                                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "different_scale_factors"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1698
                                                                                                        return;
1699
                                                                                                }
1700
                                                                                        }
1701
                                                                                }
1702
                                                                                
1703
                                                                                hasChanged_v2X = false;
1704
                                                                                hasChanged_v2Y = false;
1705
                                                                        }                                                                        
1706
                                                                }
1707
                                                                else {
1708
                                                                        // If has to move the area
1709
                                                                        if (getJToggleButtonMove().isSelected()) {
1710
                                                                                // Move in X
1711
                                                                                if ((hasChanged_v1X) || (hasChanged_v2X)) {
1712
                                                                                        double c1 = Double.parseDouble(getJTextFieldVertex1X().getText());
1713
                                                                                        double c2 = Double.parseDouble(getJTextFieldVertex2X().getText());
1714
                                                                                        double d1, d2;
1715
                                                                                        
1716
                                                                                        if (hasChanged_v1X)
1717
                                                                                                d1 = c1 - Double.parseDouble(last_Coordinates[0]);
1718
                                                                                        else
1719
                                                                                                d1 = 0.0;
1720
                                                                                        
1721
                                                                                        if (hasChanged_v2X)
1722
                                                                                                d2 = c2 - Double.parseDouble(last_Coordinates[2]);
1723
                                                                                        else
1724
                                                                                                d2 = 0.0;
1725
        
1726
                                                                                        if (d1 == 0.0) {
1727
                                                                                                // It's supposed that d2 != 0
1728
                                                                                                c1 += d2;
1729
                                                                                                
1730
                                                                                                if (c1 < Double.parseDouble(getJTextFieldVertex2X().getText())) {
1731
                                                                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v1x") + " < " + PluginServices.getText(jRadioButtonPreviewArea, "v2x"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1732
                                                                                                        getJTextFieldVertex1X().setText(last_Coordinates[0]); // Restore to the last value
1733
                                                                                                        return;
1734
                                                                                                }
1735
                                                                                                
1736
                                                                                                getJTextFieldVertex1X().setText(Double.toString(c1));
1737
                                                                                        }
1738
                                                                                        else {
1739
                                                                                                if (d2 == 0.0) {
1740
                                                                                                        // It's supposed that d1 != 0
1741
                                                                                                        c2 += d1;
1742

    
1743
                                                                                                        if (c2 > Double.parseDouble(getJTextFieldVertex1X().getText())) {
1744
                                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v2x") + " > " + PluginServices.getText(jRadioButtonPreviewArea, "v1x"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1745
                                                                                                                getJTextFieldVertex2X().setText(last_Coordinates[2]); // Restore to the last value
1746
                                                                                                                return;
1747
                                                                                                        }
1748
                                                                                                        
1749
                                                                                                        getJTextFieldVertex2X().setText(Double.toString(c2));
1750
                                                                                                }
1751
                                                                                                else {
1752
                                                                                                        // If there has been an error -> can't move different distances in X the two vertexes
1753
                                                                                                        if (d1 != d2) {
1754
                                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "different_distances_in_X"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1755
                                                                                                                return;
1756
                                                                                                        }
1757
                                                                                                }
1758
                                                                                        }
1759
                                                                                        
1760
                                                                                        hasChanged_v1X = false;
1761
                                                                                        hasChanged_v2X = false;
1762
                                                                                }
1763
                                                                                
1764
                                                                                // Move in Y
1765
                                                                                if ((hasChanged_v1Y) || (hasChanged_v2Y)) {
1766
                                                                                        double c1 = Double.parseDouble(getJTextFieldVertex1Y().getText());
1767
                                                                                        double c2 = Double.parseDouble(getJTextFieldVertex2Y().getText());
1768
                                                                                        double d1, d2;
1769
                                                                                        
1770
                                                                                        if (hasChanged_v1Y)
1771
                                                                                                d1 = c1 - Double.parseDouble(last_Coordinates[1]);
1772
                                                                                        else
1773
                                                                                                d1 = 0.0;
1774
                                                                                        
1775
                                                                                        if (hasChanged_v2Y)
1776
                                                                                                d2 = c2 - Double.parseDouble(last_Coordinates[3]);
1777
                                                                                        else
1778
                                                                                                d2 = 0.0;
1779
                                                                                        
1780
                                                                                        if (d1 == 0.0) {
1781
                                                                                                // It's supposed that d2 != 0
1782
                                                                                                c1 += d2;
1783
                                                                                                
1784
                                                                                                if (c1 < Double.parseDouble(getJTextFieldVertex2Y().getText())) {
1785
                                                                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v1y") + " < " + PluginServices.getText(jRadioButtonPreviewArea, "v2y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1786
                                                                                                        getJTextFieldVertex1Y().setText(last_Coordinates[1]); // Restore to the last value
1787
                                                                                                        return;
1788
                                                                                                }
1789

    
1790
                                                                                                getJTextFieldVertex1Y().setText(Double.toString(c1));
1791
                                                                                        }
1792
                                                                                        else {
1793
                                                                                                if (d2 == 0.0) {
1794
                                                                                                        // It's supposed that d1 != 0
1795
                                                                                                        c2 += d1;
1796

    
1797
                                                                                                        if (c2 > Double.parseDouble(getJTextFieldVertex1Y().getText())) {
1798
                                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jRadioButtonPreviewArea, "v2y") + " > " + PluginServices.getText(jRadioButtonPreviewArea, "v1y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1799
                                                                                                                getJTextFieldVertex2Y().setText(last_Coordinates[3]); // Restore to the last value
1800
                                                                                                                return;
1801
                                                                                                        }
1802
                                                                                                        
1803
                                                                                                        getJTextFieldVertex2Y().setText(Double.toString(c2));
1804
                                                                                                }
1805
                                                                                                else {
1806
                                                                                                        // If there has been an error -> can't move different distances in Y the two vertexes
1807
                                                                                                        if (d1 != d2) {
1808
                                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "different_distances_in_Y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1809
                                                                                                                return;
1810
                                                                                                        }
1811
                                                                                                }
1812
                                                                                        }
1813
        
1814
                                                                                        hasChanged_v1Y = false;
1815
                                                                                        hasChanged_v2Y = false;
1816
                                                                                }
1817
                                                                        }
1818
                                                                        else {
1819
                                                                                boolean canSetExtent = true;
1820
                                                                                
1821
                                                                                // Check if there is a impossible coordinate
1822
                                                                                if (hasChanged_v1X) {
1823
                                                                                        if (Double.parseDouble(getJTextFieldVertex1X().getText()) < Double.parseDouble(getJTextFieldVertex2X().getText())) {
1824
                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "v1x") + " < " + PluginServices.getText(jRadioButtonPreviewArea, "v2x"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1825
                                                                                                getJTextFieldVertex1X().setText(last_Coordinates[0]); // Restores its last value
1826
                                                                                                canSetExtent = false;
1827
                                                                                        }
1828
                                                                                        
1829
                                                                                        hasChanged_v1X = false;
1830
                                                                                }
1831
                                                                                
1832
                                                                                if (hasChanged_v1Y) {
1833
                                                                                        if (Double.parseDouble(getJTextFieldVertex1Y().getText()) < Double.parseDouble(getJTextFieldVertex2Y().getText())) {
1834
                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "v1y") + " < " + PluginServices.getText(jRadioButtonPreviewArea, "v2y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1835
                                                                                                getJTextFieldVertex1Y().setText(last_Coordinates[1]); // Restores its last value
1836
                                                                                                canSetExtent = false;
1837
                                                                                        }
1838
                                                                                        
1839
                                                                                        hasChanged_v1Y = false;
1840
                                                                                }
1841

    
1842
                                                                                if (hasChanged_v2X) {
1843
                                                                                        if (Double.parseDouble(getJTextFieldVertex2X().getText()) > Double.parseDouble(getJTextFieldVertex1X().getText())) {
1844
                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "v2x") + " > " + PluginServices.getText(jRadioButtonPreviewArea, "v1x"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1845
                                                                                                getJTextFieldVertex2X().setText(last_Coordinates[2]); // Restores its last value
1846
                                                                                                canSetExtent = false;
1847
                                                                                        }
1848
                                                                                        
1849
                                                                                        hasChanged_v2X = false;
1850
                                                                                }
1851

    
1852
                                                                                if (hasChanged_v2Y) {
1853
                                                                                        if (Double.parseDouble(getJTextFieldVertex2Y().getText()) > Double.parseDouble(getJTextFieldVertex1Y().getText())) {
1854
                                                                                                JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "v2y") + " > " + PluginServices.getText(jRadioButtonPreviewArea, "v1y"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1855
                                                                                                getJTextFieldVertex2Y().setText(last_Coordinates[3]); // Restores its last value
1856
                                                                                                canSetExtent = false;
1857
                                                                                        }
1858
                                                                                        
1859
                                                                                        hasChanged_v2Y = false;
1860
                                                                                }
1861
                                                                                
1862
                                                                                // If can set the new Extent -> finish
1863
                                                                                if (!canSetExtent)
1864
                                                                                        return;
1865
                                                                        }
1866
                                                                }
1867
                                                                                                                                
1868
                                                                //Rectangle2D r2d = vP.getExtent();
1869
                                                                if (vP.getExtent() != null){
1870
        //                                                                getCoordinatesPanel().setExtent(r2d);
1871
//                                                                        getCoordinatesPanel().getJTextFieldVertex1X().setText(Double.toString(r2d.getMinX()));
1872
//                                                                        getCoordinatesPanel().getJTextFieldVertex1Y().setText(Double.toString(r2d.getMinY()));
1873
//                                                                        getCoordinatesPanel().getJTextFieldVertex2X().setText(Double.toString(r2d.getMaxX()));
1874
//                                                                        getCoordinatesPanel().getJTextFieldVertex2Y().setText(Double.toString(r2d.getMaxY()));
1875
                                                                        //r2d.setRect(getNewRectangleByCoordinates());
1876
                                                                        vP.setExtent(getNewRectangleByCoordinates());
1877
                                                                        vP.refreshExtent();
1878
                                                                }
1879
                                                        }
1880
                                                }
1881
                                                else {
1882
                                                        JOptionPane.showMessageDialog(jRadioButtonPreviewArea, PluginServices.getText(jRadioButtonPreviewArea, "at_least_one_incorrect_coordinate"), PluginServices.getText(jRadioButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1883
                                                }
1884
                                        }        
1885
                                });
1886
                        }                
1887
                        return jRadioButtonPreviewArea;
1888
                }
1889
                
1890
                private Rectangle2D getNewRectangleByCoordinates() {
1891
                        return new Rectangle2D.Double(Double.parseDouble(getJTextFieldVertex2X().getText()), Double.parseDouble(getJTextFieldVertex2Y().getText()), Double.parseDouble(getJTextFieldVertex1X().getText()) - Double.parseDouble(getJTextFieldVertex2X().getText()), Double.parseDouble(getJTextFieldVertex1Y().getText()) - Double.parseDouble(getJTextFieldVertex2Y().getText()));
1892
//                        return new Rectangle2D.Double(Double.parseDouble(getJTextFieldVertex2X().getText()), Double.parseDouble(getJTextFieldVertex1Y().getText()), Double.parseDouble(getJTextFieldVertex1X().getText()) - Double.parseDouble(getJTextFieldVertex2X().getText()), Double.parseDouble(getJTextFieldVertex2Y().getText()) - Double.parseDouble(getJTextFieldVertex1Y().getText()));
1893
                }
1894

    
1895
                /**
1896
                 * Sets the extent
1897
                 * @param extent
1898
                 */
1899
                public void setExtent(Rectangle2D extent){
1900
                        getJTextFieldVertex1X().setText(String.valueOf(extent.getMaxX()));
1901
                        getJTextFieldVertex1Y().setText(String.valueOf(extent.getMaxY()));
1902
                        getJTextFieldVertex2X().setText(String.valueOf(extent.getMinX()));
1903
                        getJTextFieldVertex2Y().setText(String.valueOf(extent.getMinY()));
1904
                }
1905
                
1906
                /**
1907
                 * Gets the extent
1908
                 * @return
1909
                 */
1910
                public Rectangle2D getExtent(){
1911
                        if ((!getJTextFieldVertex1X().getText().equals("")) &&
1912
                                        (!getJTextFieldVertex1Y().getText().equals("")) &&
1913
                                        (!getJTextFieldVertex2X().getText().equals("")) &&
1914
                                        (!getJTextFieldVertex2Y().getText().equals(""))){
1915
                                Rectangle2D r2d = new Rectangle2D.Double(new Double(getJTextFieldVertex1X().getText()).doubleValue(),
1916
                                                new Double(getJTextFieldVertex1Y().getText()).doubleValue(),
1917
                                                new Double(getJTextFieldVertex2X().getText()).doubleValue(),
1918
                                                new Double(getJTextFieldVertex2Y().getText()).doubleValue());
1919
                                return r2d;
1920
                        }
1921
                        return null;
1922
                }
1923
                
1924
                /**
1925
                 * Enables or disables all inner JTextField
1926
                 * 
1927
                 * @param b A boolean value
1928
                 */
1929
                public void setAllTextFieldsEnabled(boolean b) {
1930
                        getJTextFieldVertex1X().setEnabled(b);
1931
                        getJTextFieldVertex1Y().setEnabled(b);
1932
                        getJTextFieldVertex2X().setEnabled(b);
1933
                        getJTextFieldVertex2Y().setEnabled(b);
1934
                }
1935
                
1936
//                public void updateCoordinates(Rectangle r) {
1937
//                        
1938
//                }
1939
                
1940
                /**
1941
                 * Updates the inner attribute that stores the values of the last coordinates
1942
                 */
1943
                private void updateLastCoordinates() {
1944
                        last_Coordinates[0] = getJTextFieldVertex1X().getText();
1945
                        last_Coordinates[1] = getJTextFieldVertex1Y().getText();
1946
                        last_Coordinates[2] = getJTextFieldVertex2X().getText();
1947
                        last_Coordinates[3] = getJTextFieldVertex2Y().getText();
1948
                }
1949
        }
1950
        
1951
        /**
1952
         * 
1953
         * 
1954
         * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
1955
         */
1956
        private class SelectableMapControlAreaPanel extends MapControl implements Serializable {
1957
                private MouseListener[] mouseListeners;
1958
                private MouseWheelListener[] mouseWheelListeners;
1959
                private MouseMotionListener[] mouseMotionListeners;
1960
                
1961
                public SelectableMapControlAreaPanel() {
1962
                        super();                        
1963
                        initialize();
1964
                }
1965
                
1966
                public void initialize() {
1967
                        
1968
                        
1969
                        /* Sets Bounds of this graphical component */
1970
                        this.setBounds(DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE);
1971

    
1972
                        
1973
                        /* Sets border to this graphical component */
1974
                        this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
1975
                        
1976
//                        this.addPropertyChangeListener(new PropertyChangeListener() {
1977
//
1978
//                                public void propertyChange(PropertyChangeEvent arg0) {
1979
//                                        // TODO Auto-generated method stub
1980
//                                        System.out.println("Propiedad ha cambiado: " + arg0.getPropertyName());
1981
//                                        
1982
//                                        if (getMapContext().getViewPort().getExtents().hasPrevious())
1983
//                                                getJButtonZoomPrevious().setEnabled(true);
1984
//                                        else
1985
//                                                getJButtonZoomPrevious().setEnabled(false);
1986
//                                }
1987
//                                
1988
//                        });
1989

    
1990
                        /* Sets a clone of the current active view map context to this MapControl */
1991
                        try {
1992
                                MapContext mp = ((View) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
1993
                                this.setMapContext(mp.cloneFMap());
1994
                        } catch (XMLException e) {
1995
                                e.printStackTrace();
1996
                        }
1997

    
1998
                        /* Adds listeners to this MapControl */
1999
                        this.addToolsListeners();
2000
                        
2001
                        /* Sets default tool */
2002
                        this.setTool(PAN_TOOL);
2003
                }
2004
                
2005
                /**
2006
                 * Refresh the active view
2007
                 */
2008
                public void refreshWithTheActiveView() {
2009
                        try {
2010
                                MapContext mp = ((View) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
2011
                                this.setMapContext(mp.cloneFMap());
2012
                                this.getViewPort().refreshExtent();
2013

    
2014
                        } catch (XMLException e) {
2015
                                e.printStackTrace();
2016
                        }
2017
                }
2018
                
2019
//                public void refresh() {
2020
//                        // Gets the active view
2021
//                        View view = (View) PluginServices.getMDIManager().getActiveWindow();
2022
//                        //layoutControl.setLayoutContext()
2023
//                        
2024
////                        view.getTOC().getTree().
2025
//                        
2026
////                        // Gets the map control of the view
2027
////                        MapControl mapControl = view.getMapControl();
2028
////                        FLayers fLayers = mapControl.getMapContext().getLayers();
2029
////                        fLayers.getL
2030
////                        
2031
////                        layoutControl.
2032
//                        
2033
//                        // Gets the current selected layer
2034
////                        mapControl.
2035
//                        
2036
//                        
2037
////                        IFFrame fframeAux=fframe.cloneFFrame(layout);
2038
////                        fframeAux.setBoundBox(r);
2039
////                        layout.getLayoutContext().getEFS().modifyFFrame(fframe,fframeAux);
2040
////                        layout.getLayoutContext().updateFFrames();
2041
//                        
2042
////                         /* Adds the layers to the View */
2043
////                         // To prevent that events that take place(are produced) could be a nuisance to the load of the layers
2044
////                         mapControl.getMapContext().beginAtomicEvent();
2045
////
2046
////                         int numberOfLayers = mapControl.getMapContext().getLayers().getLayersCount();
2047
////                         
2048
////                         // Adds the layers
2049
////                         mapControl.getMapContext().getLayers().addLayer(ideeLayer);
2050
////                         
2051
////                         // Changes the name of the layers into more intuitive other one
2052
////                         mapControl.getMapContext().getLayers().getLayer(numberOfLayers).setName((String)info.get("name"));
2053
////                                
2054
////                         // End To prevent that events that take place(are produced) could be a nuisance to the load of the layers                 
2055
////                         mapControl.getMapContext().endAtomicEvent();
2056
////                    
2057
////                         // Refresh the view
2058
////                         mapControl.getMapContext().invalidate();
2059
//                }
2060
//        }
2061
        
2062
//        /**
2063
//         * DOCUMENTAR!!
2064
//         * 
2065
//         * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
2066
//         */
2067
//        public class AreaMapControlPanel extends MapControl {
2068
////                private final Rectangle DEFAULT_AREA_MAPCONTROL_RECTANGLE = new Rectangle(0, 0, DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE.width, DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE.height);
2069
//                
2070
////                private MapControl m_MapControl = null;
2071
//                
2072
//                /**
2073
//                 * Default constructor
2074
//                 */
2075
//                public AreaMapControlPanel() {
2076
//                        this.initialize();
2077
//                }
2078
//                
2079
//                /**
2080
//                 * This method initializes this
2081
//                 */
2082
//                private void initialize() {
2083
//                        this.setLayout(null);
2084
//                        this.setBounds(DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE);
2085
//                        this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
2086
////                        this.setBorder(javax.swing.BorderFactory.createTitledBorder(
2087
////                        null, PluginServices.getText(this, "select_by_graphical_area"),
2088
////                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
2089
////                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
2090
////                        this.add(this.getMapControl(DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE.getSize()));
2091
//                }
2092
//                
2093
////                /*
2094
////                 *  (non-Javadoc)
2095
////                 * @see java.awt.Component#setEnabled(boolean)
2096
////                 */
2097
////                public void setEnabled(boolean enabled) {
2098
////                        this.setEnabled(false);
2099
////                        this.getMapControl().setEnabled(false);
2100
////                }
2101
//                
2102
////                /*
2103
////                 *  (non-Javadoc)
2104
////                 * @see com.iver.cit.gvsig.project.documents.view.gui.IView#getMapControl()
2105
////                 */
2106
////                public MapControl getMapControl() {
2107
////                        return this.m_MapControl;
2108
////                }
2109
//                
2110
//
2111
//                /**
2112
//                 * Adds listeners to the inner MapControl of the inner area JPanel ??
2113
//                 * (SOBRAR?N ALGUNOS)
2114
//                 */
2115
//                private void addListeneresToAreaPanel() {
2116
////                    //Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado
2117
////                StatusBarListener sbl = new StatusBarListener(this.areaMapControlPanel.getMapControl());
2118
//        //
2119
////                // Zoom out (pinchas y el mapa se centra y te muestra m?s).
2120
////                // No es dibujando un rect?ngulo, es solo pinchando.
2121
////                ZoomOutListener zol = new ZoomOutListener(this.areaMapControlPanel.getMapControl());
2122
////                this.areaMapControlPanel.getMapControl().addMapTool("zoomOut", new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)});
2123
//        //
2124
////                // Pan
2125
////                PanListener pl = new PanListener(this.areaMapControlPanel.getMapControl());
2126
////                this.areaMapControlPanel.getMapControl().addMapTool("pan", new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)});
2127
//        //
2128
////                // Medir
2129
////                MeasureListener mli = new MeasureListener(this.areaMapControlPanel.getMapControl());
2130
////                this.areaMapControlPanel.getMapControl().addMapTool("medicion", new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)});
2131
//        //
2132
////                // Area
2133
////                AreaListener ali = new AreaListener(this.areaMapControlPanel.getMapControl());
2134
////                this.areaMapControlPanel.getMapControl().addMapTool("area", new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)});
2135
//        //
2136
////                // Seleccion por punto
2137
////                PointSelectListener psl = new PointSelectListener(this.areaMapControlPanel.getMapControl());
2138
////                this.areaMapControlPanel.getMapControl().addMapTool("pointSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
2139
//        //
2140
////                // Info por punto
2141
////                InfoListener il = new InfoListener(this.areaMapControlPanel.getMapControl());
2142
////                this.areaMapControlPanel.getMapControl().addMapTool("info", new Behavior[]{new PointBehavior(il), new MouseMovementBehavior(sbl)});
2143
//        //
2144
////                // Link por punto
2145
////                LinkListener ll = new LinkListener(this.areaMapControlPanel.getMapControl());
2146
////                this.areaMapControlPanel.getMapControl().addMapTool("link", new Behavior[]{new PointBehavior(ll), new MouseMovementBehavior(sbl)});
2147
//        //
2148
////                // Selecci?n por rect?ngulo
2149
////                RectangleSelectListener rsl = new RectangleSelectListener(this.areaMapControlPanel.getMapControl());
2150
////                this.areaMapControlPanel.getMapControl().addMapTool("rectSelection", new Behavior[]{new RectangleBehavior(rsl), new MouseMovementBehavior(sbl)});
2151
//        //
2152
////                // Selecci?n por pol?gono
2153
////                PolygonSelectListener poligSel = new PolygonSelectListener(this.areaMapControlPanel.getMapControl());
2154
////                this.areaMapControlPanel.getMapControl().addMapTool("polSelection", new Behavior[]{new PolygonBehavior(poligSel), new MouseMovementBehavior(sbl)});
2155
//        //
2156
////                // Zoom por rect?ngulo
2157
////                ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(this.areaMapControlPanel.getMapControl());
2158
////                ZoomInListener zil = new ZoomInListener(this.areaMapControlPanel.getMapControl());
2159
////                this.areaMapControlPanel.getMapControl().addMapTool("zoomIn", new Behavior[]{new RectangleBehavior(zil),
2160
////                                                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
2161
//        //
2162
////                SelectImageListener sil = new SelectImageListener(this.areaMapControlPanel.getMapControl());
2163
////                this.areaMapControlPanel.getMapControl().addMapTool("selectImage", new Behavior[]{
2164
////                                        new PointBehavior(sil), new MouseMovementBehavior(sbl)});
2165
//        //setEnabled
2166
////                ZoomPixelCursorListener zp = new ZoomPixelCursorListener(this.areaMapControlPanel.getMapControl());
2167
////                this.areaMapControlPanel.getMapControl().addMapTool("zoom_pixel_cursor", new Behavior[]{new PointBehavior(zp), new MouseMovementBehavior(sbl)});
2168
//        //
2169
////                this.areaMapControlPanel.getMapControl().setTool("zoomIn"); // Por defecto
2170
////                // m_MapControl.setPaintEnabled(true);
2171
//                }
2172
//                
2173
////                /**
2174
////                 * This method initializes m_MapControl        
2175
////                 *         
2176
////                 * @return com.iver.cit.gvsig.fmap.MapControl
2177
////                 */
2178
////                private MapControl getMapControl(Dimension d) {
2179
////                        if (m_MapControl == null) {
2180
////                        m_MapControl = new MapControl(); // Default is paintEnabled = false.
2181
////                        m_MapControl.setBounds(DEFAULT_AREA_MAPCONTROL_RECTANGLE);
2182
////                        }
2183
////
2184
////                        return m_MapControl;
2185
////                }
2186
//
2187
//                /**
2188
//                 * @see MapControl#drawMap(boolean)
2189
//                 */
2190
//                public void repaintMap() {
2191
//                        this.drawMap(false);
2192
//                }
2193
////                
2194
////                /**
2195
////                 * @see MapControl#getImage()
2196
////                 */
2197
////                public BufferedImage getImage() {
2198
////                        return getMapControl().getImage();
2199
////                }
2200
////                
2201
////                /**
2202
////                 * @see MapControl#setProjection(IProjection)
2203
////                 */
2204
////                public void setProjection(IProjection proj)
2205
////                {
2206
////                        getMapControl().setProjection(proj);
2207
////                }
2208
////                
2209
////                /**
2210
////                 * @see MapControl#getProjection()
2211
////                 */
2212
////                public IProjection getProjection()
2213
////                {
2214
////                        return getMapControl().getProjection();
2215
////                }
2216
//                setEnabled
2217
//                public void enableTool(String Tool_ID) {
2218
//                        setTool(Tool_ID);
2219
//                }
2220
//                
2221
//                public String getEnabledTool()
2222
                
2223
                
2224
                private void addToolsListeners() {
2225
                        // MOVEMENT EVENTS LISTENER: sets mouse coordinates to the status bar
2226
                StatusBarListener sbl = new StatusBarListener(this);
2227

    
2228
                // ZOOM OUT (Presses on the map and it will be centered showing a bigger area)
2229
                // Only pressing, not selecting a rectangle area
2230
                ZoomOutListener zol = new ZoomOutListener(this);
2231
                this.addMapTool(ZOOM_OUT_TOOL, new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)});
2232

    
2233
                // ZOOM IN (Using a Rectangle or a simple mouse click)
2234
                ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(this);
2235
                ZoomInListener zil = new ZoomInListener(this);
2236
                this.addMapTool(ZOOM_IN_TOOL, new Behavior[]{new RectangleBehavior(zil),
2237
                                                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
2238
                
2239
                // PAN
2240
                PanListener pl = new PanListener(this);
2241
                this.addMapTool(PAN_TOOL, new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)});
2242

    
2243
                // MEASURE DISTANCES
2244
                MeasureListener mli = new MeasureListener(this);
2245
                this.addMapTool(MEASURE_DISTANCES_TOOL, new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)});
2246

    
2247
                // MEASURE AREA
2248
                AreaListener ali = new AreaListener(this);
2249
                this.addMapTool(MEASURE_AREA_TOOL, new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)});
2250
                
2251
//                // INFORMATION ABOUT A POINT
2252
//                InfoListener il = new InfoListener(this);
2253
//                this.addMapTool(INFO_TOOL, new Behavior[]{new PointBehavior(il), new MouseMovementBehavior(sbl)});
2254

    
2255
//                // ZOOM RECTANGLE SELECTION
2256
//                RectangleSelectListener rsl = new RectangleSelectListener(this);
2257
//                this.addMapTool(ZOOM_RECTANGLE_SELECTION_TOOL, new Behavior[]{new RectangleBehavior(rsl), new MouseMovementBehavior(sbl)});
2258

    
2259

    
2260
//                // Medir
2261
//
2262
//                MeasureListener mli = new MeasureListener(this);
2263
//                this.addMapTool("medicion", new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)});
2264
//
2265
//                // Area
2266
//
2267
//                AreaListener ali = new AreaListener(this);
2268
//                this.addMapTool("area", new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)});
2269
//
2270
//                //Seleccion por punto
2271
//                PointSelectListener psl = new PointSelectListener(this);
2272
//                this.addMapTool("pointSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
2273
//
2274
//                //Info por punto
2275
//                InfoListener il = new InfoListener(this);
2276
//                this.addMapTool("info", new Behavior[]{new PointBehavior(il), new MouseMovementBehavior(sbl)});
2277
//
2278
////              Link por punto
2279
//                LinkListener ll = new LinkListener(this);
2280
//                this.addMapTool("link", new Behavior[]{new PointBehavior(ll), new MouseMovementBehavior(sbl)});
2281
//
2282
//                //Selecci?n por rect?ngulo
2283
//                RectangleSelectListener rsl = new RectangleSelectListener(this);
2284
//                this.addMapTool("rectSelection", new Behavior[]{new RectangleBehavior(rsl), new MouseMovementBehavior(sbl)});
2285
//
2286
//                //Selecci?n por pol?gono
2287
//                PolygonSelectListener poligSel = new PolygonSelectListener(this);
2288
//                this.addMapTool("polSelection", new Behavior[]{new PolygonBehavior(poligSel), new MouseMovementBehavior(sbl)});
2289
//
2290
//
2291
//                SelectImageListener sil = new SelectImageListener(this);
2292
//                this.addMapTool("selectImage", new Behavior[]{
2293
//                                        new PointBehavior(sil), new MouseMovementBehavior(sbl)});
2294
//
2295
//                ZoomPixelCursorListener zp = new ZoomPixelCursorListener(this);
2296
//                this.addMapTool("zoom_pixel_cursor", new Behavior[]{new PointBehavior(zp), new MouseMovementBehavior(sbl)});
2297
//
2298
//                this.setTool(PAN_TOOL); // Por defecto
2299
              //   m_MapControl.setPaintEnabled(true);
2300
                
2301
                this.getViewPort().addViewPortListener(new ViewPortListener() {
2302
                        /*
2303
                         *  (non-Javadoc)
2304
                         * @see com.iver.cit.gvsig.fmap.ViewPortListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
2305
                         */
2306
                                public void extentChanged(ExtentEvent e) {
2307
                                        if (getMapContext().getViewPort().getExtents().hasPrevious()) {
2308
//                                                Rectangle2D r2d = getViewPort().getAdjustedExtent();
2309
                                                Rectangle2D r2d = getViewPort().getExtent();
2310

    
2311
                                                if (r2d != null)
2312
                                                        getCoordinatesPanel().setExtent(r2d);
2313
                                                
2314
                                                getJButtonZoomPrevious().setEnabled(true);
2315
                                                getJButtonUndo().setEnabled(true);
2316
                                        }
2317
                                        else {
2318
                                                getJButtonZoomPrevious().setEnabled(false);
2319
                                                getJButtonUndo().setEnabled(false);
2320
                                        }
2321
                                        
2322
//                                        View activeView = 
2323
//                                                (View) PluginServices.getMDIManager().getActiveWindow();
2324
                                        
2325
//                                        updateCoordinates(getMapContext().getViewPort().getExtent());
2326
                                        
2327
//                                        // Updates the context of the Active View with the new selected context
2328
//                                        MapControl mCOV = ((View)PluginServices.getMDIManager().getActiveWindow()).getMapControl();
2329
//                                        MapContext last_View_MapContext = mCOV.getMapContext(); 
2330
//                                        try {
2331
//                                                // Sets in view a clone of the selected Map Context
2332
//                                                mCOV.setMapContext(getMapContext().cloneFMap());
2333
//                                        } catch (XMLException e1) {
2334
//                                                // If fails the clonation -> show stack trace and restore the last mapContext of the view
2335
//                                                e1.printStackTrace();
2336
//                                                
2337
//                                                mCOV.setMapContext(last_View_MapContext);
2338
//                                                setMapContext(last_View_MapContext);
2339
//                                        }
2340
                                        
2341
//                                        // Updates the context of the Active View with the new selected context
2342
//                                        MapControl mCOV = ((View)PluginServices.getMDIManager().getActiveWindow()).getMapControl();
2343
//                                        MapContext last_View_MapContext = mCOV.getMapContext(); 
2344
//                                        try {
2345
//                                                // Sets in view a clone of the selected Map Context
2346
//                                                mCOV.setMapContext(getMapContext().cloneFMap());
2347
//                                                mCOV.repaint();
2348
//                                        } catch (XMLException e1) {
2349
//                                                // If fails the clonation -> show stack trace and restore the last mapContext of the view
2350
//                                                e1.printStackTrace();
2351
//                                                
2352
//                                                mCOV.setMapContext(last_View_MapContext);
2353
//                                                setMapContext(last_View_MapContext);
2354
//                                        }
2355
                                }
2356

    
2357
                                /*
2358
                                 *  (non-Javadoc)
2359
                                 * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
2360
                                 */
2361
                                public void backColorChanged(ColorEvent e) {
2362
                                }
2363

    
2364
                                /*
2365
                                 *  (non-Javadoc)
2366
                                 * @see com.iver.cit.gvsig.fmap.ViewPortListener#projectionChanged(com.iver.cit.gvsig.fmap.ProjectionEvent)
2367
                                 */
2368
                                public void projectionChanged(ProjectionEvent e) {
2369
                                }
2370
                        
2371
                });
2372
                }
2373
                
2374
                public void setEnabled(boolean b) {
2375
                        super.setEnabled(b);
2376
                        
2377
                        if (b)
2378
                                enableAllMouseListeners();
2379
                        else
2380
                                disableAllMouseListeners();
2381
                }
2382
                
2383
                public void disableAllMouseListeners() {
2384
                        int i;
2385
                        
2386
                        // Only disable listeners if there are listeners to remove (it's supposed that there are always the same number of mouse listeners, and this listeners
2387
                        //   are referenciated by this component or by the private attribute 'mouseListeners')
2388
                        
2389
                        // Mouse Button Listeners
2390
                        if (mouseListeners == null) {
2391
                                mouseListeners = this.getMouseListeners();
2392
                                
2393
                                for (i = 0; i < mouseListeners.length; i++) {
2394
                                        removeMouseListener(mouseListeners[i]);
2395
                                }
2396
                        }
2397
                        
2398
                        // Mouse Wheel Listeners
2399
                        if (mouseWheelListeners == null) {
2400
                                mouseWheelListeners = this.getMouseWheelListeners();
2401
                                
2402
                                for (i = 0; i < mouseWheelListeners.length; i++) {
2403
                                        removeMouseWheelListener(mouseWheelListeners[i]);
2404
                                }
2405
                        }
2406
                        
2407
                        // Mouse motion listeners
2408
                        if (mouseMotionListeners == null) {
2409
                                mouseMotionListeners = this.getMouseMotionListeners();
2410
                                
2411
                                for (i = 0; i < mouseMotionListeners.length; i++) {
2412
                                        removeMouseMotionListener(mouseMotionListeners[i]);
2413
                                }
2414
                        }
2415
                }
2416
                        
2417
                public void enableAllMouseListeners() {
2418
                        int i;
2419
                        
2420
                        // Mouse Button Listeners
2421
                        for (i = 0; i < mouseListeners.length; i++) {
2422
                                addMouseListener(mouseListeners[i]);
2423
                        }
2424
                        
2425
                        mouseListeners = null;
2426
                        
2427
                        // Mouse Wheel Listeners
2428
                        for (i = 0; i < mouseWheelListeners.length; i++) {
2429
                                addMouseWheelListener(mouseWheelListeners[i]);
2430
                        }
2431
                        
2432
                        mouseWheelListeners = null;
2433
                        
2434
                        // Mouse motion listeners
2435
                        for (i = 0; i < mouseMotionListeners.length; i++) {
2436
                                addMouseMotionListener(mouseMotionListeners[i]);
2437
                        }
2438
                        
2439
                        mouseMotionListeners = null;
2440
                }
2441
        }
2442
}