gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / clip / ui / listener / ClippingPanelListener.java @ 5474
History | View | Annotate | Download (38.5 KB)
1 | 2480 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.raster.tools.app.basic.tool.clip.ui.listener; |
||
23 | |||
24 | import java.awt.Component; |
||
25 | import java.awt.Cursor; |
||
26 | import java.awt.Dimension; |
||
27 | import java.awt.Image; |
||
28 | import java.awt.event.ActionEvent; |
||
29 | import java.awt.event.ActionListener; |
||
30 | import java.awt.geom.AffineTransform; |
||
31 | import java.awt.geom.NoninvertibleTransformException; |
||
32 | import java.awt.geom.Point2D; |
||
33 | import java.io.File; |
||
34 | import java.util.EventObject; |
||
35 | import java.util.List; |
||
36 | |||
37 | import javax.swing.JOptionPane; |
||
38 | |||
39 | import org.gvsig.andami.PluginServices; |
||
40 | import org.gvsig.andami.Utilities; |
||
41 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
42 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
43 | import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
||
44 | import org.gvsig.fmap.dal.coverage.RasterLocator; |
||
45 | import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
||
46 | import org.gvsig.fmap.dal.coverage.exception.ROIException; |
||
47 | import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
||
48 | 5474 | llmarques | import org.gvsig.fmap.geom.Geometry; |
49 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
50 | import org.gvsig.fmap.geom.GeometryLocator; |
||
51 | import org.gvsig.fmap.geom.GeometryManager; |
||
52 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
53 | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
||
54 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
55 | 2480 | nbrodin | import org.gvsig.fmap.geom.primitive.Envelope; |
56 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
57 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
58 | import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
||
59 | import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
||
60 | import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior; |
||
61 | import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
||
62 | import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
||
63 | import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
||
64 | import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
||
65 | import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
||
66 | import org.gvsig.gui.beans.coordinatespanel.CoordinatesEvent; |
||
67 | import org.gvsig.gui.beans.coordinatespanel.CoordinatesListener; |
||
68 | import org.gvsig.gui.beans.coordinatespanel.CoordinatesPanel; |
||
69 | import org.gvsig.gui.beans.datainput.DataInputContainerListener; |
||
70 | import org.gvsig.gui.beans.table.models.CheckBoxModel; |
||
71 | import org.gvsig.i18n.Messages; |
||
72 | import org.gvsig.raster.algorithm.process.DataProcess; |
||
73 | import org.gvsig.raster.algorithm.process.IProcessActions; |
||
74 | import org.gvsig.raster.fmap.layers.FLyrRaster; |
||
75 | import org.gvsig.raster.roi.ROI; |
||
76 | import org.gvsig.raster.swing.RasterSwingLibrary; |
||
77 | import org.gvsig.raster.swing.RasterSwingLocator; |
||
78 | import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
||
79 | import org.gvsig.raster.tools.app.basic.raster.process.ClippingProcess; |
||
80 | import org.gvsig.raster.tools.app.basic.tool.clip.ClippingData; |
||
81 | import org.gvsig.raster.tools.app.basic.tool.clip.ui.ClippingPanel; |
||
82 | import org.gvsig.raster.tools.app.basic.tool.clip.ui.panel.ClippingCoordinatesPanel; |
||
83 | import org.gvsig.raster.tools.app.basic.tool.clip.ui.panel.ClippingOptionsPanel; |
||
84 | import org.gvsig.raster.tools.app.basic.tool.clip.ui.panel.ClippingResolutionPanel; |
||
85 | import org.gvsig.raster.tools.app.basic.tool.clip.ui.panel.ClippingSelectionPanel; |
||
86 | 5474 | llmarques | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
87 | import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
||
88 | import org.slf4j.Logger; |
||
89 | import org.slf4j.LoggerFactory; |
||
90 | 2480 | nbrodin | |
91 | /**
|
||
92 | * <code>ClippingPanelListener</code> es una clase donde se recoger?n y
|
||
93 | * tratar?n todos los eventos del panel de recorte
|
||
94 | *
|
||
95 | * @author BorSanZa - Borja S?nchez Zamorano
|
||
96 | */
|
||
97 | public class ClippingPanelListener implements ActionListener, RectangleListener, ButtonsPanelListener, CoordinatesListener, DataInputContainerListener, IProcessActions { |
||
98 | 5474 | llmarques | |
99 | private static final Logger LOG = LoggerFactory.getLogger(ClippingPanelListener.class); |
||
100 | |||
101 | 2480 | nbrodin | private Dimension dim = new Dimension(); |
102 | private AffineTransform at = null; |
||
103 | private ClippingPanel clippingPanel = null; |
||
104 | private ClippingData data = null; |
||
105 | private boolean enableValueChangedEvent = true; |
||
106 | private FLyrRaster fLayer = null; |
||
107 | private MapControl mapControl = null; |
||
108 | /**
|
||
109 | * Herramienta seleccionada en el momento de la apertura del dialogo
|
||
110 | */
|
||
111 | private String lastTool = null; |
||
112 | private String viewName = null; |
||
113 | private static ClippingData lastDataSaved = null; |
||
114 | |||
115 | /**
|
||
116 | * Crea un nuevo <code>ClippingPanelListener</code> con el
|
||
117 | * <code>ClippingPanelListener</code> asociado
|
||
118 | * @param panel
|
||
119 | */
|
||
120 | public ClippingPanelListener(ClippingPanel clippingPanel) {
|
||
121 | this.clippingPanel = clippingPanel;
|
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * Asigna el modelo de datos
|
||
126 | * @param data
|
||
127 | */
|
||
128 | public void setData(ClippingData data) { |
||
129 | this.data = data;
|
||
130 | if(fLayer != null) { |
||
131 | data.setPxWidth((int)fLayer.getDataStore().getWidth());
|
||
132 | data.setPxHeight((int)fLayer.getDataStore().getHeight());
|
||
133 | } |
||
134 | } |
||
135 | |||
136 | /**
|
||
137 | * Asigna la matriz de transformaci?n entre puntos en coordenadas del raster y
|
||
138 | * puntos en coordenadas reales.
|
||
139 | * @param AffineTransform
|
||
140 | */
|
||
141 | private void setAffineTransform(AffineTransform at) { |
||
142 | this.at = at;
|
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * Asigna la dimensi?n del raster
|
||
147 | * @param dim
|
||
148 | */
|
||
149 | public void setDimension(Dimension dim) { |
||
150 | this.dim = dim;
|
||
151 | } |
||
152 | |||
153 | /**
|
||
154 | * M?todo que se invoca cuando se disparan los eventos de los botones de
|
||
155 | * extensi?n completa o de seleccion de extensi?n con el rat?n
|
||
156 | */
|
||
157 | public void actionPerformed(ActionEvent e) { |
||
158 | // Bot?n de selecci?n del extent completo
|
||
159 | // Modificamos las coordenadas reales y recalculamos las coordenadas pixel
|
||
160 | if (e.getSource() == getResolutionPanel().getButtonRestore()) {
|
||
161 | getClippingPanel().restoreStatus(data); |
||
162 | } |
||
163 | |||
164 | //Load parameters
|
||
165 | if (e.getSource() == getCoordinatesPanel().getButtonBarContainer().getButton(0)) { |
||
166 | if(lastDataSaved != null) { |
||
167 | data = (ClippingData)lastDataSaved.clone(); |
||
168 | data.addObserver(getClippingPanel()); |
||
169 | data.updateObservers(); |
||
170 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
|
||
171 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setEnabled(true);
|
||
172 | } else
|
||
173 | RasterSwingLibrary.messageBoxError(Messages.getText("no_data_saved"), null); |
||
174 | } |
||
175 | |||
176 | //Save parameters
|
||
177 | if (e.getSource() == getCoordinatesPanel().getButtonBarContainer().getButton(1)) { |
||
178 | lastDataSaved = (ClippingData)data.clone(); |
||
179 | } |
||
180 | |||
181 | //Redondear las coordenadas p?xel
|
||
182 | if (e.getSource() == getCoordinatesPanel().getButtonBarContainer().getButton(2)) { |
||
183 | roundPixels(); |
||
184 | return;
|
||
185 | } |
||
186 | |||
187 | //Bot?n de selecci?n del ?rea m?xima asociada a los ROIs
|
||
188 | if (e.getSource() == getCoordinatesPanel().getButtonBarContainer().getButton(3)) { |
||
189 | try {
|
||
190 | List<ROI> roiList = getFLayer().getRois();
|
||
191 | if(roiList != null && roiList.size() > 0) { |
||
192 | Extent ext = RasterLocator.getManager().getRasterUtils().getROIsMaximunExtent(roiList); |
||
193 | assignROISExtent(ext, getFLayer()); |
||
194 | } else
|
||
195 | assignFullExtent(); |
||
196 | } catch (ROIException e1) {
|
||
197 | RasterSwingLibrary.messageBoxError(Messages.getText("problems_loading_rois"), null); |
||
198 | } |
||
199 | |||
200 | return;
|
||
201 | } |
||
202 | |||
203 | // Bot?n de selecci?n del extent completo
|
||
204 | // Modificamos las coordenadas reales y recalculamos las coordenadas pixel
|
||
205 | if (e.getSource() == getCoordinatesPanel().getButtonBarContainer().getButton(4)) { |
||
206 | assignFullExtent(); |
||
207 | return;
|
||
208 | } |
||
209 | |||
210 | // Bot?n de selecci?n de la herramienta de seleccionar desde la vista
|
||
211 | if (e.getSource() == getCoordinatesPanel().getButtonBarContainer().getButton(5)) { |
||
212 | selectToolButton(); |
||
213 | return;
|
||
214 | } |
||
215 | |||
216 | } |
||
217 | |||
218 | /**
|
||
219 | * Round off the pixels value
|
||
220 | */
|
||
221 | private void roundPixels() { |
||
222 | data.setUlxPx((int)(data.getUlxPx()));
|
||
223 | data.setUlyPx((int)(data.getUlyPx()));
|
||
224 | data.setLrxPx((int)(data.getLrxPx()));
|
||
225 | data.setLryPx((int)(data.getLryPx()));
|
||
226 | data.setUrxPx((int)(data.getUrxPx()));
|
||
227 | data.setUryPx((int)(data.getUryPx()));
|
||
228 | data.setLlxPx((int)(data.getLlxPx()));
|
||
229 | data.setLlyPx((int)(data.getLlyPx()));
|
||
230 | |||
231 | Point2D ulWc = new Point2D.Double(); |
||
232 | Point2D lrWc = new Point2D.Double(); |
||
233 | Point2D llWc = new Point2D.Double(); |
||
234 | Point2D urWc = new Point2D.Double(); |
||
235 | |||
236 | at.transform(new Point2D.Double(data.getUlxPx(), data.getUlyPx()), ulWc); |
||
237 | at.transform(new Point2D.Double(data.getLrxPx() + 1, data.getLryPx() + 1), lrWc); |
||
238 | at.transform(new Point2D.Double(data.getLlxPx(), data.getLlyPx() + 1), llWc); |
||
239 | at.transform(new Point2D.Double(data.getUrxPx() + 1, data.getUryPx()), urWc); |
||
240 | |||
241 | data.setCoorReal(ulWc, lrWc, llWc, urWc); |
||
242 | data.setAffineTransform(at); |
||
243 | data.initSize(); |
||
244 | data.updateObservers(); |
||
245 | } |
||
246 | |||
247 | /**
|
||
248 | * Asigna el extent completo a los cuadros de texto donde se introducen las coordenadas
|
||
249 | * reales y p?xel.
|
||
250 | */
|
||
251 | private void assignROISExtent(Extent ext, FLyrRaster layer) { |
||
252 | AffineTransform at = layer.getAffineTransform();
|
||
253 | Point2D ulWc = new Point2D.Double(ext.minX(), ext.maxY()); |
||
254 | Point2D lrWc = new Point2D.Double(ext.maxX(), ext.minY()); |
||
255 | Point2D llWc = new Point2D.Double(ext.minX(), ext.minY()); |
||
256 | Point2D urWc = new Point2D.Double(ext.maxX(), ext.maxY()); |
||
257 | |||
258 | ulWc = getFLayer().adjustWorldRequest(ulWc); |
||
259 | lrWc = getFLayer().adjustWorldRequest(lrWc); |
||
260 | llWc = getFLayer().adjustWorldRequest(llWc); |
||
261 | urWc = getFLayer().adjustWorldRequest(urWc); |
||
262 | |||
263 | Point2D ulPx = new Point2D.Double(); |
||
264 | Point2D lrPx = new Point2D.Double(); |
||
265 | Point2D llPx = new Point2D.Double(); |
||
266 | Point2D urPx = new Point2D.Double(); |
||
267 | |||
268 | try {
|
||
269 | at.inverseTransform(ulWc, ulPx); |
||
270 | at.inverseTransform(lrWc, lrPx); |
||
271 | at.inverseTransform(ulWc, llPx); |
||
272 | at.inverseTransform(lrWc, urPx); |
||
273 | } catch (NoninvertibleTransformException e) { |
||
274 | JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), Messages.getText("coordenadas_erroneas")); |
||
275 | return;
|
||
276 | } |
||
277 | |||
278 | data.setCoorPixel(ulPx, lrPx, llPx, urPx); |
||
279 | data.setCoorReal(ulWc, lrWc, llWc, urWc); |
||
280 | data.setAffineTransform(at); |
||
281 | data.initSize(); |
||
282 | getClippingPanel().saveStatus(data); |
||
283 | |||
284 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
|
||
285 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setEnabled(true);
|
||
286 | } |
||
287 | |||
288 | /**
|
||
289 | * Asigna el extent completo a los cuadros de texto donde se introducen las coordenadas
|
||
290 | * reales y p?xel.
|
||
291 | */
|
||
292 | private void assignFullExtent() { |
||
293 | Point2D ulPx = new Point2D.Double(0, 0); |
||
294 | Point2D lrPx = new Point2D.Double(dim.width, dim.height); |
||
295 | Point2D urPx = new Point2D.Double(dim.width, 0); |
||
296 | Point2D llPx = new Point2D.Double(0, dim.height); |
||
297 | |||
298 | //Convertimos nuevamente a coordenadas reales
|
||
299 | Point2D ulWc = new Point2D.Double(); |
||
300 | Point2D lrWc = new Point2D.Double(); |
||
301 | Point2D urWc = new Point2D.Double(); |
||
302 | Point2D llWc = new Point2D.Double(); |
||
303 | at.transform(ulPx, ulWc); |
||
304 | at.transform(lrPx, lrWc); |
||
305 | at.transform(urPx, urWc); |
||
306 | at.transform(llPx, llWc); |
||
307 | |||
308 | ulPx = new Point2D.Double(0, 0); |
||
309 | lrPx = new Point2D.Double(dim.width - 1, dim.height - 1); |
||
310 | urPx = new Point2D.Double(dim.width - 1, 0); |
||
311 | llPx = new Point2D.Double(0, dim.height - 1); |
||
312 | |||
313 | data.setCoorPixel(ulPx, lrPx, llPx, urPx); |
||
314 | data.setCoorReal(ulWc, lrWc, llWc, urWc); |
||
315 | data.setAffineTransform(at); |
||
316 | data.initSize(); |
||
317 | |||
318 | getClippingPanel().saveStatus(data); |
||
319 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
|
||
320 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setEnabled(true);
|
||
321 | } |
||
322 | |||
323 | /**
|
||
324 | * Al producirse un evento de perdida de foco o pulsaci?n de "enter" en un campo de texto de coordenadas
|
||
325 | * hay que asignar el nuevo valor introducido.
|
||
326 | * @param obj
|
||
327 | */
|
||
328 | private void eventJTextField(CoordinatesEvent e) { |
||
329 | try {
|
||
330 | if (e.getSource() == getCoordinatesPanel().getPixelCoordinates()) {
|
||
331 | if (e.getName().equals("11")) { |
||
332 | data.setUlxPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue11()).doubleValue());
|
||
333 | data.setLlxPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue11()).doubleValue());
|
||
334 | } |
||
335 | if (e.getName().equals("12")) { |
||
336 | data.setUlyPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue12()).doubleValue());
|
||
337 | data.setUryPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue12()).doubleValue());
|
||
338 | } |
||
339 | if (e.getName().equals("21")) { |
||
340 | data.setLrxPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue21()).doubleValue());
|
||
341 | data.setUrxPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue21()).doubleValue());
|
||
342 | } |
||
343 | if (e.getName().equals("22")) { |
||
344 | data.setLryPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue22()).doubleValue());
|
||
345 | data.setLlyPx(Double.valueOf(getCoordinatesPanel().getPixelCoordinates().getValue22()).doubleValue());
|
||
346 | } |
||
347 | data.updateObservers(); |
||
348 | } |
||
349 | |||
350 | if (e.getSource() == getCoordinatesPanel().getRealCoordinates()) {
|
||
351 | if (e.getName().equals("11")) { |
||
352 | data.setUlxWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue11()).doubleValue());
|
||
353 | data.setLlxWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue11()).doubleValue());
|
||
354 | } |
||
355 | if (e.getName().equals("12")) { |
||
356 | data.setUlyWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue12()).doubleValue());
|
||
357 | data.setUryWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue12()).doubleValue());
|
||
358 | } |
||
359 | if (e.getName().equals("21")) { |
||
360 | data.setLrxWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue21()).doubleValue());
|
||
361 | data.setUrxWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue21()).doubleValue());
|
||
362 | } |
||
363 | if (e.getName().equals("22")) { |
||
364 | data.setLryWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue22()).doubleValue());
|
||
365 | data.setLlyWc(Double.valueOf(getCoordinatesPanel().getRealCoordinates().getValue22()).doubleValue());
|
||
366 | } |
||
367 | data.updateObservers(); |
||
368 | } |
||
369 | } catch (NumberFormatException ex1) { |
||
370 | // No hay valores parseables a decimal en las cajas de texto. No hacemos nada
|
||
371 | } |
||
372 | } |
||
373 | |||
374 | |||
375 | /**
|
||
376 | * Recalcula el valor de los campos de coordenadas reales y pixel. Cuando modificamos alg?n campo
|
||
377 | * de las coordenadas reales se modifican los pixeles y viceversa.
|
||
378 | * @param modifyPx true si se ha modificado alg?n campo de coordenadas pixel y false si se ha modificado
|
||
379 | * alg?n campo de las coordenadas reales.
|
||
380 | */
|
||
381 | private void recalcCoordFields(boolean modifyPx) { |
||
382 | try {
|
||
383 | Point2D ulPx = new Point2D.Double(data.getUlxPx(), data.getUlyPx()); |
||
384 | Point2D lrPx = new Point2D.Double(data.getLrxPx(), data.getLryPx()); |
||
385 | Point2D llPx = new Point2D.Double(data.getLlxPx(), data.getLlyPx()); |
||
386 | Point2D urPx = new Point2D.Double(data.getUrxPx(), data.getUryPx()); |
||
387 | |||
388 | Point2D ulWc = new Point2D.Double(data.getUlxWc(), data.getUlyWc()); |
||
389 | Point2D lrWc = new Point2D.Double(data.getLrxWc(), data.getLryWc()); |
||
390 | Point2D llWc = new Point2D.Double(data.getLlxWc(), data.getLlyWc()); |
||
391 | Point2D urWc = new Point2D.Double(data.getUrxWc(), data.getUryWc()); |
||
392 | |||
393 | if (modifyPx) {
|
||
394 | at.transform(new Point2D.Double(ulPx.getX(), ulPx.getY()), ulWc); |
||
395 | at.transform(new Point2D.Double(lrPx.getX() + 1, lrPx.getY() + 1), lrWc); |
||
396 | at.transform(new Point2D.Double(llPx.getX(), llPx.getY() + 1), llWc); |
||
397 | at.transform(new Point2D.Double(urPx.getX() + 1, urPx.getY()), urWc); |
||
398 | |||
399 | data.setCoorReal(ulWc, lrWc, llWc, urWc); |
||
400 | data.setAffineTransform(at); |
||
401 | data.initSize(); |
||
402 | |||
403 | getClippingPanel().saveStatus(data); |
||
404 | } else {
|
||
405 | try {
|
||
406 | at.inverseTransform(ulWc, ulPx); |
||
407 | at.inverseTransform(lrWc, lrPx); |
||
408 | at.inverseTransform(llWc, llPx); |
||
409 | at.inverseTransform(urWc, urPx); |
||
410 | } catch (NoninvertibleTransformException e) { |
||
411 | JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "coordenadas_erroneas")); |
||
412 | return;
|
||
413 | } |
||
414 | |||
415 | //adjustPoints(ulPx, lrPx);
|
||
416 | //adjustPoints(llPx, urPx);
|
||
417 | lrPx = new Point2D.Double(lrPx.getX() - 1, lrPx.getY() - 1); |
||
418 | llPx = new Point2D.Double(llPx.getX(), llPx.getY() - 1); |
||
419 | urPx = new Point2D.Double(urPx.getX() - 1, urPx.getY()); |
||
420 | data.setCoorPixel(ulPx, lrPx, llPx, urPx); |
||
421 | data.setAffineTransform(at); |
||
422 | data.initSize(); |
||
423 | getClippingPanel().saveStatus(data); |
||
424 | } |
||
425 | |||
426 | //Condiciones para activar botones.
|
||
427 | if(activeButtons(ulPx, lrPx, ulWc, lrWc)) {
|
||
428 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
|
||
429 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setEnabled(true);
|
||
430 | } else {
|
||
431 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
||
432 | getClippingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setEnabled(false);
|
||
433 | } |
||
434 | |||
435 | } catch (NumberFormatException ex) { |
||
436 | return;
|
||
437 | } |
||
438 | |||
439 | } |
||
440 | |||
441 | public boolean activeButtons(Point2D ulPx, Point2D lrPx, Point2D ulWc, Point2D lrWc) { |
||
442 | if(ulPx.getX() < lrPx.getX() && ulPx.getY() < lrPx.getY() &&
|
||
443 | ulWc.getX() < lrWc.getX() && ulWc.getY() > lrWc.getY() && |
||
444 | (lrPx.getX() - ulPx.getX()) >= 2 && (lrPx.getY() - ulPx.getY()) >= 2 && |
||
445 | ulPx.getX() >= 0 && ulPx.getY() >= 0 && |
||
446 | ((int)lrPx.getX()) <= (fLayer.getDataStore().getWidth() - 1) && |
||
447 | ((int)lrPx.getY()) <= (fLayer.getDataStore().getHeight() - 1)) { |
||
448 | return true; |
||
449 | } |
||
450 | return false; |
||
451 | } |
||
452 | |||
453 | /**
|
||
454 | * Turns world coordinates into entire numbers to avoid rounds errors
|
||
455 | * @param ul
|
||
456 | * Upper left coordinate
|
||
457 | * @param lr
|
||
458 | * Lower right coordinate
|
||
459 | */
|
||
460 | @SuppressWarnings("unused") |
||
461 | private void adjustPoints(Point2D ul, Point2D lr) { |
||
462 | double a = (ul.getX() - (int)ul.getX()); |
||
463 | double b = (ul.getY() - (int)ul.getY()); |
||
464 | double c = (lr.getX() - (int)lr.getX()); |
||
465 | double d = (lr.getY() - (int)lr.getY()); |
||
466 | ul.setLocation( (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), |
||
467 | (b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY()); |
||
468 | lr.setLocation( (c > 0.95 || c < 0.05) ? Math.round(lr.getX()) : lr.getX(), |
||
469 | (d > 0.95 || d < 0.05) ? Math.round(lr.getY()) : lr.getY()); |
||
470 | } |
||
471 | |||
472 | /**
|
||
473 | * Ajusta las coordenadas especificadas en los par?metros al ?rea m?xima
|
||
474 | * del raster en p?xeles
|
||
475 | * @param req
|
||
476 | */
|
||
477 | @SuppressWarnings("unused") |
||
478 | private Point2D adjustPixelRequest(Point2D req) { |
||
479 | req.setLocation(Math.max(0, req.getX()), Math.max(0, req.getY())); |
||
480 | req.setLocation(Math.min(dim.width - 1, req.getX()), Math.min(dim.height - 1, req.getY())); |
||
481 | return req;
|
||
482 | } |
||
483 | |||
484 | /**
|
||
485 | * Invocaci?n de los eventos de la ventana de <code>DefaultButtonsPanel</code>
|
||
486 | */
|
||
487 | public void actionButtonPressed(ButtonsPanelEvent e) { |
||
488 | // Bot?n de Aceptar
|
||
489 | if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
||
490 | accept(); |
||
491 | close(); |
||
492 | } |
||
493 | |||
494 | // Bot?n de Aplicar
|
||
495 | if (e.getButton() == ButtonsPanel.BUTTON_APPLY)
|
||
496 | accept(); |
||
497 | |||
498 | // Bot?n de Cerrar
|
||
499 | if (e.getButton() == ButtonsPanel.BUTTON_CANCEL)
|
||
500 | close(); |
||
501 | |||
502 | getFLayer().getMapContext().invalidate(); |
||
503 | } |
||
504 | |||
505 | /**
|
||
506 | * Cerrar la ventana del recorte
|
||
507 | */
|
||
508 | private void close() { |
||
509 | try {
|
||
510 | if (getLastTool() != null) |
||
511 | getMapControl().setTool(getLastTool()); |
||
512 | PluginServices.getMDIManager().closeWindow(getClippingPanel().getClippingDialog()); |
||
513 | } catch (ArrayIndexOutOfBoundsException ex) { |
||
514 | // Si la ventana no se puede eliminar no hacemos nada
|
||
515 | } |
||
516 | } |
||
517 | |||
518 | /**
|
||
519 | * Obtener el <code>ClippingPanel</code> asociado
|
||
520 | * @return ClippingPanel
|
||
521 | */
|
||
522 | private ClippingPanel getClippingPanel() {
|
||
523 | return clippingPanel;
|
||
524 | } |
||
525 | |||
526 | private ClippingCoordinatesPanel getCoordinatesPanel() {
|
||
527 | return getClippingPanel().getCoordinatesPanel();
|
||
528 | } |
||
529 | |||
530 | private ClippingResolutionPanel getResolutionPanel() {
|
||
531 | return getClippingPanel().getResolutionPanel();
|
||
532 | } |
||
533 | |||
534 | private ClippingOptionsPanel getOptionsPanel() {
|
||
535 | return getClippingPanel().getOptionsPanel();
|
||
536 | } |
||
537 | |||
538 | private ClippingSelectionPanel getSelectionPanel() {
|
||
539 | return getClippingPanel().getSelectionPanel();
|
||
540 | } |
||
541 | |||
542 | /**
|
||
543 | * Acciones realizadas cuando se acepta en el dialogo. Se obtendr?n los datos
|
||
544 | * de recorte desde el dialogo, crearemos el objeto ClippingProcess que
|
||
545 | * gestiona el recortado, ajustamos el tama?o del grid de salida y procesamos.
|
||
546 | */
|
||
547 | private void accept() { |
||
548 | if(data.getPxHeight() == 0 || data.getPxWidth() == 0) { |
||
549 | RasterSwingLibrary.messageBoxError(RasterToolsUtil.getText(this, "wrong_resolution"), null); |
||
550 | return;
|
||
551 | } |
||
552 | |||
553 | // Controlamos las coordenadas del recorte que no se salgan de la imagen.
|
||
554 | // De ser as? mostramos un error
|
||
555 | CoordinatesPanel coordinatesReales = getCoordinatesPanel().getRealCoordinates(); |
||
556 | double ulx = 0; |
||
557 | double lrx = 0; |
||
558 | double lry = 0; |
||
559 | double uly = 0; |
||
560 | try {
|
||
561 | ulx = Double.parseDouble(coordinatesReales.getValue11());
|
||
562 | lry = Double.parseDouble(coordinatesReales.getValue22());
|
||
563 | lrx = Double.parseDouble(coordinatesReales.getValue21());
|
||
564 | uly = Double.parseDouble(coordinatesReales.getValue12());
|
||
565 | Envelope ext = getFLayer().getFullEnvelope(); |
||
566 | if (((int) ulx) > ((int) ext.getMaximum(0)) || ((int) lrx) < ((int) ext.getMinimum(0)) || ((int) uly) > ((int) ext.getMaximum(1)) || ((int) lry) < ((int) ext.getMinimum(1))) { |
||
567 | RasterSwingLibrary.messageBoxError(Messages.getText("coordenadas_erroneas"), null); |
||
568 | return;
|
||
569 | } |
||
570 | } catch (NumberFormatException e) { |
||
571 | RasterSwingLibrary.messageBoxError(Messages.getText("coordenadas_erroneas"), null); |
||
572 | return;
|
||
573 | } |
||
574 | |||
575 | // Seleccionamos las bandas que se usaran en el recorte a partir de la tabla
|
||
576 | int countBands = 0; |
||
577 | int rowCount = ((CheckBoxModel) getSelectionPanel().getTableContainer().getModel()).getRowCount();
|
||
578 | for (int iRow = 0; iRow < rowCount; iRow++) |
||
579 | if ((((Boolean) ((CheckBoxModel) getSelectionPanel().getTableContainer().getModel()).getValueAt(iRow, 0))).booleanValue()) |
||
580 | countBands++; |
||
581 | |||
582 | int[] drawableBands = new int[countBands]; |
||
583 | int i = 0; |
||
584 | for (int iRow = 0; iRow < rowCount; iRow++) { |
||
585 | if ((((Boolean) ((CheckBoxModel) getSelectionPanel().getTableContainer().getModel()).getValueAt(iRow, 0))).booleanValue()) { |
||
586 | int row = ((Integer) ((CheckBoxModel) getSelectionPanel().getTableContainer().getModel()).getValueAt(iRow, 2)).intValue(); |
||
587 | drawableBands[i++] = row; |
||
588 | } |
||
589 | } |
||
590 | |||
591 | /**
|
||
592 | * Donde se va a guardar el fichero
|
||
593 | */
|
||
594 | String path;
|
||
595 | if (getOptionsPanel().getCbSaveFile().isSelected()) {
|
||
596 | path = getOptionsPanel().getDirectoryTextField().getText(); |
||
597 | File f = new File(path); |
||
598 | if(!f.exists() || !f.canWrite()) {
|
||
599 | RasterSwingLibrary.messageBoxError(Messages.getText("path_not_valid"), null); |
||
600 | return;
|
||
601 | } |
||
602 | } else
|
||
603 | path = Utilities.createTempDirectory();
|
||
604 | |||
605 | String file = getOptionsPanel().getFilenameTextField().getText();
|
||
606 | if (file.compareTo(RasterLocator.getManager().getFileUtils().getOnlyLayerName()) == 0) |
||
607 | RasterLocator.getManager().getFileUtils().usesOnlyLayerName(); |
||
608 | |||
609 | if (file == "") |
||
610 | file = "cutlayer";
|
||
611 | |||
612 | String filename = path + File.separator + file; |
||
613 | |||
614 | if (new File(filename + ".tif").exists()) |
||
615 | if (!RasterSwingLibrary.messageBoxYesOrNot("raster_error_file_exists", getOptionsPanel())) |
||
616 | return;
|
||
617 | |||
618 | /**
|
||
619 | * Preparacion para la generacion del proceso del recorte
|
||
620 | */
|
||
621 | 5474 | llmarques | if (getFLayer() == null){ |
622 | return;
|
||
623 | } |
||
624 | |||
625 | double[] pxValues = data.getPxCoordinatesToClip(); |
||
626 | boolean pxRound = arePixelsRound(pxValues);
|
||
627 | double[] wcValues = data.getWcCoordinatesToClip(); |
||
628 | |||
629 | if (getFLayer().getCoordTrans() != null) { |
||
630 | 2480 | nbrodin | |
631 | 5474 | llmarques | GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
632 | Envelope envelope = null;
|
||
633 | Envelope storeEnvelope = null;
|
||
634 | Envelope projectedEnvelope = null;
|
||
635 | Extent extent = getFLayer().getDataStore().getExtent(); |
||
636 | |||
637 | try {
|
||
638 | // Create envelope with coordinates of clip area
|
||
639 | envelope = |
||
640 | geometryManager.createEnvelope(wcValues[0], wcValues[3], wcValues[2], |
||
641 | wcValues[1], SUBTYPES.GEOM2D);
|
||
642 | |||
643 | } catch (CreateEnvelopeException e) {
|
||
644 | String errorMessage =
|
||
645 | String.format("Can not create envelope with [%1d,%1d,%1d,%1d,%1s] parameters", |
||
646 | wcValues[0], wcValues[3], wcValues[2], wcValues[1], SUBTYPES.GEOM2D); |
||
647 | LOG.error(errorMessage, e); |
||
648 | |||
649 | ThreadSafeDialogsManager tsdm = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
650 | tsdm.messageDialog("error_cutting", "_error", |
||
651 | JOptionPane.ERROR_MESSAGE);
|
||
652 | return;
|
||
653 | } |
||
654 | |||
655 | // Get envelope of raster store
|
||
656 | try {
|
||
657 | storeEnvelope = |
||
658 | geometryManager.createEnvelope(extent.getMin().getX(), extent.getMin().getY(), |
||
659 | extent.getMax().getX(), extent.getMax().getY(), SUBTYPES.GEOM2D); |
||
660 | } catch (CreateEnvelopeException e) {
|
||
661 | String errorMessage =
|
||
662 | String.format("Can not create envelope with [%1d,%1d,%1d,%1d,%1s] parameters", |
||
663 | extent.getMin().getX(), extent.getMin().getY(), extent.getMax().getX(), |
||
664 | extent.getMax().getY(), SUBTYPES.GEOM2D); |
||
665 | LOG.error(errorMessage, e); |
||
666 | |||
667 | ThreadSafeDialogsManager tsdm = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
668 | tsdm.messageDialog("error_cutting", "_error", |
||
669 | JOptionPane.ERROR_MESSAGE);
|
||
670 | return;
|
||
671 | } |
||
672 | |||
673 | // Reproject to store projection using layer coordinate transform
|
||
674 | projectedEnvelope = envelope.convert(getFLayer().getCoordTrans().getInverted()); |
||
675 | try {
|
||
676 | // Get instersection to fix projected envelope
|
||
677 | Geometry intersection = |
||
678 | projectedEnvelope.getGeometry().intersection(storeEnvelope.getGeometry()); |
||
679 | projectedEnvelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D); |
||
680 | projectedEnvelope.add(intersection); |
||
681 | } catch (GeometryOperationNotSupportedException | GeometryOperationException e) {
|
||
682 | String errorMessage =
|
||
683 | String.format(
|
||
684 | "Can not intersects [%1s] projected envelope with [%1s] store envelope",
|
||
685 | projectedEnvelope, storeEnvelope); |
||
686 | LOG.error(errorMessage, e); |
||
687 | |||
688 | ThreadSafeDialogsManager tsdm = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
689 | tsdm.messageDialog("error_cutting", "_error", |
||
690 | JOptionPane.ERROR_MESSAGE);
|
||
691 | return;
|
||
692 | } catch (CreateEnvelopeException e) {
|
||
693 | String errorMessage =
|
||
694 | String.format("Can not create envelope with [%1s] parameters", SUBTYPES.GEOM2D); |
||
695 | LOG.error(errorMessage, e); |
||
696 | |||
697 | ThreadSafeDialogsManager tsdm = ToolsSwingLocator.getThreadSafeDialogsManager(); |
||
698 | tsdm.messageDialog("error_cutting", "_error", |
||
699 | JOptionPane.ERROR_MESSAGE);
|
||
700 | return;
|
||
701 | } |
||
702 | |||
703 | wcValues[0] = projectedEnvelope.getLowerCorner().getX();
|
||
704 | wcValues[3] = projectedEnvelope.getLowerCorner().getY();
|
||
705 | wcValues[2] = projectedEnvelope.getUpperCorner().getX();
|
||
706 | wcValues[1] = projectedEnvelope.getUpperCorner().getY();
|
||
707 | } |
||
708 | |||
709 | 2480 | nbrodin | AffineTransform transf = null; |
710 | if(pxRound &&
|
||
711 | ((pxValues[2] - pxValues[0]) == data.getPxWidth()) && |
||
712 | ((pxValues[3] - pxValues[1]) == data.getPxHeight())) |
||
713 | transf = new AffineTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), wcValues[0], wcValues[1]); |
||
714 | else
|
||
715 | transf = calcAffineTransform(wcValues[0], wcValues[1], wcValues[2], wcValues[3], |
||
716 | Math.round(data.getPxWidth()), Math.round(data.getPxHeight()), at); |
||
717 | |||
718 | |||
719 | int interpMethod = getResolutionPanel().getSelectedInterpolationMethod();
|
||
720 | |||
721 | // Creamos la interpretaci?n de color para el caso de que la salida tenga
|
||
722 | // m?s de una banda por fichero. Siempre creamos RED, GREEN y BLUE
|
||
723 | String[] ci = new String[drawableBands.length]; |
||
724 | for (int j = 0; j < ci.length; j++) { |
||
725 | switch (j) {
|
||
726 | case 0: |
||
727 | if (ci.length >= 3) |
||
728 | ci[j] = ColorInterpretation.RED_BAND; |
||
729 | else
|
||
730 | ci[j] = ColorInterpretation.GRAY_BAND; |
||
731 | break;
|
||
732 | case 1: |
||
733 | if (ci.length >= 3) |
||
734 | ci[j] = ColorInterpretation.GREEN_BAND; |
||
735 | else
|
||
736 | ci[j] = ColorInterpretation.UNDEF_BAND; |
||
737 | break;
|
||
738 | case 2: |
||
739 | ci[j] = ColorInterpretation.BLUE_BAND; |
||
740 | break;
|
||
741 | default:
|
||
742 | ci[j] = ColorInterpretation.UNDEF_BAND; |
||
743 | break;
|
||
744 | } |
||
745 | } |
||
746 | |||
747 | DataProcess clippingProcess = new ClippingProcess();
|
||
748 | clippingProcess.setActions(this);
|
||
749 | clippingProcess.addParam("viewname", getViewName());
|
||
750 | if(pxRound)
|
||
751 | clippingProcess.addParam("pixelcoordinates", pxValues);
|
||
752 | else
|
||
753 | clippingProcess.addParam("realcoordinates", wcValues);
|
||
754 | clippingProcess.addParam("suffix", ".tif"); |
||
755 | clippingProcess.addParam("filename", filename);
|
||
756 | clippingProcess.addParam("layer", getFLayer().getDataStore());
|
||
757 | clippingProcess.addParam("drawablebands", drawableBands);
|
||
758 | clippingProcess.addParam("onelayerperband", new Boolean(getOptionsPanel().getCbOneLyrPerBand().isSelected())); |
||
759 | clippingProcess.addParam("interpolationmethod", new Integer(interpMethod)); |
||
760 | clippingProcess.addParam("affinetransform", transf);
|
||
761 | clippingProcess.addParam("colorInterpretation", RasterLocator.getManager().getDataStructFactory().createColorInterpretation(ci));
|
||
762 | clippingProcess.addParam("resolution", new int[]{(int) Math.round(data.getPxWidth()), |
||
763 | (int) Math.round(data.getPxHeight())}); |
||
764 | clippingProcess.addParam("viewProjection", mapControl.getProjection());
|
||
765 | clippingProcess.start(); |
||
766 | } |
||
767 | |||
768 | /**
|
||
769 | * Calcula la matriz de transformaci?n que se usar? para el nuevo raster generado.
|
||
770 | * @param ulx Coordenada X real de la esquina superior izquierda
|
||
771 | * @param uly Coordenada Y real de la esquina superior izquierda
|
||
772 | * @param lrx Coordenada X real de la esquina inferior derecha
|
||
773 | * @param lry Coordenada Y real de la esquina inferior derecha
|
||
774 | * @param width Ancho en p?xeles del nuevo raster
|
||
775 | * @param height Alto en p?xeles del nuevo raster
|
||
776 | * @param trans Matriz de transformaci?n de la nueva capa
|
||
777 | * @return Matriz de transformaci?n para el nuevo raster
|
||
778 | */
|
||
779 | private AffineTransform calcAffineTransform(double ulx, double uly, double lrx, double lry, |
||
780 | double width, double height, AffineTransform trans) { |
||
781 | Point2D ul = new Point2D.Double(ulx, uly); |
||
782 | Point2D lr = new Point2D.Double(lrx, lry); |
||
783 | try {
|
||
784 | trans.inverseTransform(ul, ul); |
||
785 | trans.inverseTransform(lr, lr); |
||
786 | } catch (NoninvertibleTransformException e) { |
||
787 | JOptionPane.showMessageDialog(null, RasterToolsUtil.getText(this, "coordenadas_erroneas")); |
||
788 | return new AffineTransform(); |
||
789 | } |
||
790 | double w = Math.abs(lr.getX() - ul.getX()); |
||
791 | |||
792 | Point2D ur = new Point2D.Double(ul.getX() + w, ul.getY()); |
||
793 | Point2D ll = new Point2D.Double(lr.getX() - w, lr.getY() ); |
||
794 | |||
795 | //Obtenemos la georreferenciaci?n de las cuatro esquinas del nuevo raster
|
||
796 | trans.transform(ul, ul); |
||
797 | trans.transform(ur, ur); |
||
798 | trans.transform(lr, lr); |
||
799 | trans.transform(ll, ll); |
||
800 | |||
801 | double pixelSizeX = (lrx - ulx) / width;
|
||
802 | double pixelSizeY = (lry - uly) / height;
|
||
803 | double rotX = trans.getShearX();
|
||
804 | double rotY = trans.getShearY();
|
||
805 | return new AffineTransform(pixelSizeX, rotY, rotX, pixelSizeY, ulx, uly); |
||
806 | } |
||
807 | |||
808 | /**
|
||
809 | * Returns true if the pixels are round
|
||
810 | * @param pxValues
|
||
811 | * @return
|
||
812 | */
|
||
813 | private boolean arePixelsRound(double[] pxValues) { |
||
814 | if((((int)pxValues[0]) - pxValues[0]) == 0 && |
||
815 | (((int)pxValues[1]) - pxValues[1]) == 0 && |
||
816 | (((int)pxValues[2]) - pxValues[2]) == 0 && |
||
817 | (((int)pxValues[3]) - pxValues[3]) == 0) { |
||
818 | return true; |
||
819 | } |
||
820 | return false; |
||
821 | } |
||
822 | |||
823 | public boolean cancelDrawing() { |
||
824 | return false; |
||
825 | } |
||
826 | |||
827 | public Cursor getCursor() { |
||
828 | return null; |
||
829 | } |
||
830 | |||
831 | public void actionValueChanged(CoordinatesEvent e) { |
||
832 | if (e.getSource() == getCoordinatesPanel().getPixelCoordinates()) {
|
||
833 | eventJTextField(e); |
||
834 | if (e.getName().equals("11") || |
||
835 | e.getName().equals("12") ||
|
||
836 | e.getName().equals("21") ||
|
||
837 | e.getName().equals("22"))
|
||
838 | recalcCoordFields(true);
|
||
839 | |||
840 | } |
||
841 | if (e.getSource() == getCoordinatesPanel().getRealCoordinates()) {
|
||
842 | eventJTextField(e); |
||
843 | if (e.getName().equals("11") || |
||
844 | e.getName().equals("12") ||
|
||
845 | e.getName().equals("21") ||
|
||
846 | e.getName().equals("22"))
|
||
847 | recalcCoordFields(false);
|
||
848 | } |
||
849 | } |
||
850 | |||
851 | public void actionValueChanged(EventObject e) { |
||
852 | if(!enableValueChangedEvent)
|
||
853 | return;
|
||
854 | |||
855 | enableValueChangedEvent = false; //Desactivamos el evento de cambio de valor de las cajas de texto para que no se bucle |
||
856 | |||
857 | if (e.getSource() == getResolutionPanel().getCCellSize().getDataInputField()) {
|
||
858 | // Cambiamos PS ==> wPx=wWC/PS & hPx=wPx/rel
|
||
859 | double ps = 0; |
||
860 | try {
|
||
861 | ps = Double.parseDouble(getResolutionPanel().getCCellSize().getValue());
|
||
862 | } catch (NumberFormatException ex) { |
||
863 | return;
|
||
864 | } |
||
865 | data.setPxWidth(data.getWcWidth() / ps); |
||
866 | data.setPxHeight(data.getWcHeight() / ps); |
||
867 | data.updateObservers(); |
||
868 | } else if (e.getSource() == getResolutionPanel().getCWidth().getDataInputField()) { |
||
869 | // Cambiamos wPx ==> hPx=wPx/rel & PS=wWC/wPx
|
||
870 | double wPx = 0; |
||
871 | try {
|
||
872 | wPx = Double.parseDouble(getResolutionPanel().getCWidth().getValue());
|
||
873 | } catch (NumberFormatException ex) { |
||
874 | return;
|
||
875 | } |
||
876 | data.setPxWidth(wPx); |
||
877 | data.setPxHeight(Math.round(wPx / data.getRatio()));
|
||
878 | data.updateObservers(); |
||
879 | } else if (e.getSource() == getResolutionPanel().getCHeight().getDataInputField()) { |
||
880 | // Cambiamos hPx ==> wPx=rel*wPx & PS=hWC/hPx
|
||
881 | double hPx = 0; |
||
882 | try {
|
||
883 | hPx = Double.parseDouble(getResolutionPanel().getCHeight().getValue());
|
||
884 | } catch (NumberFormatException ex) { |
||
885 | return;
|
||
886 | } |
||
887 | data.setPxHeight(hPx); |
||
888 | data.setPxWidth(Math.round(Math.round(hPx * data.getRatio()))); |
||
889 | data.updateObservers(); |
||
890 | } |
||
891 | enableValueChangedEvent = true;
|
||
892 | } |
||
893 | |||
894 | /**
|
||
895 | * Asigna el valor para la activaci?n y desactivaci?n del evento de cambio de valor en
|
||
896 | * las cajas de texto.
|
||
897 | * @param enableValueChangedEvent
|
||
898 | */
|
||
899 | public void setEnableValueChangedEvent(boolean enableValueChangedEvent) { |
||
900 | this.enableValueChangedEvent = enableValueChangedEvent;
|
||
901 | } |
||
902 | |||
903 | public void end(Object params) { |
||
904 | if( params instanceof Object[] && |
||
905 | ((Object[])params).length == 2 && |
||
906 | ((Object[])params)[0] instanceof String && |
||
907 | ((Object[])params)[1] instanceof Long) { |
||
908 | |||
909 | String fName = (String)((Object[])params)[0]; |
||
910 | long milis = ((Long)((Object[])params)[1]).longValue(); |
||
911 | |||
912 | RasterSwingLocator.getSwingManager().showSummaryProcessDialog(fName, milis); |
||
913 | } |
||
914 | } |
||
915 | |||
916 | /**
|
||
917 | * Obtener la capa de un raster.
|
||
918 | * @return
|
||
919 | */
|
||
920 | public FLyrRaster getFLayer() {
|
||
921 | return fLayer;
|
||
922 | } |
||
923 | |||
924 | /**
|
||
925 | * Obtiene la ultima herramienta seleccionada antes de cargar el recorte
|
||
926 | * @return
|
||
927 | */
|
||
928 | public String getLastTool() { |
||
929 | return lastTool;
|
||
930 | } |
||
931 | |||
932 | /**
|
||
933 | * Obtiene el nombre de la vista
|
||
934 | * @return
|
||
935 | */
|
||
936 | public String getViewName() { |
||
937 | return viewName;
|
||
938 | } |
||
939 | |||
940 | /**
|
||
941 | * Establecer la capa para usarla en el recorte
|
||
942 | * @param fLayer
|
||
943 | */
|
||
944 | public void setLayer(FLyrRaster fLayer) { |
||
945 | this.fLayer = fLayer;
|
||
946 | AbstractViewPanel view = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
||
947 | viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle(); |
||
948 | mapControl = view.getMapControl(); |
||
949 | |||
950 | lastTool = mapControl.getCurrentTool(); |
||
951 | |||
952 | // Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
||
953 | // la barra de estado
|
||
954 | StatusBarListener sbl = new StatusBarListener(mapControl);
|
||
955 | |||
956 | // Cortar Raster
|
||
957 | ClippingMouseViewListener clippingMouseViewListener = new ClippingMouseViewListener(mapControl, getClippingPanel(), data, fLayer);
|
||
958 | mapControl.addBehavior("cutRaster", new Behavior[] { |
||
959 | new RectangleBehavior(clippingMouseViewListener), new MouseMovementBehavior(sbl) |
||
960 | } |
||
961 | ); |
||
962 | |||
963 | getSelectionPanel().setLayer(fLayer); |
||
964 | |||
965 | // Obtener la extension completa de la capa
|
||
966 | |||
967 | setAffineTransform(fLayer.getAffineTransform()); |
||
968 | setDimension(new Dimension((int)fLayer.getDataStore().getWidth(), (int)fLayer.getDataStore().getHeight())); |
||
969 | |||
970 | //Limitaciones del recorte para un servicio remoto
|
||
971 | //1-Interpolaci?n deshabilitada. Se hace la petici?n al servidor de los pixeles que queramos
|
||
972 | //2-No se pueden intercambiar bandas. Puede hacerse a posteriori cuando ya est? en disco
|
||
973 | //3-No se puede seleccionar por coordenadas pixel. Si la fuente es WebMapService puede no tener resoluci?n
|
||
974 | //en pixeles por lo que puede no tener sentido este tipo de selecci?n
|
||
975 | if(getFLayer().isRemote()) {
|
||
976 | getResolutionPanel().getComboInterpolation().setEnabled(false);
|
||
977 | getClippingPanel().removeTab(getSelectionPanel()); |
||
978 | getCoordinatesPanel().getPixelCoordinates().setVisible(false);
|
||
979 | } |
||
980 | } |
||
981 | |||
982 | /**
|
||
983 | * Acciones que se realizan para seleccionar la tool CutRaster
|
||
984 | */
|
||
985 | public void selectToolButton() { |
||
986 | // seleccionamos la vista de gvSIG
|
||
987 | org.gvsig.app.project.documents.view.gui.AbstractViewPanel theView = null;
|
||
988 | try {
|
||
989 | IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
|
||
990 | for (int i = 0; i < allViews.length; i++) { |
||
991 | if (allViews[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel |
||
992 | && PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) allViews[i]) |
||
993 | .getTitle().equals(viewName)) |
||
994 | theView = (org.gvsig.app.project.documents.view.gui.AbstractViewPanel) allViews[i]; |
||
995 | } |
||
996 | if (theView == null) |
||
997 | return;
|
||
998 | } catch (ClassCastException ex) { |
||
999 | // RasterToolsUtil.messageBoxError("cant_get_view "), this, ex);
|
||
1000 | return;
|
||
1001 | } |
||
1002 | MapControl m_MapControl = theView.getMapControl(); |
||
1003 | |||
1004 | // Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
||
1005 | // la barra de estado
|
||
1006 | //StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
||
1007 | |||
1008 | // Cortar Raster
|
||
1009 | /*ClippingMouseViewListener clippingMouseViewListener = new ClippingMouseViewListener(m_MapControl, getClippingPanel(), data, getFLayer());
|
||
1010 | m_MapControl.addMapTool("cutRaster", new Behavior[] {
|
||
1011 | new RectangleBehavior(clippingMouseViewListener), new MouseMovementBehavior(sbl)
|
||
1012 | }
|
||
1013 | );*/
|
||
1014 | |||
1015 | m_MapControl.setTool("clipRaster");
|
||
1016 | } |
||
1017 | |||
1018 | /**
|
||
1019 | * Obtiene el <code>MapControl</code> de gvSIG
|
||
1020 | * @return <code>MapControl</code>
|
||
1021 | */
|
||
1022 | public MapControl getMapControl() {
|
||
1023 | return mapControl;
|
||
1024 | } |
||
1025 | |||
1026 | |||
1027 | public void rectangle(EnvelopeEvent event) throws BehaviorException {} |
||
1028 | public void interrupted() {} |
||
1029 | |||
1030 | public Image getImageCursor() { |
||
1031 | return null; |
||
1032 | } |
||
1033 | |||
1034 | public void updateProgress(int current, int total) { |
||
1035 | |||
1036 | } |
||
1037 | } |