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