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