Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / WFSAreaPanel.java @ 36037

History | View | Annotate | Download (97.1 KB)

1
package org.gvsig.wfs.gui.panels;
2

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

    
23
import javax.swing.AbstractButton;
24
import javax.swing.JButton;
25
import javax.swing.JCheckBox;
26
import javax.swing.JComboBox;
27
import javax.swing.JLabel;
28
import javax.swing.JOptionPane;
29
import javax.swing.JPanel;
30
import javax.swing.JTextField;
31
import javax.swing.JToggleButton;
32
import javax.swing.SwingConstants;
33

    
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.messages.NotificationManager;
36
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
37
import org.gvsig.app.project.documents.view.toolListeners.AreaListener;
38
import org.gvsig.app.project.documents.view.toolListeners.MeasureListener;
39
import org.gvsig.app.project.documents.view.toolListeners.PanListener;
40
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
41
import org.gvsig.app.project.documents.view.toolListeners.ZoomInListener;
42
import org.gvsig.app.project.documents.view.toolListeners.ZoomOutListener;
43
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer;
44
import org.gvsig.fmap.geom.Geometry;
45
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
46
import org.gvsig.fmap.geom.Geometry.TYPES;
47
import org.gvsig.fmap.geom.GeometryLocator;
48
import org.gvsig.fmap.geom.GeometryManager;
49
import org.gvsig.fmap.geom.exception.CreateGeometryException;
50
import org.gvsig.fmap.geom.primitive.Envelope;
51
import org.gvsig.fmap.geom.primitive.Surface;
52
import org.gvsig.fmap.mapcontext.ExtentHistory;
53
import org.gvsig.fmap.mapcontext.MapContext;
54
import org.gvsig.fmap.mapcontext.ViewPort;
55
import org.gvsig.fmap.mapcontext.events.ColorEvent;
56
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
57
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
58
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
59
import org.gvsig.fmap.mapcontext.layers.FLayer;
60
import org.gvsig.fmap.mapcontrol.MapControl;
61
import org.gvsig.fmap.mapcontrol.tools.ZoomOutRightButtonListener;
62
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
63
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
64
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveBehavior;
65
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
66
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior;
67
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior;
68
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior;
69
import org.gvsig.gui.beans.panelGroup.IPanelGroup;
70
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP;
71
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.ImageIconItemInfo;
72
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.JComboBoxWithImageIconItems;
73
import org.gvsig.utils.stringNumberUtilities.StringNumberUtilities;
74
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
75

    
76

    
77
/* gvSIG. Geographic Information System of the Valencian Government
78
*
79
* Copyright (C) 2007-2008 Infrastructures and Transports Department
80
* of the Valencian Government (CIT)
81
* 
82
* This program is free software; you can redistribute it and/or
83
* modify it under the terms of the GNU General Public License
84
* as published by the Free Software Foundation; either version 2
85
* of the License, or (at your option) any later version.
86
* 
87
* This program is distributed in the hope that it will be useful,
88
* but WITHOUT ANY WARRANTY; without even the implied warranty of
89
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
90
* GNU General Public License for more details.
91
* 
92
* You should have received a copy of the GNU General Public License
93
* along with this program; if not, write to the Free Software
94
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
95
* MA  02110-1301, USA.
96
* 
97
*/
98

    
99
/**
100
 * VERSI?N PROVISIONAL ESTABLE
101
 *
102
 * This panel allows user to select the area he/she wants to get in the view.
103
 * There are two options to do this:
104
 *  - Indicating the coordinates of the top-left and down-right corners
105
 *  - Selecting the area with some visual tool
106
 *
107
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
108
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
109
 */
110
public class WFSAreaPanel extends AbstractWFSPanel {
111
    private final Rectangle DEFAULT_BOUNDS = new Rectangle(10, 5, 490, 380);
112
    private final Rectangle DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE = new Rectangle(8, 20, 481, 60);
113
    private final Rectangle DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE = new Rectangle(8, 115, 481, 265);
114
    private final Rectangle DEFAULT_UNDO_ICON_BUTTON_RECTANGLE = new Rectangle (250, 85, 25, 25);
115
    private final Rectangle DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (277, 85, 25, 25);
116
    private final Rectangle DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (304, 85, 25, 25);
117
    private final Rectangle DEFAULT_PAN_ICON_BUTTON_RECTANGLE = new Rectangle(250, 85, 25, 25);
118
    private final Rectangle DEFAULT_TOOL_JCOMBOBOX_RECTANGLE = new Rectangle(10, 87, 230, 21);
119
    private final Rectangle DEFAULT_ENABLING_CHECKBOX_RECTANGLE = new Rectangle(10, 87, 150, 21);
120
    private final Rectangle DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE = new Rectangle(277, 85, 47, 25);
121
    private final Rectangle DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE = new Rectangle(326, 85, 25, 25);
122
    private final Rectangle DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE = new Rectangle(353, 85, 25, 25);
123
    private final Rectangle DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE = new Rectangle(380, 85, 47, 25);
124
    private final Rectangle DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE = new Rectangle(429, 85, 47, 25);
125

    
126
    private static GeometryManager geometryManager = GeometryLocator.getGeometryManager();
127
    private final int DISABLED_OPERATION = 0;
128
    private final int SELECTION_BY_COORDINATES_OPERATION = 1;
129
    private final int SELECTION_BY_AREA_OPERATION = 2;
130
    private boolean hasUserDefinedAnArea = false;
131
    //        private Rectangle2D lastExtentValid = null;
132
    private ExtentHistory previousExtentValids = null;
133

    
134
    private WFSServerExplorer serverExplorer = null;
135
    private AreaCoordinatesPanel coordinatesPanel = null;
136
    private SelectableMapControlAreaPanel selectableMapAreaPanel = null;
137
    private JComboBox jComboBoxToolSelection = null;
138
    private JButton jButtonUndo = null;
139
    //        private JButton jButtonRedo = null;
140
    private JToggleButton jToggleButtonMove = null;
141
    private JToggleButton jToggleButtonScaling = null;
142
    private JButton jButtonPan = null;
143
    private JButton jButtonZoomPrevious = null;
144
    private JButton jButtonZoomComplete = null;
145
    private JComboBoxWithImageIconItems jComboBoxZoomInAndOut = null;
146
    private JComboBoxWithImageIconItems jComboBoxZoomInAndOutViewCentered = null;
147
    private JComboBoxWithImageIconItems jComboBoxOtherTools = null;
148
    private JCheckBox jEnablingCheckBox = null;
149

    
150
    /* Tool identifier constants */
151
    private final String PAN_TOOL = "HAND";
152
    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'
153
    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'
154
    private final String ZOOM_IN_VIEW_CENTERED_TOOL = "ZOOM_IN_VIEW_CENTERED";
155
    private final String ZOOM_OUT_VIEW_CENTERED_TOOL = "ZOOM_OUT_VIEW_CENTERED";
156
    private final String MEASURE_DISTANCES_TOOL = "MEASURE_DISTANCES";
157
    private final String MEASURE_AREA_TOOL = "MEASURE_AREA";
158
    /* End tool identifier constants */
159

    
160
    private JPanel northPanel = null;
161

    
162

    
163
    /**
164
     * This method initializes
165
     */
166
    public WFSAreaPanel() {
167
        super();
168
        initialize();
169
    }
170

    
171
    /**
172
     * Write the view coordinates into the coordinates panel
173
     */
174
    private void initCoordinates(){
175
        AbstractViewPanel activeView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
176
        // We will use the adjusted extent because increases the usability
177
        Envelope envelope = activeView.getMapControl().getViewPort().getAdjustedExtent();
178
        //                Rectangle2D r2d = activeView.getMapControl().getViewPort().getExtent();
179

    
180
        if (envelope != null){
181
            previousExtentValids.put(new Rectangle2D.Double(envelope.getMinimum(0),
182
                envelope.getMinimum(1),
183
                envelope.getMaximum(0)-envelope.getMaximum(0),
184
                envelope.getMaximum(1)-envelope.getMinimum(1)));
185

    
186
            setCoordinates(envelope.getMaximum(0), envelope.getMaximum(1),
187
                envelope.getMinimum(0), envelope.getMinimum(1));
188
        }
189
    }
190

    
191
    /**
192
     * Removes all registered extents
193
     */
194
    public void clearCoordinates() {
195
        this.hasUserDefinedAnArea = false;
196

    
197
        while (previousExtentValids.hasPrevious()) {
198
            previousExtentValids.removePrev();
199
        }
200
    }
201

    
202
    /**
203
     * <p>Sets the coordinates of all the text fields. It's supposed that all coordinates are valid.</p>
204
     *
205
     * @param v1x value of the x coordinate of the right-up corner of the rectangle
206
     * @param v1y value of the y coordinate of the right-up corner of the rectangle
207
     * @param v2x value of the x coordinate of the left-up corner of the rectangle
208
     * @param v2y value of the y coordinate of the left-up corner of the rectangle
209
     */
210
    private void setCoordinates(double v1x, double v1y, double v2x, double v2y) {
211
        getCoordinatesPanel().getJTextFieldVertex1X().setText(Double.toString(v1x));
212
        getCoordinatesPanel().getJTextFieldVertex1Y().setText(Double.toString(v1y));
213
        getCoordinatesPanel().getJTextFieldVertex2X().setText(Double.toString(v2x));
214
        getCoordinatesPanel().getJTextFieldVertex2Y().setText(Double.toString(v2y));
215
    }
216

    
217
    /**
218
     * <p>Sets the coordinates of all the text fields. It's supposed that all coordinates are valid.</p>
219
     *
220
     * @param bbox the bounding box that represents a rectangle with the information of all coordinates
221
     */
222
    private void setCoordinates(Rectangle2D bbox) {
223
        getCoordinatesPanel().getJTextFieldVertex1X().setText(Double.toString(bbox.getMaxX()));
224
        getCoordinatesPanel().getJTextFieldVertex1Y().setText(Double.toString(bbox.getMaxY()));
225
        getCoordinatesPanel().getJTextFieldVertex2X().setText(Double.toString(bbox.getMinX()));
226
        getCoordinatesPanel().getJTextFieldVertex2Y().setText(Double.toString(bbox.getMinY()));
227
    }
228

    
229
    /**
230
     * This method initializes coordinatesPanel
231
     *
232
     * @return javax.swing.JPanel
233
     */
234
    private AreaCoordinatesPanel getCoordinatesPanel() {
235
        if (coordinatesPanel == null) {
236
            coordinatesPanel = new AreaCoordinatesPanel();
237
        }
238
        return coordinatesPanel;
239
    }
240

    
241
    /**
242
     * This method initializes jEnablingCheckBox
243
     *
244
     * @return javax.swing.JCheckBox
245
     */
246
    private JCheckBox getEnablingJCheckBox() {
247
        if (jEnablingCheckBox == null) {
248
            jEnablingCheckBox = new JCheckBox(PluginServices.getText(this, "enabled"));
249
            jEnablingCheckBox.setBounds(DEFAULT_ENABLING_CHECKBOX_RECTANGLE);
250
            jEnablingCheckBox.setToolTipText(PluginServices.getText(this, "enable_filter_by_area"));
251
            jEnablingCheckBox.setSelected(false);
252
            jEnablingCheckBox.addItemListener(new ItemListener() {
253
                /*
254
                 * (non-Javadoc)
255
                 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
256
                 */
257
                public void itemStateChanged(ItemEvent e) {
258
                    if (e.getStateChange() == ItemEvent.SELECTED) {
259
                        jEnablingCheckBox.setToolTipText(PluginServices.getText(this, "disable_filter_by_area"));
260
                        enableCoorderatesRegionOperation();
261
                    }
262
                    else {
263
                        jEnablingCheckBox.setToolTipText(PluginServices.getText(this, "enable_filter_by_area"));
264
                        disableCoorderatesRegionOperation();
265
                    }
266

    
267
                    IPanelGroup panelGroup = getPanelGroup();
268

    
269
                    if (panelGroup == null)
270
                        return;
271

    
272
                    ((WFSParamsPanel)panelGroup).setApplicable(true);
273
                }
274
            });
275

    
276
            // By default, the tool is disabled
277
            disableCoorderatesRegionOperation();
278
        }
279
        return jEnablingCheckBox;
280
    }
281

    
282
    /**
283
     * This method initializes jComboBoxToolSelection
284
     *
285
     * @return  javax.swing.JComboBox
286
     */
287
    private JComboBox getJComboBoxToolSelection() {
288
        if (jComboBoxToolSelection == null) {
289
            jComboBoxToolSelection = new JComboBox();
290
            jComboBoxToolSelection.setBounds(DEFAULT_TOOL_JCOMBOBOX_RECTANGLE);
291
            jComboBoxToolSelection.setToolTipText(PluginServices.getText(this, "select_a_tool"));
292
            jComboBoxToolSelection.setEditable(false);
293
            jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "disabled"), this.DISABLED_OPERATION));
294
            jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "define_absolute_coordinates"), this.SELECTION_BY_COORDINATES_OPERATION));
295
            jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "define_coordinates_using_view"), this.SELECTION_BY_AREA_OPERATION));
296

    
297
            jComboBoxToolSelection.addActionListener(new ActionListener() {
298
                /*
299
                 * (non-Javadoc)
300
                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
301
                 */
302
                public void actionPerformed(ActionEvent e) {
303
                    JComboBox cb = (JComboBox)e.getSource();
304
                    switch(((ItemOperation)cb.getSelectedItem()).getOperation()) {
305
                    case DISABLED_OPERATION:
306
                        disableCoorderatesRegionOperation();
307
                        disableAreaRegionOperation();
308
                        break;
309
                    case SELECTION_BY_COORDINATES_OPERATION:
310
                        disableAreaRegionOperation();
311
                        enableCoorderatesRegionOperation();
312
                        break;
313
                    case SELECTION_BY_AREA_OPERATION:
314
                        // Only enable the area operation if there is data loaded in this MapControl
315
                        if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) {
316
                            disableCoorderatesRegionOperation();
317
                            enableAreaRegionOperation();
318
                        }
319
                        else {
320
                            JOptionPane.showMessageDialog(jComboBoxToolSelection, PluginServices.getText(null, "there_is_no_layer_loaded_in_the_active_view"), PluginServices.getText(null, "information"), JOptionPane.INFORMATION_MESSAGE);
321

    
322
                            // Select: no tools
323
                            jComboBoxToolSelection.setSelectedIndex(0);
324
                            disableCoorderatesRegionOperation();
325
                        }
326

    
327
                        break;
328
                    }
329
                }
330
            });
331
        }
332
        return jComboBoxToolSelection;
333
    }
334

    
335
    /**
336
     * Enables the components associated to the selection of area by coordinates
337
     */
338
    private void enableCoorderatesRegionOperation() {
339
        getCoordinatesPanel().setAllTextFieldsEnabled(true);
340

    
341
        // If the current active view has layers -> set the area in the fields:
342
        // Adds the extent of the viewport of the current active view
343
        AbstractViewPanel view = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
344
        ViewPort vP = view.getMapControl().getMapContext().getViewPort();
345

    
346
        // Update extent (we will use the adjusted extent because increases the usability)
347
        Envelope envelope = vP.getAdjustedExtent();
348

    
349
        if (envelope != null) {
350
            getCoordinatesPanel().updateCoordinates(envelope);
351
        }
352

    
353
        getCoordinatesPanel().getJButtonValidateArea().setEnabled(true);
354

    
355
        this.repaint();
356
    }
357

    
358
    /**
359
     * Enables the components associated to the selection of area by view
360
     */
361
    private void enableAreaRegionOperation() {
362
        // Adds associated icons
363
        this.add(getJButtonPan(), null);
364
        this.add(getJComboBoxZoomInAndOut(), null);
365
        getJComboBoxZoomInAndOut().revalidate(); // Force update this component
366
        this.add(getJButtonZoomPrevious(), null);
367
        this.add(getJButtonZoomComplete(), null);
368
        this.add(getJComboBoxZoomInAndOutViewCentered(), null);
369
        getJComboBoxZoomInAndOutViewCentered().revalidate(); // Force update this component
370
        this.add(getJComboBoxOtherTools(), null);
371
        getJComboBoxOtherTools().revalidate(); // Force update this component
372

    
373
        // Enables the MapControl area
374
        getSelectableMapAreaPanel().setEnabled(true);
375
    }
376

    
377
    /**
378
     * Disables the components associated to the selection of area by coordinates
379
     */
380
    private void disableCoorderatesRegionOperation() {
381
        getCoordinatesPanel().setAllTextFieldsEnabled(false);
382
        getCoordinatesPanel().getJButtonValidateArea().setEnabled(false);
383

    
384
        this.repaint();
385
    }
386

    
387
    /**
388
     * Disables the components associated to the selection of area by view
389
     */
390
    private void disableAreaRegionOperation() {
391
        // Removes associated icons
392
        this.remove(getJButtonPan());
393
        this.remove(getJComboBoxZoomInAndOut());
394
        this.remove(getJButtonZoomPrevious());
395
        this.remove(getJButtonZoomComplete());
396
        this.remove(getJComboBoxZoomInAndOutViewCentered());
397
        this.remove(getJComboBoxOtherTools());
398

    
399
        // Disables the MapControl area
400
        getSelectableMapAreaPanel().setEnabled(false);
401
    }
402

    
403
    /**
404
     * This method initializes areaMapControlPanel
405
     *
406
     * @return A reference to an object of SelectableMapControlAreaPanel
407
     */
408
    private SelectableMapControlAreaPanel getSelectableMapAreaPanel() {
409
        if (selectableMapAreaPanel == null) {
410
            selectableMapAreaPanel = new SelectableMapControlAreaPanel();
411
        }
412

    
413
        return selectableMapAreaPanel;
414
    }
415

    
416
    /**
417
     * This method initializes jButtonUndo
418
     *
419
     * @return javax.swing.JButton
420
     */
421
    private JButton getJButtonUndo() {
422
        if (jButtonUndo == null) {
423
            jButtonUndo = new JButton();
424
            jButtonUndo.setBounds(DEFAULT_UNDO_ICON_BUTTON_RECTANGLE);
425
            jButtonUndo.setIcon(PluginServices.getIconTheme().get("edit-undo"));
426
            jButtonUndo.setToolTipText(PluginServices.getText(this, "previous_area"));
427
            jButtonUndo.addMouseListener(new MouseAdapter() {
428
                public void mouseClicked(MouseEvent e) {
429
                    goToPreviousZoom();
430
                }
431
            });
432
        }
433

    
434
        return jButtonUndo;
435
    }
436

    
437
    /**
438
     * This method initializes jToggleButtonMove
439
     *
440
     * @return javax.swing.JButton
441
     */
442
    private JToggleButton getJToggleButtonMove() {
443
        if (jToggleButtonMove == null) {
444
            jToggleButtonMove = new JToggleButton();
445
            jToggleButtonMove.setBounds(DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE);
446
            jToggleButtonMove.setIcon(PluginServices.getIconTheme().get("WFS-move"));
447
            jToggleButtonMove.setToolTipText(PluginServices.getText(this, "move") + ": " + PluginServices.getText(this, "area_move_explanation"));
448
            jToggleButtonMove.addItemListener(new ItemListener() {
449
                public void itemStateChanged(ItemEvent e) {
450
                    // Isn't allowed that the two JToggleButton would be selected (can't move and scale)
451
                    if (jToggleButtonMove.isSelected())
452
                        jToggleButtonScaling.setSelected(false);
453
                }
454
            });
455
        }
456

    
457
        return jToggleButtonMove;
458
    }
459

    
460
    /**
461
     * This method initializes jToggleButtonScaling
462
     *
463
     * @return javax.swing.JButton
464
     */
465
    private JToggleButton getJToggleButtonScaling() {
466
        if (jToggleButtonScaling == null) {
467
            jToggleButtonScaling = new JToggleButton();
468
            jToggleButtonScaling.setBounds(DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE);
469
            jToggleButtonScaling.setIcon(PluginServices.getIconTheme().get("WFS-scaling"));
470
            jToggleButtonScaling.setToolTipText(PluginServices.getText(this, "scaling") + ": " + PluginServices.getText(this, "area_scaling_explanation"));
471
            jToggleButtonScaling.addItemListener(new ItemListener() {
472
                public void itemStateChanged(ItemEvent e) {
473
                    // Isn't allowed that the two JToggleButton would be selected (can't move and scale)
474
                    if (jToggleButtonScaling.isSelected())
475
                        jToggleButtonMove.setSelected(false);
476
                }
477
            });
478
        }
479

    
480
        return jToggleButtonScaling;
481
    }
482
    /**
483
     * This method initializes jButtonPan
484
     *
485
     * @return javax.swing.JButton
486
     */
487
    private JButton getJButtonPan() {
488
        if (jButtonPan == null) {
489
            jButtonPan = new JButton();
490
            jButtonPan.setBounds(DEFAULT_PAN_ICON_BUTTON_RECTANGLE);
491
            jButtonPan.setIcon(PluginServices.getIconTheme().get("view-pan"));
492
            jButtonPan.setToolTipText(PluginServices.getText(this, "Desplazamiento"));
493
            jButtonPan.addMouseListener(new MouseAdapter() {
494
                public void mouseClicked(MouseEvent e) {
495
                    getSelectableMapAreaPanel().setTool(PAN_TOOL);
496
                }
497
            });
498
        }
499
        return jButtonPan;
500
    }
501

    
502
    /**
503
     * This method initializes jComboBoxZoomInAndOut
504
     *
505
     * @return A JComboBoxWithImageIconItems object reference
506
     */
507
    private JComboBoxWithImageIconItems getJComboBoxZoomInAndOut() {
508
        if (jComboBoxZoomInAndOut == null) {
509
            jComboBoxZoomInAndOut = new JComboBoxWithImageIconItems();
510
            jComboBoxZoomInAndOut.setBounds(DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE);
511
            jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo("images/ZoomIn.png",PluginServices.getIconTheme().get("view-zoom-in"),PluginServices.getText(this, "Zoom_Mas"), ZOOM_IN_TOOL));
512
            jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo("images/ZoomOut.png",PluginServices.getIconTheme().get("view-zoom-out"), PluginServices.getText(this, "Zoom_Menos"), ZOOM_OUT_TOOL));
513
            jComboBoxZoomInAndOut.addActionListener(new ActionListener() {
514
                public void actionPerformed(ActionEvent e) {
515
                    JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
516
                    ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
517
                    getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
518
                }
519
            });
520
        }
521

    
522
        return jComboBoxZoomInAndOut;
523
    }
524

    
525
    /**
526
     * This method initializes jButtonZoomPrevious
527
     *
528
     * @return javax.swing.JButton
529
     */
530
    private JButton getJButtonZoomPrevious() {
531
        if (jButtonZoomPrevious == null) {
532
            jButtonZoomPrevious = new JButton();
533
            jButtonZoomPrevious.setBounds(DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE);
534
            jButtonZoomPrevious.setIcon(PluginServices.getIconTheme().get("view-zoom-back"));
535
            jButtonZoomPrevious.setToolTipText(PluginServices.getText(this, "Zoom_Previo"));
536
            jButtonZoomPrevious.addMouseListener(new MouseAdapter() {
537
                public void mouseClicked(MouseEvent e) {
538
                    goToPreviousZoom();
539
                }
540
            });
541
        }
542
        return jButtonZoomPrevious;
543
    }
544

    
545
    /**
546
     * This method initializes jButtonZoomComplete
547
     *
548
     * @return javax.swing.JButton
549
     */
550
    private JButton getJButtonZoomComplete() {
551
        if (jButtonZoomComplete == null) {
552
            jButtonZoomComplete = new JButton();
553
            jButtonZoomComplete.setBounds(DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE);
554
            jButtonZoomComplete.setIcon(PluginServices.getIconTheme().get("view-zoom-map-contents"));
555
            jButtonZoomComplete.setToolTipText(PluginServices.getText(this, "Zoom_Completo"));
556
            jButtonZoomComplete.addMouseListener(new MouseAdapter() {
557
                public void mouseClicked(MouseEvent e) {
558
                    getSelectableMapAreaPanel().getViewPort().setEnvelope(getSelectableMapAreaPanel().getMapContext().getLayers().getFullEnvelope());
559
                    AbstractViewPanel view =((AbstractViewPanel)PluginServices.getMDIManager().getActiveWindow());
560
                    view.repaintMap();
561
                }
562
            });
563
        }
564
        return jButtonZoomComplete;
565
    }
566

    
567
    /**
568
     * This method initializes jComboBoxZoomInAndOut
569
     *
570
     * @return A JComboBoxWithImageIconItems object reference
571
     */
572
    private JComboBoxWithImageIconItems getJComboBoxZoomInAndOutViewCentered() {
573
        if (jComboBoxZoomInAndOutViewCentered == null) {
574
            jComboBoxZoomInAndOutViewCentered = new JComboBoxWithImageIconItems();
575
            jComboBoxZoomInAndOutViewCentered.setBounds(DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE);
576
            jComboBoxZoomInAndOutViewCentered.addImageIconItem(new ImageIconItemInfo("images/zoommas.png",PluginServices.getIconTheme().get("view-zoom-mas"), PluginServices.getText(this, "Zoom_Acercar"), ZOOM_IN_VIEW_CENTERED_TOOL));
577
            jComboBoxZoomInAndOutViewCentered.addImageIconItem(new ImageIconItemInfo("images/ZoomOut.png",PluginServices.getIconTheme().get("view-zoom-menos"), PluginServices.getText(this, "Zoom_Alejar"), ZOOM_OUT_VIEW_CENTERED_TOOL));
578
            jComboBoxZoomInAndOutViewCentered.addActionListener(new ActionListener() {
579
                public void actionPerformed(ActionEvent e) {
580
                    JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
581
                    ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
582

    
583
                    if (((String)iiii.getItemValue()).compareTo(ZOOM_IN_VIEW_CENTERED_TOOL) == 0) {
584
                        getSelectableMapAreaPanel().zoomIn();
585
                    }
586
                    else {
587
                        getSelectableMapAreaPanel().zoomOut();
588
                    }
589
                }
590
            });
591
        }
592
        return jComboBoxZoomInAndOutViewCentered;
593
    }
594

    
595
    /**
596
     * This method initializes jComboBoxOtherTools
597
     *
598
     * @return A JComboBoxWithImageIconItems object reference
599
     */
600
    private JComboBoxWithImageIconItems getJComboBoxOtherTools() {
601
        if (jComboBoxOtherTools == null) {
602
            jComboBoxOtherTools = new JComboBoxWithImageIconItems();
603
            jComboBoxOtherTools.setBounds(DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE);
604
            jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Distancia.png",PluginServices.getIconTheme().get("view-query-distance"),PluginServices.getText(this, "medir_distancias"), MEASURE_DISTANCES_TOOL));
605
            jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo("images/Poligono16.png",PluginServices.getIconTheme().get("view-query-area"), PluginServices.getText(this, "medir_area"), MEASURE_AREA_TOOL));
606
            jComboBoxOtherTools.addActionListener(new ActionListener() {
607
                public void actionPerformed(ActionEvent e) {
608
                    JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource();
609
                    ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem();
610
                    getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
611
                }
612
            });
613
        }
614

    
615
        return jComboBoxOtherTools;
616
    }
617

    
618
    /**
619
     * Goes to previous zoom
620
     */
621
    private void goToPreviousZoom() {
622
        // Gets the view port and sets its previous extent
623
        ViewPort vp = getSelectableMapAreaPanel().getMapContext().getViewPort();
624

    
625
        if (vp.getExtents().hasPrevious()) {
626
            vp.setPreviousExtent();
627

    
628
            // We will use the adjusted extent because increases the usability
629
            getCoordinatesPanel().updateCoordinates(vp.getAdjustedExtent());
630
        }
631
    }
632

    
633
    /**
634
     * Sets the extent
635
     *
636
     * @param java.awt.geom.Rectangle2D
637
     */
638
    public void setEnvelope(Envelope envelope) {
639
        if (envelope != null) {
640
            // Update coordinates in text fields
641
            getCoordinatesPanel().updateCoordinates(envelope);
642

    
643
            // If there is any layer loaded in the MapControl -> set the extent
644
            if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) {
645
                getSelectableMapAreaPanel().getMapContext().getViewPort().setEnvelope(envelope);
646
            }
647
        }
648
    }
649

    
650
    /**
651
     * 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
652
     *
653
     * @return java.awt.geom.Rectangle2D or null if the data is invalid
654
     */
655
    public Geometry getArea() {
656
        if (!getEnablingJCheckBox().isSelected())
657
            return null;
658

    
659
        if (!hasUserDefinedAnArea)
660
            return null;
661

    
662
        if (getCoordinatesPanel().areAllCoordinatesUndefined()) {
663
            return null; // Return null if there is no coordinate
664
        }
665
        else {
666
            if (getCoordinatesPanel().validVertexes()) {                                
667
                try {
668
                    return getCoordinatesPanel().getSurface();
669
                } catch (CreateGeometryException e) {
670
                    logger.error("Creating the area", e);
671
                    return null;
672
                }
673
            }
674
            else {
675
                return null; // Returns null if coordinates aren't valid
676
            }
677
        }
678
    }
679

    
680
    public void setArea(Geometry area){
681
        if ((area != null) && (area.getType() == TYPES.SURFACE)){
682
            getCoordinatesPanel().setSurface((Surface)area);
683
        }
684
    }
685

    
686
    /**
687
     * Set parent's 'Applicable' button enable or disable according the value of the parameter
688
     *
689
     * @param b A boolean value
690
     */
691
    private void setApplicable(boolean b) {
692
        IPanelGroup panelGroup = getPanelGroup();
693

    
694
        if (panelGroup == null)
695
            return;
696

    
697
        if (! ((WFSParamsPanel)panelGroup).getFilterPanel().getWFSFilterPanelIsAsTabForWFSLayersLoad())
698
            ((WFSParamsPanel)panelGroup).setApplicable(b);
699
        //                        parent.isApplicable(true);
700
    }
701

    
702
    /**
703
     * If there is some coordinate text field that has text, returns true; else returns false
704
     *
705
     * @return A boolean value
706
     */
707
    public boolean areThereSomeCoordinatesWritten() {
708
        return getCoordinatesPanel().areThereSomeCoordinatesWritten();
709
    }
710

    
711
    /**
712
     * If there is some coordinate text field that isn't undefined, returns true; else returns false
713
     *
714
     * @return A boolean value
715
     */
716
    public boolean areThereSomeCoordinatesUndefined() {
717
        return getCoordinatesPanel().isThereAnyCoordinateUndefined();
718
    }
719

    
720
    /**
721
     * If user has or hasn't defined an area
722
     *
723
     * @return A boolean value
724
     */
725
    public boolean hasUserDefinedAnArea() {
726
        return hasUserDefinedAnArea;
727
    }
728

    
729
    /**
730
     * Restores the inner attribute 'hasUserDefinedAnArea' to its default value (false)
731
     */
732
    public void setUserHasntDefineAnArea() {
733
        hasUserDefinedAnArea = false;
734
    }
735

    
736
    /**
737
     * Updates the current area information with the area of the active view
738
     */
739
    public void updateWFSArea() {
740
        this.getSelectableMapAreaPanel().disableAllMouseListeners();
741

    
742
        // To prevent that events that take place (are produced) could be a nuisance to the load of the layers
743
        this.getSelectableMapAreaPanel().getMapContext().beginAtomicEvent();
744

    
745
        try {
746
            MapContext mapContext = this.getSelectableMapAreaPanel().getMapContext();
747

    
748
            // Removes all layers in the view area
749
            int numberOfLayers = mapContext.getLayers().getLayersCount();
750
            int i;
751

    
752
            for (i = (numberOfLayers-1); i >= 0; i--) {
753
                mapContext.getLayers().removeLayer(i);
754
            }
755
            PluginServices.getMainFrame().enableControls();
756
            // Adds the extent of the viewport of the current active view
757
            AbstractViewPanel view = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
758
            ViewPort vP = view.getMapControl().getMapContext().getViewPort();
759

    
760
            // Update extent (we will use the adjusted extent because increases the usability)
761
            Envelope envelope = vP.getAdjustedExtent();
762
            //                        Rectangle2D r2D = vP.getExtent();
763

    
764
            if (envelope == null) {
765
                // End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
766
                this.getSelectableMapAreaPanel().getMapContext().endAtomicEvent();
767

    
768
                // No tools enabled
769
                getJComboBoxToolSelection().setSelectedIndex(0);
770

    
771
                return;
772
            }
773

    
774
            getCoordinatesPanel().updateCoordinates(envelope);
775
            mapContext.getViewPort().setEnvelope(envelope);
776

    
777
            // Adds the active layers of the current active view
778
            MapContext mC = view.getMapControl().getMapContext();
779

    
780
            numberOfLayers = mC.getLayers().getLayersCount();
781

    
782
            for (i = (numberOfLayers-1); i >= 0; i--) {
783
                FLayer clonedLayer = mC.getLayers().getLayer(i).cloneLayer();
784
                mapContext.getLayers().addLayer(clonedLayer);
785
                clonedLayer.dispose();
786
            }
787

    
788
            // If has to enable all listeners of all tools on the view area
789
            if (((ItemOperation)this.getJComboBoxToolSelection().getSelectedItem()).getOperation() == SELECTION_BY_AREA_OPERATION)
790
                this.getSelectableMapAreaPanel().enableAllMouseListeners();
791

    
792
            // End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
793
            this.getSelectableMapAreaPanel().getMapContext().endAtomicEvent();
794

    
795
            // Refresh the view
796
            this.getSelectableMapAreaPanel().getViewPort().refreshExtent();
797
        } catch (Exception e) {
798
            NotificationManager.addError(e);
799

    
800
            // End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
801
            this.getSelectableMapAreaPanel().getMapContext().endAtomicEvent();
802

    
803
            // No tools enabled
804
            getJComboBoxToolSelection().setSelectedIndex(0);
805
            return;
806
        }
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 {
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 JTextFieldWithSCP jTextFieldVertex1X = null;
898
        private JTextFieldWithSCP jTextFieldVertex1Y = null;
899
        private JTextFieldWithSCP jTextFieldVertex2X = null;
900
        private JTextFieldWithSCP 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 String previous_Coordinate_Value[];
908

    
909
        private short current_coordinate_with_focus;
910

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

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

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

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

    
940
            // By default no coordinates have changed
941
            this.resetCoordinatesFlags();
942

    
943
            GridBagConstraints gridBagConstraints = null;
944
            gridBagConstraints = new java.awt.GridBagConstraints();
945
            gridBagConstraints.gridx = 0;
946
            gridBagConstraints.gridy = 0;
947
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
948
            gridBagConstraints.weightx = 1.0;                                
949
            this.add(getJPanelVertex1(), gridBagConstraints);
950

    
951
            gridBagConstraints = new java.awt.GridBagConstraints();
952
            gridBagConstraints.gridx = 1;
953
            gridBagConstraints.gridy = 0;
954
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
955
            gridBagConstraints.weightx = 1.0;        
956
            this.add(getJPanelVertex2(), gridBagConstraints);
957

    
958
            gridBagConstraints = new java.awt.GridBagConstraints();
959
            gridBagConstraints.gridx = 2;
960
            gridBagConstraints.gridy = 0;
961
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
962
            gridBagConstraints.weightx = 1.0;        
963
            this.add(getJButtonValidateArea(), gridBagConstraints);
964
        }
965

    
966
        /**
967
         * Returns the default width of this component
968
         *
969
         * @return The default width
970
         */
971
        public int getDefaultWidth() {
972
            return DEFAULT_COORDINATE_WIDTH * 2;
973
        }
974

    
975
        /**
976
         * Returns the default height of this component
977
         *
978
         * @return The default height
979
         */
980
        public int getDefaultHeight() {
981
            return DEFAULT_COORDINATE_HEIGHT * 2;
982
        }
983

    
984
        /**
985
         * Sets all flags about if a coordinate has change to false (haven't changed)
986
         */
987
        private void resetCoordinatesFlags() {
988
            hasChanged_v1X = false;
989
            hasChanged_v1Y = false;
990
            hasChanged_v2X = false;
991
            hasChanged_v2Y = false;
992
        }
993

    
994
        /**last_Coordinated_that_Changed
995
         * This method initializes jPanelVertex1
996
         *
997
         * @return javax.swing.JPanel
998
         */
999
        private JPanel getJPanelVertex1() {
1000
            if (jPanelVertex1 == null) {
1001
                jPanelVertex1 = new JPanel();
1002
                jPanelVertex1.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT);
1003
                jPanelVertex1.setLayout(new GridBagLayout());
1004

    
1005
                GridBagConstraints gridBagConstraints = null;
1006
                gridBagConstraints = new java.awt.GridBagConstraints();
1007
                gridBagConstraints.gridx = 0;
1008
                gridBagConstraints.gridy = 0;
1009
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
1010
                gridBagConstraints.weightx = 1.0;                        
1011
                jPanelVertex1.add(getJLabelVertex1(), gridBagConstraints);
1012

    
1013
                gridBagConstraints = new java.awt.GridBagConstraints();
1014
                gridBagConstraints.gridx = 0;
1015
                gridBagConstraints.gridy = 1;
1016
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
1017
                gridBagConstraints.weightx = 1.0;
1018
                jPanelVertex1.add(getJPanelVertex1X(), gridBagConstraints);
1019

    
1020
                gridBagConstraints = new java.awt.GridBagConstraints();
1021
                gridBagConstraints.gridx = 0;
1022
                gridBagConstraints.gridy = 2;
1023
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
1024
                gridBagConstraints.weightx = 1.0;
1025
                jPanelVertex1.add(getJPanelVertex1Y(), gridBagConstraints);
1026
            }
1027

    
1028
            return jPanelVertex1;
1029
        }
1030

    
1031
        /**
1032
         * This method initializes jPanelVertex2
1033
         *
1034
         * @return javax.swing.JPanel
1035
         */
1036
        private JPanel getJPanelVertex2() {
1037
            if (jPanelVertex2 == null) {
1038
                jPanelVertex2 = new JPanel();
1039
                jPanelVertex2.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION + DEFAULT_COORDINATE_HEIGHT, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT);
1040
                jPanelVertex2.setLayout(new GridBagLayout());
1041

    
1042
                GridBagConstraints gridBagConstraints = null;
1043
                gridBagConstraints = new java.awt.GridBagConstraints();
1044
                gridBagConstraints.gridx = 0;
1045
                gridBagConstraints.gridy = 0;
1046
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
1047
                gridBagConstraints.weightx = 1.0;                        
1048
                jPanelVertex2.add(getJLabelVertex2(), gridBagConstraints);
1049

    
1050
                gridBagConstraints = new java.awt.GridBagConstraints();
1051
                gridBagConstraints.gridx = 0;
1052
                gridBagConstraints.gridy = 1;
1053
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
1054
                gridBagConstraints.weightx = 1.0;                                                
1055
                jPanelVertex2.add(getJPanelVertex2X(), gridBagConstraints);
1056

    
1057
                gridBagConstraints = new java.awt.GridBagConstraints();
1058
                gridBagConstraints.gridx = 0;
1059
                gridBagConstraints.gridy = 2;
1060
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
1061
                gridBagConstraints.weightx = 1.0;                        
1062
                jPanelVertex2.add(getJPanelVertex2Y(), gridBagConstraints);
1063
            }
1064

    
1065
            return jPanelVertex2;
1066
        }
1067

    
1068
        /**
1069
         * This method initializes jLabelVertex1
1070
         *
1071
         * @return javax.swing.JPanel
1072
         */
1073
        private JLabel getJLabelVertex1() {
1074
            if (jLabelVertex1 == null) {
1075
                jLabelVertex1 = new JLabel();
1076
                jLabelVertex1.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION);
1077
                jLabelVertex1.setToolTipText(PluginServices.getText(this, "coordinates_from_area_right_up_vertex"));
1078
                jLabelVertex1.setText(PluginServices.getText(this, "vertex") + " 1:");
1079
                jLabelVertex1.setHorizontalAlignment(SwingConstants.LEFT);
1080
                jLabelVertex1.setVerticalAlignment(SwingConstants.CENTER);
1081
                jLabelVertex1.setForeground(new Color(0, 0, 255)); // Blue color for text
1082
            }
1083
            return jLabelVertex1;
1084
        }
1085

    
1086
        /**
1087
         * This method initializes jLabelVertex2
1088
         *
1089
         * @return javax.swing.JPanel
1090
         */
1091
        private JLabel getJLabelVertex2() {
1092
            if (jLabelVertex2 == null) {
1093
                jLabelVertex2 = new JLabel();
1094
                jLabelVertex2.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION);
1095
                jLabelVertex2.setToolTipText(PluginServices.getText(this, "coordinates_from_area_left_bottom_vertex"));
1096
                jLabelVertex2.setText(PluginServices.getText(this, "vertex") + " 2:");
1097
                jLabelVertex2.setHorizontalAlignment(SwingConstants.LEFT);
1098
                jLabelVertex2.setVerticalAlignment(SwingConstants.CENTER);
1099
                jLabelVertex2.setForeground(new Color(128, 64, 0)); // Brown color for text
1100
            }
1101
            return jLabelVertex2;
1102
        }
1103

    
1104
        /**
1105
         * This method initializes jPanelVertex1X
1106
         *
1107
         * @return javax.swing.JPanel
1108
         */
1109
        private JPanel getJPanelVertex1X() {
1110
            if (jPanelVertex1X == null) {
1111
                jPanelVertex1X = new JPanel();
1112
                jPanelVertex1X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1113
                jPanelVertex1X.setLayout(new GridBagLayout());
1114
                jPanelVertex1X.add(getJLabelVertex1X(), null);
1115
                jPanelVertex1X.add(getJTextFieldVertex1X(), null);
1116
            }
1117
            return jPanelVertex1X;
1118
        }
1119

    
1120
        /**
1121
         * This method initializes jPanelVertex1Y
1122
         *
1123
         * @return javax.swing.JPanel
1124
         */
1125
        private JPanel getJPanelVertex1Y() {
1126
            if (jPanelVertex1Y == null) {
1127
                jPanelVertex1Y = new JPanel();
1128
                jPanelVertex1Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1129
                jPanelVertex1Y.setLayout(new GridBagLayout());
1130
                jPanelVertex1Y.add(getJLabelVertex1Y(), null);
1131
                jPanelVertex1Y.add(getJTextFieldVertex1Y(), null);
1132
            }
1133
            return jPanelVertex1Y;
1134
        }
1135

    
1136
        /**
1137
         * This method initializes jPanelVertex2X
1138
         *
1139
         * @return javax.swing.JPanel
1140
         */
1141
        private JPanel getJPanelVertex2X() {
1142
            if (jPanelVertex2X == null) {
1143
                jPanelVertex2X = new JPanel();
1144
                jPanelVertex2X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1145
                jPanelVertex2X.setLayout(new GridBagLayout());
1146
                jPanelVertex2X.add(getJLabelVertex2X(), null);
1147
                jPanelVertex2X.add(getJTextFieldVertex2X(), null);
1148
            }
1149
            return jPanelVertex2X;
1150
        }
1151

    
1152
        /**
1153
         * This method initializes jPanelVertex2Y
1154
         *
1155
         * @return javax.swing.JPanel
1156
         */
1157
        private JPanel getJPanelVertex2Y() {
1158
            if (jPanelVertex2Y == null) {
1159
                jPanelVertex2Y = new JPanel();
1160
                jPanelVertex2Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT)));
1161
                jPanelVertex2Y.setLayout(new GridBagLayout());
1162
                jPanelVertex2Y.add(getJLabelVertex2Y(), null);
1163
                jPanelVertex2Y.add(getJTextFieldVertex2Y(), null);
1164
            }
1165
            return jPanelVertex2Y;
1166
        }
1167

    
1168
        /**
1169
         * This method initializes jLabelVertex1X
1170
         *
1171
         * @return  javax.swing.JLabel
1172
         */
1173
        private JLabel getJLabelVertex1X() {
1174
            if (jLabelVertex1X == null) {
1175
                jLabelVertex1X = new JLabel();
1176
                jLabelVertex1X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1177
                jLabelVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1178
                jLabelVertex1X.setText(PluginServices.getText(this, "x") + ":");
1179
                jLabelVertex1X.setHorizontalAlignment(SwingConstants.CENTER);
1180
                jLabelVertex1X.setVerticalAlignment(SwingConstants.CENTER);
1181
                jLabelVertex1X.setForeground(new Color(0, 0, 255)); // Blue color for text
1182
            }
1183
            return jLabelVertex1X;
1184
        }
1185

    
1186
        /**
1187
         * This method initializes jLabelVertex2X
1188
         *
1189
         * @return  javax.swing.JLabel
1190
         */
1191
        private JLabel getJLabelVertex2X() {
1192
            if (jLabelVertex2X == null) {
1193
                jLabelVertex2X = new JLabel();
1194
                jLabelVertex2X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1195
                jLabelVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1196
                jLabelVertex2X.setText(PluginServices.getText(this, "x") + ":");
1197
                jLabelVertex2X.setHorizontalAlignment(SwingConstants.CENTER);
1198
                jLabelVertex2X.setVerticalAlignment(SwingConstants.CENTER);
1199
                jLabelVertex2X.setForeground(new Color(128, 64, 0)); // Brown color for text
1200
            }
1201
            return jLabelVertex2X;
1202
        }
1203

    
1204
        /**
1205
         * This method initializes jLabelVertex1Y
1206
         *
1207
         * @return  javax.swing.JLabel
1208
         */
1209
        private JLabel getJLabelVertex1Y() {
1210
            if (jLabelVertex1Y == null) {
1211
                jLabelVertex1Y = new JLabel();
1212
                jLabelVertex1Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1213
                jLabelVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1214
                jLabelVertex1Y.setText(PluginServices.getText(this, "y") + ":");
1215
                jLabelVertex1Y.setHorizontalAlignment(SwingConstants.CENTER);
1216
                jLabelVertex1Y.setVerticalAlignment(SwingConstants.CENTER);
1217
                jLabelVertex1Y.setForeground(new Color(0, 0, 255)); // Blue color for text
1218
            }
1219
            return jLabelVertex1Y;
1220
        }
1221

    
1222
        /**
1223
         * This method initializes jLabelVertex2Y
1224
         *
1225
         * @return  javax.swing.JLabel
1226
         */
1227
        private JLabel getJLabelVertex2Y() {
1228
            if (jLabelVertex2Y == null) {
1229
                jLabelVertex2Y = new JLabel();
1230
                jLabelVertex2Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1231
                jLabelVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1232
                jLabelVertex2Y.setText(PluginServices.getText(this, "y") + ":");
1233
                jLabelVertex2Y.setHorizontalAlignment(SwingConstants.CENTER);
1234
                jLabelVertex2Y.setVerticalAlignment(SwingConstants.CENTER);
1235
                jLabelVertex2Y.setForeground(new Color(128, 64, 0)); // Brown color for text
1236
            }
1237
            return jLabelVertex2Y;
1238
        }
1239

    
1240
        /**
1241
         * Returns a focus listener for validate the text of a JTextField when that component loses its focus
1242
         *
1243
         * @return java.awt.event.FocusListener
1244
         */
1245
        private FocusListener getFocusListenerForCoordinateValidation() {
1246
            if (focusListenerForCoordinateValidation == null) {
1247
                focusListenerForCoordinateValidation = new FocusListener() {
1248
                    public void focusGained(FocusEvent e) {
1249
                        JTextField jTF = (JTextField)e.getSource();
1250

    
1251
                        // Stores which coordinate has gotten the focus
1252
                        if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1253
                            current_coordinate_with_focus = JTEXTFIELD_V1X;
1254
                            return;
1255
                        }
1256

    
1257
                        if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1258
                            current_coordinate_with_focus = JTEXTFIELD_V1Y;
1259
                            return;
1260
                        }
1261

    
1262
                        if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1263
                            current_coordinate_with_focus = JTEXTFIELD_V2X;
1264
                            return;
1265
                        }
1266

    
1267
                        if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1268
                            current_coordinate_with_focus = JTEXTFIELD_V2Y;
1269
                            return;
1270
                        }
1271
                    }
1272

    
1273
                    public void focusLost(FocusEvent e) {
1274
                        if (!getEnablingJCheckBox().isSelected())
1275
                            return;
1276

    
1277
                        JTextField jTF = (JTextField)e.getSource();
1278

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

    
1282
                        if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1283

    
1284
                            if (text.compareTo(last_Coordinates[0]) != 0) {
1285
                                hasChanged_v1X = true;
1286
                                hasUserDefinedAnArea = true;
1287
                            }
1288

    
1289
                            return;
1290
                        }
1291

    
1292
                        if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1293
                            if (text.compareTo(last_Coordinates[1]) != 0) {
1294
                                hasChanged_v1Y = true;
1295
                                hasUserDefinedAnArea = true;
1296
                            }
1297
                            return;
1298
                        }
1299

    
1300
                        if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1301
                            if (text.compareTo(last_Coordinates[2]) != 0) {
1302
                                hasChanged_v2X = true;
1303
                                hasUserDefinedAnArea = true;
1304
                            }
1305
                            return;
1306
                        }
1307

    
1308
                        if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1309
                            if (text.compareTo(last_Coordinates[3]) != 0) {
1310
                                hasChanged_v2Y = true;
1311
                                hasUserDefinedAnArea = true;
1312
                            }
1313
                            return;
1314
                        }
1315
                    }
1316
                };
1317
            }
1318

    
1319
            return focusListenerForCoordinateValidation;
1320
        }
1321

    
1322
        private KeyListener getKeyListenerForCoordinateValidation() {
1323
            if (keyListenerForCoordinateValidation == null) {
1324
                keyListenerForCoordinateValidation = new KeyListener() {
1325

    
1326
                    public void keyPressed(KeyEvent e) {
1327
                    }
1328

    
1329
                    public void keyReleased(KeyEvent e) {
1330
                        validateCoordinate(current_coordinate_with_focus);
1331
                    }
1332

    
1333
                    public void keyTyped(KeyEvent e) {
1334
                    }
1335
                };
1336
            }
1337

    
1338
            return keyListenerForCoordinateValidation;
1339
        }
1340

    
1341
        /**
1342
         * This method initializes jTextFieldVertex1X
1343
         *
1344
         * @return JTextFieldWithSCP
1345
         */
1346
        private JTextFieldWithSCP getJTextFieldVertex1X() {
1347
            if (jTextFieldVertex1X == null) {
1348
                jTextFieldVertex1X = new JTextFieldWithSCP("");
1349
                jTextFieldVertex1X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1350
                jTextFieldVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1351
                jTextFieldVertex1X.addFocusListener(getFocusListenerForCoordinateValidation());
1352
                jTextFieldVertex1X.addKeyListener(getKeyListenerForCoordinateValidation());
1353
                jTextFieldVertex1X.setName(JTEXTFIELD_V1X_NAME);
1354
            }
1355
            return jTextFieldVertex1X;
1356
        }
1357

    
1358
        /**
1359
         * This method initializes jTextFieldVertex1Y
1360
         *
1361
         * @return JTextFieldWithSCP
1362
         */
1363
        private JTextFieldWithSCP getJTextFieldVertex1Y() {
1364
            if (jTextFieldVertex1Y == null) {
1365
                jTextFieldVertex1Y = new JTextFieldWithSCP("");
1366
                jTextFieldVertex1Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1367
                jTextFieldVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1368
                jTextFieldVertex1Y.addFocusListener(getFocusListenerForCoordinateValidation());
1369
                jTextFieldVertex1Y.addKeyListener(getKeyListenerForCoordinateValidation());
1370
                jTextFieldVertex1Y.setName(JTEXTFIELD_V1Y_NAME);
1371
            }
1372
            return jTextFieldVertex1Y;
1373
        }
1374

    
1375
        /**
1376
         * This method initializes jTextFieldVertex2X
1377
         *
1378
         * @return JTextFieldWithSCP
1379
         */
1380
        private JTextFieldWithSCP getJTextFieldVertex2X() {
1381
            if (jTextFieldVertex2X == null) {
1382
                jTextFieldVertex2X = new JTextFieldWithSCP("");
1383
                jTextFieldVertex2X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1384
                jTextFieldVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1385
                jTextFieldVertex2X.addFocusListener(getFocusListenerForCoordinateValidation());
1386
                jTextFieldVertex2X.addKeyListener(getKeyListenerForCoordinateValidation());
1387
                jTextFieldVertex2X.setName(JTEXTFIELD_V2X_NAME);
1388
            }
1389
            return jTextFieldVertex2X;
1390
        }
1391

    
1392
        /**
1393
         * This method initializes jTextFieldVertex2Y
1394
         *
1395
         * @return JTextFieldWithSCP
1396
         */
1397
        private JTextFieldWithSCP getJTextFieldVertex2Y() {
1398
            if (jTextFieldVertex2Y == null) {
1399
                jTextFieldVertex2Y = new JTextFieldWithSCP("");
1400
                jTextFieldVertex2Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1401
                jTextFieldVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1402
                jTextFieldVertex2Y.addFocusListener(getFocusListenerForCoordinateValidation());
1403
                jTextFieldVertex2Y.addKeyListener(getKeyListenerForCoordinateValidation());
1404
                jTextFieldVertex2Y.setName(JTEXTFIELD_V2Y_NAME);
1405
            }
1406
            return jTextFieldVertex2Y;
1407
        }
1408

    
1409
        /**
1410
         * Returns the double value of the text field V1X
1411
         *
1412
         * @return A double number type
1413
         */
1414
        public double getDoubleValueOfJTextFieldV1X() {
1415
            return Double.parseDouble(getJTextFieldVertex1X().getText());
1416
        }
1417

    
1418
        /**
1419
         * Returns the double value of the text field V1Y
1420
         *
1421
         * @return A double number type
1422
         */
1423
        public double getDoubleValueOfJTextFieldV1Y() {
1424
            return Double.parseDouble(getJTextFieldVertex1Y().getText());
1425
        }
1426

    
1427
        /**
1428
         * Returns the double value of the text field V2X
1429
         *
1430
         * @return A double number type
1431
         */
1432
        public double getDoubleValueOfJTextFieldV2X() {
1433
            return Double.parseDouble(getJTextFieldVertex2X().getText());
1434
        }
1435

    
1436
        /**
1437
         * Returns the double value of the text field V2Y
1438
         *
1439
         * @return A double number type
1440
         */
1441
        public double getDoubleValueOfJTextFieldV2Y() {
1442
            return Double.parseDouble(getJTextFieldVertex2Y().getText());
1443
        }
1444

    
1445
        /**
1446
         * Retuns the double value of the last text field V1X value
1447
         *
1448
         * @return A double number type
1449
         */
1450
        public double getDoubleValueOfLastJTextFieldV1XValue() {
1451
            return Double.parseDouble(last_Coordinates[0]);
1452
        }
1453

    
1454
        /**
1455
         * Retuns the double value of the last text field V1Y value
1456
         *
1457
         * @return A double number type
1458
         */
1459
        public double getDoubleValueOfLastJTextFieldV1YValue() {
1460
            return Double.parseDouble(last_Coordinates[1]);
1461
        }
1462

    
1463
        /**
1464
         * Retuns the double value of the last text field V2X value
1465
         *
1466
         * @return A double number type
1467
         */
1468
        public double getDoubleValueOfLastJTextFieldV2XValue() {
1469
            return Double.parseDouble(last_Coordinates[2]);
1470
        }
1471

    
1472
        /**
1473
         * Retuns the double value of the last text field V2Y value
1474
         *
1475
         * @return A double number type
1476
         */
1477
        public double getDoubleValueOfLastJTextFieldV2YValue() {
1478
            return Double.parseDouble(last_Coordinates[3]);
1479
        }
1480

    
1481
        /**
1482
         * Validates the coordinate of a JTextField: returns true if it's valid; else returns false
1483
         *
1484
         * @param coordinate javax.swing.JTextField
1485
         * @return A boolean value
1486
         */
1487
        private boolean validateCoordinate(JTextField coordinate) {
1488
            if (coordinate != null) {
1489
                // If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text
1490
                if ((coordinate.getText().compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(coordinate.getText()))) {
1491
   
1492
                    return false;
1493
                }
1494
                else {
1495
                    return true;
1496
                }
1497
            }
1498

    
1499
            return false; // If coordinate is null
1500
        }
1501

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

    
1512
            switch (coordinate_ID) {
1513
            case JTEXTFIELD_V1X:
1514
                coordinate = getJTextFieldVertex1X();
1515
                text = coordinate.getText();
1516

    
1517
                if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1518
                    JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1519
                    coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1520
                    return false;
1521
                }
1522
                else {
1523
                    previous_Coordinate_Value[0] = text;
1524
                    return true;
1525
                }
1526
            case JTEXTFIELD_V1Y:
1527
                coordinate = getJTextFieldVertex1Y();
1528
                text = coordinate.getText();
1529

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

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

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

    
1570
        /**
1571
         * This method initializes jButtonPreviewArea
1572
         *
1573
         * @return javax.swing.JButton
1574
         */
1575
        private JButton getJButtonValidateArea() {
1576
            if (jButtonPreviewArea == null) {
1577
                jButtonPreviewArea = new JButton();
1578
                jButtonPreviewArea.setBounds(DEFAULT_JBUTTON_GO_TO_AREA_RECTANGLE);
1579
                //                                jButtonPreviewArea.setToolTipText(PluginServices.getText(this, "to_previsualize"));
1580
                jButtonPreviewArea.setToolTipText(PluginServices.getText(this, "to_validate_coodinates"));
1581
                jButtonPreviewArea.setVerticalTextPosition(AbstractButton.CENTER);
1582
                jButtonPreviewArea.setHorizontalTextPosition(AbstractButton.CENTER);
1583
                jButtonPreviewArea.setIcon(PluginServices.getIconTheme().get("validate-area"));
1584
                jButtonPreviewArea.addMouseListener(new MouseAdapter() {
1585
                    public void mouseClicked(MouseEvent e) {
1586
                        validVertexes();
1587
                    }                                        
1588
                });
1589
            }
1590
            return jButtonPreviewArea;
1591
        }
1592

    
1593
        /**
1594
         * Calculates the new rectangle using the coordinates of the text fields
1595
         *
1596
         * @return java.awt.geom.Rectangle2D
1597
         */
1598
        private Rectangle2D getNewRectangleByCoordinates() {
1599
            return new Rectangle2D.Double(getDoubleValueOfJTextFieldV2X(), getDoubleValueOfJTextFieldV2Y(), getDoubleValueOfJTextFieldV1X() - getDoubleValueOfJTextFieldV2X(), getDoubleValueOfJTextFieldV1Y() - getDoubleValueOfJTextFieldV2Y());
1600
        }
1601

    
1602
        /**
1603
         * Restores the value of all text fields with coordinates modified to their last value
1604
         */
1605
        private void restoreAllModifiedCoordinates() {
1606
            if (hasChanged_v1X) {
1607
                getJTextFieldVertex1X().setText(last_Coordinates[0]);
1608
                hasChanged_v1X = false;
1609
            }
1610

    
1611
            if (hasChanged_v1Y) {
1612
                getJTextFieldVertex1Y().setText(last_Coordinates[1]);
1613
                hasChanged_v1Y = false;
1614
            }
1615

    
1616
            if (hasChanged_v2X) {
1617
                getJTextFieldVertex2X().setText(last_Coordinates[2]);
1618
                hasChanged_v2X = false;
1619
            }
1620

    
1621
            if (hasChanged_v2Y) {
1622
                getJTextFieldVertex2Y().setText(last_Coordinates[3]);
1623
                hasChanged_v2Y = false;
1624
            }
1625
        }
1626

    
1627
        /**
1628
         * Enables or disables all inner JTextField
1629
         *
1630
         * @param b A boolean value
1631
         */
1632
        public void setAllTextFieldsEnabled(boolean b) {
1633
            getJTextFieldVertex1X().setEnabled(b);
1634
            getJTextFieldVertex1Y().setEnabled(b);
1635
            getJTextFieldVertex2X().setEnabled(b);
1636
            getJTextFieldVertex2Y().setEnabled(b);
1637
        }
1638

    
1639
        /**
1640
         * Sets the extent into the text fields
1641
         *
1642
         * @param envelope java.awt.geom.Rectangle2D
1643
         */
1644
        public void updateCoordinates(Envelope envelope){
1645
            getJTextFieldVertex1X().setText(String.valueOf(envelope.getMaximum(0)));
1646
            last_Coordinates[0] = getJTextFieldVertex1X().getText();
1647
            previous_Coordinate_Value[0] = last_Coordinates[0];
1648

    
1649
            getJTextFieldVertex1Y().setText(String.valueOf(envelope.getMaximum(1)));
1650
            last_Coordinates[1] = getJTextFieldVertex1Y().getText();
1651
            previous_Coordinate_Value[1] = last_Coordinates[1];
1652

    
1653
            getJTextFieldVertex2X().setText(String.valueOf(envelope.getMinimum(0)));
1654
            last_Coordinates[2] = getJTextFieldVertex2X().getText();
1655
            previous_Coordinate_Value[2] = last_Coordinates[2];
1656

    
1657
            getJTextFieldVertex2Y().setText(String.valueOf(envelope.getMinimum(0)));
1658
            last_Coordinates[3] = getJTextFieldVertex2Y().getText();
1659
            previous_Coordinate_Value[3] = last_Coordinates[3];
1660

    
1661
            resetCoordinatesFlags();
1662
        }
1663

    
1664
        /**
1665
         * Changes the color of all coordinates text fields to <code>c</code>.
1666
         *
1667
         * @param c the new background color
1668
         */
1669
        private void setBackGroundColorToCoordinatesFields(Color c) {
1670
            getJTextFieldVertex1X().setBackground(c);
1671
            getJTextFieldVertex1Y().setBackground(c);
1672
            getJTextFieldVertex2X().setBackground(c);
1673
            getJTextFieldVertex2Y().setBackground(c);
1674
        }
1675

    
1676
        /**
1677
         * Validates all coordinates of both vertexes separately
1678
         *
1679
         * @return A ValidationInfo object reference
1680
         */
1681
        private ValidationInfo validVertexesCoordinates() {
1682
            String infoPrefix = null, infoSufix = null;
1683

    
1684
            if (! validateCoordinate(getJTextFieldVertex1X())) {
1685
                if (infoSufix == null) {
1686
                    infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": ";
1687
                    infoSufix = PluginServices.getText(this, "v1x");
1688
                }
1689
                getJTextFieldVertex1X().setBackground(Color.RED);
1690
            }
1691

    
1692
            if (! validateCoordinate(getJTextFieldVertex1Y())) {
1693
                if (infoSufix == null) {
1694
                    infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": ";
1695
                    infoSufix = PluginServices.getText(this, "v1y");
1696
                }
1697
                else {
1698
                    infoPrefix = PluginServices.getText(this, "invalid_coordinates") + ": ";
1699
                    infoSufix += ", " + PluginServices.getText(this, "v1y");
1700
                }
1701

    
1702
                getJTextFieldVertex1Y().setBackground(Color.RED);
1703
            }
1704

    
1705
            if (! validateCoordinate(getJTextFieldVertex2X())) {
1706
                if (infoSufix == null) {
1707
                    infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": ";
1708
                    infoSufix = PluginServices.getText(this, "v2x");
1709
                }
1710
                else {
1711
                    infoPrefix = PluginServices.getText(this, "invalid_coordinates") + ": ";
1712
                    infoSufix += ", " + PluginServices.getText(this, "v2x");
1713
                }
1714

    
1715
                getJTextFieldVertex2X().setBackground(Color.RED);
1716
            }
1717

    
1718
            if (! validateCoordinate(getJTextFieldVertex2Y())) {
1719
                if (infoSufix == null) {
1720
                    infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": ";
1721
                    infoSufix = PluginServices.getText(this, "v2y");
1722
                }
1723
                else {
1724
                    infoPrefix = PluginServices.getText(this, "invalid_coordinates") + ": ";
1725
                    infoSufix += ", " + PluginServices.getText(this, "v2y");
1726
                }
1727

    
1728
                getJTextFieldVertex2Y().setBackground(Color.RED);
1729
            }
1730

    
1731
            if (infoPrefix != null)
1732
                return new ValidationInfo(false, infoPrefix + infoSufix);
1733

    
1734
            // If arrives here, all coordinates are valid
1735
            setBackGroundColorToCoordinatesFields(Color.GREEN);
1736
            return new ValidationInfo(true, "");
1737
        }
1738

    
1739
        /**
1740
         * Validates that Vertex1 is in the right-up corner and the Vertex2 in the left-down corner of the area/rectangle <br>
1741
         * (It's supposed that coordinates of the vertexes are valid) <br>
1742
         * (It's supposed that going to right or up, the coordinate value increases)
1743
         *
1744
         * @return A ValidationInfo object reference
1745
         */
1746
        private ValidationInfo validVertexesPositions() {
1747
            String infoPrefix = null, infoSufix = null;
1748

    
1749
            // Check if no coordinate it's defined
1750
            if (getJTextFieldVertex1X().getText().compareTo("") == 0) {
1751
                if (infoSufix == null) {
1752
                    infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": ";
1753
                    infoSufix = PluginServices.getText(this, "v1x");
1754
                }
1755

    
1756
                getJTextFieldVertex1X().setBackground(Color.RED);
1757
            }
1758

    
1759
            if (getJTextFieldVertex1Y().getText().compareTo("") == 0) {
1760
                if (infoSufix == null) {
1761
                    infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": ";
1762
                    infoSufix = PluginServices.getText(this, "v1y");
1763
                }
1764
                else {
1765
                    infoPrefix = PluginServices.getText(this, "undefined_coordinates") + ": ";
1766
                    infoSufix += ", " + PluginServices.getText(this, "v1y");
1767
                }
1768

    
1769
                getJTextFieldVertex1Y().setBackground(Color.RED);
1770
                //                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v1y"));
1771
            }
1772

    
1773
            if (getJTextFieldVertex2X().getText().compareTo("") == 0) {
1774
                if (infoSufix == null) {
1775
                    infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": ";
1776
                    infoSufix = PluginServices.getText(this, "v2x");
1777
                }
1778
                else {
1779
                    infoPrefix = PluginServices.getText(this, "undefined_coordinates") + ": ";
1780
                    infoSufix += ", " + PluginServices.getText(this, "v2x");
1781
                }
1782

    
1783
                getJTextFieldVertex2X().setBackground(Color.RED);
1784
                //                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v2x"));
1785
            }
1786

    
1787
            if (getJTextFieldVertex2Y().getText().compareTo("") == 0) {
1788
                if (infoSufix == null) {
1789
                    infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": ";
1790
                    infoSufix = PluginServices.getText(this, "v2y");
1791
                }
1792
                else {
1793
                    infoPrefix = PluginServices.getText(this, "undefined_coordinates") + ": ";
1794
                    infoSufix += ", " + PluginServices.getText(this, "v2y");
1795
                }
1796

    
1797
                getJTextFieldVertex2Y().setBackground(Color.RED);
1798
                //                                return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v2y"));
1799
            }
1800

    
1801
            if (infoPrefix != null)
1802
                return new ValidationInfo(false, infoPrefix + infoSufix);
1803

    
1804
            // Check if the vertex V1 is in the right-up corner and the vertex V2 is in the left-down corner
1805
            if (getDoubleValueOfJTextFieldV1X() < getDoubleValueOfJTextFieldV2X()) {
1806
                getJTextFieldVertex1X().setBackground(Color.RED);
1807
                getJTextFieldVertex2X().setBackground(Color.RED);
1808
                return new ValidationInfo(false, PluginServices.getText(this, "v1x") + " < " + PluginServices.getText(this, "v2x"));
1809
            }
1810

    
1811
            if (getDoubleValueOfJTextFieldV1Y() < getDoubleValueOfJTextFieldV2Y()) {
1812
                getJTextFieldVertex1Y().setBackground(Color.RED);
1813
                getJTextFieldVertex2Y().setBackground(Color.RED);
1814
                return new ValidationInfo(false, PluginServices.getText(this, "v1y") + " < " + PluginServices.getText(this, "v2y"));
1815
            }
1816

    
1817
            // If arrives here -> vertexes positions are valid
1818
            setBackGroundColorToCoordinatesFields(Color.GREEN);
1819
            return new ValidationInfo(true, "");
1820
        }
1821

    
1822
        /**
1823
         * Validate each coordinate of each vertex and the position of the vertexes
1824
         *
1825
         * @return A boolean value
1826
         */
1827
        public boolean validVertexes() {
1828
            ValidationInfo v1 = validVertexesCoordinates();
1829

    
1830
            if (!v1.isValid()) {
1831

    
1832
                // Notify to user that no filter area will be applied
1833
                JOptionPane.showMessageDialog(null, PluginServices.getText(null, PluginServices.getText(this, "invalid_coordinates") + ": " + v1.getMessage()), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
1834

    
1835
                // Restore the previous valid extent
1836
                if (previousExtentValids.hasPrevious()) {
1837
                    Rectangle2D previousExtent = previousExtentValids.removePrev();
1838
                    setCoordinates(previousExtent);
1839

    
1840
                    if (!previousExtentValids.hasPrevious()) {
1841
                        hasUserDefinedAnArea = false;
1842
                        setApplicable(false);
1843
                    }
1844

    
1845
                    previousExtentValids.put(previousExtent);
1846
                }
1847

    
1848
                return false;
1849
            }
1850
            else {
1851
                ValidationInfo v2 = validVertexesPositions();
1852
                if (!v2.isValid()) {
1853
                    //                                        setApplicable(false);
1854

    
1855
                    // Notify to user that no filter area will be applied
1856
                    JOptionPane.showMessageDialog(null, PluginServices.getText(null, PluginServices.getText(this, "invalid_coordinates") + ": " + v2.getMessage()), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE);
1857

    
1858
                    // Restore the previous valid extent
1859
                    if (previousExtentValids.hasPrevious()) {
1860
                        Rectangle2D previousExtent = previousExtentValids.removePrev();
1861
                        setCoordinates(previousExtent);
1862

    
1863
                        if (!previousExtentValids.hasPrevious()) {
1864
                            hasUserDefinedAnArea = false;
1865
                            setApplicable(false);
1866
                        }
1867

    
1868
                        previousExtentValids.put(previousExtent);
1869
                    }
1870

    
1871
                    return false;
1872
                }
1873
                else {
1874
                    // Once has been validated -> allow apply with the new extent, and save it
1875
                    if (previousExtentValids.hasPrevious()) {
1876
                        Rectangle2D previousExtent = previousExtentValids.removePrev();
1877
                        if (! areEqual(previousExtent, getExtent())) {
1878
                            previousExtentValids.put(previousExtent);
1879
                            previousExtentValids.put(getExtent());
1880
                            setApplicable(true);
1881
                        }
1882
                        else {
1883
                            previousExtentValids.put(previousExtent);
1884
                        }
1885
                    }
1886
                    else {
1887
                        previousExtentValids.put(getExtent());
1888
                        setApplicable(true);
1889
                    }
1890

    
1891
                    return true;
1892
                }
1893
            }
1894
        }
1895

    
1896
        /**
1897
         * <p>Compares two bi-dimensional rectangles, and returns <code>true</code> if both are equals.</p>
1898
         *
1899
         * @param rect1 first rectangle 2D to compare
1900
         * @param rect2 second rectangle 2D to compare
1901
         *
1902
         * @return <code>true</code> if both are equals; otherwise <code>false</code>
1903
         */
1904
        private boolean areEqual(Rectangle2D rect1, Rectangle2D rect2) {
1905
            return ((rect1.getX() == rect2.getX()) && (rect1.getY() == rect2.getY()) &&
1906
                (rect1.getWidth() == rect2.getWidth()) && (rect1.getHeight() == rect2.getHeight()));
1907
        }
1908

    
1909
        /**
1910
         * Gets the extent (rectangle) represented by the values of the coordinate text fields
1911
         *
1912
         * @return java.awt.geom.Rectangle2D
1913
         */
1914
        public Rectangle2D getExtent() {
1915
            double v1x = getDoubleValueOfJTextFieldV1X();
1916
            double v1y = getDoubleValueOfJTextFieldV1Y();
1917
            double v2x = getDoubleValueOfJTextFieldV2X();
1918
            double v2y = getDoubleValueOfJTextFieldV2Y();
1919

    
1920
            return new Rectangle2D.Double(v2x, v2y, (v1x - v2x), (v1y  - v2y));
1921
        }
1922

    
1923
        public Surface getSurface() throws CreateGeometryException {
1924
            double v1x = getDoubleValueOfJTextFieldV1X();
1925
            double v1y = getDoubleValueOfJTextFieldV1Y();
1926
            double v2x = getDoubleValueOfJTextFieldV2X();
1927
            double v2y = getDoubleValueOfJTextFieldV2Y();   
1928

    
1929
            Surface surface = (Surface)geometryManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);              
1930
            surface.addMoveToVertex(geometryManager.createPoint(v1x, v1y, SUBTYPES.GEOM2D));
1931
            surface.addVertex(geometryManager.createPoint(v1x, v2y, SUBTYPES.GEOM2D));
1932
            surface.addVertex(geometryManager.createPoint(v2x, v2y, SUBTYPES.GEOM2D));
1933
            surface.addVertex(geometryManager.createPoint(v2x, v1y, SUBTYPES.GEOM2D));            
1934
            surface.closePrimitive();
1935

    
1936
            return surface;
1937
        }
1938

    
1939
        public void setSurface(Surface surface){
1940
            getJTextFieldVertex1X().setText(String.valueOf(surface.getVertex(0).getX()));
1941
            getJTextFieldVertex1Y().setText(String.valueOf(surface.getVertex(0).getY()));
1942
            getJTextFieldVertex2X().setText(String.valueOf(surface.getVertex(2).getX()));
1943
            getJTextFieldVertex2Y().setText(String.valueOf(surface.getVertex(2).getY()));
1944
        }
1945

    
1946
        /**
1947
         * Returns true if there is some coordinate text field with data; else returns false
1948
         *
1949
         * @return A boolean value
1950
         */
1951
        public boolean areThereSomeCoordinatesWritten() {
1952
            return ((getJTextFieldVertex1X().getText().compareTo("") != 0) | (getJTextFieldVertex1Y().getText().compareTo("") != 0) | (getJTextFieldVertex2X().getText().compareTo("") != 0) | (getJTextFieldVertex2Y().getText().compareTo("") != 0));
1953
        }
1954

    
1955
        /**
1956
         * Returns true if all coordinate text fields are undefined (without values)
1957
         *
1958
         * @return A boolean value
1959
         */
1960
        public boolean areAllCoordinatesUndefined() {
1961
            return ((getJTextFieldVertex1X().getText().compareTo("") == 0) & (getJTextFieldVertex1Y().getText().compareTo("") == 0) & (getJTextFieldVertex2X().getText().compareTo("") == 0) & (getJTextFieldVertex2Y().getText().compareTo("") == 0));
1962
        }
1963

    
1964

    
1965
        /**
1966
         * Returns true if there is some coordinate undefined (without values)
1967
         *
1968
         * @return A boolean value
1969
         */
1970
        public boolean isThereAnyCoordinateUndefined() {
1971
            return ((getJTextFieldVertex1X().getText().compareTo("") == 0) | (getJTextFieldVertex1Y().getText().compareTo("") == 0) | (getJTextFieldVertex2X().getText().compareTo("") == 0) | (getJTextFieldVertex2Y().getText().compareTo("") == 0));
1972
        }
1973
    }
1974

    
1975
    /**
1976
     * This class is a MapControl JComponent that has visual information and allows user interact with some tools and view the results
1977
     *
1978
     * @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
1979
     */
1980
    private class SelectableMapControlAreaPanel extends MapControl {
1981
        private MouseListener[] mouseListeners;
1982
        private MouseWheelListener[] mouseWheelListeners;
1983
        private MouseMotionListener[] mouseMotionListeners;
1984

    
1985
        /**
1986
         * Default constructor
1987
         */
1988
        public SelectableMapControlAreaPanel() {
1989
            super();
1990
            initialize();
1991
        }
1992

    
1993
        /**
1994
         * This method initializes this component
1995
         */
1996
        public void initialize() {
1997
            /* Sets Bounds of this graphical component */
1998
            this.setBounds(DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE);
1999

    
2000
            /* Sets border to this graphical component */
2001
            this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
2002

    
2003
            MapContext mp = ((AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
2004

    
2005
            this.setMapContext(mp.cloneFMap());
2006
            ViewPort vP = this.getViewPort();
2007

    
2008
            // We will use the adjusted extent because increases the usability
2009
            Envelope envelope = vP.getAdjustedExtent();
2010

    
2011
            if (envelope != null) {
2012
                vP.refreshExtent();
2013
                getCoordinatesPanel().updateCoordinates(envelope);
2014
            }
2015

    
2016
            /* Adds listeners to this MapControl */
2017
            this.addToolsListeners();
2018

    
2019
            /* Sets default tool */
2020
            this.setTool(PAN_TOOL);
2021
        }
2022

    
2023
        /**
2024
         * Refresh the active view
2025
         */
2026
        public void refreshWithTheActiveView() {
2027
            MapContext mp = ((AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
2028
            this.setMapContext(mp.cloneFMap());
2029
            ViewPort vP = this.getViewPort();
2030

    
2031
            // We will use the adjusted extent because increases the usability
2032
            Envelope envelope = vP.getAdjustedExtent();
2033
            //                                Rectangle2D r2D = vP.getExtent();
2034

    
2035
            if (envelope != null) {
2036
                vP.refreshExtent();
2037
                getCoordinatesPanel().updateCoordinates(envelope);
2038
            }
2039
        }
2040

    
2041
        /**
2042
         * Adds listeners that allows user interact with it's mouse over this component and that represents different tools
2043
         */
2044
        private void addToolsListeners() {
2045
            // MOVEMENT EVENTS LISTENER: sets mouse coordinates to the status bar
2046
            StatusBarListener sbl = new StatusBarListener(this);
2047

    
2048
            // ZOOM OUT (Presses on the map and it will be centered showing a bigger area)
2049
            // Only pressing, not selecting a rectangle area
2050
            ZoomOutListener zol = new ZoomOutListener(this);
2051
            this.addBehavior(ZOOM_OUT_TOOL, new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)});
2052

    
2053
            // ZOOM IN (Using a Rectangle or a simple mouse click)
2054
            ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(this);
2055
            ZoomInListener zil = new ZoomInListener(this);
2056
            this.addBehavior(ZOOM_IN_TOOL, new Behavior[]{new RectangleBehavior(zil),
2057
                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
2058

    
2059
            // PAN
2060
            PanListener pl = new PanListener(this);
2061
            this.addBehavior(PAN_TOOL, new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)});
2062

    
2063
            // MEASURE DISTANCES
2064
            MeasureListener mli = new MeasureListener(this);
2065
            this.addBehavior(MEASURE_DISTANCES_TOOL, new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)});
2066

    
2067
            // MEASURE AREA
2068
            AreaListener ali = new AreaListener(this);
2069
            this.addBehavior(MEASURE_AREA_TOOL, new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)});
2070

    
2071
            this.getViewPort().addViewPortListener(new ViewPortListener() {
2072
                public void extentChanged(ExtentEvent e) {
2073
                    if (!getEnablingJCheckBox().isSelected())
2074
                        return;
2075

    
2076
                    if (getMapContext().getViewPort().getExtents().hasPrevious()) {
2077
                        // We will use the adjusted extent because increases the usability
2078
                        Envelope envelope = getViewPort().getAdjustedExtent();
2079
                        //                                                Rectangle2D r2d = getViewPort().getExtent();
2080

    
2081
                        if (envelope != null) {
2082
                            getCoordinatesPanel().updateCoordinates(envelope);
2083

    
2084
                            //                                                        if (getJComboBoxToolSelection().getSelectedIndex() != 0) {
2085
                            hasUserDefinedAnArea = true;
2086
                            //                                                        }
2087
                        }
2088

    
2089
                        getJButtonZoomPrevious().setEnabled(true);
2090
                        getJButtonUndo().setEnabled(true);
2091
                    }
2092
                    else {
2093
                        getJButtonZoomPrevious().setEnabled(false);
2094
                        getJButtonUndo().setEnabled(false);
2095
                    }
2096
                }
2097

    
2098
                public void backColorChanged(ColorEvent e) {
2099
                }
2100
             
2101
                public void projectionChanged(ProjectionEvent e) {
2102
                }
2103

    
2104
            });
2105
        }
2106

    
2107
        /*
2108
         *  (non-Javadoc)
2109
         * @see java.awt.Component#setEnabled(boolean)
2110
         */
2111
        public void setEnabled(boolean b) {
2112
            super.setEnabled(b);
2113

    
2114
            if (b)
2115
                enableAllMouseListeners();
2116
            else
2117
                disableAllMouseListeners();
2118
        }
2119

    
2120
        /**
2121
         * Disables all mouse listeners
2122
         */
2123
        public void disableAllMouseListeners() {
2124
            int i;
2125

    
2126
            // 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
2127
            //   are referenciated by this component or by the private attribute 'mouseListeners')
2128

    
2129
            // Mouse Button Listeners
2130
            if (mouseListeners == null) {
2131
                mouseListeners = this.getMouseListeners();
2132

    
2133
                for (i = 0; i < mouseListeners.length; i++) {
2134
                    removeMouseListener(mouseListeners[i]);
2135
                }
2136
            }
2137

    
2138
            // Mouse Wheel Listeners
2139
            if (mouseWheelListeners == null) {
2140
                mouseWheelListeners = this.getMouseWheelListeners();
2141

    
2142
                for (i = 0; i < mouseWheelListeners.length; i++) {
2143
                    removeMouseWheelListener(mouseWheelListeners[i]);
2144
                }
2145
            }
2146

    
2147
            // Mouse motion listeners
2148
            if (mouseMotionListeners == null) {
2149
                mouseMotionListeners = this.getMouseMotionListeners();
2150

    
2151
                for (i = 0; i < mouseMotionListeners.length; i++) {
2152
                    removeMouseMotionListener(mouseMotionListeners[i]);
2153
                }
2154
            }
2155
        }
2156

    
2157
        /**
2158
         * Enables all mouse listeners
2159
         */
2160
        public void enableAllMouseListeners() {
2161
            int i;
2162

    
2163
            // Mouse Button Listeners
2164
            for (i = 0; i < mouseListeners.length; i++) {
2165
                addMouseListener(mouseListeners[i]);
2166
            }
2167

    
2168
            mouseListeners = null;
2169

    
2170
            // Mouse Wheel Listeners
2171
            for (i = 0; i < mouseWheelListeners.length; i++) {
2172
                addMouseWheelListener(mouseWheelListeners[i]);
2173
            }
2174

    
2175
            mouseWheelListeners = null;
2176

    
2177
            // Mouse motion listeners
2178
            for (i = 0; i < mouseMotionListeners.length; i++) {
2179
                addMouseMotionListener(mouseMotionListeners[i]);
2180
            }
2181

    
2182
            mouseMotionListeners = null;
2183
        }
2184
    }
2185

    
2186
    /**
2187
     * This class has information about a validation: <br>
2188
     *   - A boolean value -> if has been or not validated <br>
2189
     *   - An String -> a message about the invalid
2190
     *
2191
     * @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
2192
     */
2193
    private class ValidationInfo {
2194
        private boolean _valid;
2195
        private String _message;
2196

    
2197
        /**
2198
         * Default constructor with two parameters
2199
         *
2200
         * @param valid If was valid or not
2201
         * @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
2202
         *                  an explanation about the invalidation)
2203
         */
2204
        public ValidationInfo(boolean valid, String message) {
2205
            _valid = valid;
2206
            _message = message;
2207
        }
2208

    
2209
        /**
2210
         * Returns the value of the inner attribute '_valid'
2211
         *
2212
         * @return A boolean value
2213
         */
2214
        public boolean isValid() {
2215
            return _valid;
2216
        }
2217

    
2218
        /**
2219
         * Returns the value of the inner attribute '_message'
2220
         *
2221
         * @return java.lang.String
2222
         */
2223
        public String getMessage() {
2224
            return _message;
2225
        }
2226
    }
2227

    
2228
    protected void initialize() {
2229
        setLabel(PluginServices.getText(this, "area"));
2230
        setLabelGroup(PluginServices.getText(this, "wfs"));
2231
        this.setLayout(new java.awt.BorderLayout());
2232
        java.awt.GridBagConstraints gridBagConstraints;
2233

    
2234
        northPanel = new JPanel();
2235
        northPanel.setLayout(new java.awt.GridBagLayout());                
2236

    
2237
        northPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
2238
            null, PluginServices.getText(this, "select_by_area"),
2239
            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
2240
            javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
2241

    
2242
        // By default, user hasn't defined an area
2243
        this.hasUserDefinedAnArea = false;
2244

    
2245
        // Adds JPanel with the coordinates
2246
        gridBagConstraints = new java.awt.GridBagConstraints();
2247
        gridBagConstraints.gridx = 0;
2248
        gridBagConstraints.gridy = 0;
2249
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
2250
        gridBagConstraints.weightx = 1.0;        
2251
        northPanel.add(getCoordinatesPanel(), gridBagConstraints);
2252

    
2253
        // Adds a check box to enable or enable this kind of filtering
2254
        gridBagConstraints = new java.awt.GridBagConstraints();
2255
        gridBagConstraints.gridx = 0;
2256
        gridBagConstraints.gridy = 1;
2257
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
2258
        gridBagConstraints.weightx = 1.0;
2259
        northPanel.add(getEnablingJCheckBox(), gridBagConstraints);
2260

    
2261
        previousExtentValids = new ExtentHistory();
2262
        initCoordinates();
2263

    
2264
        add(northPanel, java.awt.BorderLayout.NORTH);
2265
    }
2266

    
2267
    public void refresh(WFSSelectedFeature layer) {
2268
        
2269
    }
2270
}