svn-gvsig-desktop / tags / v2_0_0_Build_2065 / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / WFSAreaPanel.java @ 40276
History | View | Annotate | Download (95.9 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.andami.ui.mdiManager.IWindow; |
37 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
38 |
import org.gvsig.app.ApplicationLocator; |
39 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
40 |
import org.gvsig.app.project.documents.view.gui.IView; |
41 |
import org.gvsig.app.project.documents.view.toolListeners.AreaListener; |
42 |
import org.gvsig.app.project.documents.view.toolListeners.MeasureListener; |
43 |
import org.gvsig.app.project.documents.view.toolListeners.PanListener; |
44 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
45 |
import org.gvsig.app.project.documents.view.toolListeners.ZoomInListener; |
46 |
import org.gvsig.app.project.documents.view.toolListeners.ZoomOutListener; |
47 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
48 |
import org.gvsig.fmap.geom.Geometry; |
49 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
50 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
51 |
import org.gvsig.fmap.geom.GeometryLocator; |
52 |
import org.gvsig.fmap.geom.GeometryManager; |
53 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
54 |
import org.gvsig.fmap.geom.primitive.Envelope; |
55 |
import org.gvsig.fmap.geom.primitive.Surface; |
56 |
import org.gvsig.fmap.mapcontext.ExtentHistory; |
57 |
import org.gvsig.fmap.mapcontext.MapContext; |
58 |
import org.gvsig.fmap.mapcontext.ViewPort; |
59 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
60 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
61 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
62 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
64 |
import org.gvsig.fmap.mapcontrol.MapControl; |
65 |
import org.gvsig.fmap.mapcontrol.tools.ZoomOutRightButtonListener; |
66 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
67 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
68 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveBehavior; |
69 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
70 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior; |
71 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior; |
72 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior; |
73 |
import org.gvsig.gui.beans.panelGroup.IPanelGroup; |
74 |
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP; |
75 |
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.ImageIconItemInfo; |
76 |
import org.gvsig.gui.beans.swing.jComboBoxWithImageIconItems.JComboBoxWithImageIconItems; |
77 |
import org.gvsig.utils.stringNumberUtilities.StringNumberUtilities; |
78 |
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature; |
79 |
|
80 |
|
81 |
/* gvSIG. Geographic Information System of the Valencian Government
|
82 |
*
|
83 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
84 |
* of the Valencian Government (CIT)
|
85 |
*
|
86 |
* This program is free software; you can redistribute it and/or
|
87 |
* modify it under the terms of the GNU General Public License
|
88 |
* as published by the Free Software Foundation; either version 2
|
89 |
* of the License, or (at your option) any later version.
|
90 |
*
|
91 |
* This program is distributed in the hope that it will be useful,
|
92 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
93 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
94 |
* GNU General Public License for more details.
|
95 |
*
|
96 |
* You should have received a copy of the GNU General Public License
|
97 |
* along with this program; if not, write to the Free Software
|
98 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
99 |
* MA 02110-1301, USA.
|
100 |
*
|
101 |
*/
|
102 |
|
103 |
/**
|
104 |
* VERSI?N PROVISIONAL ESTABLE
|
105 |
*
|
106 |
* This panel allows user to select the area he/she wants to get in the view.
|
107 |
* There are two options to do this:
|
108 |
* - Indicating the coordinates of the top-left and down-right corners
|
109 |
* - Selecting the area with some visual tool
|
110 |
*
|
111 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
112 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
113 |
*/
|
114 |
public class WFSAreaPanel extends AbstractWFSPanel { |
115 |
private final Rectangle DEFAULT_BOUNDS = new Rectangle(10, 5, 490, 380); |
116 |
private final Rectangle DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE = new Rectangle(8, 20, 481, 60); |
117 |
private final Rectangle DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE = new Rectangle(8, 115, 481, 265); |
118 |
private final Rectangle DEFAULT_UNDO_ICON_BUTTON_RECTANGLE = new Rectangle (250, 85, 25, 25); |
119 |
private final Rectangle DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (277, 85, 25, 25); |
120 |
private final Rectangle DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE = new Rectangle (304, 85, 25, 25); |
121 |
private final Rectangle DEFAULT_PAN_ICON_BUTTON_RECTANGLE = new Rectangle(250, 85, 25, 25); |
122 |
private final Rectangle DEFAULT_TOOL_JCOMBOBOX_RECTANGLE = new Rectangle(10, 87, 230, 21); |
123 |
private final Rectangle DEFAULT_ENABLING_CHECKBOX_RECTANGLE = new Rectangle(10, 87, 150, 21); |
124 |
private final Rectangle DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE = new Rectangle(277, 85, 47, 25); |
125 |
private final Rectangle DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE = new Rectangle(326, 85, 25, 25); |
126 |
private final Rectangle DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE = new Rectangle(353, 85, 25, 25); |
127 |
private final Rectangle DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE = new Rectangle(380, 85, 47, 25); |
128 |
private final Rectangle DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE = new Rectangle(429, 85, 47, 25); |
129 |
|
130 |
private static GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
131 |
private final int DISABLED_OPERATION = 0; |
132 |
private final int SELECTION_BY_COORDINATES_OPERATION = 1; |
133 |
private final int SELECTION_BY_AREA_OPERATION = 2; |
134 |
// private Rectangle2D lastExtentValid = null;
|
135 |
private ExtentHistory previousExtentValids = null; |
136 |
|
137 |
private WFSServerExplorer serverExplorer = null; |
138 |
private AreaCoordinatesPanel coordinatesPanel = null; |
139 |
private SelectableMapControlAreaPanel selectableMapAreaPanel = null; |
140 |
private JComboBox jComboBoxToolSelection = null; |
141 |
private JButton jButtonUndo = null; |
142 |
// private JButton jButtonRedo = null;
|
143 |
private JToggleButton jToggleButtonMove = null; |
144 |
private JToggleButton jToggleButtonScaling = null; |
145 |
private JButton jButtonPan = null; |
146 |
private JButton jButtonZoomPrevious = null; |
147 |
private JButton jButtonZoomComplete = null; |
148 |
private JComboBoxWithImageIconItems jComboBoxZoomInAndOut = null; |
149 |
private JComboBoxWithImageIconItems jComboBoxZoomInAndOutViewCentered = null; |
150 |
private JComboBoxWithImageIconItems jComboBoxOtherTools = null; |
151 |
private JCheckBox jEnablingCheckBox = null; |
152 |
|
153 |
/* Tool identifier constants */
|
154 |
private final String PAN_TOOL = "HAND"; |
155 |
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' |
156 |
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' |
157 |
private final String ZOOM_IN_VIEW_CENTERED_TOOL = "ZOOM_IN_VIEW_CENTERED"; |
158 |
private final String ZOOM_OUT_VIEW_CENTERED_TOOL = "ZOOM_OUT_VIEW_CENTERED"; |
159 |
private final String MEASURE_DISTANCES_TOOL = "MEASURE_DISTANCES"; |
160 |
private final String MEASURE_AREA_TOOL = "MEASURE_AREA"; |
161 |
/* End tool identifier constants */
|
162 |
|
163 |
private JPanel northPanel = null; |
164 |
|
165 |
|
166 |
/**
|
167 |
* This method initializes
|
168 |
*/
|
169 |
public WFSAreaPanel() {
|
170 |
super();
|
171 |
initialize(); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* Write the view coordinates into the coordinates panel
|
176 |
*/
|
177 |
private void initCoordinates(){ |
178 |
AbstractViewPanel activeView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
179 |
// We will use the adjusted extent because increases the usability
|
180 |
Envelope envelope = activeView.getMapControl().getViewPort().getAdjustedExtent(); |
181 |
// Rectangle2D r2d = activeView.getMapControl().getViewPort().getExtent();
|
182 |
|
183 |
if (envelope != null){ |
184 |
previousExtentValids.put(new Rectangle2D.Double(envelope.getMinimum(0), |
185 |
envelope.getMinimum(1),
|
186 |
envelope.getMaximum(0)-envelope.getMaximum(0), |
187 |
envelope.getMaximum(1)-envelope.getMinimum(1))); |
188 |
|
189 |
setCoordinates(envelope.getMaximum(0), envelope.getMaximum(1), |
190 |
envelope.getMinimum(0), envelope.getMinimum(1)); |
191 |
} |
192 |
} |
193 |
|
194 |
/**
|
195 |
* Removes all registered extents
|
196 |
*/
|
197 |
public void clearCoordinates() { |
198 |
while (previousExtentValids.hasPrevious()) {
|
199 |
previousExtentValids.removePrev(); |
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* <p>Sets the coordinates of all the text fields. It's supposed that all coordinates are valid.</p>
|
205 |
*
|
206 |
* @param v1x value of the x coordinate of the right-up corner of the rectangle
|
207 |
* @param v1y value of the y coordinate of the right-up corner of the rectangle
|
208 |
* @param v2x value of the x coordinate of the left-up corner of the rectangle
|
209 |
* @param v2y value of the y coordinate of the left-up corner of the rectangle
|
210 |
*/
|
211 |
private void setCoordinates(double v1x, double v1y, double v2x, double v2y) { |
212 |
getCoordinatesPanel().getJTextFieldVertex1X().setText(Double.toString(v1x));
|
213 |
getCoordinatesPanel().getJTextFieldVertex1Y().setText(Double.toString(v1y));
|
214 |
getCoordinatesPanel().getJTextFieldVertex2X().setText(Double.toString(v2x));
|
215 |
getCoordinatesPanel().getJTextFieldVertex2Y().setText(Double.toString(v2y));
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* <p>Sets the coordinates of all the text fields. It's supposed that all coordinates are valid.</p>
|
220 |
*
|
221 |
* @param bbox the bounding box that represents a rectangle with the information of all coordinates
|
222 |
*/
|
223 |
private void setCoordinates(Rectangle2D bbox) { |
224 |
getCoordinatesPanel().getJTextFieldVertex1X().setText(Double.toString(bbox.getMaxX()));
|
225 |
getCoordinatesPanel().getJTextFieldVertex1Y().setText(Double.toString(bbox.getMaxY()));
|
226 |
getCoordinatesPanel().getJTextFieldVertex2X().setText(Double.toString(bbox.getMinX()));
|
227 |
getCoordinatesPanel().getJTextFieldVertex2Y().setText(Double.toString(bbox.getMinY()));
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* This method initializes coordinatesPanel
|
232 |
*
|
233 |
* @return javax.swing.JPanel
|
234 |
*/
|
235 |
private AreaCoordinatesPanel getCoordinatesPanel() {
|
236 |
if (coordinatesPanel == null) { |
237 |
coordinatesPanel = new AreaCoordinatesPanel();
|
238 |
} |
239 |
return coordinatesPanel;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* This method initializes jEnablingCheckBox
|
244 |
*
|
245 |
* @return javax.swing.JCheckBox
|
246 |
*/
|
247 |
private JCheckBox getEnablingJCheckBox() { |
248 |
if (jEnablingCheckBox == null) { |
249 |
jEnablingCheckBox = new JCheckBox(PluginServices.getText(this, "enabled")); |
250 |
jEnablingCheckBox.setBounds(DEFAULT_ENABLING_CHECKBOX_RECTANGLE); |
251 |
jEnablingCheckBox.setToolTipText(PluginServices.getText(this, "enable_filter_by_area")); |
252 |
jEnablingCheckBox.setSelected(false);
|
253 |
jEnablingCheckBox.addItemListener(new ItemListener() { |
254 |
public void itemStateChanged(ItemEvent e) { |
255 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
256 |
jEnablingCheckBox.setToolTipText(PluginServices.getText(this, "disable_filter_by_area")); |
257 |
enableCoorderatesRegionOperation(); |
258 |
} |
259 |
else {
|
260 |
jEnablingCheckBox.setToolTipText(PluginServices.getText(this, "enable_filter_by_area")); |
261 |
disableCoorderatesRegionOperation(); |
262 |
} |
263 |
|
264 |
IPanelGroup panelGroup = getPanelGroup(); |
265 |
|
266 |
if (panelGroup == null) |
267 |
return;
|
268 |
|
269 |
((WFSParamsPanel)panelGroup).setApplicable(true);
|
270 |
} |
271 |
}); |
272 |
|
273 |
// By default, the tool is disabled
|
274 |
disableCoorderatesRegionOperation(); |
275 |
} |
276 |
return jEnablingCheckBox;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* This method initializes jComboBoxToolSelection
|
281 |
*
|
282 |
* @return javax.swing.JComboBox
|
283 |
*/
|
284 |
private JComboBox getJComboBoxToolSelection() { |
285 |
if (jComboBoxToolSelection == null) { |
286 |
jComboBoxToolSelection = new JComboBox(); |
287 |
jComboBoxToolSelection.setBounds(DEFAULT_TOOL_JCOMBOBOX_RECTANGLE); |
288 |
jComboBoxToolSelection.setToolTipText(PluginServices.getText(this, "select_a_tool")); |
289 |
jComboBoxToolSelection.setEditable(false);
|
290 |
jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "disabled"), this.DISABLED_OPERATION)); |
291 |
jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "define_absolute_coordinates"), this.SELECTION_BY_COORDINATES_OPERATION)); |
292 |
jComboBoxToolSelection.addItem(new ItemOperation(PluginServices.getText(this, "define_coordinates_using_view"), this.SELECTION_BY_AREA_OPERATION)); |
293 |
|
294 |
jComboBoxToolSelection.addActionListener(new ActionListener() { |
295 |
/*
|
296 |
* (non-Javadoc)
|
297 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
298 |
*/
|
299 |
public void actionPerformed(ActionEvent e) { |
300 |
JComboBox cb = (JComboBox)e.getSource(); |
301 |
switch(((ItemOperation)cb.getSelectedItem()).getOperation()) {
|
302 |
case DISABLED_OPERATION:
|
303 |
disableCoorderatesRegionOperation(); |
304 |
disableAreaRegionOperation(); |
305 |
break;
|
306 |
case SELECTION_BY_COORDINATES_OPERATION:
|
307 |
disableAreaRegionOperation(); |
308 |
enableCoorderatesRegionOperation(); |
309 |
break;
|
310 |
case SELECTION_BY_AREA_OPERATION:
|
311 |
// Only enable the area operation if there is data loaded in this MapControl
|
312 |
if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) { |
313 |
disableCoorderatesRegionOperation(); |
314 |
enableAreaRegionOperation(); |
315 |
} |
316 |
else {
|
317 |
JOptionPane.showMessageDialog(jComboBoxToolSelection, PluginServices.getText(null, "there_is_no_layer_loaded_in_the_active_view"), PluginServices.getText(null, "information"), JOptionPane.INFORMATION_MESSAGE); |
318 |
|
319 |
// Select: no tools
|
320 |
jComboBoxToolSelection.setSelectedIndex(0);
|
321 |
disableCoorderatesRegionOperation(); |
322 |
} |
323 |
|
324 |
break;
|
325 |
} |
326 |
} |
327 |
}); |
328 |
} |
329 |
return jComboBoxToolSelection;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* Enables the components associated to the selection of area by coordinates
|
334 |
*/
|
335 |
private void enableCoorderatesRegionOperation() { |
336 |
getCoordinatesPanel().setAllTextFieldsEnabled(true);
|
337 |
|
338 |
if (!getEnablingJCheckBox().isSelected()){
|
339 |
MDIManager mdiManager = ApplicationLocator.getManager().getUIManager(); |
340 |
IWindow[] windows = mdiManager.getOrderedWindows();
|
341 |
IView view = null;
|
342 |
for (int i=0 ; i<windows.length ; i++){ |
343 |
if (windows[i] instanceof IView){ |
344 |
view = (IView)windows[i]; |
345 |
} |
346 |
} |
347 |
|
348 |
ViewPort viewPort = view.getMapControl().getMapContext().getViewPort(); |
349 |
|
350 |
// Update extent (we will use the adjusted extent because increases the usability)
|
351 |
Envelope envelope = viewPort.getAdjustedEnvelope(); |
352 |
|
353 |
if (envelope != null) { |
354 |
getCoordinatesPanel().updateCoordinates(envelope); |
355 |
} |
356 |
} |
357 |
|
358 |
getCoordinatesPanel().getJButtonValidateArea().setEnabled(true);
|
359 |
|
360 |
this.repaint();
|
361 |
} |
362 |
|
363 |
/**
|
364 |
* Enables the components associated to the selection of area by view
|
365 |
*/
|
366 |
private void enableAreaRegionOperation() { |
367 |
// Adds associated icons
|
368 |
this.add(getJButtonPan(), null); |
369 |
this.add(getJComboBoxZoomInAndOut(), null); |
370 |
getJComboBoxZoomInAndOut().revalidate(); // Force update this component
|
371 |
this.add(getJButtonZoomPrevious(), null); |
372 |
this.add(getJButtonZoomComplete(), null); |
373 |
this.add(getJComboBoxZoomInAndOutViewCentered(), null); |
374 |
getJComboBoxZoomInAndOutViewCentered().revalidate(); // Force update this component
|
375 |
this.add(getJComboBoxOtherTools(), null); |
376 |
getJComboBoxOtherTools().revalidate(); // Force update this component
|
377 |
|
378 |
// Enables the MapControl area
|
379 |
getSelectableMapAreaPanel().setEnabled(true);
|
380 |
} |
381 |
|
382 |
/**
|
383 |
* Disables the components associated to the selection of area by coordinates
|
384 |
*/
|
385 |
private void disableCoorderatesRegionOperation() { |
386 |
getCoordinatesPanel().setAllTextFieldsEnabled(false);
|
387 |
getCoordinatesPanel().getJButtonValidateArea().setEnabled(false);
|
388 |
|
389 |
this.repaint();
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* Disables the components associated to the selection of area by view
|
394 |
*/
|
395 |
private void disableAreaRegionOperation() { |
396 |
// Removes associated icons
|
397 |
this.remove(getJButtonPan());
|
398 |
this.remove(getJComboBoxZoomInAndOut());
|
399 |
this.remove(getJButtonZoomPrevious());
|
400 |
this.remove(getJButtonZoomComplete());
|
401 |
this.remove(getJComboBoxZoomInAndOutViewCentered());
|
402 |
this.remove(getJComboBoxOtherTools());
|
403 |
|
404 |
// Disables the MapControl area
|
405 |
getSelectableMapAreaPanel().setEnabled(false);
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* This method initializes areaMapControlPanel
|
410 |
*
|
411 |
* @return A reference to an object of SelectableMapControlAreaPanel
|
412 |
*/
|
413 |
private SelectableMapControlAreaPanel getSelectableMapAreaPanel() {
|
414 |
if (selectableMapAreaPanel == null) { |
415 |
selectableMapAreaPanel = new SelectableMapControlAreaPanel();
|
416 |
} |
417 |
|
418 |
return selectableMapAreaPanel;
|
419 |
} |
420 |
|
421 |
/**
|
422 |
* This method initializes jButtonUndo
|
423 |
*
|
424 |
* @return javax.swing.JButton
|
425 |
*/
|
426 |
private JButton getJButtonUndo() { |
427 |
if (jButtonUndo == null) { |
428 |
jButtonUndo = new JButton(); |
429 |
jButtonUndo.setBounds(DEFAULT_UNDO_ICON_BUTTON_RECTANGLE); |
430 |
jButtonUndo.setIcon(PluginServices.getIconTheme().get("wfs-properties-undo"));
|
431 |
jButtonUndo.setToolTipText(PluginServices.getText(this, "previous_area")); |
432 |
jButtonUndo.addMouseListener(new MouseAdapter() { |
433 |
public void mouseClicked(MouseEvent e) { |
434 |
goToPreviousZoom(); |
435 |
} |
436 |
}); |
437 |
} |
438 |
|
439 |
return jButtonUndo;
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* This method initializes jToggleButtonMove
|
444 |
*
|
445 |
* @return javax.swing.JButton
|
446 |
*/
|
447 |
private JToggleButton getJToggleButtonMove() { |
448 |
if (jToggleButtonMove == null) { |
449 |
jToggleButtonMove = new JToggleButton(); |
450 |
jToggleButtonMove.setBounds(DEFAULT_MOVE_ICON_TOGGLE_BUTTON_RECTANGLE); |
451 |
jToggleButtonMove.setIcon(PluginServices.getIconTheme().get("wfs-properties-move"));
|
452 |
jToggleButtonMove.setToolTipText(PluginServices.getText(this, "move") + ": " + PluginServices.getText(this, "area_move_explanation")); |
453 |
jToggleButtonMove.addItemListener(new ItemListener() { |
454 |
public void itemStateChanged(ItemEvent e) { |
455 |
// Isn't allowed that the two JToggleButton would be selected (can't move and scale)
|
456 |
if (jToggleButtonMove.isSelected())
|
457 |
jToggleButtonScaling.setSelected(false);
|
458 |
} |
459 |
}); |
460 |
} |
461 |
|
462 |
return jToggleButtonMove;
|
463 |
} |
464 |
|
465 |
/**
|
466 |
* This method initializes jToggleButtonScaling
|
467 |
*
|
468 |
* @return javax.swing.JButton
|
469 |
*/
|
470 |
private JToggleButton getJToggleButtonScaling() { |
471 |
if (jToggleButtonScaling == null) { |
472 |
jToggleButtonScaling = new JToggleButton(); |
473 |
jToggleButtonScaling.setBounds(DEFAULT_SCALING_ICON_TOGGLE_BUTTON_RECTANGLE); |
474 |
jToggleButtonScaling.setIcon(PluginServices.getIconTheme().get("wfs-properties-scaling"));
|
475 |
jToggleButtonScaling.setToolTipText(PluginServices.getText(this, "scaling") + ": " + PluginServices.getText(this, "area_scaling_explanation")); |
476 |
jToggleButtonScaling.addItemListener(new ItemListener() { |
477 |
public void itemStateChanged(ItemEvent e) { |
478 |
// Isn't allowed that the two JToggleButton would be selected (can't move and scale)
|
479 |
if (jToggleButtonScaling.isSelected())
|
480 |
jToggleButtonMove.setSelected(false);
|
481 |
} |
482 |
}); |
483 |
} |
484 |
|
485 |
return jToggleButtonScaling;
|
486 |
} |
487 |
/**
|
488 |
* This method initializes jButtonPan
|
489 |
*
|
490 |
* @return javax.swing.JButton
|
491 |
*/
|
492 |
private JButton getJButtonPan() { |
493 |
if (jButtonPan == null) { |
494 |
jButtonPan = new JButton(); |
495 |
jButtonPan.setBounds(DEFAULT_PAN_ICON_BUTTON_RECTANGLE); |
496 |
jButtonPan.setIcon(PluginServices.getIconTheme().get("wfs-properties-pan"));
|
497 |
jButtonPan.setToolTipText(PluginServices.getText(this, "Desplazamiento")); |
498 |
jButtonPan.addMouseListener(new MouseAdapter() { |
499 |
public void mouseClicked(MouseEvent e) { |
500 |
getSelectableMapAreaPanel().setTool(PAN_TOOL); |
501 |
} |
502 |
}); |
503 |
} |
504 |
return jButtonPan;
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* This method initializes jComboBoxZoomInAndOut
|
509 |
*
|
510 |
* @return A JComboBoxWithImageIconItems object reference
|
511 |
*/
|
512 |
private JComboBoxWithImageIconItems getJComboBoxZoomInAndOut() {
|
513 |
if (jComboBoxZoomInAndOut == null) { |
514 |
jComboBoxZoomInAndOut = new JComboBoxWithImageIconItems();
|
515 |
jComboBoxZoomInAndOut.setBounds(DEFAULT_ZOOMINANDOUT_JCOMBOBOX_RECTANGLE); |
516 |
jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo(null,PluginServices.getIconTheme().get("wfs-properties-zoom-in"),PluginServices.getText(this, "Zoom_Mas"), ZOOM_IN_TOOL)); |
517 |
jComboBoxZoomInAndOut.addImageIconItem(new ImageIconItemInfo(null,PluginServices.getIconTheme().get("wfs-properties-zoom-out"), PluginServices.getText(this, "Zoom_Menos"), ZOOM_OUT_TOOL)); |
518 |
jComboBoxZoomInAndOut.addActionListener(new ActionListener() { |
519 |
public void actionPerformed(ActionEvent e) { |
520 |
JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource(); |
521 |
ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem(); |
522 |
getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
|
523 |
} |
524 |
}); |
525 |
} |
526 |
|
527 |
return jComboBoxZoomInAndOut;
|
528 |
} |
529 |
|
530 |
/**
|
531 |
* This method initializes jButtonZoomPrevious
|
532 |
*
|
533 |
* @return javax.swing.JButton
|
534 |
*/
|
535 |
private JButton getJButtonZoomPrevious() { |
536 |
if (jButtonZoomPrevious == null) { |
537 |
jButtonZoomPrevious = new JButton(); |
538 |
jButtonZoomPrevious.setBounds(DEFAULT_ZOOMPREVIOUS_ICON_BUTTON_RECTANGLE); |
539 |
jButtonZoomPrevious.setIcon(PluginServices.getIconTheme().get("wfs-properties-zoom-back"));
|
540 |
jButtonZoomPrevious.setToolTipText(PluginServices.getText(this, "Zoom_Previo")); |
541 |
jButtonZoomPrevious.addMouseListener(new MouseAdapter() { |
542 |
public void mouseClicked(MouseEvent e) { |
543 |
goToPreviousZoom(); |
544 |
} |
545 |
}); |
546 |
} |
547 |
return jButtonZoomPrevious;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* This method initializes jButtonZoomComplete
|
552 |
*
|
553 |
* @return javax.swing.JButton
|
554 |
*/
|
555 |
private JButton getJButtonZoomComplete() { |
556 |
if (jButtonZoomComplete == null) { |
557 |
jButtonZoomComplete = new JButton(); |
558 |
jButtonZoomComplete.setBounds(DEFAULT_ZOOMCOMPLETE_ICON_BUTTON_RECTANGLE); |
559 |
jButtonZoomComplete.setIcon(PluginServices.getIconTheme().get("wfs-properties-zoom-all"));
|
560 |
jButtonZoomComplete.setToolTipText(PluginServices.getText(this, "Zoom_Completo")); |
561 |
jButtonZoomComplete.addMouseListener(new MouseAdapter() { |
562 |
public void mouseClicked(MouseEvent e) { |
563 |
getSelectableMapAreaPanel().getViewPort().setEnvelope(getSelectableMapAreaPanel().getMapContext().getLayers().getFullEnvelope()); |
564 |
AbstractViewPanel view =((AbstractViewPanel)PluginServices.getMDIManager().getActiveWindow()); |
565 |
view.repaintMap(); |
566 |
} |
567 |
}); |
568 |
} |
569 |
return jButtonZoomComplete;
|
570 |
} |
571 |
|
572 |
/**
|
573 |
* This method initializes jComboBoxZoomInAndOut
|
574 |
*
|
575 |
* @return A JComboBoxWithImageIconItems object reference
|
576 |
*/
|
577 |
private JComboBoxWithImageIconItems getJComboBoxZoomInAndOutViewCentered() {
|
578 |
if (jComboBoxZoomInAndOutViewCentered == null) { |
579 |
jComboBoxZoomInAndOutViewCentered = new JComboBoxWithImageIconItems();
|
580 |
jComboBoxZoomInAndOutViewCentered.setBounds(DEFAULT_ZOOMINANDOUTVIEWCENTERED_JCOMBOBOX_RECTANGLE); |
581 |
jComboBoxZoomInAndOutViewCentered.addImageIconItem(new ImageIconItemInfo(null,PluginServices.getIconTheme().get("wfs-properties-zoom-plus"), PluginServices.getText(this, "Zoom_Acercar"), ZOOM_IN_VIEW_CENTERED_TOOL)); |
582 |
jComboBoxZoomInAndOutViewCentered.addImageIconItem(new ImageIconItemInfo(null,PluginServices.getIconTheme().get("wfs-properties-zoom-minus"), PluginServices.getText(this, "Zoom_Alejar"), ZOOM_OUT_VIEW_CENTERED_TOOL)); |
583 |
jComboBoxZoomInAndOutViewCentered.addActionListener(new ActionListener() { |
584 |
public void actionPerformed(ActionEvent e) { |
585 |
JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource(); |
586 |
ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem(); |
587 |
|
588 |
if (((String)iiii.getItemValue()).compareTo(ZOOM_IN_VIEW_CENTERED_TOOL) == 0) { |
589 |
getSelectableMapAreaPanel().zoomIn(); |
590 |
} |
591 |
else {
|
592 |
getSelectableMapAreaPanel().zoomOut(); |
593 |
} |
594 |
} |
595 |
}); |
596 |
} |
597 |
return jComboBoxZoomInAndOutViewCentered;
|
598 |
} |
599 |
|
600 |
/**
|
601 |
* This method initializes jComboBoxOtherTools
|
602 |
*
|
603 |
* @return A JComboBoxWithImageIconItems object reference
|
604 |
*/
|
605 |
private JComboBoxWithImageIconItems getJComboBoxOtherTools() {
|
606 |
if (jComboBoxOtherTools == null) { |
607 |
jComboBoxOtherTools = new JComboBoxWithImageIconItems();
|
608 |
jComboBoxOtherTools.setBounds(DEFAULT_OTHER_TOOLS_JCOMBOBOX_RECTANGLE); |
609 |
jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo(null,PluginServices.getIconTheme().get("wfs-properties-query-distance"),PluginServices.getText(this, "medir_distancias"), MEASURE_DISTANCES_TOOL)); |
610 |
jComboBoxOtherTools.addImageIconItem(new ImageIconItemInfo(null,PluginServices.getIconTheme().get("wfs-properties-query-area"), PluginServices.getText(this, "medir_area"), MEASURE_AREA_TOOL)); |
611 |
jComboBoxOtherTools.addActionListener(new ActionListener() { |
612 |
public void actionPerformed(ActionEvent e) { |
613 |
JComboBoxWithImageIconItems cb = (JComboBoxWithImageIconItems)e.getSource(); |
614 |
ImageIconItemInfo iiii = (ImageIconItemInfo)cb.getSelectedItem(); |
615 |
getSelectableMapAreaPanel().setTool((String)iiii.getItemValue());
|
616 |
} |
617 |
}); |
618 |
} |
619 |
|
620 |
return jComboBoxOtherTools;
|
621 |
} |
622 |
|
623 |
/**
|
624 |
* Goes to previous zoom
|
625 |
*/
|
626 |
private void goToPreviousZoom() { |
627 |
// Gets the view port and sets its previous extent
|
628 |
ViewPort vp = getSelectableMapAreaPanel().getMapContext().getViewPort(); |
629 |
|
630 |
if (vp.getExtents().hasPrevious()) {
|
631 |
vp.setPreviousExtent(); |
632 |
|
633 |
// We will use the adjusted extent because increases the usability
|
634 |
getCoordinatesPanel().updateCoordinates(vp.getAdjustedExtent()); |
635 |
} |
636 |
} |
637 |
|
638 |
/**
|
639 |
* Sets the extent
|
640 |
*
|
641 |
* @param java.awt.geom.Rectangle2D
|
642 |
*/
|
643 |
public void setEnvelope(Envelope envelope) { |
644 |
if (envelope != null) { |
645 |
// Update coordinates in text fields
|
646 |
getCoordinatesPanel().updateCoordinates(envelope); |
647 |
|
648 |
// If there is any layer loaded in the MapControl -> set the extent
|
649 |
if (getSelectableMapAreaPanel().getMapContext().getLayers().getLayersCount() > 0) { |
650 |
getSelectableMapAreaPanel().getMapContext().getViewPort().setEnvelope(envelope); |
651 |
} |
652 |
} |
653 |
} |
654 |
|
655 |
/**
|
656 |
* 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
|
657 |
*
|
658 |
* @return java.awt.geom.Rectangle2D or null if the data is invalid
|
659 |
*/
|
660 |
public Geometry getArea() {
|
661 |
if (!getEnablingJCheckBox().isSelected())
|
662 |
return null; |
663 |
|
664 |
if (getCoordinatesPanel().areAllCoordinatesUndefined()) {
|
665 |
return null; |
666 |
} |
667 |
else {
|
668 |
if (getCoordinatesPanel().validVertexes()) {
|
669 |
try {
|
670 |
return getCoordinatesPanel().getSurface();
|
671 |
} catch (CreateGeometryException e) {
|
672 |
logger.error("Creating the area", e);
|
673 |
return null; |
674 |
} |
675 |
} |
676 |
else {
|
677 |
return null; // Returns null if coordinates aren't valid |
678 |
} |
679 |
} |
680 |
} |
681 |
|
682 |
public void setArea(Geometry area){ |
683 |
if ((area != null) && (area.getType() == TYPES.SURFACE)){ |
684 |
getCoordinatesPanel().setSurface((Surface)area); |
685 |
getEnablingJCheckBox().setSelected(true);
|
686 |
} |
687 |
} |
688 |
|
689 |
/**
|
690 |
* Set parent's 'Applicable' button enable or disable according the value of the parameter
|
691 |
*
|
692 |
* @param b A boolean value
|
693 |
*/
|
694 |
private void setApplicable(boolean b) { |
695 |
IPanelGroup panelGroup = getPanelGroup(); |
696 |
|
697 |
if (panelGroup == null) |
698 |
return;
|
699 |
|
700 |
if (! ((WFSParamsPanel)panelGroup).getFilterPanel().getWFSFilterPanelIsAsTabForWFSLayersLoad())
|
701 |
((WFSParamsPanel)panelGroup).setApplicable(b); |
702 |
// parent.isApplicable(true);
|
703 |
} |
704 |
|
705 |
/**
|
706 |
* If there is some coordinate text field that has text, returns true; else returns false
|
707 |
*
|
708 |
* @return A boolean value
|
709 |
*/
|
710 |
public boolean areThereSomeCoordinatesWritten() { |
711 |
return getCoordinatesPanel().areThereSomeCoordinatesWritten();
|
712 |
} |
713 |
|
714 |
/**
|
715 |
* If there is some coordinate text field that isn't undefined, returns true; else returns false
|
716 |
*
|
717 |
* @return A boolean value
|
718 |
*/
|
719 |
public boolean areThereSomeCoordinatesUndefined() { |
720 |
return getCoordinatesPanel().isThereAnyCoordinateUndefined();
|
721 |
} |
722 |
|
723 |
/**
|
724 |
* Updates the current area information with the area of the active view
|
725 |
*/
|
726 |
public void updateWFSArea() { |
727 |
this.getSelectableMapAreaPanel().disableAllMouseListeners();
|
728 |
|
729 |
// To prevent that events that take place (are produced) could be a nuisance to the load of the layers
|
730 |
this.getSelectableMapAreaPanel().getMapContext().beginAtomicEvent();
|
731 |
|
732 |
try {
|
733 |
MapContext mapContext = this.getSelectableMapAreaPanel().getMapContext();
|
734 |
|
735 |
// Removes all layers in the view area
|
736 |
int numberOfLayers = mapContext.getLayers().getLayersCount();
|
737 |
int i;
|
738 |
|
739 |
for (i = (numberOfLayers-1); i >= 0; i--) { |
740 |
mapContext.getLayers().removeLayer(i); |
741 |
} |
742 |
PluginServices.getMainFrame().enableControls(); |
743 |
// Adds the extent of the viewport of the current active view
|
744 |
AbstractViewPanel view = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
745 |
ViewPort vP = view.getMapControl().getMapContext().getViewPort(); |
746 |
|
747 |
// Update extent (we will use the adjusted extent because increases the usability)
|
748 |
Envelope envelope = vP.getAdjustedExtent(); |
749 |
// Rectangle2D r2D = vP.getExtent();
|
750 |
|
751 |
if (envelope == null) { |
752 |
// End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
|
753 |
this.getSelectableMapAreaPanel().getMapContext().endAtomicEvent();
|
754 |
|
755 |
// No tools enabled
|
756 |
getJComboBoxToolSelection().setSelectedIndex(0);
|
757 |
|
758 |
return;
|
759 |
} |
760 |
|
761 |
getCoordinatesPanel().updateCoordinates(envelope); |
762 |
mapContext.getViewPort().setEnvelope(envelope); |
763 |
|
764 |
// Adds the active layers of the current active view
|
765 |
MapContext mC = view.getMapControl().getMapContext(); |
766 |
|
767 |
numberOfLayers = mC.getLayers().getLayersCount(); |
768 |
|
769 |
for (i = (numberOfLayers-1); i >= 0; i--) { |
770 |
FLayer clonedLayer = mC.getLayers().getLayer(i).cloneLayer(); |
771 |
mapContext.getLayers().addLayer(clonedLayer); |
772 |
clonedLayer.dispose(); |
773 |
} |
774 |
|
775 |
// If has to enable all listeners of all tools on the view area
|
776 |
if (((ItemOperation)this.getJComboBoxToolSelection().getSelectedItem()).getOperation() == SELECTION_BY_AREA_OPERATION) |
777 |
this.getSelectableMapAreaPanel().enableAllMouseListeners();
|
778 |
|
779 |
// End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
|
780 |
this.getSelectableMapAreaPanel().getMapContext().endAtomicEvent();
|
781 |
|
782 |
// Refresh the view
|
783 |
this.getSelectableMapAreaPanel().getViewPort().refreshExtent();
|
784 |
} catch (Exception e) { |
785 |
NotificationManager.addError(e); |
786 |
|
787 |
// End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
|
788 |
this.getSelectableMapAreaPanel().getMapContext().endAtomicEvent();
|
789 |
|
790 |
// No tools enabled
|
791 |
getJComboBoxToolSelection().setSelectedIndex(0);
|
792 |
return;
|
793 |
} |
794 |
} |
795 |
|
796 |
/**
|
797 |
* Represents an object that stores the necessary information for know each operation of the 'jComboBoxToolSelection'
|
798 |
*
|
799 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
800 |
*/
|
801 |
private class ItemOperation { |
802 |
String _name;
|
803 |
int _operation;
|
804 |
|
805 |
/**
|
806 |
* Default constructor with two parameters
|
807 |
*
|
808 |
* @param name Name of the operation
|
809 |
* @param operation A code that identifies the operation
|
810 |
*/
|
811 |
public ItemOperation(String name, int operation) { |
812 |
_name = new String(name); |
813 |
_operation = operation; |
814 |
} |
815 |
|
816 |
/**
|
817 |
* Returns the name of the operation
|
818 |
*
|
819 |
* @return An String
|
820 |
*/
|
821 |
public String getName() { |
822 |
return _name;
|
823 |
} |
824 |
|
825 |
/**
|
826 |
* Returns the code that identifies the operation
|
827 |
*
|
828 |
* @return An integer value
|
829 |
*/
|
830 |
public int getOperation() { |
831 |
return _operation;
|
832 |
} |
833 |
|
834 |
/**
|
835 |
* The name of the operation that will use JComboBox
|
836 |
*/
|
837 |
public String toString() { |
838 |
return _name;
|
839 |
} |
840 |
} |
841 |
|
842 |
/**
|
843 |
* This class is a panel width four fields for indicate the coordinates of two points:
|
844 |
* One for the ritgh-up point and another for the left-down point of a rectangle area
|
845 |
*
|
846 |
* @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
|
847 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
848 |
*/
|
849 |
private class AreaCoordinatesPanel extends JPanel { |
850 |
private final Rectangle DEFAULT_JBUTTON_GO_TO_AREA_RECTANGLE = new Rectangle(412, 5, 62, 51); // @jve:decl-index=0: |
851 |
private final int DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT = 20; |
852 |
private final int DEFAULT_COORDIANTE_LABEL_WIDTH = 20; |
853 |
private final int DEFAULT_TEXT_FIELDS_WIDTH = 132; |
854 |
private final int DEFAULT_X_LOCATION = 8; |
855 |
private final int DEFAULT_Y_LEFT_UP_CORNER_LOCATION = 6; |
856 |
private final int DEFAULT_COORDINATE_WIDTH = DEFAULT_COORDIANTE_LABEL_WIDTH + DEFAULT_TEXT_FIELDS_WIDTH + 10; |
857 |
private final int DEFAULT_COORDINATE_HEIGHT = 25; |
858 |
private final Dimension DEFAULT_JLABEL_VERTEX_DIMENSION = new Dimension(60, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT); // @jve:decl-index=0: |
859 |
private final int DEFAULT_XY_COORDINATES_WIDTH = 2 * DEFAULT_COORDINATE_WIDTH + DEFAULT_JLABEL_VERTEX_DIMENSION.width + 10 ; |
860 |
|
861 |
private final String JTEXTFIELD_V1X_NAME = "V1X"; |
862 |
private final String JTEXTFIELD_V1Y_NAME = "V1Y"; |
863 |
private final String JTEXTFIELD_V2X_NAME = "V2X"; |
864 |
private final String JTEXTFIELD_V2Y_NAME = "V2Y"; |
865 |
|
866 |
private final short JTEXTFIELD_V1X = 1; |
867 |
private final short JTEXTFIELD_V1Y = 2; |
868 |
private final short JTEXTFIELD_V2X = 3; |
869 |
private final short JTEXTFIELD_V2Y = 4; |
870 |
|
871 |
private JPanel jPanelVertex1 = null; |
872 |
private JPanel jPanelVertex2 = null; |
873 |
private JPanel jPanelVertex1X = null; |
874 |
private JPanel jPanelVertex1Y = null; |
875 |
private JPanel jPanelVertex2X = null; |
876 |
private JPanel jPanelVertex2Y = null; |
877 |
|
878 |
private JLabel jLabelVertex1 = null; |
879 |
private JLabel jLabelVertex2 = null; |
880 |
private JLabel jLabelVertex1X = null; |
881 |
private JLabel jLabelVertex1Y = null; |
882 |
private JLabel jLabelVertex2X = null; |
883 |
private JLabel jLabelVertex2Y = null; |
884 |
private JTextFieldWithSCP jTextFieldVertex1X = null; |
885 |
private JTextFieldWithSCP jTextFieldVertex1Y = null; |
886 |
private JTextFieldWithSCP jTextFieldVertex2X = null; |
887 |
private JTextFieldWithSCP jTextFieldVertex2Y = null; |
888 |
private JButton jButtonPreviewArea = null; |
889 |
private String last_Coordinates[]; |
890 |
private boolean hasChanged_v1X; |
891 |
private boolean hasChanged_v1Y; |
892 |
private boolean hasChanged_v2X; |
893 |
private boolean hasChanged_v2Y; |
894 |
private String previous_Coordinate_Value[]; |
895 |
|
896 |
private short current_coordinate_with_focus; |
897 |
|
898 |
private FocusListener focusListenerForCoordinateValidation = null; |
899 |
private KeyListener keyListenerForCoordinateValidation = null; |
900 |
|
901 |
/**
|
902 |
* This is the default constructor
|
903 |
*/
|
904 |
public AreaCoordinatesPanel() {
|
905 |
super();
|
906 |
initialize(); |
907 |
} |
908 |
|
909 |
/**
|
910 |
* This method initializes this
|
911 |
*
|
912 |
* @return void
|
913 |
*/
|
914 |
private void initialize() { |
915 |
this.setLayout(new GridBagLayout()); |
916 |
this.setBounds(DEFAULT_AREA_COORDINATES_PANEL_RECTANGLE);
|
917 |
this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1)); |
918 |
this.setToolTipText(PluginServices.getText(this, "select_by_vertexes_coordinates")); |
919 |
|
920 |
this.last_Coordinates = new String[4]; |
921 |
this.last_Coordinates[0] = ""; |
922 |
this.last_Coordinates[1] = ""; |
923 |
this.last_Coordinates[2] = ""; |
924 |
this.last_Coordinates[3] = ""; |
925 |
this.previous_Coordinate_Value = new String[4]; |
926 |
|
927 |
// By default no coordinates have changed
|
928 |
this.resetCoordinatesFlags();
|
929 |
|
930 |
GridBagConstraints gridBagConstraints = null; |
931 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
932 |
gridBagConstraints.gridx = 0;
|
933 |
gridBagConstraints.gridy = 0;
|
934 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
935 |
gridBagConstraints.weightx = 1.0;
|
936 |
this.add(getJPanelVertex1(), gridBagConstraints);
|
937 |
|
938 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
939 |
gridBagConstraints.gridx = 1;
|
940 |
gridBagConstraints.gridy = 0;
|
941 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
942 |
gridBagConstraints.weightx = 1.0;
|
943 |
this.add(getJPanelVertex2(), gridBagConstraints);
|
944 |
|
945 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
946 |
gridBagConstraints.gridx = 2;
|
947 |
gridBagConstraints.gridy = 0;
|
948 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
949 |
gridBagConstraints.weightx = 1.0;
|
950 |
this.add(getJButtonValidateArea(), gridBagConstraints);
|
951 |
} |
952 |
|
953 |
/**
|
954 |
* Returns the default width of this component
|
955 |
*
|
956 |
* @return The default width
|
957 |
*/
|
958 |
public int getDefaultWidth() { |
959 |
return DEFAULT_COORDINATE_WIDTH * 2; |
960 |
} |
961 |
|
962 |
/**
|
963 |
* Returns the default height of this component
|
964 |
*
|
965 |
* @return The default height
|
966 |
*/
|
967 |
public int getDefaultHeight() { |
968 |
return DEFAULT_COORDINATE_HEIGHT * 2; |
969 |
} |
970 |
|
971 |
/**
|
972 |
* Sets all flags about if a coordinate has change to false (haven't changed)
|
973 |
*/
|
974 |
private void resetCoordinatesFlags() { |
975 |
hasChanged_v1X = false;
|
976 |
hasChanged_v1Y = false;
|
977 |
hasChanged_v2X = false;
|
978 |
hasChanged_v2Y = false;
|
979 |
} |
980 |
|
981 |
/**last_Coordinated_that_Changed
|
982 |
* This method initializes jPanelVertex1
|
983 |
*
|
984 |
* @return javax.swing.JPanel
|
985 |
*/
|
986 |
private JPanel getJPanelVertex1() { |
987 |
if (jPanelVertex1 == null) { |
988 |
jPanelVertex1 = new JPanel(); |
989 |
jPanelVertex1.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT); |
990 |
jPanelVertex1.setLayout(new GridBagLayout()); |
991 |
|
992 |
GridBagConstraints gridBagConstraints = null; |
993 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
994 |
gridBagConstraints.gridx = 0;
|
995 |
gridBagConstraints.gridy = 0;
|
996 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
997 |
gridBagConstraints.weightx = 1.0;
|
998 |
jPanelVertex1.add(getJLabelVertex1(), gridBagConstraints); |
999 |
|
1000 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
1001 |
gridBagConstraints.gridx = 0;
|
1002 |
gridBagConstraints.gridy = 1;
|
1003 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
1004 |
gridBagConstraints.weightx = 1.0;
|
1005 |
jPanelVertex1.add(getJPanelVertex1X(), gridBagConstraints); |
1006 |
|
1007 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
1008 |
gridBagConstraints.gridx = 0;
|
1009 |
gridBagConstraints.gridy = 2;
|
1010 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
1011 |
gridBagConstraints.weightx = 1.0;
|
1012 |
jPanelVertex1.add(getJPanelVertex1Y(), gridBagConstraints); |
1013 |
} |
1014 |
|
1015 |
return jPanelVertex1;
|
1016 |
} |
1017 |
|
1018 |
/**
|
1019 |
* This method initializes jPanelVertex2
|
1020 |
*
|
1021 |
* @return javax.swing.JPanel
|
1022 |
*/
|
1023 |
private JPanel getJPanelVertex2() { |
1024 |
if (jPanelVertex2 == null) { |
1025 |
jPanelVertex2 = new JPanel(); |
1026 |
jPanelVertex2.setBounds(DEFAULT_X_LOCATION, DEFAULT_Y_LEFT_UP_CORNER_LOCATION + DEFAULT_COORDINATE_HEIGHT, DEFAULT_XY_COORDINATES_WIDTH, DEFAULT_COORDINATE_HEIGHT); |
1027 |
jPanelVertex2.setLayout(new GridBagLayout()); |
1028 |
|
1029 |
GridBagConstraints gridBagConstraints = null; |
1030 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
1031 |
gridBagConstraints.gridx = 0;
|
1032 |
gridBagConstraints.gridy = 0;
|
1033 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
1034 |
gridBagConstraints.weightx = 1.0;
|
1035 |
jPanelVertex2.add(getJLabelVertex2(), gridBagConstraints); |
1036 |
|
1037 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
1038 |
gridBagConstraints.gridx = 0;
|
1039 |
gridBagConstraints.gridy = 1;
|
1040 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
1041 |
gridBagConstraints.weightx = 1.0;
|
1042 |
jPanelVertex2.add(getJPanelVertex2X(), gridBagConstraints); |
1043 |
|
1044 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
1045 |
gridBagConstraints.gridx = 0;
|
1046 |
gridBagConstraints.gridy = 2;
|
1047 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
1048 |
gridBagConstraints.weightx = 1.0;
|
1049 |
jPanelVertex2.add(getJPanelVertex2Y(), gridBagConstraints); |
1050 |
} |
1051 |
|
1052 |
return jPanelVertex2;
|
1053 |
} |
1054 |
|
1055 |
/**
|
1056 |
* This method initializes jLabelVertex1
|
1057 |
*
|
1058 |
* @return javax.swing.JPanel
|
1059 |
*/
|
1060 |
private JLabel getJLabelVertex1() { |
1061 |
if (jLabelVertex1 == null) { |
1062 |
jLabelVertex1 = new JLabel(); |
1063 |
jLabelVertex1.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION); |
1064 |
jLabelVertex1.setToolTipText(PluginServices.getText(this, "coordinates_from_area_right_up_vertex")); |
1065 |
jLabelVertex1.setText(PluginServices.getText(this, "vertex") + " 1:"); |
1066 |
jLabelVertex1.setHorizontalAlignment(SwingConstants.LEFT);
|
1067 |
jLabelVertex1.setVerticalAlignment(SwingConstants.CENTER);
|
1068 |
jLabelVertex1.setForeground(new Color(0, 0, 255)); // Blue color for text |
1069 |
} |
1070 |
return jLabelVertex1;
|
1071 |
} |
1072 |
|
1073 |
/**
|
1074 |
* This method initializes jLabelVertex2
|
1075 |
*
|
1076 |
* @return javax.swing.JPanel
|
1077 |
*/
|
1078 |
private JLabel getJLabelVertex2() { |
1079 |
if (jLabelVertex2 == null) { |
1080 |
jLabelVertex2 = new JLabel(); |
1081 |
jLabelVertex2.setPreferredSize(DEFAULT_JLABEL_VERTEX_DIMENSION); |
1082 |
jLabelVertex2.setToolTipText(PluginServices.getText(this, "coordinates_from_area_left_bottom_vertex")); |
1083 |
jLabelVertex2.setText(PluginServices.getText(this, "vertex") + " 2:"); |
1084 |
jLabelVertex2.setHorizontalAlignment(SwingConstants.LEFT);
|
1085 |
jLabelVertex2.setVerticalAlignment(SwingConstants.CENTER);
|
1086 |
jLabelVertex2.setForeground(new Color(128, 64, 0)); // Brown color for text |
1087 |
} |
1088 |
return jLabelVertex2;
|
1089 |
} |
1090 |
|
1091 |
/**
|
1092 |
* This method initializes jPanelVertex1X
|
1093 |
*
|
1094 |
* @return javax.swing.JPanel
|
1095 |
*/
|
1096 |
private JPanel getJPanelVertex1X() { |
1097 |
if (jPanelVertex1X == null) { |
1098 |
jPanelVertex1X = new JPanel(); |
1099 |
jPanelVertex1X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT))); |
1100 |
jPanelVertex1X.setLayout(new GridBagLayout()); |
1101 |
jPanelVertex1X.add(getJLabelVertex1X(), null);
|
1102 |
jPanelVertex1X.add(getJTextFieldVertex1X(), null);
|
1103 |
} |
1104 |
return jPanelVertex1X;
|
1105 |
} |
1106 |
|
1107 |
/**
|
1108 |
* This method initializes jPanelVertex1Y
|
1109 |
*
|
1110 |
* @return javax.swing.JPanel
|
1111 |
*/
|
1112 |
private JPanel getJPanelVertex1Y() { |
1113 |
if (jPanelVertex1Y == null) { |
1114 |
jPanelVertex1Y = new JPanel(); |
1115 |
jPanelVertex1Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT))); |
1116 |
jPanelVertex1Y.setLayout(new GridBagLayout()); |
1117 |
jPanelVertex1Y.add(getJLabelVertex1Y(), null);
|
1118 |
jPanelVertex1Y.add(getJTextFieldVertex1Y(), null);
|
1119 |
} |
1120 |
return jPanelVertex1Y;
|
1121 |
} |
1122 |
|
1123 |
/**
|
1124 |
* This method initializes jPanelVertex2X
|
1125 |
*
|
1126 |
* @return javax.swing.JPanel
|
1127 |
*/
|
1128 |
private JPanel getJPanelVertex2X() { |
1129 |
if (jPanelVertex2X == null) { |
1130 |
jPanelVertex2X = new JPanel(); |
1131 |
jPanelVertex2X.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT))); |
1132 |
jPanelVertex2X.setLayout(new GridBagLayout()); |
1133 |
jPanelVertex2X.add(getJLabelVertex2X(), null);
|
1134 |
jPanelVertex2X.add(getJTextFieldVertex2X(), null);
|
1135 |
} |
1136 |
return jPanelVertex2X;
|
1137 |
} |
1138 |
|
1139 |
/**
|
1140 |
* This method initializes jPanelVertex2Y
|
1141 |
*
|
1142 |
* @return javax.swing.JPanel
|
1143 |
*/
|
1144 |
private JPanel getJPanelVertex2Y() { |
1145 |
if (jPanelVertex2Y == null) { |
1146 |
jPanelVertex2Y = new JPanel(); |
1147 |
jPanelVertex2Y.setPreferredSize(new Dimension(new Dimension(DEFAULT_COORDINATE_WIDTH, DEFAULT_COORDINATE_HEIGHT))); |
1148 |
jPanelVertex2Y.setLayout(new GridBagLayout()); |
1149 |
jPanelVertex2Y.add(getJLabelVertex2Y(), null);
|
1150 |
jPanelVertex2Y.add(getJTextFieldVertex2Y(), null);
|
1151 |
} |
1152 |
return jPanelVertex2Y;
|
1153 |
} |
1154 |
|
1155 |
/**
|
1156 |
* This method initializes jLabelVertex1X
|
1157 |
*
|
1158 |
* @return javax.swing.JLabel
|
1159 |
*/
|
1160 |
private JLabel getJLabelVertex1X() { |
1161 |
if (jLabelVertex1X == null) { |
1162 |
jLabelVertex1X = new JLabel(); |
1163 |
jLabelVertex1X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
|
1164 |
jLabelVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex")); |
1165 |
jLabelVertex1X.setText(PluginServices.getText(this, "x") + ":"); |
1166 |
jLabelVertex1X.setHorizontalAlignment(SwingConstants.CENTER);
|
1167 |
jLabelVertex1X.setVerticalAlignment(SwingConstants.CENTER);
|
1168 |
jLabelVertex1X.setForeground(new Color(0, 0, 255)); // Blue color for text |
1169 |
} |
1170 |
return jLabelVertex1X;
|
1171 |
} |
1172 |
|
1173 |
/**
|
1174 |
* This method initializes jLabelVertex2X
|
1175 |
*
|
1176 |
* @return javax.swing.JLabel
|
1177 |
*/
|
1178 |
private JLabel getJLabelVertex2X() { |
1179 |
if (jLabelVertex2X == null) { |
1180 |
jLabelVertex2X = new JLabel(); |
1181 |
jLabelVertex2X.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
|
1182 |
jLabelVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex")); |
1183 |
jLabelVertex2X.setText(PluginServices.getText(this, "x") + ":"); |
1184 |
jLabelVertex2X.setHorizontalAlignment(SwingConstants.CENTER);
|
1185 |
jLabelVertex2X.setVerticalAlignment(SwingConstants.CENTER);
|
1186 |
jLabelVertex2X.setForeground(new Color(128, 64, 0)); // Brown color for text |
1187 |
} |
1188 |
return jLabelVertex2X;
|
1189 |
} |
1190 |
|
1191 |
/**
|
1192 |
* This method initializes jLabelVertex1Y
|
1193 |
*
|
1194 |
* @return javax.swing.JLabel
|
1195 |
*/
|
1196 |
private JLabel getJLabelVertex1Y() { |
1197 |
if (jLabelVertex1Y == null) { |
1198 |
jLabelVertex1Y = new JLabel(); |
1199 |
jLabelVertex1Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
|
1200 |
jLabelVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex")); |
1201 |
jLabelVertex1Y.setText(PluginServices.getText(this, "y") + ":"); |
1202 |
jLabelVertex1Y.setHorizontalAlignment(SwingConstants.CENTER);
|
1203 |
jLabelVertex1Y.setVerticalAlignment(SwingConstants.CENTER);
|
1204 |
jLabelVertex1Y.setForeground(new Color(0, 0, 255)); // Blue color for text |
1205 |
} |
1206 |
return jLabelVertex1Y;
|
1207 |
} |
1208 |
|
1209 |
/**
|
1210 |
* This method initializes jLabelVertex2Y
|
1211 |
*
|
1212 |
* @return javax.swing.JLabel
|
1213 |
*/
|
1214 |
private JLabel getJLabelVertex2Y() { |
1215 |
if (jLabelVertex2Y == null) { |
1216 |
jLabelVertex2Y = new JLabel(); |
1217 |
jLabelVertex2Y.setPreferredSize(new java.awt.Dimension(DEFAULT_COORDIANTE_LABEL_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
|
1218 |
jLabelVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex")); |
1219 |
jLabelVertex2Y.setText(PluginServices.getText(this, "y") + ":"); |
1220 |
jLabelVertex2Y.setHorizontalAlignment(SwingConstants.CENTER);
|
1221 |
jLabelVertex2Y.setVerticalAlignment(SwingConstants.CENTER);
|
1222 |
jLabelVertex2Y.setForeground(new Color(128, 64, 0)); // Brown color for text |
1223 |
} |
1224 |
return jLabelVertex2Y;
|
1225 |
} |
1226 |
|
1227 |
/**
|
1228 |
* Returns a focus listener for validate the text of a JTextField when that component loses its focus
|
1229 |
*
|
1230 |
* @return java.awt.event.FocusListener
|
1231 |
*/
|
1232 |
private FocusListener getFocusListenerForCoordinateValidation() { |
1233 |
if (focusListenerForCoordinateValidation == null) { |
1234 |
focusListenerForCoordinateValidation = new FocusListener() { |
1235 |
public void focusGained(FocusEvent e) { |
1236 |
JTextField jTF = (JTextField)e.getSource(); |
1237 |
|
1238 |
// Stores which coordinate has gotten the focus
|
1239 |
if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) { |
1240 |
current_coordinate_with_focus = JTEXTFIELD_V1X; |
1241 |
return;
|
1242 |
} |
1243 |
|
1244 |
if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) { |
1245 |
current_coordinate_with_focus = JTEXTFIELD_V1Y; |
1246 |
return;
|
1247 |
} |
1248 |
|
1249 |
if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) { |
1250 |
current_coordinate_with_focus = JTEXTFIELD_V2X; |
1251 |
return;
|
1252 |
} |
1253 |
|
1254 |
if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) { |
1255 |
current_coordinate_with_focus = JTEXTFIELD_V2Y; |
1256 |
return;
|
1257 |
} |
1258 |
} |
1259 |
|
1260 |
public void focusLost(FocusEvent e) { |
1261 |
if (!getEnablingJCheckBox().isSelected())
|
1262 |
return;
|
1263 |
|
1264 |
JTextField jTF = (JTextField)e.getSource(); |
1265 |
|
1266 |
// If a coordinate has lost focus, is valid and has changed -> store the new value and set its related 'hasChanged' flag to true
|
1267 |
String text = jTF.getText();
|
1268 |
|
1269 |
if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) { |
1270 |
|
1271 |
if (text.compareTo(last_Coordinates[0]) != 0) { |
1272 |
hasChanged_v1X = true;
|
1273 |
} |
1274 |
|
1275 |
return;
|
1276 |
} |
1277 |
|
1278 |
if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) { |
1279 |
if (text.compareTo(last_Coordinates[1]) != 0) { |
1280 |
hasChanged_v1Y = true;
|
1281 |
} |
1282 |
return;
|
1283 |
} |
1284 |
|
1285 |
if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) { |
1286 |
if (text.compareTo(last_Coordinates[2]) != 0) { |
1287 |
hasChanged_v2X = true;
|
1288 |
} |
1289 |
return;
|
1290 |
} |
1291 |
|
1292 |
if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) { |
1293 |
if (text.compareTo(last_Coordinates[3]) != 0) { |
1294 |
hasChanged_v2Y = true;
|
1295 |
} |
1296 |
return;
|
1297 |
} |
1298 |
} |
1299 |
}; |
1300 |
} |
1301 |
|
1302 |
return focusListenerForCoordinateValidation;
|
1303 |
} |
1304 |
|
1305 |
private KeyListener getKeyListenerForCoordinateValidation() { |
1306 |
if (keyListenerForCoordinateValidation == null) { |
1307 |
keyListenerForCoordinateValidation = new KeyListener() { |
1308 |
|
1309 |
public void keyPressed(KeyEvent e) { |
1310 |
} |
1311 |
|
1312 |
public void keyReleased(KeyEvent e) { |
1313 |
validateCoordinate(current_coordinate_with_focus); |
1314 |
} |
1315 |
|
1316 |
public void keyTyped(KeyEvent e) { |
1317 |
} |
1318 |
}; |
1319 |
} |
1320 |
|
1321 |
return keyListenerForCoordinateValidation;
|
1322 |
} |
1323 |
|
1324 |
/**
|
1325 |
* This method initializes jTextFieldVertex1X
|
1326 |
*
|
1327 |
* @return JTextFieldWithSCP
|
1328 |
*/
|
1329 |
private JTextFieldWithSCP getJTextFieldVertex1X() {
|
1330 |
if (jTextFieldVertex1X == null) { |
1331 |
jTextFieldVertex1X = new JTextFieldWithSCP(""); |
1332 |
jTextFieldVertex1X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT)); |
1333 |
jTextFieldVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex")); |
1334 |
jTextFieldVertex1X.addFocusListener(getFocusListenerForCoordinateValidation()); |
1335 |
jTextFieldVertex1X.addKeyListener(getKeyListenerForCoordinateValidation()); |
1336 |
jTextFieldVertex1X.setName(JTEXTFIELD_V1X_NAME); |
1337 |
} |
1338 |
return jTextFieldVertex1X;
|
1339 |
} |
1340 |
|
1341 |
/**
|
1342 |
* This method initializes jTextFieldVertex1Y
|
1343 |
*
|
1344 |
* @return JTextFieldWithSCP
|
1345 |
*/
|
1346 |
private JTextFieldWithSCP getJTextFieldVertex1Y() {
|
1347 |
if (jTextFieldVertex1Y == null) { |
1348 |
jTextFieldVertex1Y = new JTextFieldWithSCP(""); |
1349 |
jTextFieldVertex1Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT)); |
1350 |
jTextFieldVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex")); |
1351 |
jTextFieldVertex1Y.addFocusListener(getFocusListenerForCoordinateValidation()); |
1352 |
jTextFieldVertex1Y.addKeyListener(getKeyListenerForCoordinateValidation()); |
1353 |
jTextFieldVertex1Y.setName(JTEXTFIELD_V1Y_NAME); |
1354 |
} |
1355 |
return jTextFieldVertex1Y;
|
1356 |
} |
1357 |
|
1358 |
/**
|
1359 |
* This method initializes jTextFieldVertex2X
|
1360 |
*
|
1361 |
* @return JTextFieldWithSCP
|
1362 |
*/
|
1363 |
private JTextFieldWithSCP getJTextFieldVertex2X() {
|
1364 |
if (jTextFieldVertex2X == null) { |
1365 |
jTextFieldVertex2X = new JTextFieldWithSCP(""); |
1366 |
jTextFieldVertex2X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT)); |
1367 |
jTextFieldVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex")); |
1368 |
jTextFieldVertex2X.addFocusListener(getFocusListenerForCoordinateValidation()); |
1369 |
jTextFieldVertex2X.addKeyListener(getKeyListenerForCoordinateValidation()); |
1370 |
jTextFieldVertex2X.setName(JTEXTFIELD_V2X_NAME); |
1371 |
} |
1372 |
return jTextFieldVertex2X;
|
1373 |
} |
1374 |
|
1375 |
/**
|
1376 |
* This method initializes jTextFieldVertex2Y
|
1377 |
*
|
1378 |
* @return JTextFieldWithSCP
|
1379 |
*/
|
1380 |
private JTextFieldWithSCP getJTextFieldVertex2Y() {
|
1381 |
if (jTextFieldVertex2Y == null) { |
1382 |
jTextFieldVertex2Y = new JTextFieldWithSCP(""); |
1383 |
jTextFieldVertex2Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT)); |
1384 |
jTextFieldVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex")); |
1385 |
jTextFieldVertex2Y.addFocusListener(getFocusListenerForCoordinateValidation()); |
1386 |
jTextFieldVertex2Y.addKeyListener(getKeyListenerForCoordinateValidation()); |
1387 |
jTextFieldVertex2Y.setName(JTEXTFIELD_V2Y_NAME); |
1388 |
} |
1389 |
return jTextFieldVertex2Y;
|
1390 |
} |
1391 |
|
1392 |
/**
|
1393 |
* Returns the double value of the text field V1X
|
1394 |
*
|
1395 |
* @return A double number type
|
1396 |
*/
|
1397 |
public double getDoubleValueOfJTextFieldV1X() { |
1398 |
return Double.parseDouble(getJTextFieldVertex1X().getText()); |
1399 |
} |
1400 |
|
1401 |
/**
|
1402 |
* Returns the double value of the text field V1Y
|
1403 |
*
|
1404 |
* @return A double number type
|
1405 |
*/
|
1406 |
public double getDoubleValueOfJTextFieldV1Y() { |
1407 |
return Double.parseDouble(getJTextFieldVertex1Y().getText()); |
1408 |
} |
1409 |
|
1410 |
/**
|
1411 |
* Returns the double value of the text field V2X
|
1412 |
*
|
1413 |
* @return A double number type
|
1414 |
*/
|
1415 |
public double getDoubleValueOfJTextFieldV2X() { |
1416 |
return Double.parseDouble(getJTextFieldVertex2X().getText()); |
1417 |
} |
1418 |
|
1419 |
/**
|
1420 |
* Returns the double value of the text field V2Y
|
1421 |
*
|
1422 |
* @return A double number type
|
1423 |
*/
|
1424 |
public double getDoubleValueOfJTextFieldV2Y() { |
1425 |
return Double.parseDouble(getJTextFieldVertex2Y().getText()); |
1426 |
} |
1427 |
|
1428 |
/**
|
1429 |
* Retuns the double value of the last text field V1X value
|
1430 |
*
|
1431 |
* @return A double number type
|
1432 |
*/
|
1433 |
public double getDoubleValueOfLastJTextFieldV1XValue() { |
1434 |
return Double.parseDouble(last_Coordinates[0]); |
1435 |
} |
1436 |
|
1437 |
/**
|
1438 |
* Retuns the double value of the last text field V1Y value
|
1439 |
*
|
1440 |
* @return A double number type
|
1441 |
*/
|
1442 |
public double getDoubleValueOfLastJTextFieldV1YValue() { |
1443 |
return Double.parseDouble(last_Coordinates[1]); |
1444 |
} |
1445 |
|
1446 |
/**
|
1447 |
* Retuns the double value of the last text field V2X value
|
1448 |
*
|
1449 |
* @return A double number type
|
1450 |
*/
|
1451 |
public double getDoubleValueOfLastJTextFieldV2XValue() { |
1452 |
return Double.parseDouble(last_Coordinates[2]); |
1453 |
} |
1454 |
|
1455 |
/**
|
1456 |
* Retuns the double value of the last text field V2Y value
|
1457 |
*
|
1458 |
* @return A double number type
|
1459 |
*/
|
1460 |
public double getDoubleValueOfLastJTextFieldV2YValue() { |
1461 |
return Double.parseDouble(last_Coordinates[3]); |
1462 |
} |
1463 |
|
1464 |
/**
|
1465 |
* Validates the coordinate of a JTextField: returns true if it's valid; else returns false
|
1466 |
*
|
1467 |
* @param coordinate javax.swing.JTextField
|
1468 |
* @return A boolean value
|
1469 |
*/
|
1470 |
private boolean validateCoordinate(JTextField coordinate) { |
1471 |
if (coordinate != null) { |
1472 |
// If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text
|
1473 |
if ((coordinate.getText().compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(coordinate.getText()))) { |
1474 |
|
1475 |
return false; |
1476 |
} |
1477 |
else {
|
1478 |
return true; |
1479 |
} |
1480 |
} |
1481 |
|
1482 |
return false; // If coordinate is null |
1483 |
} |
1484 |
|
1485 |
/**
|
1486 |
* Validates the coordinate of a JTextField: returns true if it's valid; else returns false
|
1487 |
*
|
1488 |
* @param coordinate javax.swing.JTextField
|
1489 |
* @return A boolean value
|
1490 |
*/
|
1491 |
private boolean validateCoordinate(int coordinate_ID) { |
1492 |
JTextField coordinate = null; |
1493 |
String text;
|
1494 |
|
1495 |
switch (coordinate_ID) {
|
1496 |
case JTEXTFIELD_V1X:
|
1497 |
coordinate = getJTextFieldVertex1X(); |
1498 |
text = coordinate.getText(); |
1499 |
|
1500 |
if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) { |
1501 |
JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE); |
1502 |
coordinate.setText(previous_Coordinate_Value[0]); // Set last value |
1503 |
return false; |
1504 |
} |
1505 |
else {
|
1506 |
previous_Coordinate_Value[0] = text;
|
1507 |
return true; |
1508 |
} |
1509 |
case JTEXTFIELD_V1Y:
|
1510 |
coordinate = getJTextFieldVertex1Y(); |
1511 |
text = coordinate.getText(); |
1512 |
|
1513 |
if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) { |
1514 |
JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE); |
1515 |
coordinate.setText(previous_Coordinate_Value[1]); // Set last value |
1516 |
return false; |
1517 |
} |
1518 |
else {
|
1519 |
previous_Coordinate_Value[1] = text;
|
1520 |
return true; |
1521 |
} |
1522 |
case JTEXTFIELD_V2X:
|
1523 |
coordinate = getJTextFieldVertex2X(); |
1524 |
text = coordinate.getText(); |
1525 |
|
1526 |
if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) { |
1527 |
JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE); |
1528 |
coordinate.setText(previous_Coordinate_Value[2]); // Set last value |
1529 |
return false; |
1530 |
} |
1531 |
else {
|
1532 |
previous_Coordinate_Value[2] = text;
|
1533 |
return true; |
1534 |
} |
1535 |
case JTEXTFIELD_V2Y:
|
1536 |
coordinate = getJTextFieldVertex2Y(); |
1537 |
text = coordinate.getText(); |
1538 |
|
1539 |
if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) { |
1540 |
JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE); |
1541 |
coordinate.setText(previous_Coordinate_Value[3]); // Set last value |
1542 |
return false; |
1543 |
} |
1544 |
else {
|
1545 |
previous_Coordinate_Value[3] = text;
|
1546 |
return true; |
1547 |
} |
1548 |
default:
|
1549 |
return true; // Avoid problems |
1550 |
} |
1551 |
} |
1552 |
|
1553 |
/**
|
1554 |
* This method initializes jButtonPreviewArea
|
1555 |
*
|
1556 |
* @return javax.swing.JButton
|
1557 |
*/
|
1558 |
private JButton getJButtonValidateArea() { |
1559 |
if (jButtonPreviewArea == null) { |
1560 |
jButtonPreviewArea = new JButton(); |
1561 |
jButtonPreviewArea.setBounds(DEFAULT_JBUTTON_GO_TO_AREA_RECTANGLE); |
1562 |
// jButtonPreviewArea.setToolTipText(PluginServices.getText(this, "to_previsualize"));
|
1563 |
jButtonPreviewArea.setToolTipText(PluginServices.getText(this, "to_validate_coodinates")); |
1564 |
jButtonPreviewArea.setVerticalTextPosition(AbstractButton.CENTER);
|
1565 |
jButtonPreviewArea.setHorizontalTextPosition(AbstractButton.CENTER);
|
1566 |
jButtonPreviewArea.setIcon(PluginServices.getIconTheme().get("wfs-properties-validate-area"));
|
1567 |
jButtonPreviewArea.addMouseListener(new MouseAdapter() { |
1568 |
public void mouseClicked(MouseEvent e) { |
1569 |
validVertexes(); |
1570 |
} |
1571 |
}); |
1572 |
} |
1573 |
return jButtonPreviewArea;
|
1574 |
} |
1575 |
|
1576 |
/**
|
1577 |
* Calculates the new rectangle using the coordinates of the text fields
|
1578 |
*
|
1579 |
* @return java.awt.geom.Rectangle2D
|
1580 |
*/
|
1581 |
private Rectangle2D getNewRectangleByCoordinates() { |
1582 |
return new Rectangle2D.Double(getDoubleValueOfJTextFieldV2X(), getDoubleValueOfJTextFieldV2Y(), getDoubleValueOfJTextFieldV1X() - getDoubleValueOfJTextFieldV2X(), getDoubleValueOfJTextFieldV1Y() - getDoubleValueOfJTextFieldV2Y()); |
1583 |
} |
1584 |
|
1585 |
/**
|
1586 |
* Restores the value of all text fields with coordinates modified to their last value
|
1587 |
*/
|
1588 |
private void restoreAllModifiedCoordinates() { |
1589 |
if (hasChanged_v1X) {
|
1590 |
getJTextFieldVertex1X().setText(last_Coordinates[0]);
|
1591 |
hasChanged_v1X = false;
|
1592 |
} |
1593 |
|
1594 |
if (hasChanged_v1Y) {
|
1595 |
getJTextFieldVertex1Y().setText(last_Coordinates[1]);
|
1596 |
hasChanged_v1Y = false;
|
1597 |
} |
1598 |
|
1599 |
if (hasChanged_v2X) {
|
1600 |
getJTextFieldVertex2X().setText(last_Coordinates[2]);
|
1601 |
hasChanged_v2X = false;
|
1602 |
} |
1603 |
|
1604 |
if (hasChanged_v2Y) {
|
1605 |
getJTextFieldVertex2Y().setText(last_Coordinates[3]);
|
1606 |
hasChanged_v2Y = false;
|
1607 |
} |
1608 |
} |
1609 |
|
1610 |
/**
|
1611 |
* Enables or disables all inner JTextField
|
1612 |
*
|
1613 |
* @param b A boolean value
|
1614 |
*/
|
1615 |
public void setAllTextFieldsEnabled(boolean b) { |
1616 |
getJTextFieldVertex1X().setEnabled(b); |
1617 |
getJTextFieldVertex1Y().setEnabled(b); |
1618 |
getJTextFieldVertex2X().setEnabled(b); |
1619 |
getJTextFieldVertex2Y().setEnabled(b); |
1620 |
} |
1621 |
|
1622 |
/**
|
1623 |
* Sets the extent into the text fields
|
1624 |
*
|
1625 |
* @param envelope java.awt.geom.Rectangle2D
|
1626 |
*/
|
1627 |
public void updateCoordinates(Envelope envelope){ |
1628 |
getJTextFieldVertex1X().setText(String.valueOf(envelope.getMaximum(0))); |
1629 |
last_Coordinates[0] = getJTextFieldVertex1X().getText();
|
1630 |
previous_Coordinate_Value[0] = last_Coordinates[0]; |
1631 |
|
1632 |
getJTextFieldVertex1Y().setText(String.valueOf(envelope.getMaximum(1))); |
1633 |
last_Coordinates[1] = getJTextFieldVertex1Y().getText();
|
1634 |
previous_Coordinate_Value[1] = last_Coordinates[1]; |
1635 |
|
1636 |
getJTextFieldVertex2X().setText(String.valueOf(envelope.getMinimum(0))); |
1637 |
last_Coordinates[2] = getJTextFieldVertex2X().getText();
|
1638 |
previous_Coordinate_Value[2] = last_Coordinates[2]; |
1639 |
|
1640 |
getJTextFieldVertex2Y().setText(String.valueOf(envelope.getMinimum(1))); |
1641 |
last_Coordinates[3] = getJTextFieldVertex2Y().getText();
|
1642 |
previous_Coordinate_Value[3] = last_Coordinates[3]; |
1643 |
|
1644 |
resetCoordinatesFlags(); |
1645 |
} |
1646 |
|
1647 |
/**
|
1648 |
* Changes the color of all coordinates text fields to <code>c</code>.
|
1649 |
*
|
1650 |
* @param c the new background color
|
1651 |
*/
|
1652 |
private void setBackGroundColorToCoordinatesFields(Color c) { |
1653 |
getJTextFieldVertex1X().setBackground(c); |
1654 |
getJTextFieldVertex1Y().setBackground(c); |
1655 |
getJTextFieldVertex2X().setBackground(c); |
1656 |
getJTextFieldVertex2Y().setBackground(c); |
1657 |
} |
1658 |
|
1659 |
/**
|
1660 |
* Validates all coordinates of both vertexes separately
|
1661 |
*
|
1662 |
* @return A ValidationInfo object reference
|
1663 |
*/
|
1664 |
private ValidationInfo validVertexesCoordinates() {
|
1665 |
String infoPrefix = null, infoSufix = null; |
1666 |
|
1667 |
if (! validateCoordinate(getJTextFieldVertex1X())) {
|
1668 |
if (infoSufix == null) { |
1669 |
infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": "; |
1670 |
infoSufix = PluginServices.getText(this, "v1x"); |
1671 |
} |
1672 |
getJTextFieldVertex1X().setBackground(Color.RED);
|
1673 |
} |
1674 |
|
1675 |
if (! validateCoordinate(getJTextFieldVertex1Y())) {
|
1676 |
if (infoSufix == null) { |
1677 |
infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": "; |
1678 |
infoSufix = PluginServices.getText(this, "v1y"); |
1679 |
} |
1680 |
else {
|
1681 |
infoPrefix = PluginServices.getText(this, "invalid_coordinates") + ": "; |
1682 |
infoSufix += ", " + PluginServices.getText(this, "v1y"); |
1683 |
} |
1684 |
|
1685 |
getJTextFieldVertex1Y().setBackground(Color.RED);
|
1686 |
} |
1687 |
|
1688 |
if (! validateCoordinate(getJTextFieldVertex2X())) {
|
1689 |
if (infoSufix == null) { |
1690 |
infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": "; |
1691 |
infoSufix = PluginServices.getText(this, "v2x"); |
1692 |
} |
1693 |
else {
|
1694 |
infoPrefix = PluginServices.getText(this, "invalid_coordinates") + ": "; |
1695 |
infoSufix += ", " + PluginServices.getText(this, "v2x"); |
1696 |
} |
1697 |
|
1698 |
getJTextFieldVertex2X().setBackground(Color.RED);
|
1699 |
} |
1700 |
|
1701 |
if (! validateCoordinate(getJTextFieldVertex2Y())) {
|
1702 |
if (infoSufix == null) { |
1703 |
infoPrefix = PluginServices.getText(this, "invalid_coordinate") + ": "; |
1704 |
infoSufix = PluginServices.getText(this, "v2y"); |
1705 |
} |
1706 |
else {
|
1707 |
infoPrefix = PluginServices.getText(this, "invalid_coordinates") + ": "; |
1708 |
infoSufix += ", " + PluginServices.getText(this, "v2y"); |
1709 |
} |
1710 |
|
1711 |
getJTextFieldVertex2Y().setBackground(Color.RED);
|
1712 |
} |
1713 |
|
1714 |
if (infoPrefix != null) |
1715 |
return new ValidationInfo(false, infoPrefix + infoSufix); |
1716 |
|
1717 |
// If arrives here, all coordinates are valid
|
1718 |
setBackGroundColorToCoordinatesFields(Color.GREEN);
|
1719 |
return new ValidationInfo(true, ""); |
1720 |
} |
1721 |
|
1722 |
/**
|
1723 |
* Validates that Vertex1 is in the right-up corner and the Vertex2 in the left-down corner of the area/rectangle <br>
|
1724 |
* (It's supposed that coordinates of the vertexes are valid) <br>
|
1725 |
* (It's supposed that going to right or up, the coordinate value increases)
|
1726 |
*
|
1727 |
* @return A ValidationInfo object reference
|
1728 |
*/
|
1729 |
private ValidationInfo validVertexesPositions() {
|
1730 |
String infoPrefix = null, infoSufix = null; |
1731 |
|
1732 |
// Check if no coordinate it's defined
|
1733 |
if (getJTextFieldVertex1X().getText().compareTo("") == 0) { |
1734 |
if (infoSufix == null) { |
1735 |
infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": "; |
1736 |
infoSufix = PluginServices.getText(this, "v1x"); |
1737 |
} |
1738 |
|
1739 |
getJTextFieldVertex1X().setBackground(Color.RED);
|
1740 |
} |
1741 |
|
1742 |
if (getJTextFieldVertex1Y().getText().compareTo("") == 0) { |
1743 |
if (infoSufix == null) { |
1744 |
infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": "; |
1745 |
infoSufix = PluginServices.getText(this, "v1y"); |
1746 |
} |
1747 |
else {
|
1748 |
infoPrefix = PluginServices.getText(this, "undefined_coordinates") + ": "; |
1749 |
infoSufix += ", " + PluginServices.getText(this, "v1y"); |
1750 |
} |
1751 |
|
1752 |
getJTextFieldVertex1Y().setBackground(Color.RED);
|
1753 |
// return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v1y"));
|
1754 |
} |
1755 |
|
1756 |
if (getJTextFieldVertex2X().getText().compareTo("") == 0) { |
1757 |
if (infoSufix == null) { |
1758 |
infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": "; |
1759 |
infoSufix = PluginServices.getText(this, "v2x"); |
1760 |
} |
1761 |
else {
|
1762 |
infoPrefix = PluginServices.getText(this, "undefined_coordinates") + ": "; |
1763 |
infoSufix += ", " + PluginServices.getText(this, "v2x"); |
1764 |
} |
1765 |
|
1766 |
getJTextFieldVertex2X().setBackground(Color.RED);
|
1767 |
// return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v2x"));
|
1768 |
} |
1769 |
|
1770 |
if (getJTextFieldVertex2Y().getText().compareTo("") == 0) { |
1771 |
if (infoSufix == null) { |
1772 |
infoPrefix = PluginServices.getText(this, "undefined_coordinate") + ": "; |
1773 |
infoSufix = PluginServices.getText(this, "v2y"); |
1774 |
} |
1775 |
else {
|
1776 |
infoPrefix = PluginServices.getText(this, "undefined_coordinates") + ": "; |
1777 |
infoSufix += ", " + PluginServices.getText(this, "v2y"); |
1778 |
} |
1779 |
|
1780 |
getJTextFieldVertex2Y().setBackground(Color.RED);
|
1781 |
// return new ValidationInfo(false, PluginServices.getText(this, "undefined_coordinate") + ": " + PluginServices.getText(this, "v2y"));
|
1782 |
} |
1783 |
|
1784 |
if (infoPrefix != null) |
1785 |
return new ValidationInfo(false, infoPrefix + infoSufix); |
1786 |
|
1787 |
// Check if the vertex V1 is in the right-up corner and the vertex V2 is in the left-down corner
|
1788 |
if (getDoubleValueOfJTextFieldV1X() < getDoubleValueOfJTextFieldV2X()) {
|
1789 |
getJTextFieldVertex1X().setBackground(Color.RED);
|
1790 |
getJTextFieldVertex2X().setBackground(Color.RED);
|
1791 |
return new ValidationInfo(false, PluginServices.getText(this, "v1x") + " < " + PluginServices.getText(this, "v2x")); |
1792 |
} |
1793 |
|
1794 |
if (getDoubleValueOfJTextFieldV1Y() < getDoubleValueOfJTextFieldV2Y()) {
|
1795 |
getJTextFieldVertex1Y().setBackground(Color.RED);
|
1796 |
getJTextFieldVertex2Y().setBackground(Color.RED);
|
1797 |
return new ValidationInfo(false, PluginServices.getText(this, "v1y") + " < " + PluginServices.getText(this, "v2y")); |
1798 |
} |
1799 |
|
1800 |
// If arrives here -> vertexes positions are valid
|
1801 |
setBackGroundColorToCoordinatesFields(Color.GREEN);
|
1802 |
return new ValidationInfo(true, ""); |
1803 |
} |
1804 |
|
1805 |
/**
|
1806 |
* Validate each coordinate of each vertex and the position of the vertexes
|
1807 |
*
|
1808 |
* @return A boolean value
|
1809 |
*/
|
1810 |
public boolean validVertexes() { |
1811 |
ValidationInfo v1 = validVertexesCoordinates(); |
1812 |
|
1813 |
if (!v1.isValid()) {
|
1814 |
|
1815 |
// Notify to user that no filter area will be applied
|
1816 |
JOptionPane.showMessageDialog(null, PluginServices.getText(null, PluginServices.getText(this, "invalid_coordinates") + ": " + v1.getMessage()), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE); |
1817 |
|
1818 |
// Restore the previous valid extent
|
1819 |
if (previousExtentValids.hasPrevious()) {
|
1820 |
Rectangle2D previousExtent = previousExtentValids.removePrev();
|
1821 |
setCoordinates(previousExtent); |
1822 |
|
1823 |
if (!previousExtentValids.hasPrevious()) {
|
1824 |
setApplicable(false);
|
1825 |
} |
1826 |
|
1827 |
previousExtentValids.put(previousExtent); |
1828 |
} |
1829 |
|
1830 |
return false; |
1831 |
} |
1832 |
else {
|
1833 |
ValidationInfo v2 = validVertexesPositions(); |
1834 |
if (!v2.isValid()) {
|
1835 |
// setApplicable(false);
|
1836 |
|
1837 |
// Notify to user that no filter area will be applied
|
1838 |
JOptionPane.showMessageDialog(null, PluginServices.getText(null, PluginServices.getText(this, "invalid_coordinates") + ": " + v2.getMessage()), PluginServices.getText(null, "warning"), JOptionPane.WARNING_MESSAGE); |
1839 |
|
1840 |
// Restore the previous valid extent
|
1841 |
if (previousExtentValids.hasPrevious()) {
|
1842 |
Rectangle2D previousExtent = previousExtentValids.removePrev();
|
1843 |
setCoordinates(previousExtent); |
1844 |
|
1845 |
if (!previousExtentValids.hasPrevious()) {
|
1846 |
setApplicable(false);
|
1847 |
} |
1848 |
|
1849 |
previousExtentValids.put(previousExtent); |
1850 |
} |
1851 |
|
1852 |
return false; |
1853 |
} |
1854 |
else {
|
1855 |
// Once has been validated -> allow apply with the new extent, and save it
|
1856 |
if (previousExtentValids.hasPrevious()) {
|
1857 |
Rectangle2D previousExtent = previousExtentValids.removePrev();
|
1858 |
if (! areEqual(previousExtent, getExtent())) {
|
1859 |
previousExtentValids.put(previousExtent); |
1860 |
previousExtentValids.put(getExtent()); |
1861 |
setApplicable(true);
|
1862 |
} |
1863 |
else {
|
1864 |
previousExtentValids.put(previousExtent); |
1865 |
} |
1866 |
} |
1867 |
else {
|
1868 |
previousExtentValids.put(getExtent()); |
1869 |
setApplicable(true);
|
1870 |
} |
1871 |
|
1872 |
return true; |
1873 |
} |
1874 |
} |
1875 |
} |
1876 |
|
1877 |
/**
|
1878 |
* <p>Compares two bi-dimensional rectangles, and returns <code>true</code> if both are equals.</p>
|
1879 |
*
|
1880 |
* @param rect1 first rectangle 2D to compare
|
1881 |
* @param rect2 second rectangle 2D to compare
|
1882 |
*
|
1883 |
* @return <code>true</code> if both are equals; otherwise <code>false</code>
|
1884 |
*/
|
1885 |
private boolean areEqual(Rectangle2D rect1, Rectangle2D rect2) { |
1886 |
return ((rect1.getX() == rect2.getX()) && (rect1.getY() == rect2.getY()) &&
|
1887 |
(rect1.getWidth() == rect2.getWidth()) && (rect1.getHeight() == rect2.getHeight())); |
1888 |
} |
1889 |
|
1890 |
/**
|
1891 |
* Gets the extent (rectangle) represented by the values of the coordinate text fields
|
1892 |
*
|
1893 |
* @return java.awt.geom.Rectangle2D
|
1894 |
*/
|
1895 |
public Rectangle2D getExtent() { |
1896 |
double v1x = getDoubleValueOfJTextFieldV1X();
|
1897 |
double v1y = getDoubleValueOfJTextFieldV1Y();
|
1898 |
double v2x = getDoubleValueOfJTextFieldV2X();
|
1899 |
double v2y = getDoubleValueOfJTextFieldV2Y();
|
1900 |
|
1901 |
return new Rectangle2D.Double(v2x, v2y, (v1x - v2x), (v1y - v2y)); |
1902 |
} |
1903 |
|
1904 |
public Surface getSurface() throws CreateGeometryException { |
1905 |
double v1x = getDoubleValueOfJTextFieldV1X();
|
1906 |
double v1y = getDoubleValueOfJTextFieldV1Y();
|
1907 |
double v2x = getDoubleValueOfJTextFieldV2X();
|
1908 |
double v2y = getDoubleValueOfJTextFieldV2Y();
|
1909 |
|
1910 |
Surface surface = (Surface)geometryManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
1911 |
surface.addMoveToVertex(geometryManager.createPoint(v1x, v1y, SUBTYPES.GEOM2D)); |
1912 |
surface.addVertex(geometryManager.createPoint(v1x, v2y, SUBTYPES.GEOM2D)); |
1913 |
surface.addVertex(geometryManager.createPoint(v2x, v2y, SUBTYPES.GEOM2D)); |
1914 |
surface.addVertex(geometryManager.createPoint(v2x, v1y, SUBTYPES.GEOM2D)); |
1915 |
surface.closePrimitive(); |
1916 |
|
1917 |
return surface;
|
1918 |
} |
1919 |
|
1920 |
public void setSurface(Surface surface){ |
1921 |
Envelope envelope = surface.getEnvelope(); |
1922 |
updateCoordinates(envelope); |
1923 |
} |
1924 |
|
1925 |
/**
|
1926 |
* Returns true if there is some coordinate text field with data; else returns false
|
1927 |
*
|
1928 |
* @return A boolean value
|
1929 |
*/
|
1930 |
public boolean areThereSomeCoordinatesWritten() { |
1931 |
return ((getJTextFieldVertex1X().getText().compareTo("") != 0) | (getJTextFieldVertex1Y().getText().compareTo("") != 0) | (getJTextFieldVertex2X().getText().compareTo("") != 0) | (getJTextFieldVertex2Y().getText().compareTo("") != 0)); |
1932 |
} |
1933 |
|
1934 |
/**
|
1935 |
* Returns true if all coordinate text fields are undefined (without values)
|
1936 |
*
|
1937 |
* @return A boolean value
|
1938 |
*/
|
1939 |
public boolean areAllCoordinatesUndefined() { |
1940 |
return ((getJTextFieldVertex1X().getText().compareTo("") == 0) & (getJTextFieldVertex1Y().getText().compareTo("") == 0) & (getJTextFieldVertex2X().getText().compareTo("") == 0) & (getJTextFieldVertex2Y().getText().compareTo("") == 0)); |
1941 |
} |
1942 |
|
1943 |
|
1944 |
/**
|
1945 |
* Returns true if there is some coordinate undefined (without values)
|
1946 |
*
|
1947 |
* @return A boolean value
|
1948 |
*/
|
1949 |
public boolean isThereAnyCoordinateUndefined() { |
1950 |
return ((getJTextFieldVertex1X().getText().compareTo("") == 0) | (getJTextFieldVertex1Y().getText().compareTo("") == 0) | (getJTextFieldVertex2X().getText().compareTo("") == 0) | (getJTextFieldVertex2Y().getText().compareTo("") == 0)); |
1951 |
} |
1952 |
} |
1953 |
|
1954 |
/**
|
1955 |
* This class is a MapControl JComponent that has visual information and allows user interact with some tools and view the results
|
1956 |
*
|
1957 |
* @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
|
1958 |
*/
|
1959 |
private class SelectableMapControlAreaPanel extends MapControl { |
1960 |
private MouseListener[] mouseListeners; |
1961 |
private MouseWheelListener[] mouseWheelListeners; |
1962 |
private MouseMotionListener[] mouseMotionListeners; |
1963 |
|
1964 |
/**
|
1965 |
* Default constructor
|
1966 |
*/
|
1967 |
public SelectableMapControlAreaPanel() {
|
1968 |
super();
|
1969 |
initialize(); |
1970 |
} |
1971 |
|
1972 |
/**
|
1973 |
* This method initializes this component
|
1974 |
*/
|
1975 |
public void initialize() { |
1976 |
/* Sets Bounds of this graphical component */
|
1977 |
this.setBounds(DEFAULT_AREA_MAPCONTROL_PANEL_RECTANGLE);
|
1978 |
|
1979 |
/* Sets border to this graphical component */
|
1980 |
this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1)); |
1981 |
|
1982 |
MapContext mp = ((AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext(); |
1983 |
|
1984 |
this.setMapContext(mp.cloneFMap());
|
1985 |
ViewPort vP = this.getViewPort();
|
1986 |
|
1987 |
// We will use the adjusted extent because increases the usability
|
1988 |
Envelope envelope = vP.getAdjustedExtent(); |
1989 |
|
1990 |
if (envelope != null) { |
1991 |
vP.refreshExtent(); |
1992 |
getCoordinatesPanel().updateCoordinates(envelope); |
1993 |
} |
1994 |
|
1995 |
/* Adds listeners to this MapControl */
|
1996 |
this.addToolsListeners();
|
1997 |
|
1998 |
/* Sets default tool */
|
1999 |
this.setTool(PAN_TOOL);
|
2000 |
} |
2001 |
|
2002 |
/**
|
2003 |
* Refresh the active view
|
2004 |
*/
|
2005 |
public void refreshWithTheActiveView() { |
2006 |
MapContext mp = ((AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext(); |
2007 |
this.setMapContext(mp.cloneFMap());
|
2008 |
ViewPort vP = this.getViewPort();
|
2009 |
|
2010 |
// We will use the adjusted extent because increases the usability
|
2011 |
Envelope envelope = vP.getAdjustedExtent(); |
2012 |
// Rectangle2D r2D = vP.getExtent();
|
2013 |
|
2014 |
if (envelope != null) { |
2015 |
vP.refreshExtent(); |
2016 |
getCoordinatesPanel().updateCoordinates(envelope); |
2017 |
} |
2018 |
} |
2019 |
|
2020 |
/**
|
2021 |
* Adds listeners that allows user interact with it's mouse over this component and that represents different tools
|
2022 |
*/
|
2023 |
private void addToolsListeners() { |
2024 |
// MOVEMENT EVENTS LISTENER: sets mouse coordinates to the status bar
|
2025 |
StatusBarListener sbl = new StatusBarListener(this); |
2026 |
|
2027 |
// ZOOM OUT (Presses on the map and it will be centered showing a bigger area)
|
2028 |
// Only pressing, not selecting a rectangle area
|
2029 |
ZoomOutListener zol = new ZoomOutListener(this); |
2030 |
this.addBehavior(ZOOM_OUT_TOOL, new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)}); |
2031 |
|
2032 |
// ZOOM IN (Using a Rectangle or a simple mouse click)
|
2033 |
ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(this); |
2034 |
ZoomInListener zil = new ZoomInListener(this); |
2035 |
this.addBehavior(ZOOM_IN_TOOL, new Behavior[]{new RectangleBehavior(zil), |
2036 |
new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
2037 |
|
2038 |
// PAN
|
2039 |
PanListener pl = new PanListener(this); |
2040 |
this.addBehavior(PAN_TOOL, new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)}); |
2041 |
|
2042 |
// MEASURE DISTANCES
|
2043 |
MeasureListener mli = new MeasureListener(this); |
2044 |
this.addBehavior(MEASURE_DISTANCES_TOOL, new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)}); |
2045 |
|
2046 |
// MEASURE AREA
|
2047 |
AreaListener ali = new AreaListener(this); |
2048 |
this.addBehavior(MEASURE_AREA_TOOL, new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)}); |
2049 |
|
2050 |
this.getViewPort().addViewPortListener(new ViewPortListener() { |
2051 |
public void extentChanged(ExtentEvent e) { |
2052 |
if (!getEnablingJCheckBox().isSelected())
|
2053 |
return;
|
2054 |
|
2055 |
if (getMapContext().getViewPort().getEnvelopes().hasPrevious()) {
|
2056 |
// We will use the adjusted extent because increases the usability
|
2057 |
Envelope envelope = getViewPort().getAdjustedEnvelope(); |
2058 |
|
2059 |
if (envelope != null) { |
2060 |
getCoordinatesPanel().updateCoordinates(envelope); |
2061 |
} |
2062 |
|
2063 |
getJButtonZoomPrevious().setEnabled(true);
|
2064 |
getJButtonUndo().setEnabled(true);
|
2065 |
} |
2066 |
else {
|
2067 |
getJButtonZoomPrevious().setEnabled(false);
|
2068 |
getJButtonUndo().setEnabled(false);
|
2069 |
} |
2070 |
} |
2071 |
|
2072 |
public void backColorChanged(ColorEvent e) { |
2073 |
} |
2074 |
|
2075 |
public void projectionChanged(ProjectionEvent e) { |
2076 |
} |
2077 |
|
2078 |
}); |
2079 |
} |
2080 |
|
2081 |
/*
|
2082 |
* (non-Javadoc)
|
2083 |
* @see java.awt.Component#setEnabled(boolean)
|
2084 |
*/
|
2085 |
public void setEnabled(boolean b) { |
2086 |
super.setEnabled(b);
|
2087 |
|
2088 |
if (b)
|
2089 |
enableAllMouseListeners(); |
2090 |
else
|
2091 |
disableAllMouseListeners(); |
2092 |
} |
2093 |
|
2094 |
/**
|
2095 |
* Disables all mouse listeners
|
2096 |
*/
|
2097 |
public void disableAllMouseListeners() { |
2098 |
int i;
|
2099 |
|
2100 |
// 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
|
2101 |
// are referenciated by this component or by the private attribute 'mouseListeners')
|
2102 |
|
2103 |
// Mouse Button Listeners
|
2104 |
if (mouseListeners == null) { |
2105 |
mouseListeners = this.getMouseListeners();
|
2106 |
|
2107 |
for (i = 0; i < mouseListeners.length; i++) { |
2108 |
removeMouseListener(mouseListeners[i]); |
2109 |
} |
2110 |
} |
2111 |
|
2112 |
// Mouse Wheel Listeners
|
2113 |
if (mouseWheelListeners == null) { |
2114 |
mouseWheelListeners = this.getMouseWheelListeners();
|
2115 |
|
2116 |
for (i = 0; i < mouseWheelListeners.length; i++) { |
2117 |
removeMouseWheelListener(mouseWheelListeners[i]); |
2118 |
} |
2119 |
} |
2120 |
|
2121 |
// Mouse motion listeners
|
2122 |
if (mouseMotionListeners == null) { |
2123 |
mouseMotionListeners = this.getMouseMotionListeners();
|
2124 |
|
2125 |
for (i = 0; i < mouseMotionListeners.length; i++) { |
2126 |
removeMouseMotionListener(mouseMotionListeners[i]); |
2127 |
} |
2128 |
} |
2129 |
} |
2130 |
|
2131 |
/**
|
2132 |
* Enables all mouse listeners
|
2133 |
*/
|
2134 |
public void enableAllMouseListeners() { |
2135 |
int i;
|
2136 |
|
2137 |
// Mouse Button Listeners
|
2138 |
for (i = 0; i < mouseListeners.length; i++) { |
2139 |
addMouseListener(mouseListeners[i]); |
2140 |
} |
2141 |
|
2142 |
mouseListeners = null;
|
2143 |
|
2144 |
// Mouse Wheel Listeners
|
2145 |
for (i = 0; i < mouseWheelListeners.length; i++) { |
2146 |
addMouseWheelListener(mouseWheelListeners[i]); |
2147 |
} |
2148 |
|
2149 |
mouseWheelListeners = null;
|
2150 |
|
2151 |
// Mouse motion listeners
|
2152 |
for (i = 0; i < mouseMotionListeners.length; i++) { |
2153 |
addMouseMotionListener(mouseMotionListeners[i]); |
2154 |
} |
2155 |
|
2156 |
mouseMotionListeners = null;
|
2157 |
} |
2158 |
} |
2159 |
|
2160 |
/**
|
2161 |
* This class has information about a validation: <br>
|
2162 |
* - A boolean value -> if has been or not validated <br>
|
2163 |
* - An String -> a message about the invalid
|
2164 |
*
|
2165 |
* @author Pablo Piqueras Bartolom? (p_queras_pab@hotmail.com)
|
2166 |
*/
|
2167 |
private class ValidationInfo { |
2168 |
private boolean _valid; |
2169 |
private String _message; |
2170 |
|
2171 |
/**
|
2172 |
* Default constructor with two parameters
|
2173 |
*
|
2174 |
* @param valid If was valid or not
|
2175 |
* @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
|
2176 |
* an explanation about the invalidation)
|
2177 |
*/
|
2178 |
public ValidationInfo(boolean valid, String message) { |
2179 |
_valid = valid; |
2180 |
_message = message; |
2181 |
} |
2182 |
|
2183 |
/**
|
2184 |
* Returns the value of the inner attribute '_valid'
|
2185 |
*
|
2186 |
* @return A boolean value
|
2187 |
*/
|
2188 |
public boolean isValid() { |
2189 |
return _valid;
|
2190 |
} |
2191 |
|
2192 |
/**
|
2193 |
* Returns the value of the inner attribute '_message'
|
2194 |
*
|
2195 |
* @return java.lang.String
|
2196 |
*/
|
2197 |
public String getMessage() { |
2198 |
return _message;
|
2199 |
} |
2200 |
} |
2201 |
|
2202 |
protected void initialize() { |
2203 |
setLabel(PluginServices.getText(this, "area")); |
2204 |
setLabelGroup(PluginServices.getText(this, "wfs")); |
2205 |
this.setLayout(new java.awt.BorderLayout()); |
2206 |
java.awt.GridBagConstraints gridBagConstraints; |
2207 |
|
2208 |
northPanel = new JPanel(); |
2209 |
northPanel.setLayout(new java.awt.GridBagLayout());
|
2210 |
|
2211 |
northPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
2212 |
null, PluginServices.getText(this, "select_by_area"), |
2213 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
2214 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
2215 |
|
2216 |
// Adds JPanel with the coordinates
|
2217 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
2218 |
gridBagConstraints.gridx = 0;
|
2219 |
gridBagConstraints.gridy = 0;
|
2220 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
2221 |
gridBagConstraints.weightx = 1.0;
|
2222 |
northPanel.add(getCoordinatesPanel(), gridBagConstraints); |
2223 |
|
2224 |
// Adds a check box to enable or enable this kind of filtering
|
2225 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
2226 |
gridBagConstraints.gridx = 0;
|
2227 |
gridBagConstraints.gridy = 1;
|
2228 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
2229 |
gridBagConstraints.weightx = 1.0;
|
2230 |
northPanel.add(getEnablingJCheckBox(), gridBagConstraints); |
2231 |
|
2232 |
previousExtentValids = new ExtentHistory();
|
2233 |
initCoordinates(); |
2234 |
|
2235 |
add(northPanel, java.awt.BorderLayout.NORTH); |
2236 |
} |
2237 |
|
2238 |
public void refresh(WFSSelectedFeature layer) { |
2239 |
|
2240 |
} |
2241 |
} |