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