Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSAreaPanel.java @ 10775

History | View | Annotate | Download (85 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.Rectangle;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.awt.event.FocusEvent;
10
import java.awt.event.FocusListener;
11
import java.awt.event.ItemEvent;
12
import java.awt.event.ItemListener;
13
import java.awt.event.KeyEvent;
14
import java.awt.event.KeyListener;
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.AbstractButton;
24
import javax.swing.ImageIcon;
25
import javax.swing.JComboBox;
26
import javax.swing.JLabel;
27
import javax.swing.JOptionPane;
28
import javax.swing.JPanel;
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.cit.gvsig.fmap.ColorEvent;
35
import com.iver.cit.gvsig.fmap.ExtentEvent;
36
import com.iver.cit.gvsig.fmap.MapContext;
37
import com.iver.cit.gvsig.fmap.MapControl;
38
import com.iver.cit.gvsig.fmap.ProjectionEvent;
39
import com.iver.cit.gvsig.fmap.ViewPort;
40
import com.iver.cit.gvsig.fmap.ViewPortListener;
41
import com.iver.cit.gvsig.fmap.layers.XMLException;
42
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
43
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
44
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
45
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior;
46
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
47
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior;
48
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior;
49
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
50
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
51
import com.iver.cit.gvsig.project.documents.view.gui.View;
52
import com.iver.cit.gvsig.project.documents.view.toolListeners.AreaListener;
53
import com.iver.cit.gvsig.project.documents.view.toolListeners.MeasureListener;
54
import com.iver.cit.gvsig.project.documents.view.toolListeners.PanListener;
55
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
56
import com.iver.cit.gvsig.project.documents.view.toolListeners.ZoomInListener;
57
import com.iver.cit.gvsig.project.documents.view.toolListeners.ZoomOutListener;
58
import com.iver.utiles.stringNumberUtilities.StringNumberUtilities;
59

    
60
import javax.swing.JButton;
61

    
62
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.ImageIconItemInfo;
63
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.JComboBoxWithImageIconItems;
64
import org.gvsig.gui.beans.swing.jTextFieldWithSpecificCaretPosition.JTextFieldWithSpecificCaretPosition;
65

    
66
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
67
 *
68
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
69
 *
70
 * This program is free software; you can redistribute it and/or
71
 * modify it under the terms of the GNU General Public License
72
 * as published by the Free Software Foundation; either version 2
73
 * of the License, or (at your option) any later version.
74
 *
75
 * This program is distributed in the hope that it will be useful,
76
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
77
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
78
 * GNU General Public License for more details.
79
 *
80
 * You should have received a copy of the GNU General Public License
81
 * along with this program; if not, write to the Free Software
82
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
83
 *
84
 * For more information, contact:
85
 *
86
 *  Generalitat Valenciana
87
 *   Conselleria d'Infraestructures i Transport
88
 *   Av. Blasco Ib??ez, 50
89
 *   46010 VALENCIA
90
 *   SPAIN
91
 *
92
 *      +34 963862235
93
 *   gvsig@gva.es
94
 *      www.gvsig.gva.es
95
 *
96
 *    or
97
 *
98
 *   IVER T.I. S.A
99
 *   Salamanca 50
100
 *   46005 Valencia
101
 *   Spain
102
 *
103
 *   +34 963163400
104
 *   dac@iver.es
105
 */
106
/* CVS MESSAGES:
107
 *
108
 * $Id: WFSAreaPanel.java 10775 2007-03-15 13:32:44Z ppiqueras $
109
 * $Log$
110
 * Revision 1.27  2007-03-15 13:32:44  ppiqueras
111
 * -Corregido bug de excepci?n que se lanzaba cuando se filtraba y no se pod?a cargar la capa.
112
 * - Mejorada la interfaz
113
 *
114
 * Revision 1.26  2007/03/06 18:01:03  caballero
115
 * Exceptions
116
 *
117
 * Revision 1.25  2007/03/05 13:47:42  ppiqueras
118
 * Eliminadas l?neas que sobraban.
119
 *
120
 * Revision 1.24  2007/03/01 13:13:58  ppiqueras
121
 * A?adido m?todo para que si no se ha modificado el ?rea que no se aplique filtro por ?rea. Y mejorado el m?todo getExtent() (obtenci?n del Rectangle2D que define el ?rea: si el usuario no ha seleccionado un ?rea distinta, devolver? null).
122
 *
123
 * Revision 1.23  2007/02/26 13:40:28  ppiqueras
124
 * - Eliminado bot?n zoom siguiente
125
 * - En caso de que no haya vista cargada, que los botones de escalar y desplazar est?n deshabilitados
126
 *
127
 * Revision 1.22  2007/02/26 12:58:09  ppiqueras
128
 * En caso de escribir una coordenada con formato incorrecto, avisa al usuario y restaura el valor anterior.
129
 *
130
 * Revision 1.21  2007/02/22 13:17:57  ppiqueras
131
 * Mejor documentado el c?digo.
132
 *
133
 * Revision 1.20  2007/02/22 12:23:32  ppiqueras
134
 * Varias mejoras:
135
 * - Aviso de error en caso de intentar cargar capa con ?rea mal indicada.
136
 * - Obtenci?n del ?rea de las coordenadas.
137
 * - Alg?n bug corregido.
138
 *
139
 * Revision 1.19  2007/02/20 13:13:26  ppiqueras
140
 * Se habilita el bot?n aplicar del panel padre en caso de alg?n cambio de coordendas, y mejora en la obtenci?n del ?rea del usuario.
141
 *
142
 * Revision 1.18  2007/02/20 11:31:11  ppiqueras
143
 * Eliminados comentarios que sobraban.
144
 *
145
 * Revision 1.17  2007/02/16 13:36:53  ppiqueras
146
 * Que el ?rea seleccionada en el panel WFSArea sea accesible una vez se va a aplicar.
147
 *
148
 * Revision 1.16  2007/02/16 13:14:21  ppiqueras
149
 * Mejorada la selecci?n por coordenadas absolutas  y corregido alg?n bug.
150
 *
151
 * Revision 1.15  2007/02/15 11:36:57  ppiqueras
152
 * Mejorada la interfaz: nuevas herramientas, mejoradas las de coordenadas absolutas. Y corregido alg?n bug de interacci?n con otros paneles.
153
 *
154
 * Revision 1.14  2007/02/12 11:29:37  ppiqueras
155
 * Mejoras de la interfaz y uso de las herramientas
156
 *
157
 * Revision 1.13  2007/02/09 14:22:07  ppiqueras
158
 * Mejoras de funcionalidad
159
 *
160
 * Revision 1.12  2007/02/09 13:56:56  ppiqueras
161
 * Mejorada la funcionalidad de la interfaz: ya hay varias herramientas que se pueden usar.
162
 *
163
 * Revision 1.11  2007/02/08 14:18:57  ppiqueras
164
 * Carga de la vista actual.
165
 *
166
 * Revision 1.10  2007/02/05 13:49:26  ppiqueras
167
 * Mejorada la interfaz y a?adidos componentes de tipo lista desplegable con iconos como ?tems.
168
 *
169
 * Revision 1.9  2007/02/02 12:22:03  ppiqueras
170
 * Mejorada la interfaz.
171
 *
172
 * Revision 1.8  2007/01/26 14:23:56  ppiqueras
173
 * Mejorada la interfaz
174
 *
175
 * Revision 1.7  2007/01/25 14:37:16  ppiqueras
176
 * Utiliza JTextFieldWithSpecificCaretPosition
177
 *
178
 * Revision 1.6  2007/01/25 09:31:09  ppiqueras
179
 * Mejorada la interfaz.
180
 *
181
 * Revision 1.5  2007/01/19 14:24:30  ppiqueras
182
 * + Avanzada.
183
 *
184
 * Revision 1.4  2007/01/12 13:09:41  jorpiell
185
 * added searches by area
186
 *
187
 * Revision 1.3  2007/01/10 09:01:25  jorpiell
188
 * The coordinates panel is opened with the view coordinates
189
 *
190
 * Revision 1.2  2006/12/22 11:45:53  jorpiell
191
 * Actualizado el driver del WFS
192
 *
193
 * Revision 1.1  2006/10/10 12:55:06  jorpiell
194
 * Se ha a?adido el soporte de features complejas
195
 *
196
 *
197
 */
198

    
199
/**
200
 * This panel allows user to select the area he/she wants to get in the view.
201
 * There are two options to do this:
202
 *  - Indicating the coordinates of the top-left and down-right corners
203
 *  - Selecting the area with the mouse
204
 *
205
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
206
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
207
 */
208
public class WFSAreaPanel extends JPanel {
209
        private final Rectangle DEFAULT_BOUNDS = new Rectangle(10, 5, 490, 380);
210
        private final Rectangle DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE = new Rectangle(8, 20, 481, 60);
211
        private final Rectangle DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE = new Rectangle(8, 115, 481, 265);
212
        private final Rectangle DEFAULT_UNDO_ICON_BUTTON_RECTANGLE = new Rectangle (250, 85, 25, 25);
213
//        private final Rectangle DEFAULT_REDO_ICON_BUTTON_RECTANGLE = new Rectangle (277, 85, 25, 25);
214
//        private final Rectangle DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (304, 85, 25, 25);
215
//        private final Rectangle DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (331, 85, 25, 25);
216
        private final Rectangle DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (277, 85, 25, 25);
217
        private final Rectangle DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (304, 85, 25, 25);
218
        private final Rectangle DEFAULT_PAN_ICON_BUTTON_RECTANGLE = new Rectangle(250, 85, 25, 25);
219
        private final Rectangle DEFAULT_TOOL_JCOMBOBOX_RECTANGLE = new Rectangle(10, 87, 230, 21);
220
        private final Rectangle DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE = new Rectangle(277, 85, 47, 25);
221
        private final Rectangle DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE = new Rectangle(326, 85, 25, 25);
222
        private final Rectangle DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE = new Rectangle(353, 85, 25, 25);
223
        private final Rectangle DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE = new Rectangle(380, 85, 47, 25);
224
        private final Rectangle DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE = new Rectangle(429, 85, 47, 25);
225

    
226
        private final int DISABLED_OPERATION = 0;
227
        private final int SELECTION_BY_COORDINATES_OPERATION = 1;
228
        private final int SELECTION_BY_AREA_OPERATION = 2;
229
        private boolean hasUserDefinedAnArea;
230

    
231
        private WFSWizardData data = null;
232
        private WFSParamsPanel parent = null;
233
        private AreaCoordinatesPanel coordinatesPanel = null;
234
        private SelectableMapControlAreaPanel selectableMapAreaPanel = null;
235
        private JComboBox jComboBoxToolSelection = null;
236
        private JButton jButtonUndo = null;
237
//        private JButton jButtonRedo = null;
238
        private JToggleButton jToggleButtonMove = null;
239
        private JToggleButton jToggleButtonScaling = null;
240
        private JButton jButtonPan = null;
241
        private JButton jButtonZoomPrevious = null;
242
        private JButton jButtonZoomComplete = null;
243
        private JComboBoxWithImageIconItems jComboBoxZoomInAndOut = null;
244
        private JComboBoxWithImageIconItems jComboBoxZoomInAndOutViewCentered = null;
245
        private JComboBoxWithImageIconItems jComboBoxOtherTools = null;
246

    
247
        /* Tool identifier constants */
248
        private final String PAN_TOOL = "HAND";
249
        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'
250
        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'
251
        private final String ZOOM_IN_VIEW_CENTERED_TOOL = "ZOOM_IN_VIEW_CENTERED";
252
        private final String ZOOM_OUT_VIEW_CENTERED_TOOL = "ZOOM_OUT_VIEW_CENTERED";
253
        private final String MEASURE_DISTANCES_TOOL = "MEASURE_DISTANCES";
254
        private final String MEASURE_AREA_TOOL = "MEASURE_AREA";
255
        /* End tool identifier constants */
256

    
257

    
258
        /**
259
         * This method initializes
260
         */
261
        public WFSAreaPanel(WFSParamsPanel parent) {
262
                super();
263
                this.parent = parent;
264
                initialize();
265
        }
266

    
267
        /**
268
         * This method initializes this
269
         */
270
        private void initialize() {
271
                this.setLayout(null);
272
                this.setBounds(DEFAULT_BOUNDS);
273
                this.setBorder(javax.swing.BorderFactory.createTitledBorder(
274
                                null, PluginServices.getText(this, "select_by_area"),
275
                                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
276
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
277

    
278
                // By default, user hasn't defined an area
279
                this.hasUserDefinedAnArea = false;
280

    
281
                // Adds JPanel with the coordinates
282
                this.add(getCoordinatesPanel(), null);
283

    
284
                // Adds JComboBox to select a part of the graphical interface
285
                this.add(getJComboBoxToolSelection(), null);
286
                this.getJComboBoxToolSelection().setSelectedIndex(0); // By default select first element
287

    
288
                // Adds JPanel with the view
289
                this.add(getSelectableMapAreaPanel(), null);
290

    
291
                initCoordinates();
292
        }
293

    
294
        /**
295
         * Write the view coordinates into the coordinates panel
296
         */
297
        private void initCoordinates(){
298
                View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
299
                Rectangle2D r2d = activeView.getMapControl().getViewPort().getExtent();
300
                if (r2d != null){
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
                                                                 disableCoorderatesRegionOperation();
363
                                                         }
364

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

    
373
        /**
374
         * Enables the components associated to the selection of area by coordinates
375
         */
376
        private void enableCoorderatesRegionOperation() {
377
                // Adds associated icons
378
                this.add(getJButtonUndo(), null);
379
//                this.add(getJButtonRedo(), null);
380
                this.add(getJToggleButtonMove(), null);
381
                this.add(getJToggleButtonScaling(), null);
382

    
383
                getCoordinatesPanel().setAllTextFieldsEnabled(true);
384

    
385
                 // Only enable the area operation if there is data loaded in this MapControl
386
                 if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) {
387
                         getJToggleButtonMove().setEnabled(true);
388
                         getJToggleButtonScaling().setEnabled(true);
389
                         getCoordinatesPanel().getJButtonPreviewArea().setEnabled(true);
390
                 }
391
                 else {
392
                         getJToggleButtonMove().setEnabled(false);
393
                         getJToggleButtonScaling().setEnabled(false);
394
                 }
395
        }
396

    
397
        /**
398
         * Enables the components associated to the selection of area by view
399
         */
400
        private void enableAreaRegionOperation() {
401
                // Adds associated icons
402
                this.add(getJButtonPan(), null);
403
                this.add(getJComboBoxZoomInAndOut(), null);
404
                getJComboBoxZoomInAndOut().revalidate(); // Force update this component
405
                this.add(getJButtonZoomPrevious(), null);
406
                this.add(getJButtonZoomComplete(), null);
407
                this.add(getJComboBoxZoomInAndOutViewCentered(), null);
408
                getJComboBoxZoomInAndOutViewCentered().revalidate(); // Force update this component
409
                this.add(getJComboBoxOtherTools(), null);
410
                getJComboBoxOtherTools().revalidate(); // Force update this component
411

    
412
                // Enables the MapControl area
413
                getSelectableMapAreaPanel().setEnabled(true);
414
        }
415

    
416
        /**
417
         * Disables the components associated to the selection of area by coordinates
418
         */
419
        private void disableCoorderatesRegionOperation() {
420
                // Removes associated icons
421
                this.remove(getJButtonUndo());
422
//                this.remove(getJButtonRedo());
423
                this.remove(getJToggleButtonMove());
424
                this.remove(getJToggleButtonScaling());
425

    
426
                getCoordinatesPanel().setAllTextFieldsEnabled(false);
427
                getCoordinatesPanel().getJButtonPreviewArea().setEnabled(false);
428
        }
429

    
430
        /**
431
         * Disables the components associated to the selection of area by view
432
         */
433
        private void disableAreaRegionOperation() {
434
                // Removes associated icons
435
                this.remove(getJButtonPan());
436
                this.remove(getJComboBoxZoomInAndOut());
437
                this.remove(getJButtonZoomPrevious());
438
                this.remove(getJButtonZoomComplete());
439
                this.remove(getJComboBoxZoomInAndOutViewCentered());
440
                this.remove(getJComboBoxOtherTools());
441

    
442
                // Disables the MapControl area
443
                getSelectableMapAreaPanel().setEnabled(false);
444
        }
445

    
446
        /**
447
         * This method initializes areaMapControlPanel
448
         *
449
         * @return A reference to an object of SelectableMapControlAreaPanel
450
         */
451
        private SelectableMapControlAreaPanel getSelectableMapAreaPanel() {
452
                if (selectableMapAreaPanel == null) {
453
                        selectableMapAreaPanel = new SelectableMapControlAreaPanel();
454
                }
455

    
456
                return selectableMapAreaPanel;
457
        }
458

    
459
        /**
460
         * This method initializes jButtonUndo
461
         *
462
         * @return javax.swing.JButton
463
         */
464
        private JButton getJButtonUndo() {
465
                if (jButtonUndo == null) {
466
                        jButtonUndo = new JButton();
467
                        jButtonUndo.setBounds(DEFAULT_UNDO_ICON_BUTTON_RECTANGLE);
468
                        jButtonUndo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/edit-undo.png")));
469
                        jButtonUndo.setToolTipText(PluginServices.getText(this, "previous_area"));
470
                        jButtonUndo.addMouseListener(new MouseAdapter() {
471
                                /*
472
                                 * (non-Javadoc)
473
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
474
                                 */
475
                                public void mouseClicked(MouseEvent e) {
476
                                        goToPreviousZoom();
477
                                }
478
                        });
479
                }
480

    
481
                return jButtonUndo;
482
        }
483

    
484
//        /**
485
//         * This method initializes jButtonUndo
486
//         *
487
//         * @return javax.swing.JButton
488
//         */
489
//        private JButton getJButtonRedo() {
490
//                if (jButtonRedo == null) {
491
//                        jButtonRedo = new JButton();
492
//                        jButtonRedo.setBounds(DEFAULT_REDO_ICON_BUTTON_RECTANGLE);
493
//                        jButtonRedo.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/edit-redo.png")));
494
//                        jButtonRedo.setToolTipText(PluginServices.getText(this, "following_area"));
495
//                }
496
//
497
//                return jButtonRedo;
498
//        }
499

    
500
        /**
501
         * This method initializes jToggleButtonMove
502
         *
503
         * @return javax.swing.JButton
504
         */
505
        private JToggleButton getJToggleButtonMove() {
506
                if (jToggleButtonMove == null) {
507
                        jToggleButtonMove = new JToggleButton();
508
                        jToggleButtonMove.setBounds(DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE);
509
                        jToggleButtonMove.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/move.png")));
510
                        jToggleButtonMove.setToolTipText(PluginServices.getText(this, "move") + ": " + PluginServices.getText(this, "area_move_explanation"));
511
                        jToggleButtonMove.addItemListener(new ItemListener() {
512
                                /*
513
                                 *  (non-Javadoc)
514
                                 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
515
                                 */
516
                                public void itemStateChanged(ItemEvent e) {
517
                                        // Isn't allowed that the two JToggleButton would be selected (can't move and scale)
518
                                        if (jToggleButtonMove.isSelected())
519
                                                jToggleButtonScaling.setSelected(false);
520
                                }
521
                        });
522
                }
523

    
524
                return jToggleButtonMove;
525
        }
526

    
527
        /**
528
         * This method initializes jToggleButtonScaling
529
         *
530
         * @return javax.swing.JButton
531
         */
532
        private JToggleButton getJToggleButtonScaling() {
533
                if (jToggleButtonScaling == null) {
534
                        jToggleButtonScaling = new JToggleButton();
535
                        jToggleButtonScaling.setBounds(DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE);
536
                        jToggleButtonScaling.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/scaling.png")));
537
                        jToggleButtonScaling.setToolTipText(PluginServices.getText(this, "scaling") + ": " + PluginServices.getText(this, "area_scaling_explanation"));
538
                        jToggleButtonScaling.addItemListener(new ItemListener() {
539
                                /*
540
                                 *  (non-Javadoc)
541
                                 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
542
                                 */
543
                                public void itemStateChanged(ItemEvent e) {
544
                                        // Isn't allowed that the two JToggleButton would be selected (can't move and scale)
545
                                        if (jToggleButtonScaling.isSelected())
546
                                                jToggleButtonMove.setSelected(false);
547
                                }
548
                        });
549
                }
550

    
551
                return jToggleButtonScaling;
552
        }
553
        /**
554
         * This method initializes jButtonPan
555
         *
556
         * @return javax.swing.JButton
557
         */
558
        private JButton getJButtonPan() {
559
                if (jButtonPan == null) {
560
                        jButtonPan = new JButton();
561
                        jButtonPan.setBounds(DEFAULT_PAN_ICON_BUTTON_RECTANGLE);
562
                        jButtonPan.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/Pan.png")));
563
                        jButtonPan.setToolTipText(PluginServices.getText(this, "Desplazamiento"));
564
                        jButtonPan.addMouseListener(new MouseAdapter() {
565
                                /*
566
                                 * (non-Javadoc)
567
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
568
                                 */
569
                                public void mouseClicked(MouseEvent e) {
570
                                        getSelectableMapAreaPanel().setTool(PAN_TOOL);
571
                                }
572
                        });
573
                }
574
                return jButtonPan;
575
        }
576

    
577
        /**
578
         * This method initializes jComboBoxZoomInAndOut
579
         *
580
         * @return A JComboBoxWithImageIconItems object reference
581
         */
582
        private JComboBoxWithImageIconItems getJComboBoxZoomInAndOut() {
583
                if (jComboBoxZoomInAndOut == null) {
584
                        jComboBoxZoomInAndOut = new JComboBoxWithImageIconItems();
585
                        jComboBoxZoomInAndOut.setBounds(DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE);
586
                        jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo("images/ZoomIn.png", new ImageIcon(getClass().getClassLoader().getResource("images/ZoomIn.png")), PluginServices.getText(this, "Zoom_Mas"), ZOOM_IN_TOOL));
587
                        jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo("images/ZoomOut.png", new ImageIcon(getClass().getClassLoader().getResource("images/ZoomOut.png")), PluginServices.getText(this, "Zoom_Menos"), ZOOM_OUT_TOOL));
588
                        jComboBoxZoomInAndOut.addActionListener(new ActionListener() {
589
                                /*
590
                                 *  (non-Javadoc)
591
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
592
                                 */
593
                                public void actionPerformed(ActionEvent e) {
594
                                        JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
595
                                        ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
596
                                        getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
597
                                }
598
                });
599
                }
600

    
601
                return jComboBoxZoomInAndOut;
602
        }
603

    
604
        /**
605
         * This method initializes jButtonZoomPrevious
606
         *
607
         * @return javax.swing.JButton
608
         */
609
        private JButton getJButtonZoomPrevious() {
610
                if (jButtonZoomPrevious == null) {
611
                        jButtonZoomPrevious = new JButton();
612
                        jButtonZoomPrevious.setBounds(DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE);
613
                        jButtonZoomPrevious.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/ZoomPrevio.png")));
614
                        jButtonZoomPrevious.setToolTipText(PluginServices.getText(this, "Zoom_Previo"));
615
                        jButtonZoomPrevious.addMouseListener(new MouseAdapter() {
616
                                /*
617
                                 * (non-Javadoc)
618
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
619
                                 */
620
                                public void mouseClicked(MouseEvent e) {
621
                                        goToPreviousZoom();
622
                                }
623
                        });
624
                }
625
                return jButtonZoomPrevious;
626
        }
627

    
628
        /**
629
         * This method initializes jButtonZoomComplete
630
         *
631
         * @return javax.swing.JButton
632
         */
633
        private JButton getJButtonZoomComplete() {
634
                if (jButtonZoomComplete == null) {
635
                        jButtonZoomComplete = new JButton();
636
                        jButtonZoomComplete.setBounds(DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE);
637
                        jButtonZoomComplete.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/MapContents.png")));
638
                        jButtonZoomComplete.setToolTipText(PluginServices.getText(this, "Zoom_Completo"));
639
                        jButtonZoomComplete.addMouseListener(new MouseAdapter() {
640
                                /*
641
                                 * (non-Javadoc)
642
                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
643
                                 */
644
                                public void mouseClicked(MouseEvent e) {
645
                                        getSelectableMapAreaPanel().getViewPort().setExtent(getSelectableMapAreaPanel().getMapContext().getLayers().getFullExtent());
646
                                        View view =((View)PluginServices.getMDIManager().getActiveWindow());
647
                                        view.repaintMap();
648
                                }
649
                        });
650
                }
651
                return jButtonZoomComplete;
652
        }
653

    
654
        /**
655
         * This method initializes jComboBoxZoomInAndOut
656
         *
657
         * @return A JComboBoxWithImageIconItems object reference
658
         */
659
        private JComboBoxWithImageIconItems getJComboBoxZoomInAndOutViewCentered() {
660
                if (jComboBoxZoomInAndOutViewCentered == null) {
661
                        jComboBoxZoomInAndOutViewCentered = new JComboBoxWithImageIconItems();
662
                        jComboBoxZoomInAndOutViewCentered.setBounds(DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE);
663
                        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));
664
                        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));
665
                        jComboBoxZoomInAndOutViewCentered.addActionListener(new ActionListener() {
666
                                /*
667
                                 *  (non-Javadoc)
668
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
669
                                 */
670
                                public void actionPerformed(ActionEvent e) {
671
                                        JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
672
                                        ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
673

    
674
                                        if (((String)iiii.getItemValue()).compareTo(ZOOM_IN_VIEW_CENTERED_TOOL) == 0) {
675
                                                getSelectableMapAreaPanel().zoomIn();
676
                                        }
677
                                        else {
678
                                                getSelectableMapAreaPanel().zoomOut();
679
                                        }
680
                                }
681
                });
682
                }
683
                return jComboBoxZoomInAndOutViewCentered;
684
        }
685

    
686
        /**
687
         * This method initializes jComboBoxOtherTools
688
         *
689
         * @return A JComboBoxWithImageIconItems object reference
690
         */
691
        private JComboBoxWithImageIconItems getJComboBoxOtherTools() {
692
                if (jComboBoxOtherTools == null) {
693
                        jComboBoxOtherTools = new JComboBoxWithImageIconItems();
694
                        jComboBoxOtherTools.setBounds(DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE);
695
                        jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Distancia.png", new ImageIcon(getClass().getClassLoader().getResource("images/Distancia.png")), PluginServices.getText(this, "medir_distancias"), MEASURE_DISTANCES_TOOL));
696
                        jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Poligono16.png", new ImageIcon(getClass().getClassLoader().getResource("images/Poligono16.png")), PluginServices.getText(this, "medir_area"), MEASURE_AREA_TOOL));
697
                        jComboBoxOtherTools.addActionListener(new ActionListener() {
698
                                /*
699
                                 *  (non-Javadoc)
700
                                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
701
                                 */
702
                                public void actionPerformed(ActionEvent e) {
703
                                        JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
704
                                        ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
705
                                        getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
706
                                }
707
                });
708
                }
709

    
710
                return jComboBoxOtherTools;
711
        }
712

    
713
        /**
714
         * Goes to previous zoom
715
         */
716
        private void goToPreviousZoom() {
717
                // Gets the view port and sets its previous extent
718
                ViewPort vp = getSelectableMapAreaPanel().getMapContext().getViewPort();
719

    
720
                if (vp.getExtents().hasPrevious()) {
721
                        vp.setPreviousExtent();
722
                        getCoordinatesPanel().updateCoordinates(vp.getExtent());
723
                }
724
        }
725

    
726
        /**
727
         * Sets the extent
728
         *
729
         * @param java.awt.geom.Rectangle2D
730
         */
731
        public void setExtent(Rectangle2D extent) {
732
                if (extent != null) {
733
                        // Update coordinates in text fields
734
                        getCoordinatesPanel().updateCoordinates(extent);
735

    
736
                        // If there is any layer loaded in the MapControl -> set the extent
737
                        if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) {
738
                                getSelectableMapAreaPanel().getMapContext().getViewPort().setExtent(extent);
739
                        }
740
                }
741
        }
742

    
743
        /**
744
         * Gets the extent: a 'Rectangle2D.Double' object reference or 'null' if there is no data or if the data is invalid or user hasn't defined an area
745
         *
746
         * @return java.awt.geom.Rectangle2D or null if the data is invalid
747
         */
748
        public Rectangle2D getExtent() {
749
                if (!hasUserDefinedAnArea)
750
                        return null;
751

    
752
                if (getCoordinatesPanel().areAllCoordinatesUndefined()) {
753
                        return null; // Return null if there is no coordinate
754
                }
755
                else {
756
                        if (getCoordinatesPanel().validVertexes()) {
757
                                return getCoordinatesPanel().getExtent();
758
                        }
759
                        else {
760
                                return null; // Returns null if coordinates aren't valid
761
                        }
762
                }
763
        }
764

    
765
        /**
766
         * Set parent's 'Applicable' button enable or disable according the value of the parameter
767
         *
768
         * @param b A boolean value
769
         */
770
        private void setApplicable(boolean b) {
771
                if (!parent.getWFSFilterPanelIsAsTabForWFSLayersLoad())
772
                        parent.isApplicable(true);
773
        }
774

    
775
        /**
776
         * If there is some coordinate text field that has text, returns true; else returns false
777
         *
778
         * @return A boolean value
779
         */
780
        public boolean areThereSomeCoordinatesWritten() {
781
                return getCoordinatesPanel().areThereSomeCoordinatesWritten();
782
        }
783

    
784
        /**
785
         * If there is some coordinate text field that isn't undefined, returns true; else returns false
786
         *
787
         * @return A boolean value
788
         */
789
        public boolean areThereSomeCoordinatesUndefined() {
790
                return getCoordinatesPanel().isThereAnyCoordinateUndefined();
791
        }
792

    
793
        /**
794
         * If user has or hasn't defined an area
795
         *
796
         * @return A boolean value
797
         */
798
        public boolean hasUserDefinedAnArea() {
799
                return hasUserDefinedAnArea;
800
        }
801
        
802
        /**
803
         * Restores the inner attribute 'hasUserDefinedAnArea' to its default value (false)
804
         */
805
        public void setUserHasntDefineAnArea() {
806
                hasUserDefinedAnArea = false;        
807
        }
808

    
809
        /**
810
         * Represents an object that stores the necessary information for know each operation of the 'jComboBoxToolSelection'
811
         *
812
         * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
813
         */
814
        private class ItemOperation {
815
                String _name;
816
                int _operation;
817

    
818
                /**
819
                 * Default constructor with two parameters
820
                 *
821
                 * @param name Name of the operation
822
                 * @param operation A code that identifies the operation
823
                 */
824
                public ItemOperation(String name, int operation) {
825
                        _name = new String(name);
826
                        _operation = operation;
827
                }
828

    
829
                /**
830
                 * Returns the name of the operation
831
                 *
832
                 * @return An String
833
                 */
834
                public String getName() {
835
                        return _name;
836
                }
837

    
838
                /**
839
                 * Returns the code that identifies the operation
840
                 *
841
                 * @return An integer value
842
                 */
843
                public int getOperation() {
844
                        return _operation;
845
                }
846

    
847
                /**
848
                 * The name of the operation that will use JComboBox
849
                 */
850
                public String toString() {
851
                        return _name;
852
                }
853
        }
854

    
855
        /**
856
         * This class is a panel width four fields for indicate the coordinates of two points:
857
         *   One for the ritgh-up point and another for the left-down point of a rectangle area
858
         *
859
         * @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
860
         * @author Jorge Piera Llodr? (piera_jor@gva.es)
861
         */
862
        private class AreaCoordinatesPanel extends JPanel implements Serializable {
863
                private final Rectangle DEFAULT_JBUTTON_GO_TO_AREA_RECTANGLE = new Rectangle(412, 5, 62, 51);  //  @jve:decl-index=0:
864
                private final int DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT = 20;
865
                private final int DEFAULT_COORDIANTE_LABEL_WIDTH = 20;
866
                private final int DEFAULT_TEXT_FIELDS_WIDTH = 132;
867
                private final int DEFAULT_X_LOCATION = 8;
868
                private final int DEFAULT_Y_LEFT_UP_CORNER_LOCATION = 6;
869
                private final int DEFAULT_COORDINATE_WIDTH = DEFAULT_COORDIANTE_LABEL_WIDTH + DEFAULT_TEXT_FIELDS_WIDTH + 10;
870
                private final int DEFAULT_COORDINATE_HEIGHT = 25;
871
                private final Dimension DEFAULT_JLABEL_VERTEX_DIMENSION = new Dimension(60, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT);  //  @jve:decl-index=0:
872
                private final int DEFAULT_XY_COORDINATES_WIDTH = 2 * DEFAULT_COORDINATE_WIDTH + DEFAULT_JLABEL_VERTEX_DIMENSION.width + 10 ;
873

    
874
                private final String JTEXTFIELD_V1X_NAME = "V1X";
875
                private final String JTEXTFIELD_V1Y_NAME = "V1Y";
876
                private final String JTEXTFIELD_V2X_NAME = "V2X";
877
                private final String JTEXTFIELD_V2Y_NAME = "V2Y";
878

    
879
                private final short JTEXTFIELD_V1X = 1;
880
                private final short JTEXTFIELD_V1Y = 2;
881
                private final short JTEXTFIELD_V2X = 3;
882
                private final short JTEXTFIELD_V2Y = 4;
883

    
884
                private JPanel jPanelVertex1 = null;
885
                private JPanel jPanelVertex2 = null;
886
                private JPanel jPanelVertex1X = null;
887
                private JPanel jPanelVertex1Y = null;
888
                private JPanel jPanelVertex2X = null;
889
                private JPanel jPanelVertex2Y = null;
890

    
891
                private JLabel jLabelVertex1 = null;
892
                private JLabel jLabelVertex2 = null;
893
                private JLabel jLabelVertex1X = null;
894
                private JLabel jLabelVertex1Y = null;
895
                private JLabel jLabelVertex2X = null;
896
                private JLabel jLabelVertex2Y = null;
897
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex1X = null;
898
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex1Y = null;
899
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex2X = null;
900
                private JTextFieldWithSpecificCaretPosition jTextFieldVertex2Y = null;
901
                private JButton jButtonPreviewArea = null;
902
                private String last_Coordinates[];
903
                private boolean hasChanged_v1X;
904
                private boolean hasChanged_v1Y;
905
                private boolean hasChanged_v2X;
906
                private boolean hasChanged_v2Y;
907
                private short last_Coordinate_that_Loose_the_Focus; // 0 -> any; 1 -> V1X; 2 -> V1Y; 3 -> V2X; 4 -> V2Y
908
                private String previous_Coordinate_Value[];
909

    
910
                private short current_coordinate_with_focus;
911

    
912
                private FocusListener focusListenerForCoordinateValidation = null;
913
                private KeyListener keyListenerForCoordinateValidation = null;
914

    
915
                /**
916
                 * This is the default constructor
917
                 */
918
                public AreaCoordinatesPanel() {
919
                        super();
920
                        initialize();
921
                }
922

    
923
                /**
924
                 * This method initializes this
925
                 *
926
                 * @return void
927
                 */
928
                private void initialize() {
929
                        this.setLayout(null);
930
                        this.setBounds(DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE);
931
                        this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
932
                        this.setToolTipText(PluginServices.getText(this, "select_by_vertexes_coordinates"));
933

    
934
                        this.last_Coordinates = new String[4];
935
                        this.last_Coordinates[0] = "";
936
                        this.last_Coordinates[1] = "";
937
                        this.last_Coordinates[2] = "";
938
                        this.last_Coordinates[3] = "";
939
                        this.last_Coordinate_that_Loose_the_Focus = 0;
940
                        this.previous_Coordinate_Value = new String[4];
941

    
942
                        // By default no coordinates have changed
943
                        this.resetCoordinatesFlags();
944

    
945
                        this.add(getJPanelVertex1());
946
                        this.add(getJPanelVertex2());
947
                        this.add(getJButtonPreviewArea());
948
                }
949

    
950
                /**
951
                 * Returns the default width of this component
952
                 *
953
                 * @return The default width
954
                 */
955
                public int getDefaultWidth() {
956
                        return DEFAULT_COORDINATE_WIDTH * 2;
957
                }
958

    
959
                /**
960
                 * Returns the default height of this component
961
                 *
962
                 * @return The default height
963
                 */
964
                public int getDefaultHeight() {
965
                        return DEFAULT_COORDINATE_HEIGHT * 2;
966
                }
967

    
968
                /**
969
                 * Sets all flags about if a coordinate has change to false (haven't changed)
970
                 */
971
                private void resetCoordinatesFlags() {
972
                        hasChanged_v1X = false;
973
                        hasChanged_v1Y = false;
974
                        hasChanged_v2X = false;
975
                        hasChanged_v2Y = false;
976
                }
977

    
978
                /**last_Coordinated_that_Changed
979
                 * This method initializes jPanelVertex1
980
                 *
981
                 * @return javax.swing.JPanel
982
                 */
983
                private JPanel getJPanelVertex1() {
984
                        if (jPanelVertex1 == null) {
985
                                jPanelVertex1 = new JPanel();
986
                                jPanelVertex1.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT);
987
                                jPanelVertex1.setLayout(new GridBagLayout());
988
                                jPanelVertex1.add(getJLabelVertex1(), null);
989
                                jPanelVertex1.add(getJPanelVertex1X(), null);
990
                                jPanelVertex1.add(getJPanelVertex1Y(), null);
991
                        }
992

    
993
                        return jPanelVertex1;
994
                }
995

    
996
                /**
997
                 * This method initializes jPanelVertex2
998
                 *
999
                 * @return javax.swing.JPanel
1000
                 */
1001
                private JPanel getJPanelVertex2() {
1002
                        if (jPanelVertex2 == null) {
1003
                                jPanelVertex2 = new JPanel();
1004
                                jPanelVertex2.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION + DEFAULT_COORDINATE_HEIGHT, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT);
1005
                                jPanelVertex2.setLayout(new GridBagLayout());
1006
                                jPanelVertex2.add(getJLabelVertex2(), null);
1007
                                jPanelVertex2.add(getJPanelVertex2X(), null);
1008
                                jPanelVertex2.add(getJPanelVertex2Y(), null);
1009
                        }
1010

    
1011
                        return jPanelVertex2;
1012
                }
1013

    
1014
                /**
1015
                 * This method initializes jLabelVertex1
1016
                 *
1017
                 * @return javax.swing.JPanel
1018
                 */
1019
                private JLabel getJLabelVertex1() {
1020
                        if (jLabelVertex1 == null) {
1021
                                jLabelVertex1 = new JLabel();
1022
                                jLabelVertex1.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION);
1023
                                jLabelVertex1.setToolTipText(PluginServices.getText(this, "coordinates_from_area_right_up_vertex"));
1024
                                jLabelVertex1.setText(PluginServices.getText(this, "vertex") + " 1:");
1025
                                jLabelVertex1.setHorizontalAlignment(SwingConstants.LEFT);
1026
                                jLabelVertex1.setVerticalAlignment(SwingConstants.CENTER);
1027
                                jLabelVertex1.setForeground(new Color(0, 0, 255)); // Blue color for text
1028
                        }
1029
                        return jLabelVertex1;
1030
                }
1031

    
1032
                /**
1033
                 * This method initializes jLabelVertex2
1034
                 *
1035
                 * @return javax.swing.JPanel
1036
                 */
1037
                private JLabel getJLabelVertex2() {
1038
                        if (jLabelVertex2 == null) {
1039
                                jLabelVertex2 = new JLabel();
1040
                                jLabelVertex2.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION);
1041
                                jLabelVertex2.setToolTipText(PluginServices.getText(this, "coordinates_from_area_left_bottom_vertex"));
1042
                                jLabelVertex2.setText(PluginServices.getText(this, "vertex") + " 2:");
1043
                                jLabelVertex2.setHorizontalAlignment(SwingConstants.LEFT);
1044
                                jLabelVertex2.setVerticalAlignment(SwingConstants.CENTER);
1045
                                jLabelVertex2.setForeground(new Color(128, 64, 0)); // Brown color for text
1046
                        }
1047
                        return jLabelVertex2;
1048
                }
1049

    
1050
                /**
1051
                 * This method initializes jPanelVertex1X
1052
                 *
1053
                 * @return javax.swing.JPanel
1054
                 */
1055
                private JPanel getJPanelVertex1X() {
1056
                        if (jPanelVertex1X == null) {
1057
                                jPanelVertex1X = new JPanel();
1058
                                jPanelVertex1X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1059
                                jPanelVertex1X.setLayout(new GridBagLayout());
1060
                                jPanelVertex1X.add(getJLabelVertex1X(), null);
1061
                                jPanelVertex1X.add(getJTextFieldVertex1X(), null);
1062
                        }
1063

    
1064
                        return jPanelVertex1X;
1065
                }
1066

    
1067
                /**
1068
                 * This method initializes jPanelVertex1Y
1069
                 *
1070
                 * @return javax.swing.JPanel
1071
                 */
1072
                private JPanel getJPanelVertex1Y() {
1073
                        if (jPanelVertex1Y == null) {
1074
                                jPanelVertex1Y = new JPanel();
1075
                                jPanelVertex1Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1076
                                jPanelVertex1Y.setLayout(new GridBagLayout());
1077
                                jPanelVertex1Y.add(getJLabelVertex1Y(), null);
1078
                                jPanelVertex1Y.add(getJTextFieldVertex1Y(), null);
1079
                        }
1080

    
1081
                        return jPanelVertex1Y;
1082
                }
1083

    
1084
                /**
1085
                 * This method initializes jPanelVertex2X
1086
                 *
1087
                 * @return javax.swing.JPanel
1088
                 */
1089
                private JPanel getJPanelVertex2X() {
1090
                        if (jPanelVertex2X == null) {
1091
                                jPanelVertex2X = new JPanel();
1092
                                jPanelVertex2X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1093
                                jPanelVertex2X.setLayout(new GridBagLayout());
1094
                                jPanelVertex2X.add(getJLabelVertex2X(), null);
1095
                                jPanelVertex2X.add(getJTextFieldVertex2X(), null);
1096
                        }
1097

    
1098
                        return jPanelVertex2X;
1099
                }
1100

    
1101
                /**
1102
                 * This method initializes jPanelVertex2Y
1103
                 *
1104
                 * @return javax.swing.JPanel
1105
                 */
1106
                private JPanel getJPanelVertex2Y() {
1107
                        if (jPanelVertex2Y == null) {
1108
                                jPanelVertex2Y = new JPanel();
1109
                                jPanelVertex2Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1110
                                jPanelVertex2Y.setLayout(new GridBagLayout());
1111
                                jPanelVertex2Y.add(getJLabelVertex2Y(), null);
1112
                                jPanelVertex2Y.add(getJTextFieldVertex2Y(), null);
1113
                        }
1114

    
1115
                        return jPanelVertex2Y;
1116
                }
1117

    
1118
                /**
1119
                 * This method initializes jLabelVertex1X
1120
                 *
1121
                 * @return  javax.swing.JLabel
1122
                 */
1123
                private JLabel getJLabelVertex1X() {
1124
                        if (jLabelVertex1X == null) {
1125
                                jLabelVertex1X = new JLabel();
1126
                                jLabelVertex1X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1127
                                jLabelVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1128
                                jLabelVertex1X.setText(PluginServices.getText(this, "x") + ":");
1129
                                jLabelVertex1X.setHorizontalAlignment(SwingConstants.CENTER);
1130
                                jLabelVertex1X.setVerticalAlignment(SwingConstants.CENTER);
1131
                                jLabelVertex1X.setForeground(new Color(0, 0, 255)); // Blue color for text
1132
                        }
1133

    
1134
                        return jLabelVertex1X;
1135
                }
1136

    
1137
                /**
1138
                 * This method initializes jLabelVertex2X
1139
                 *
1140
                 * @return  javax.swing.JLabel
1141
                 */
1142
                private JLabel getJLabelVertex2X() {
1143
                        if (jLabelVertex2X == null) {
1144
                                jLabelVertex2X = new JLabel();
1145
                                jLabelVertex2X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1146
                                jLabelVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1147
                                jLabelVertex2X.setText(PluginServices.getText(this, "x") + ":");
1148
                                jLabelVertex2X.setHorizontalAlignment(SwingConstants.CENTER);
1149
                                jLabelVertex2X.setVerticalAlignment(SwingConstants.CENTER);
1150
                                jLabelVertex2X.setForeground(new Color(128, 64, 0)); // Brown color for text
1151
                        }
1152

    
1153
                        return jLabelVertex2X;
1154
                }
1155

    
1156
                /**
1157
                 * This method initializes jLabelVertex1Y
1158
                 *
1159
                 * @return  javax.swing.JLabel
1160
                 */
1161
                private JLabel getJLabelVertex1Y() {
1162
                        if (jLabelVertex1Y == null) {
1163
                                jLabelVertex1Y = new JLabel();
1164
                                jLabelVertex1Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1165
                                jLabelVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1166
                                jLabelVertex1Y.setText(PluginServices.getText(this, "y") + ":");
1167
                                jLabelVertex1Y.setHorizontalAlignment(SwingConstants.CENTER);
1168
                                jLabelVertex1Y.setVerticalAlignment(SwingConstants.CENTER);
1169
                                jLabelVertex1Y.setForeground(new Color(0, 0, 255)); // Blue color for text
1170
                        }
1171

    
1172
                        return jLabelVertex1Y;
1173
                }
1174

    
1175
                /**
1176
                 * This method initializes jLabelVertex2Y
1177
                 *
1178
                 * @return  javax.swing.JLabel
1179
                 */
1180
                private JLabel getJLabelVertex2Y() {
1181
                        if (jLabelVertex2Y == null) {
1182
                                jLabelVertex2Y = new JLabel();
1183
                                jLabelVertex2Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1184
                                jLabelVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1185
                                jLabelVertex2Y.setText(PluginServices.getText(this, "y") + ":");
1186
                                jLabelVertex2Y.setHorizontalAlignment(SwingConstants.CENTER);
1187
                                jLabelVertex2Y.setVerticalAlignment(SwingConstants.CENTER);
1188
                                jLabelVertex2Y.setForeground(new Color(128, 64, 0)); // Brown color for text
1189
                        }
1190

    
1191
                        return jLabelVertex2Y;
1192
                }
1193

    
1194
                /**
1195
                 * Returns a focus listener for validate the text of a JTextField when that component loses its focus
1196
                 *
1197
                 * @return java.awt.event.FocusListener
1198
                 */
1199
                private FocusListener getFocusListenerForCoordinateValidation() {
1200
                        if (focusListenerForCoordinateValidation == null) {
1201
                                focusListenerForCoordinateValidation = new FocusListener() {
1202

    
1203
                                        /*
1204
                                         *  (non-Javadoc)
1205
                                         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
1206
                                         */
1207
                                        public void focusGained(FocusEvent e) {
1208
                                                JTextField jTF = (JTextField)e.getSource();
1209

    
1210
                                                // Stores which coordinate has gotten the focus
1211
                                                if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1212
                                                        current_coordinate_with_focus = JTEXTFIELD_V1X;
1213

    
1214
                                                        return;
1215
                                                }
1216

    
1217
                                                if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1218
                                                        current_coordinate_with_focus = JTEXTFIELD_V1Y;
1219

    
1220
                                                        return;
1221
                                                }
1222

    
1223
                                                if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1224
                                                        current_coordinate_with_focus = JTEXTFIELD_V2X;
1225

    
1226
                                                        return;
1227
                                                }
1228

    
1229
                                                if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1230
                                                        current_coordinate_with_focus = JTEXTFIELD_V2Y;
1231

    
1232
                                                        return;
1233
                                                }
1234

    
1235
                                        }
1236

    
1237
                                        /*
1238
                                         *  (non-Javadoc)
1239
                                         * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
1240
                                         */
1241
                                        public void focusLost(FocusEvent e) {
1242
                                                JTextField jTF = (JTextField)e.getSource();
1243

    
1244
                                                // If a coordinate has lost focus, is valid and has changed -> store the new value and set its related 'hasChanged' flag to true
1245
                                                String text = jTF.getText();
1246

    
1247
                                                if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1248

    
1249
                                                        if (text.compareTo(last_Coordinates[0]) != 0) {
1250
                                                                hasChanged_v1X = true;
1251

    
1252
                                                                if (getJComboBoxToolSelection().getSelectedIndex() != 0) {
1253
                                                                        hasUserDefinedAnArea = true;
1254
                                                                }
1255
                                                        }
1256

    
1257
                                                        return;
1258
                                                }
1259

    
1260
                                                if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1261
                                                        if (text.compareTo(last_Coordinates[1]) != 0) {
1262
                                                                hasChanged_v1Y = true;
1263

    
1264
                                                                if (getJComboBoxToolSelection().getSelectedIndex() != 0) {
1265
                                                                        hasUserDefinedAnArea = true;
1266
                                                                }
1267
                                                        }
1268

    
1269
                                                        return;
1270
                                                }
1271

    
1272
                                                if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1273
                                                        if (text.compareTo(last_Coordinates[2]) != 0) {
1274
                                                                hasChanged_v2X = true;
1275

    
1276
                                                                if (getJComboBoxToolSelection().getSelectedIndex() != 0) {
1277
                                                                        hasUserDefinedAnArea = true;
1278
                                                                }
1279
                                                        }
1280

    
1281
                                                        return;
1282
                                                }
1283

    
1284
                                                if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1285
                                                        if (text.compareTo(last_Coordinates[3]) != 0) {
1286
                                                                hasChanged_v2Y = true;
1287

    
1288
                                                                if (getJComboBoxToolSelection().getSelectedIndex() != 0) {
1289
                                                                        hasUserDefinedAnArea = true;
1290
                                                                }
1291
                                                        }
1292

    
1293
                                                        return;
1294
                                                }
1295
                                        }
1296
                                };
1297
                        }
1298

    
1299
                        return focusListenerForCoordinateValidation;
1300
                }
1301

    
1302
                private KeyListener getKeyListenerForCoordinateValidation() {
1303
                        if (keyListenerForCoordinateValidation == null) {
1304
                                keyListenerForCoordinateValidation = new KeyListener() {
1305

    
1306
                                        public void keyPressed(KeyEvent e) {
1307
                                        }
1308

    
1309
                                        public void keyReleased(KeyEvent e) {
1310
                                                validateCoordinate(current_coordinate_with_focus);
1311
                                        }
1312

    
1313
                                        public void keyTyped(KeyEvent e) {
1314
                                        }
1315
                                };
1316
                        }
1317

    
1318
                        return keyListenerForCoordinateValidation;
1319
                }
1320

    
1321
                /**
1322
                 * This method initializes jTextFieldVertex1X
1323
                 *
1324
                 * @return JTextFieldWithSpecificCaretPosition
1325
                 */
1326
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex1X() {
1327
                        if (jTextFieldVertex1X == null) {
1328
                                jTextFieldVertex1X = new JTextFieldWithSpecificCaretPosition("");
1329
                                jTextFieldVertex1X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1330
                                jTextFieldVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1331
                                jTextFieldVertex1X.addFocusListener(getFocusListenerForCoordinateValidation());
1332
                                jTextFieldVertex1X.addKeyListener(getKeyListenerForCoordinateValidation());
1333
                                jTextFieldVertex1X.setName(JTEXTFIELD_V1X_NAME);
1334
                        }
1335
                        return jTextFieldVertex1X;
1336
                }
1337

    
1338
                /**
1339
                 * This method initializes jTextFieldVertex1Y
1340
                 *
1341
                 * @return JTextFieldWithSpecificCaretPosition
1342
                 */
1343
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex1Y() {
1344
                        if (jTextFieldVertex1Y == null) {
1345
                                jTextFieldVertex1Y = new JTextFieldWithSpecificCaretPosition("");
1346
                                jTextFieldVertex1Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1347
                                jTextFieldVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1348
                                jTextFieldVertex1Y.addFocusListener(getFocusListenerForCoordinateValidation());
1349
                                jTextFieldVertex1Y.addKeyListener(getKeyListenerForCoordinateValidation());
1350
                                jTextFieldVertex1Y.setName(JTEXTFIELD_V1Y_NAME);
1351
                        }
1352
                        return jTextFieldVertex1Y;
1353
                }
1354

    
1355
                /**
1356
                 * This method initializes jTextFieldVertex2X
1357
                 *
1358
                 * @return JTextFieldWithSpecificCaretPosition
1359
                 */
1360
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex2X() {
1361
                        if (jTextFieldVertex2X == null) {
1362
                                jTextFieldVertex2X = new JTextFieldWithSpecificCaretPosition("");
1363
                                jTextFieldVertex2X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1364
                                jTextFieldVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1365
                                jTextFieldVertex2X.addFocusListener(getFocusListenerForCoordinateValidation());
1366
                                jTextFieldVertex2X.addKeyListener(getKeyListenerForCoordinateValidation());
1367
                                jTextFieldVertex2X.setName(JTEXTFIELD_V2X_NAME);
1368
                        }
1369
                        return jTextFieldVertex2X;
1370
                }
1371

    
1372
                /**
1373
                 * This method initializes jTextFieldVertex2Y
1374
                 *
1375
                 * @return JTextFieldWithSpecificCaretPosition
1376
                 */
1377
                private JTextFieldWithSpecificCaretPosition getJTextFieldVertex2Y() {
1378
                        if (jTextFieldVertex2Y == null) {
1379
                                jTextFieldVertex2Y = new JTextFieldWithSpecificCaretPosition("");
1380
                                jTextFieldVertex2Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1381
                                jTextFieldVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1382
                                jTextFieldVertex2Y.addFocusListener(getFocusListenerForCoordinateValidation());
1383
                                jTextFieldVertex2Y.addKeyListener(getKeyListenerForCoordinateValidation());
1384
                                jTextFieldVertex2Y.setName(JTEXTFIELD_V2Y_NAME);
1385
                        }
1386
                        return jTextFieldVertex2Y;
1387
                }
1388

    
1389
                /**
1390
                 * Retuns the double value of the text field V1X
1391
                 *
1392
                 * @return A double number type
1393
                 */
1394
                public double getDoubleValueOfJTextFieldV1X() {
1395
                        return Double.parseDouble(getJTextFieldVertex1X().getText());
1396
                }
1397

    
1398
                /**
1399
                 * Retuns the double value of the text field V1Y
1400
                 *
1401
                 * @return A double number type
1402
                 */
1403
                public double getDoubleValueOfJTextFieldV1Y() {
1404
                        return Double.parseDouble(getJTextFieldVertex1Y().getText());
1405
                }
1406

    
1407
                /**
1408
                 * Retuns the double value of the text field V2X
1409
                 *
1410
                 * @return A double number type
1411
                 */
1412
                public double getDoubleValueOfJTextFieldV2X() {
1413
                        return Double.parseDouble(getJTextFieldVertex2X().getText());
1414
                }
1415

    
1416
                /**
1417
                 * Retuns the double value of the text field V2Y
1418
                 *
1419
                 * @return A double number type
1420
                 */
1421
                public double getDoubleValueOfJTextFieldV2Y() {
1422
                        return Double.parseDouble(getJTextFieldVertex2Y().getText());
1423
                }
1424

    
1425
                /**
1426
                 * Retuns the double value of the last text field V1X value
1427
                 *
1428
                 * @return A double number type
1429
                 */
1430
                public double getDoubleValueOfLastJTextFieldV1XValue() {
1431
                        return Double.parseDouble(last_Coordinates[0]);
1432
                }
1433

    
1434
                /**
1435
                 * Retuns the double value of the last text field V1Y value
1436
                 *
1437
                 * @return A double number type
1438
                 */
1439
                public double getDoubleValueOfLastJTextFieldV1YValue() {
1440
                        return Double.parseDouble(last_Coordinates[1]);
1441
                }
1442

    
1443
                /**
1444
                 * Retuns the double value of the last text field V2X value
1445
                 *
1446
                 * @return A double number type
1447
                 */
1448
                public double getDoubleValueOfLastJTextFieldV2XValue() {
1449
                        return Double.parseDouble(last_Coordinates[2]);
1450
                }
1451

    
1452
                /**
1453
                 * Retuns the double value of the last text field V2Y value
1454
                 *
1455
                 * @return A double number type
1456
                 */
1457
                public double getDoubleValueOfLastJTextFieldV2YValue() {
1458
                        return Double.parseDouble(last_Coordinates[3]);
1459
                }
1460

    
1461
                /**
1462
                 * Validates the coordinate of a JTextField: returns true if it's valid; else returns false
1463
                 *
1464
                 * @param coordinate javax.swing.JTextField
1465
                 * @return A boolean value
1466
                 */
1467
                private boolean validateCoordinate(JTextField coordinate) {
1468
                        if (coordinate != null) {
1469
                                // If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text
1470
                                if ((coordinate.getText().compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(coordinate.getText()))) {
1471
//                                        JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1472
//                                        switch (last_Coordinate_that_Loose_the_Focus) {
1473
//                                                case 1:
1474
//                                                        coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1475
//                                                        break;
1476
//                                                case 2:
1477
//                                                        coordinate.setText(previous_Coordinate_Value[1]); // Set last value
1478
//                                                        break;
1479
//                                                case 3:
1480
//                                                        coordinate.setText(previous_Coordinate_Value[2]); // Set last value
1481
//                                                        break;
1482
//                                                case 4:
1483
//                                                        coordinate.setText(previous_Coordinate_Value[3]); // Set last value
1484
//                                                        break;
1485
//                                                default:
1486
//                                                        // Do nothing
1487
//                                        }
1488

    
1489
                                        return false;
1490
                                }
1491
                                else {
1492
                                        return true;
1493
                                }
1494
                        }
1495

    
1496
                        return false; // If coordinate is null
1497
                }
1498

    
1499
                /**
1500
                 * Validates the coordinate of a JTextField: returns true if it's valid; else returns false
1501
                 *
1502
                 * @param coordinate javax.swing.JTextField
1503
                 * @return A boolean value
1504
                 */
1505
                private boolean validateCoordinate(int coordinate_ID) {
1506
                        JTextField coordinate = null;
1507
                        String text;
1508

    
1509
                        switch (coordinate_ID) {
1510
                                case JTEXTFIELD_V1X:
1511
                                        coordinate = getJTextFieldVertex1X();
1512
                                        text = coordinate.getText();
1513

    
1514
                                        if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1515
                                                JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1516
                                                coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1517
                                                return false;
1518
                                        }
1519
                                        else {
1520
                                                previous_Coordinate_Value[0] = text;
1521
                                                return true;
1522
                                        }
1523

    
1524
//                                        break;
1525
                                case JTEXTFIELD_V1Y:
1526
                                        coordinate = getJTextFieldVertex1Y();
1527
                                        text = coordinate.getText();
1528

    
1529
                                        if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1530
                                                JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1531
                                                coordinate.setText(previous_Coordinate_Value[1]); // Set last value
1532
                                                return false;
1533
                                        }
1534
                                        else {
1535
                                                previous_Coordinate_Value[1] = text;
1536
                                                return true;
1537
                                        }
1538

    
1539
//                                        break;
1540
                                case JTEXTFIELD_V2X:
1541
                                        coordinate = getJTextFieldVertex2X();
1542
                                        text = coordinate.getText();
1543

    
1544
                                        if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1545
                                                JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1546
                                                coordinate.setText(previous_Coordinate_Value[2]); // Set last value
1547
                                                return false;
1548
                                        }
1549
                                        else {
1550
                                                previous_Coordinate_Value[2] = text;
1551
                                                return true;
1552
                                        }
1553

    
1554
//                                        break;
1555
                                case JTEXTFIELD_V2Y:
1556
                                        coordinate = getJTextFieldVertex2Y();
1557
                                        text = coordinate.getText();
1558

    
1559
                                        if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1560
                                                JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1561
                                                coordinate.setText(previous_Coordinate_Value[3]); // Set last value
1562
                                                return false;
1563
                                        }
1564
                                        else {
1565
                                                previous_Coordinate_Value[3] = text;
1566
                                                return true;
1567
                                        }
1568

    
1569
//                                        break;
1570
                                default:
1571
                                        return true; // Avoid problems
1572
                        }
1573

    
1574
//                        if (coordinate != null) {
1575
//                                // If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text
1576
//                                        switch (coordinate_ID) {
1577
//                                                case 1:
1578
//                                                        coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1579
//                                                        break;
1580
//                                                case 2:
1581
//                                                        coordinate.setText(previous_Coordinate_Value[1]); // Set last value
1582
//                                                        break;
1583
//                                                case 3:
1584
//                                                        coordinate.setText(previous_Coordinate_Value[2]); // Set last value
1585
//                                                        break;
1586
//                                                case 4:
1587
//                                                        coordinate.setText(previous_Coordinate_Value[3]); // Set last value
1588
//                                                        break;
1589
//                                                default:
1590
//                                                        // Do nothing
1591
//                                        }
1592

    
1593
//                                        return false;
1594
//                                }
1595
//                                else
1596
//                                        return true;
1597
////                        }
1598
//
1599
//                        return false; // If coordinate is null
1600
                }
1601

    
1602
                /**
1603
                 * This method initializes jButtonPreviewArea
1604
                 *
1605
                 * @return javax.swing.JButton
1606
                 */
1607
                private JButton getJButtonPreviewArea() {
1608
                        if (jButtonPreviewArea == null) {
1609
                                jButtonPreviewArea = new JButton();
1610
                                jButtonPreviewArea.setBounds(DEFAULT_JBUTTON_GO_TO_AREA_RECTANGLE);
1611
                                jButtonPreviewArea.setToolTipText(PluginServices.getText(this, "to_previsualize"));
1612
                                jButtonPreviewArea.setVerticalTextPosition(AbstractButton.CENTER);
1613
                                jButtonPreviewArea.setHorizontalTextPosition(AbstractButton.CENTER);
1614
                                jButtonPreviewArea.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/to_previsualize_area.png")));
1615
                                jButtonPreviewArea.addMouseListener(new MouseAdapter() {
1616
                                        /*
1617
                                         *  (non-Javadoc)
1618
                                         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
1619
                                         */
1620
                                        public void mouseClicked(MouseEvent e) {
1621
                                                 // Only enable the area operation if there is data loaded in this MapControl
1622

    
1623
                                                // Do nothing if there is no layer in the map control
1624
                                                 if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() == 0) {
1625
                                                         return;
1626
                                                 }
1627

    
1628
                                                if ((validateCoordinate(getJTextFieldVertex1X())) && (validateCoordinate(getJTextFieldVertex1Y())) && (validateCoordinate(getJTextFieldVertex2X())) && (validateCoordinate(getJTextFieldVertex2Y()))) {
1629
                                                        ViewPort vP = getSelectableMapAreaPanel().getViewPort();
1630
                                                        if (vP != null) {
1631
                                                                // If has to scale the area
1632
                                                                if (getJToggleButtonScaling().isSelected()) {
1633
                                                                        // Scale Vertex 1
1634
                                                                        if ((hasChanged_v1X) || (hasChanged_v1Y)) {
1635
                                                                                double cx = getDoubleValueOfJTextFieldV1X();
1636
                                                                                double cy = getDoubleValueOfJTextFieldV1Y();
1637
                                                                                double sx, sy, aux;
1638

    
1639
                                                                                if (hasChanged_v1X) {
1640
                                                                                        aux = getDoubleValueOfLastJTextFieldV1XValue();
1641
                                                                                        if (aux == 0.0)
1642
                                                                                                sx = 1.0; // Don't scale if new coordenate is zero
1643
                                                                                        else
1644
                                                                                                sx = cx / aux;
1645
                                                                                }
1646
                                                                                else
1647
                                                                                        sx = 1.0;
1648

    
1649
                                                                                if (hasChanged_v1Y) {
1650
                                                                                        aux = getDoubleValueOfLastJTextFieldV1YValue();
1651
                                                                                        if (aux == 0.0)
1652
                                                                                                sy = 1.0; // Don't scale if new coordenate is zero
1653
                                                                                        else
1654
                                                                                                sy = cy / aux;
1655
                                                                                }
1656
                                                                                else
1657
                                                                                        sy = 1.0;
1658

    
1659
                                                                                if (sx == 1.0) {
1660
                                                                                        // It's supposed that sy != 1.0
1661
                                                                                        cx *= sy;
1662

    
1663
                                                                                        if (cx < getDoubleValueOfJTextFieldV2X()) {
1664
                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v1x") + " < " + PluginServices.getText(jButtonPreviewArea, "v2x"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1665
                                                                                                restoreAllModifiedCoordinates(); // restores the coordinates
1666
                                                                                                return;
1667
                                                                                        }
1668

    
1669
                                                                                        getJTextFieldVertex1X().setText(Double.toString(cx));
1670
                                                                                }
1671
                                                                                else {
1672
                                                                                        if (sy == 1.0) {
1673
                                                                                                // It's supposed that sx != 1.0
1674
                                                                                                cy *= sx;
1675

    
1676
                                                                                                if (cy < getDoubleValueOfJTextFieldV2Y()) {
1677
                                                                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v1y") + " < " + PluginServices.getText(jButtonPreviewArea, "v2y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1678
                                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1679
                                                                                                        return;
1680
                                                                                                }
1681

    
1682
                                                                                                getJTextFieldVertex1Y().setText(Double.toString(cy));
1683
                                                                                        }
1684
                                                                                        else {
1685
                                                                                                // If there has been an error -> can't move different distances in X the two vertexes
1686
                                                                                                if (sx != sy) {
1687
                                                                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "different_scale_factors"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1688
                                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1689
                                                                                                        return;
1690
                                                                                                }
1691
                                                                                        }
1692
                                                                                }
1693
                                                                        }
1694

    
1695
                                                                        // Scale Vertex2
1696
                                                                        if ((hasChanged_v2X) || (hasChanged_v2Y)) {
1697
                                                                                double cx = getDoubleValueOfJTextFieldV2X();
1698
                                                                                double cy = getDoubleValueOfJTextFieldV2Y();
1699
                                                                                double sx, sy, aux;
1700

    
1701
                                                                                if (hasChanged_v2X) {
1702
                                                                                        aux = getDoubleValueOfLastJTextFieldV2XValue();
1703
                                                                                        if (aux == 0.0)
1704
                                                                                                sx = 1.0; // Don't scale if new coordenate is zero
1705
                                                                                        else
1706
                                                                                                sx = cx / aux;
1707
                                                                                }
1708
                                                                                else
1709
                                                                                        sx = 1.0;
1710

    
1711
                                                                                if (hasChanged_v2Y) {
1712
                                                                                        aux = getDoubleValueOfLastJTextFieldV2YValue();
1713
                                                                                        if (aux == 0.0)
1714
                                                                                                sy = 1.0; // Don't scale if new coordenate is zero
1715
                                                                                        else
1716
                                                                                                sy = cy / aux;
1717
                                                                                }
1718
                                                                                else
1719
                                                                                        sy = 1.0;
1720

    
1721
                                                                                if (sx == 1.0) {
1722
                                                                                        // It's supposed that sy != 1.0
1723
                                                                                        cx *= sy;
1724

    
1725
                                                                                        if (cx > getDoubleValueOfJTextFieldV1X()) {
1726
                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v2x") + " > " + PluginServices.getText(jButtonPreviewArea, "v1x"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1727
                                                                                                restoreAllModifiedCoordinates(); // restores the coordinates
1728
                                                                                                return;
1729
                                                                                        }
1730

    
1731
                                                                                        getJTextFieldVertex2X().setText(Double.toString(cx));
1732
                                                                                }
1733
                                                                                else {
1734
                                                                                        if (sy == 1.0) {
1735
                                                                                                // It's supposed that sx != 1.0
1736
                                                                                                cy *= sx;
1737

    
1738
                                                                                                if (cy > getDoubleValueOfJTextFieldV1Y()) {
1739
                                                                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v2y") + " > " + PluginServices.getText(jButtonPreviewArea, "v1y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1740
                                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1741
                                                                                                        return;
1742
                                                                                                }
1743

    
1744
                                                                                                getJTextFieldVertex2Y().setText(Double.toString(cy));
1745
                                                                                        }
1746
                                                                                        else {
1747
                                                                                                // If there has been an error -> can't move different distances in X the two vertexes
1748
                                                                                                if (sx != sy) {
1749
                                                                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "different_scale_factors"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1750
                                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1751
                                                                                                        return;
1752
                                                                                                }
1753
                                                                                        }
1754
                                                                                }
1755
                                                                        }
1756
                                                                }
1757
                                                                else {
1758
                                                                        // If has to move the area
1759
                                                                        if (getJToggleButtonMove().isSelected()) {
1760
                                                                                // Move in X
1761
                                                                                if ((hasChanged_v1X) || (hasChanged_v2X)) {
1762
                                                                                        double c1 = getDoubleValueOfJTextFieldV1X();
1763
                                                                                        double c2 = getDoubleValueOfJTextFieldV2X();
1764
                                                                                        double d1, d2;
1765

    
1766
                                                                                        if (hasChanged_v1X)
1767
                                                                                                d1 = c1 - getDoubleValueOfLastJTextFieldV1XValue();
1768
                                                                                        else
1769
                                                                                                d1 = 0.0;
1770

    
1771
                                                                                        if (hasChanged_v2X)
1772
                                                                                                d2 = c2 - getDoubleValueOfLastJTextFieldV2XValue();
1773
                                                                                        else
1774
                                                                                                d2 = 0.0;
1775

    
1776
                                                                                        if (d1 == 0.0) {
1777
                                                                                                // It's supposed that d2 != 0
1778
                                                                                                c1 += d2;
1779

    
1780
                                                                                                if (c1 < getDoubleValueOfJTextFieldV2X()) {
1781
                                                                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v1x") + " < " + PluginServices.getText(jButtonPreviewArea, "v2x"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1782
                                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1783
                                                                                                        return;
1784
                                                                                                }
1785

    
1786
                                                                                                getJTextFieldVertex1X().setText(Double.toString(c1));
1787
                                                                                        }
1788
                                                                                        else {
1789
                                                                                                if (d2 == 0.0) {
1790
                                                                                                        // It's supposed that d1 != 0
1791
                                                                                                        c2 += d1;
1792

    
1793
                                                                                                        if (c2 > getDoubleValueOfJTextFieldV1X()) {
1794
                                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v2x") + " > " + PluginServices.getText(jButtonPreviewArea, "v1x"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1795
                                                                                                                restoreAllModifiedCoordinates(); // restores the coordinates
1796
                                                                                                                return;
1797
                                                                                                        }
1798

    
1799
                                                                                                        getJTextFieldVertex2X().setText(Double.toString(c2));
1800
                                                                                                }
1801
                                                                                                else {
1802
                                                                                                        // If there has been an error -> can't move different distances in X the two vertexes
1803
                                                                                                        if (d1 != d2) {
1804
                                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "different_distances_in_X"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1805
                                                                                                                restoreAllModifiedCoordinates(); // restores the coordinates
1806
                                                                                                                return;
1807
                                                                                                        }
1808
                                                                                                }
1809
                                                                                        }
1810
                                                                                }
1811

    
1812
                                                                                // Move in Y
1813
                                                                                if ((hasChanged_v1Y) || (hasChanged_v2Y)) {
1814
                                                                                        double c1 = getDoubleValueOfJTextFieldV1Y();
1815
                                                                                        double c2 = getDoubleValueOfJTextFieldV2Y();
1816
                                                                                        double d1, d2;
1817

    
1818
                                                                                        if (hasChanged_v1Y)
1819
                                                                                                d1 = c1 - getDoubleValueOfLastJTextFieldV1YValue();
1820
                                                                                        else
1821
                                                                                                d1 = 0.0;
1822

    
1823
                                                                                        if (hasChanged_v2Y)
1824
                                                                                                d2 = c2 - getDoubleValueOfLastJTextFieldV2YValue();
1825
                                                                                        else
1826
                                                                                                d2 = 0.0;
1827

    
1828
                                                                                        if (d1 == 0.0) {
1829
                                                                                                // It's supposed that d2 != 0
1830
                                                                                                c1 += d2;
1831

    
1832
                                                                                                if (c1 < getDoubleValueOfJTextFieldV2Y()) {
1833
                                                                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v1y") + " < " + PluginServices.getText(jButtonPreviewArea, "v2y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1834
                                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1835
                                                                                                        return;
1836
                                                                                                }
1837

    
1838
                                                                                                getJTextFieldVertex1Y().setText(Double.toString(c1));
1839
                                                                                        }
1840
                                                                                        else {
1841
                                                                                                if (d2 == 0.0) {
1842
                                                                                                        // It's supposed that d1 != 0
1843
                                                                                                        c2 += d1;
1844

    
1845
                                                                                                        if (c2 > getDoubleValueOfJTextFieldV1Y()) {
1846
                                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "problem_with_the_new_calculated_area") + ": " + PluginServices.getText(jButtonPreviewArea, "v2y") + " > " + PluginServices.getText(jButtonPreviewArea, "v1y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1847
                                                                                                                restoreAllModifiedCoordinates(); // restores the coordinates
1848
                                                                                                                return;
1849
                                                                                                        }
1850

    
1851
                                                                                                        getJTextFieldVertex2Y().setText(Double.toString(c2));
1852
                                                                                                }
1853
                                                                                                else {
1854
                                                                                                        // If there has been an error -> can't move different distances in Y the two vertexes
1855
                                                                                                        if (d1 != d2) {
1856
                                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "different_distances_in_Y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1857
                                                                                                                restoreAllModifiedCoordinates(); // restores the coordinates
1858
                                                                                                                return;
1859
                                                                                                        }
1860
                                                                                                }
1861
                                                                                        }
1862
                                                                                }
1863
                                                                        }
1864
                                                                        else {
1865
                                                                                boolean canSetExtent = true;
1866

    
1867
                                                                                // Check if there is a impossible coordinate
1868
                                                                                if (hasChanged_v1X) {
1869
                                                                                        if (getDoubleValueOfJTextFieldV1X() < getDoubleValueOfJTextFieldV2X()) {
1870
                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "v1x") + " < " + PluginServices.getText(jButtonPreviewArea, "v2x"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1871
                                                                                                canSetExtent = false;
1872
                                                                                        }
1873
                                                                                }
1874

    
1875
                                                                                if (hasChanged_v1Y) {
1876
                                                                                        if (getDoubleValueOfJTextFieldV1Y() < getDoubleValueOfJTextFieldV2Y()) {
1877
                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "v1y") + " < " + PluginServices.getText(jButtonPreviewArea, "v2y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1878
                                                                                                canSetExtent = false;
1879
                                                                                        }
1880
                                                                                }
1881

    
1882
                                                                                if (hasChanged_v2X) {
1883
                                                                                        if (getDoubleValueOfJTextFieldV2X() > getDoubleValueOfJTextFieldV1X()) {
1884
                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "v2x") + " > " + PluginServices.getText(jButtonPreviewArea, "v1x"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1885
                                                                                                canSetExtent = false;
1886
                                                                                        }
1887
                                                                                }
1888

    
1889
                                                                                if (hasChanged_v2Y) {
1890
                                                                                        if (getDoubleValueOfJTextFieldV2Y() > getDoubleValueOfJTextFieldV1Y()) {
1891
                                                                                                JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "v2y") + " > " + PluginServices.getText(jButtonPreviewArea, "v1y"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1892
                                                                                                canSetExtent = false;
1893
                                                                                        }
1894
                                                                                }
1895

    
1896
                                                                                // If can set the new Extent -> finish
1897
                                                                                if (!canSetExtent) {
1898
                                                                                        restoreAllModifiedCoordinates(); // restores the coordinates
1899
                                                                                        return;
1900
                                                                                }
1901
                                                                        }
1902
                                                                }
1903

    
1904
                                                                //Rectangle2D r2d = vP.getExtent();
1905
                                                                if (vP.getExtent() != null){
1906
                                                                        vP.setExtent(getNewRectangleByCoordinates());
1907
                                                                        vP.refreshExtent();
1908
                                                                }
1909
                                                        }
1910
                                                }
1911
                                                else {
1912
                                                        JOptionPane.showMessageDialog(jButtonPreviewArea, PluginServices.getText(jButtonPreviewArea, "at_least_one_incorrect_coordinate"), PluginServices.getText(jButtonPreviewArea, "error"), JOptionPane.ERROR_MESSAGE);
1913
                                                }
1914
                                        }
1915
                                });
1916
                        }
1917
                        return jButtonPreviewArea;
1918
                }
1919

    
1920
                /**
1921
                 * Calculates the new rectangle using the coordinates of the text fields
1922
                 *
1923
                 * @return java.awt.geom.Rectangle2D
1924
                 */
1925
                private Rectangle2D getNewRectangleByCoordinates() {
1926
                        return new Rectangle2D.Double(getDoubleValueOfJTextFieldV2X(), getDoubleValueOfJTextFieldV2Y(), getDoubleValueOfJTextFieldV1X() - getDoubleValueOfJTextFieldV2X(), getDoubleValueOfJTextFieldV1Y() - getDoubleValueOfJTextFieldV2Y());
1927
                }
1928

    
1929
                /**
1930
                 * Restores the value of all text fields with coordinates modified to their last value
1931
                 */
1932
                private void restoreAllModifiedCoordinates() {
1933
                        if (hasChanged_v1X) {
1934
                                getJTextFieldVertex1X().setText(last_Coordinates[0]);
1935
                                hasChanged_v1X = false;
1936
                        }
1937

    
1938
                        if (hasChanged_v1Y) {
1939
                                getJTextFieldVertex1Y().setText(last_Coordinates[1]);
1940
                                hasChanged_v1Y = false;
1941
                        }
1942

    
1943
                        if (hasChanged_v2X) {
1944
                                getJTextFieldVertex2X().setText(last_Coordinates[2]);
1945
                                hasChanged_v2X = false;
1946
                        }
1947

    
1948
                        if (hasChanged_v2Y) {
1949
                                getJTextFieldVertex2Y().setText(last_Coordinates[3]);
1950
                                hasChanged_v2Y = false;
1951
                        }
1952
                }
1953

    
1954
                /**
1955
                 * Enables or disables all inner JTextField
1956
                 *
1957
                 * @param b A boolean value
1958
                 */
1959
                public void setAllTextFieldsEnabled(boolean b) {
1960
                        getJTextFieldVertex1X().setEnabled(b);
1961
                        getJTextFieldVertex1Y().setEnabled(b);
1962
                        getJTextFieldVertex2X().setEnabled(b);
1963
                        getJTextFieldVertex2Y().setEnabled(b);
1964
                }
1965

    
1966
                /**
1967
                 * Sets the extent into the text fields
1968
                 *
1969
                 * @param extent java.awt.geom.Rectangle2D
1970
                 */
1971
                public void updateCoordinates(Rectangle2D extent){
1972
                        getJTextFieldVertex1X().setText(String.valueOf(extent.getMaxX()));
1973
                        last_Coordinates[0] = getJTextFieldVertex1X().getText();
1974
                        previous_Coordinate_Value[0] = last_Coordinates[0];
1975

    
1976
                        getJTextFieldVertex1Y().setText(String.valueOf(extent.getMaxY()));
1977
                        last_Coordinates[1] = getJTextFieldVertex1Y().getText();
1978
                        previous_Coordinate_Value[1] = last_Coordinates[1];
1979

    
1980
                        getJTextFieldVertex2X().setText(String.valueOf(extent.getMinX()));
1981
                        last_Coordinates[2] = getJTextFieldVertex2X().getText();
1982
                        previous_Coordinate_Value[2] = last_Coordinates[2];
1983

    
1984
                        getJTextFieldVertex2Y().setText(String.valueOf(extent.getMinY()));
1985
                        last_Coordinates[3] = getJTextFieldVertex2Y().getText();
1986
                        previous_Coordinate_Value[3] = last_Coordinates[3];
1987
                        
1988
                        resetCoordinatesFlags();
1989

    
1990
                        // Enable the 'Applicate' button
1991
                        setApplicable(true);
1992
                }
1993

    
1994
                /**
1995
                 * Validates all coordinates of both vertexes separately
1996
                 *
1997
                 * @return A ValidationInfo object reference
1998
                 */
1999
                private ValidationInfo validVertexesCoordinates() {
2000
                        if (! validateCoordinate(getJTextFieldVertex1X())) {
2001
                                return new ValidationInfo(false, PluginServices.getText(this, "invalid_coordinate") + ": " + PluginServices.getText(this, "v1x"));
2002
                        }
2003

    
2004
                        if (! validateCoordinate(getJTextFieldVertex1Y())) {
2005
                                return new ValidationInfo(false, PluginServices.getText(this, "invalid_coordinate") + ": " + PluginServices.getText(this, "v1y"));
2006
                        }
2007

    
2008
                        if (! validateCoordinate(getJTextFieldVertex2X())) {
2009
                                return new ValidationInfo(false, PluginServices.getText(this, "invalid_coordinate") + ": " + PluginServices.getText(this, "v2x"));
2010
                        }
2011

    
2012
                        if (! validateCoordinate(getJTextFieldVertex2Y())) {
2013
                                return new ValidationInfo(false, PluginServices.getText(this, "invalid_coordinate") + ": " + PluginServices.getText(this, "v2y"));
2014
                        }
2015

    
2016
                        // If arrives here, all coordinates are valid
2017
                        return new ValidationInfo(true, "");
2018
                }
2019

    
2020
                /**
2021
                 * Validates that Vertex1 is in the right-up corner and the Vertex2 in the left-down corner of the area/rectangle <br>
2022
                 * (It's supposed that coordinates of the vertexes are valid) <br>
2023
                 * (It's supposed that going to right or up, the coordinate value increases)
2024
                 *
2025
                 * @return A ValidationInfo object reference
2026
                 */
2027
                private ValidationInfo validVertexesPositions() {
2028
                        // Check if no coordinate it's defined
2029
                        if (getJTextFieldVertex1X().getText().compareTo("") == 0) {
2030
                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v1x"));
2031
                        }
2032

    
2033
                        if (getJTextFieldVertex2X().getText().compareTo("") == 0) {
2034
                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v2x"));
2035
                        }
2036

    
2037
                        if (getJTextFieldVertex1Y().getText().compareTo("") == 0) {
2038
                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v1y"));
2039
                        }
2040

    
2041
                        if (getJTextFieldVertex2Y().getText().compareTo("") == 0) {
2042
                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v2y"));
2043
                        }
2044

    
2045
                        // Check if the vertex V1 is in the right-up corner and the vertex V2 is in the left-down corner
2046
                        if (getDoubleValueOfJTextFieldV1X() < getDoubleValueOfJTextFieldV2X()) {
2047
                                return new ValidationInfo(false, PluginServices.getText(this, "v1x") + " < " + PluginServices.getText(this, "v2x"));
2048
                        }
2049

    
2050
                        if (getDoubleValueOfJTextFieldV1Y() < getDoubleValueOfJTextFieldV2Y()) {
2051
                                return new ValidationInfo(false, PluginServices.getText(this, "v1y") + " < " + PluginServices.getText(this, "v2y"));
2052
                        }
2053

    
2054
                        // If arrives here -> vertexes positions are valid
2055
                        return new ValidationInfo(true, "");
2056
                }
2057

    
2058
                /**
2059
                 * Validate each coordinate of each vertex and the position of the vertexes
2060
                 *
2061
                 * @return A boolean value
2062
                 */
2063
                public boolean validVertexes() {
2064
                        ValidationInfo v1 = validVertexesCoordinates();
2065

    
2066
                        if (!v1.isValid()) {
2067
                                // Notify to user that no filter area will be applied
2068
                                JOptionPane.showMessageDialog(null, PluginServices.getText(null, PluginServices.getText(this, "invalid_coordinates") + ": " + v1.getMessage()), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
2069

    
2070
                                return false;
2071
                        }
2072
                        else {
2073
                                ValidationInfo v2 = validVertexesPositions();
2074
                                if (!v2.isValid()) {
2075
                                        // Notify to user that no filter area will be applied
2076
                                        JOptionPane.showMessageDialog(null, PluginServices.getText(null, PluginServices.getText(this, "invalid_coordinates") + ": " + v2.getMessage()), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
2077

    
2078
                                        return false;
2079
                                }
2080
                                else {
2081
                                        return true;
2082
                                }
2083
                        }
2084
                }
2085

    
2086
                /**
2087
                 * Gets the extent (rectangle) represented by the values of the coordinate text fields
2088
                 *
2089
                 * @return java.awt.geom.Rectangle2D
2090
                 */
2091
                public Rectangle2D getExtent() {
2092
                        double v1x = getDoubleValueOfJTextFieldV1X();
2093
                        double v1y = getDoubleValueOfJTextFieldV1Y();
2094
                        double v2x = getDoubleValueOfJTextFieldV2X();
2095
                        double v2y = getDoubleValueOfJTextFieldV2Y();
2096

    
2097
                        return new Rectangle2D.Double(v2x, v1y, (v1x - v2x), (v1y  - v2y));
2098
                }
2099

    
2100
                /**
2101
                 * Returns true if there is some coordinate text field with data; else returns false
2102
                 *
2103
                 * @return A boolean value
2104
                 */
2105
                public boolean areThereSomeCoordinatesWritten() {
2106
                        return ((getJTextFieldVertex1X().getText().compareTo("") != 0) | (getJTextFieldVertex1Y().getText().compareTo("") != 0) | (getJTextFieldVertex2X().getText().compareTo("") != 0) | (getJTextFieldVertex2Y().getText().compareTo("") != 0));
2107
                }
2108

    
2109
                /**
2110
                 * Returns true if all coordinate text fields are undefined (without values)
2111
                 *
2112
                 * @return A boolean value
2113
                 */
2114
                public boolean areAllCoordinatesUndefined() {
2115
                        return ((getJTextFieldVertex1X().getText().compareTo("") == 0) & (getJTextFieldVertex1Y().getText().compareTo("") == 0) & (getJTextFieldVertex2X().getText().compareTo("") == 0) & (getJTextFieldVertex2Y().getText().compareTo("") == 0));
2116
                }
2117

    
2118

    
2119
                /**
2120
                 * Returns true if there is some coordinate undefined (without values)
2121
                 *
2122
                 * @return A boolean value
2123
                 */
2124
                public boolean isThereAnyCoordinateUndefined() {
2125
                        return ((getJTextFieldVertex1X().getText().compareTo("") == 0) | (getJTextFieldVertex1Y().getText().compareTo("") == 0) | (getJTextFieldVertex2X().getText().compareTo("") == 0) | (getJTextFieldVertex2Y().getText().compareTo("") == 0));
2126
                }
2127
        }
2128

    
2129
        /**
2130
         * This class is a MapControl JComponent that has visual information and allows user interact with some tools and view the results
2131
         *
2132
         * @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
2133
         */
2134
        private class SelectableMapControlAreaPanel extends MapControl implements Serializable {
2135
                private MouseListener[] mouseListeners;
2136
                private MouseWheelListener[] mouseWheelListeners;
2137
                private MouseMotionListener[] mouseMotionListeners;
2138

    
2139
                /**
2140
                 * Default constructor
2141
                 */
2142
                public SelectableMapControlAreaPanel() {
2143
                        super();
2144
                        initialize();
2145
                }
2146

    
2147
                /**
2148
                 * This method initializes this component
2149
                 */
2150
                public void initialize() {
2151
                        /* Sets Bounds of this graphical component */
2152
                        this.setBounds(DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE);
2153

    
2154
                        /* Sets border to this graphical component */
2155
                        this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
2156

    
2157
                        /* Sets a clone of the current active view map context to this MapControl */
2158
                        try {
2159
                                MapContext mp = ((View) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
2160
                                this.setMapContext(mp.cloneFMap());
2161
                                ViewPort vP = this.getViewPort();
2162

    
2163
                                Rectangle2D r2D = vP.getExtent();
2164

    
2165
                                if (r2D != null) {
2166
                                        vP.refreshExtent();
2167
                                        getCoordinatesPanel().updateCoordinates(r2D);
2168
                                }
2169
                        } catch (XMLException e) {
2170
                                e.printStackTrace();
2171
                        }
2172

    
2173
                        /* Adds listeners to this MapControl */
2174
                        this.addToolsListeners();
2175

    
2176
                        /* Sets default tool */
2177
                        this.setTool(PAN_TOOL);
2178
                }
2179

    
2180
                /**
2181
                 * Refresh the active view
2182
                 */
2183
                public void refreshWithTheActiveView() {
2184
                        try {
2185
                                MapContext mp = ((View) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
2186
                                this.setMapContext(mp.cloneFMap());
2187
                                ViewPort vP = this.getViewPort();
2188

    
2189
                                Rectangle2D r2D = vP.getExtent();
2190

    
2191
                                if (r2D != null) {
2192
                                        vP.refreshExtent();
2193
                                        getCoordinatesPanel().updateCoordinates(r2D);
2194
                                }
2195
                        } catch (XMLException e) {
2196
                                e.printStackTrace();
2197
                        }
2198
                }
2199

    
2200
                /**
2201
                 * Adds listeners that allows user interact with it's mouse over this component and that represents different tools
2202
                 */
2203
                private void addToolsListeners() {
2204
                        // MOVEMENT EVENTS LISTENER: sets mouse coordinates to the status bar
2205
                StatusBarListener sbl = new StatusBarListener(this);
2206

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

    
2212
                // ZOOM IN (Using a Rectangle or a simple mouse click)
2213
                ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(this);
2214
                ZoomInListener zil = new ZoomInListener(this);
2215
                this.addMapTool(ZOOM_IN_TOOL, new Behavior[]{new RectangleBehavior(zil),
2216
                                                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
2217

    
2218
                // PAN
2219
                PanListener pl = new PanListener(this);
2220
                this.addMapTool(PAN_TOOL, new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)});
2221

    
2222
                // MEASURE DISTANCES
2223
                MeasureListener mli = new MeasureListener(this);
2224
                this.addMapTool(MEASURE_DISTANCES_TOOL, new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)});
2225

    
2226
                // MEASURE AREA
2227
                AreaListener ali = new AreaListener(this);
2228
                this.addMapTool(MEASURE_AREA_TOOL, new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)});
2229

    
2230
                this.getViewPort().addViewPortListener(new ViewPortListener() {
2231
                        /*
2232
                         *  (non-Javadoc)
2233
                         * @see com.iver.cit.gvsig.fmap.ViewPortListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
2234
                         */
2235
                                public void extentChanged(ExtentEvent e) {
2236
                                        if (getMapContext().getViewPort().getExtents().hasPrevious()) {
2237
                                                Rectangle2D r2d = getViewPort().getExtent();
2238

    
2239
                                                if (r2d != null) {
2240
                                                        getCoordinatesPanel().updateCoordinates(r2d);
2241
                                                        
2242
                                                        if (getJComboBoxToolSelection().getSelectedIndex() != 0) {
2243
                                                                hasUserDefinedAnArea = true;
2244
                                                        }
2245
                                                }
2246

    
2247
                                                getJButtonZoomPrevious().setEnabled(true);
2248
                                                getJButtonUndo().setEnabled(true);
2249
                                        }
2250
                                        else {
2251
                                                getJButtonZoomPrevious().setEnabled(false);
2252
                                                getJButtonUndo().setEnabled(false);
2253
                                        }
2254
                                }
2255

    
2256
                                /*
2257
                                 *  (non-Javadoc)
2258
                                 * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
2259
                                 */
2260
                                public void backColorChanged(ColorEvent e) {
2261
                                }
2262

    
2263
                                /*
2264
                                 *  (non-Javadoc)
2265
                                 * @see com.iver.cit.gvsig.fmap.ViewPortListener#projectionChanged(com.iver.cit.gvsig.fmap.ProjectionEvent)
2266
                                 */
2267
                                public void projectionChanged(ProjectionEvent e) {
2268
                                }
2269

    
2270
                });
2271
                }
2272

    
2273
                /*
2274
                 *  (non-Javadoc)
2275
                 * @see java.awt.Component#setEnabled(boolean)
2276
                 */
2277
                public void setEnabled(boolean b) {
2278
                        super.setEnabled(b);
2279

    
2280
                        if (b)
2281
                                enableAllMouseListeners();
2282
                        else
2283
                                disableAllMouseListeners();
2284
                }
2285

    
2286
                /**
2287
                 * Disables all mouse listeners
2288
                 */
2289
                public void disableAllMouseListeners() {
2290
                        int i;
2291

    
2292
                        // 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
2293
                        //   are referenciated by this component or by the private attribute 'mouseListeners')
2294

    
2295
                        // Mouse Button Listeners
2296
                        if (mouseListeners == null) {
2297
                                mouseListeners = this.getMouseListeners();
2298

    
2299
                                for (i = 0; i < mouseListeners.length; i++) {
2300
                                        removeMouseListener(mouseListeners[i]);
2301
                                }
2302
                        }
2303

    
2304
                        // Mouse Wheel Listeners
2305
                        if (mouseWheelListeners == null) {
2306
                                mouseWheelListeners = this.getMouseWheelListeners();
2307

    
2308
                                for (i = 0; i < mouseWheelListeners.length; i++) {
2309
                                        removeMouseWheelListener(mouseWheelListeners[i]);
2310
                                }
2311
                        }
2312

    
2313
                        // Mouse motion listeners
2314
                        if (mouseMotionListeners == null) {
2315
                                mouseMotionListeners = this.getMouseMotionListeners();
2316

    
2317
                                for (i = 0; i < mouseMotionListeners.length; i++) {
2318
                                        removeMouseMotionListener(mouseMotionListeners[i]);
2319
                                }
2320
                        }
2321
                }
2322

    
2323
                /**
2324
                 * Enables all mouse listeners
2325
                 */
2326
                public void enableAllMouseListeners() {
2327
                        int i;
2328

    
2329
                        // Mouse Button Listeners
2330
                        for (i = 0; i < mouseListeners.length; i++) {
2331
                                addMouseListener(mouseListeners[i]);
2332
                        }
2333

    
2334
                        mouseListeners = null;
2335

    
2336
                        // Mouse Wheel Listeners
2337
                        for (i = 0; i < mouseWheelListeners.length; i++) {
2338
                                addMouseWheelListener(mouseWheelListeners[i]);
2339
                        }
2340

    
2341
                        mouseWheelListeners = null;
2342

    
2343
                        // Mouse motion listeners
2344
                        for (i = 0; i < mouseMotionListeners.length; i++) {
2345
                                addMouseMotionListener(mouseMotionListeners[i]);
2346
                        }
2347

    
2348
                        mouseMotionListeners = null;
2349
                }
2350
        }
2351

    
2352
        /**
2353
         * This class has information about a validation: <br>
2354
         *   - A boolean value -> if has been or not validated <br>
2355
         *   - An String -> a message about the invalid
2356
         *
2357
         * @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
2358
         */
2359
        private class ValidationInfo {
2360
                private boolean _valid;
2361
                private String _message;
2362

    
2363
                /**
2364
                 * Default constructor with two parameters
2365
                 *
2366
                 * @param valid If was valid or not
2367
                 * @param message A message associate to the validation (If has been valid, this attribute should be "", in the other case should have a message with
2368
                 *                  an explanation about the invalidation)
2369
                 */
2370
                public ValidationInfo(boolean valid, String message) {
2371
                        _valid = valid;
2372
                        _message = message;
2373
                }
2374

    
2375
                /**
2376
                 * Returns the value of the inner attribute '_valid'
2377
                 *
2378
                 * @return A boolean value
2379
                 */
2380
                public boolean isValid() {
2381
                        return _valid;
2382
                }
2383

    
2384
                /**
2385
                 * Returns the value of the inner attribute '_message'
2386
                 *
2387
                 * @return java.lang.String
2388
                 */
2389
                public String getMessage() {
2390
                        return _message;
2391
                }
2392
        }
2393
}