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