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