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