svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster.tools / org.gvsig.raster.tools.swing / org.gvsig.raster.tools.swing.impl / src / main / java / org / gvsig / raster / tools / swing / impl / clip / ClipPanelController.java @ 43876
History | View | Annotate | Download (45.1 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2017 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.raster.tools.swing.impl.clip; |
24 |
|
25 |
import java.awt.Image; |
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.io.File; |
29 |
import java.text.NumberFormat; |
30 |
import java.util.ArrayList; |
31 |
import java.util.List; |
32 |
import java.util.Locale; |
33 |
|
34 |
import javax.swing.JComponent; |
35 |
import javax.swing.JFileChooser; |
36 |
import javax.swing.JOptionPane; |
37 |
import javax.swing.ListSelectionModel; |
38 |
import javax.swing.event.AncestorEvent; |
39 |
import javax.swing.event.AncestorListener; |
40 |
import javax.swing.event.DocumentEvent; |
41 |
import javax.swing.event.DocumentListener; |
42 |
import javax.swing.event.ListSelectionEvent; |
43 |
import javax.swing.event.ListSelectionListener; |
44 |
import javax.swing.text.DefaultFormatterFactory; |
45 |
import javax.swing.text.NumberFormatter; |
46 |
|
47 |
import org.cresques.cts.ICoordTrans; |
48 |
import org.cresques.cts.IProjection; |
49 |
import org.slf4j.Logger; |
50 |
import org.slf4j.LoggerFactory; |
51 |
|
52 |
import org.gvsig.fmap.IconThemeHelper; |
53 |
import org.gvsig.fmap.dal.exception.DataException; |
54 |
import org.gvsig.fmap.dal.exception.InitializeException; |
55 |
import org.gvsig.fmap.dal.raster.BandDescriptor; |
56 |
import org.gvsig.fmap.dal.raster.RasterQuery; |
57 |
import org.gvsig.fmap.dal.raster.RasterSet; |
58 |
import org.gvsig.fmap.dal.raster.RasterStore; |
59 |
import org.gvsig.fmap.geom.Geometry.DIMENSIONS; |
60 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
61 |
import org.gvsig.fmap.geom.GeometryLocator; |
62 |
import org.gvsig.fmap.geom.GeometryManager; |
63 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
64 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
65 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
66 |
import org.gvsig.fmap.geom.primitive.Envelope; |
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
68 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer; |
69 |
import org.gvsig.fmap.mapcontext.raster.swing.MapContextRasterSwingLocator; |
70 |
import org.gvsig.fmap.mapcontext.raster.swing.MapContextRasterSwingManager; |
71 |
import org.gvsig.fmap.mapcontext.raster.swing.SelectableBandDescriptorsTableModel; |
72 |
import org.gvsig.fmap.mapcontrol.MapControl; |
73 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
74 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior; |
75 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
76 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
77 |
import org.gvsig.raster.lib.buffer.api.BufferDimensions; |
78 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
79 |
import org.gvsig.raster.swing.buffer.RasterSwingBufferLocator; |
80 |
import org.gvsig.raster.swing.buffer.RasterSwingBufferManager; |
81 |
import org.gvsig.raster.tools.lib.api.RasterClip; |
82 |
import org.gvsig.raster.tools.lib.api.exceptions.RasterToolCreatingPanelException; |
83 |
import org.gvsig.raster.tools.swing.api.RasterToolsSwingLocator; |
84 |
import org.gvsig.raster.tools.swing.api.clip.ClipPanel; |
85 |
import org.gvsig.tools.ToolsLocator; |
86 |
import org.gvsig.tools.i18n.I18nManager; |
87 |
import org.gvsig.tools.locator.LocatorException; |
88 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
89 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
90 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
91 |
|
92 |
/**
|
93 |
* @author fdiaz
|
94 |
*
|
95 |
*/
|
96 |
public class ClipPanelController extends ClipPanelView implements ClipPanel { |
97 |
|
98 |
/**
|
99 |
*
|
100 |
*/
|
101 |
private static final long serialVersionUID = 6979744092502525949L; |
102 |
private static final Logger LOG = LoggerFactory.getLogger(ClipPanelController.class); |
103 |
private static final String DEFAULT_LAYER_NAME= "Clip"; |
104 |
private static final String CLIP_TOOL_NAME = "raster-clip-tool"; |
105 |
|
106 |
// The elements are defined in the Buffer interface, the array should not be
|
107 |
// changed.
|
108 |
private static String[] interpolationMethods = { "_nearest_neighbour", "_bilinear", "_inverse_distance", |
109 |
"_bicubic_spline", "_bspline" }; |
110 |
|
111 |
private RasterLayer layer;
|
112 |
private Envelope layerEnvelope;
|
113 |
private double layerPixelSizeX; |
114 |
private double layerPixelSizeY; |
115 |
private int layerColumns; |
116 |
private int layerRows; |
117 |
|
118 |
private Envelope envelope;
|
119 |
private boolean updatingResolution; |
120 |
private boolean updatingEnvelope; |
121 |
private boolean updatingPixels; |
122 |
private MapControl mapControl;
|
123 |
private String previousTool; |
124 |
ICoordTrans ct; |
125 |
|
126 |
/**
|
127 |
* @throws RasterToolCreatingPanelException
|
128 |
*/
|
129 |
public ClipPanelController() throws RasterToolCreatingPanelException { |
130 |
translate(); |
131 |
initializeComponents(); |
132 |
} |
133 |
|
134 |
public void set(FLayer layer) throws RasterToolCreatingPanelException{ |
135 |
this.layer = (RasterLayer) layer;
|
136 |
if(mapControl!=null){ |
137 |
init(); |
138 |
} |
139 |
} |
140 |
|
141 |
public void set(MapControl mapControl) throws RasterToolCreatingPanelException{ |
142 |
this.mapControl = mapControl;
|
143 |
this.previousTool = mapControl.getCurrentTool();
|
144 |
if(this.layer != null){ |
145 |
init(); |
146 |
} |
147 |
} |
148 |
|
149 |
private void init() throws RasterToolCreatingPanelException{ |
150 |
this.addAncestorListener(new AncestorListener() { |
151 |
@Override
|
152 |
public void ancestorRemoved(AncestorEvent event) { |
153 |
returnMapControlToPreviousTool(); |
154 |
} |
155 |
@Override
|
156 |
public void ancestorMoved(AncestorEvent event) { |
157 |
returnMapControlToPreviousTool(); |
158 |
} |
159 |
@Override
|
160 |
public void ancestorAdded(AncestorEvent event) { |
161 |
// Do nothing
|
162 |
} |
163 |
}); |
164 |
IProjection layerProj = this.layer.getProjection();
|
165 |
IProjection viewProj = mapControl.getProjection(); |
166 |
ct = null;
|
167 |
if(!layerProj.equals(viewProj)){
|
168 |
ct = layerProj.getCT(viewProj); |
169 |
} |
170 |
// Solo cogemos de las dimensiones del store las filas y columnas porque si la capa est? reproyectada
|
171 |
// su envelope y sus pixels size no se corresponden con los del raster store.
|
172 |
try {
|
173 |
layerEnvelope = this.layer.getFullEnvelope();
|
174 |
} catch (LocatorException | DataException e1) {
|
175 |
LOG.warn("Can't get the envelope of the layer", e1);
|
176 |
throw new RasterToolCreatingPanelException("Can't get the envelope of the layer "+layer.getName(),e1); |
177 |
} |
178 |
|
179 |
RasterStore rasterStore = this.layer.getRasterStore();
|
180 |
try {
|
181 |
BufferDimensions rasterStoreDimensions = rasterStore.getDimensions(); |
182 |
layerColumns = rasterStoreDimensions.getColumns(); |
183 |
layerRows = rasterStoreDimensions.getRows(); |
184 |
layerPixelSizeX = layerEnvelope.getLength(DIMENSIONS.X)/layerColumns; |
185 |
layerPixelSizeY = layerEnvelope.getLength(DIMENSIONS.Y)/layerRows; |
186 |
} catch (InitializeException e) {
|
187 |
LOG.warn("Can't get dimensions of the layer's raster store.", e);
|
188 |
throw new RasterToolCreatingPanelException("Can't get the raster set of the layer " + layer.getName(), e); |
189 |
} |
190 |
List<BandDescriptor> descriptors = new ArrayList<BandDescriptor>(); |
191 |
for(int i=0; i<rasterStore.getBands(); i++){ |
192 |
descriptors.add(rasterStore.getBandDescriptor(i)); |
193 |
} |
194 |
|
195 |
MapContextRasterSwingManager mapContextRasterSwingManager = MapContextRasterSwingLocator.getSwingManager(); |
196 |
SelectableBandDescriptorsTableModel model = mapContextRasterSwingManager.createSelectableBandDescriptorsTableModel(descriptors); |
197 |
// tblBands.setModel(model);
|
198 |
|
199 |
RasterSwingBufferManager bufferSwingManager = RasterSwingBufferLocator.getSwingManager(); |
200 |
bufferSwingManager.makeASelectableBandsTable(tblBands, model); |
201 |
|
202 |
// tblBands.setColumnModel(new DefaultTableColumnModel());
|
203 |
// TableColumnModel columnModel = tblBands.getColumnModel();
|
204 |
// columnModel.setColumnSelectionAllowed(false);
|
205 |
// for (int i = 0; i < model.getColumnCount(); i++) {
|
206 |
// TableColumn tableColumn = new TableColumn(i);
|
207 |
// tableColumn.setIdentifier(model.getColumnName(i));
|
208 |
// tableColumn.setHeaderValue(model.getColumnName(i));
|
209 |
// columnModel.addColumn(tableColumn);
|
210 |
// }
|
211 |
|
212 |
setFullEnvelope(); |
213 |
txtCellWidth.setValue(layerPixelSizeX); |
214 |
txtCellHeight.setValue(layerPixelSizeY); |
215 |
|
216 |
updateResolution(true);
|
217 |
updatingResolution=false;
|
218 |
|
219 |
File folder = BufferLocator.getBufferManager().getLastFolderUsedToSaveRaster();
|
220 |
if(folder!=null){ |
221 |
txtFolder.setText(folder.getAbsolutePath()); |
222 |
} |
223 |
} |
224 |
|
225 |
@Override
|
226 |
public JComponent asJComponent() { |
227 |
return this; |
228 |
} |
229 |
|
230 |
private void initializeComponents() { |
231 |
// Tab coordinates
|
232 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
233 |
lblIconPix1.setIcon(iconTheme.get("upleft"));
|
234 |
lblIconPix2.setIcon(iconTheme.get("downright"));
|
235 |
lblIconReal1.setIcon(iconTheme.get("upleft"));
|
236 |
lblIconReal2.setIcon(iconTheme.get("downright"));
|
237 |
|
238 |
PixelCoordinatesDocumentListener pixelCoordinatesDocumentListener = new PixelCoordinatesDocumentListener();
|
239 |
txtPix1X.getDocument().addDocumentListener(pixelCoordinatesDocumentListener); |
240 |
txtPix1Y.getDocument().addDocumentListener(pixelCoordinatesDocumentListener); |
241 |
txtPix2X.getDocument().addDocumentListener(pixelCoordinatesDocumentListener); |
242 |
txtPix2Y.getDocument().addDocumentListener(pixelCoordinatesDocumentListener); |
243 |
|
244 |
RealCoordinatesDocumentListener realCoordinatesDocumentListener = new RealCoordinatesDocumentListener();
|
245 |
txtReal1X.getDocument().addDocumentListener(realCoordinatesDocumentListener); |
246 |
txtReal1Y.getDocument().addDocumentListener(realCoordinatesDocumentListener); |
247 |
txtReal2X.getDocument().addDocumentListener(realCoordinatesDocumentListener); |
248 |
txtReal2Y.getDocument().addDocumentListener(realCoordinatesDocumentListener); |
249 |
|
250 |
btnLoad.setIcon(iconTheme.get("loadparameters-icon"));
|
251 |
btnSave.setIcon(iconTheme.get("saveparameters-icon"));
|
252 |
btnPixelsRound.setIcon(iconTheme.get("round-icon"));
|
253 |
btnRois.setIcon(iconTheme.get("roi"));
|
254 |
btnFullLayer.setIcon(iconTheme.get("fullextent-icon"));
|
255 |
btnView.setIcon(iconTheme.get("viewextent-icon"));
|
256 |
btnViewSelection.setIcon(iconTheme.get("selecttool-icon"));
|
257 |
|
258 |
btnLoad.addActionListener(new ActionListener() { |
259 |
@Override
|
260 |
public void actionPerformed(ActionEvent e) { |
261 |
doLoadEnvelope(); |
262 |
} |
263 |
}); |
264 |
|
265 |
btnSave.addActionListener(new ActionListener() { |
266 |
@Override
|
267 |
public void actionPerformed(ActionEvent e) { |
268 |
doSaveEnvelope(); |
269 |
} |
270 |
}); |
271 |
|
272 |
btnPixelsRound.addActionListener(new ActionListener() { |
273 |
@Override
|
274 |
public void actionPerformed(ActionEvent e) { |
275 |
doPixelsRound(); |
276 |
} |
277 |
}); |
278 |
|
279 |
//FIXME: habilitarlo cuando est? implementado
|
280 |
btnRois.setEnabled(false);
|
281 |
btnRois.addActionListener(new ActionListener() { |
282 |
@Override
|
283 |
public void actionPerformed(ActionEvent e) { |
284 |
doImportROIsEnvelope(); |
285 |
} |
286 |
}); |
287 |
|
288 |
btnFullLayer.addActionListener(new ActionListener() { |
289 |
@Override
|
290 |
public void actionPerformed(ActionEvent e) { |
291 |
doImportFullLayerEnvelope(); |
292 |
} |
293 |
}); |
294 |
|
295 |
btnView.addActionListener(new ActionListener() { |
296 |
@Override
|
297 |
public void actionPerformed(ActionEvent e) { |
298 |
doImportViewExtentEnvelope(); |
299 |
} |
300 |
}); |
301 |
|
302 |
btnViewSelection.addActionListener(new ActionListener() { |
303 |
@Override
|
304 |
public void actionPerformed(ActionEvent e) { |
305 |
doImportViewSelection(); |
306 |
} |
307 |
}); |
308 |
|
309 |
// Tab resolution
|
310 |
|
311 |
rbtnCellSize.addActionListener(new ActionListener() { |
312 |
@Override
|
313 |
public void actionPerformed(ActionEvent e) { |
314 |
doSelectModeSize(); |
315 |
} |
316 |
}); |
317 |
rbtnRasterSize.addActionListener(new ActionListener() { |
318 |
@Override
|
319 |
public void actionPerformed(ActionEvent e) { |
320 |
doSelectModeSize(); |
321 |
} |
322 |
}); |
323 |
|
324 |
cmbInterpolationMethod.setSelectedIndex(0);
|
325 |
cmbInterpolationMethod.setEditable(false);
|
326 |
|
327 |
txtCellWidth.getDocument().addDocumentListener(new DocumentListener() { |
328 |
@Override
|
329 |
public void removeUpdate(DocumentEvent e) { |
330 |
changedUpdate(e); |
331 |
} |
332 |
@Override
|
333 |
public void insertUpdate(DocumentEvent e) { |
334 |
changedUpdate(e); |
335 |
} |
336 |
@Override
|
337 |
public void changedUpdate(DocumentEvent e) { |
338 |
doChangeUpdateCellWidth(); |
339 |
} |
340 |
}); |
341 |
|
342 |
txtCellHeight.getDocument().addDocumentListener(new DocumentListener() { |
343 |
@Override
|
344 |
public void removeUpdate(DocumentEvent e) { |
345 |
changedUpdate(e); |
346 |
} |
347 |
@Override
|
348 |
public void insertUpdate(DocumentEvent e) { |
349 |
changedUpdate(e); |
350 |
} |
351 |
@Override
|
352 |
public void changedUpdate(DocumentEvent e) { |
353 |
doChangeUpdateCellHeight(); |
354 |
} |
355 |
}); |
356 |
|
357 |
txtWidth.getDocument().addDocumentListener(new DocumentListener() { |
358 |
@Override
|
359 |
public void removeUpdate(DocumentEvent e) { |
360 |
changedUpdate(e); |
361 |
} |
362 |
@Override
|
363 |
public void insertUpdate(DocumentEvent e) { |
364 |
changedUpdate(e); |
365 |
} |
366 |
@Override
|
367 |
public void changedUpdate(DocumentEvent e) { |
368 |
doChangeUpdateWidth(); |
369 |
|
370 |
} |
371 |
}); |
372 |
|
373 |
txtHeight.getDocument().addDocumentListener(new DocumentListener() { |
374 |
@Override
|
375 |
public void removeUpdate(DocumentEvent e) { |
376 |
changedUpdate(e); |
377 |
} |
378 |
@Override
|
379 |
public void insertUpdate(DocumentEvent e) { |
380 |
changedUpdate(e); |
381 |
} |
382 |
@Override
|
383 |
public void changedUpdate(DocumentEvent e) { |
384 |
doChangeUpdateHeight(); |
385 |
} |
386 |
}); |
387 |
|
388 |
btnRestore.addActionListener(new ActionListener() { |
389 |
@Override
|
390 |
public void actionPerformed(ActionEvent e) { |
391 |
doRestore(); |
392 |
} |
393 |
}); |
394 |
|
395 |
btnImportCellWidthFromView.addActionListener(new ActionListener() { |
396 |
@Override
|
397 |
public void actionPerformed(ActionEvent e) { |
398 |
doImportCellWidthFromView(); |
399 |
} |
400 |
}); |
401 |
|
402 |
// Tab Bands
|
403 |
|
404 |
tblBands.setRowSelectionAllowed(true);
|
405 |
tblBands.setColumnSelectionAllowed(false);
|
406 |
tblBands.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
407 |
tblBands.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
408 |
|
409 |
@Override
|
410 |
public void valueChanged(ListSelectionEvent e) { |
411 |
doSelectionTblBandsChanged(); |
412 |
} |
413 |
}); |
414 |
|
415 |
|
416 |
this.btnUpBand.addActionListener(new ActionListener() { |
417 |
@Override
|
418 |
public void actionPerformed(ActionEvent e) { |
419 |
doUpBand(); |
420 |
} |
421 |
}); |
422 |
|
423 |
this.btnDownBand.addActionListener(new ActionListener() { |
424 |
@Override
|
425 |
public void actionPerformed(ActionEvent e) { |
426 |
doDownBand(); |
427 |
} |
428 |
}); |
429 |
|
430 |
// Tab other options
|
431 |
|
432 |
btnUpBand.setIcon(iconTheme.get("up"));
|
433 |
btnDownBand.setIcon(iconTheme.get("down"));
|
434 |
|
435 |
|
436 |
chkSaveTo.addActionListener(new ActionListener() { |
437 |
@Override
|
438 |
public void actionPerformed(ActionEvent e) { |
439 |
doCheckSaveToFolder(); |
440 |
} |
441 |
}); |
442 |
|
443 |
btnFolderChooser.addActionListener(new ActionListener() { |
444 |
@Override
|
445 |
public void actionPerformed(ActionEvent e) { |
446 |
doSelectFolder(); |
447 |
} |
448 |
}); |
449 |
|
450 |
} |
451 |
|
452 |
protected void doImportCellWidthFromView() { |
453 |
double ratio = layerPixelSizeX/layerPixelSizeY;
|
454 |
|
455 |
double pixelSizeX = mapControl.getViewPort().getDist1pixel();
|
456 |
txtCellWidth.setValue(pixelSizeX); |
457 |
// double pixelSizeY = pixelSizeX/ratio;
|
458 |
// txtCellHeight.setValue(pixelSizeY);
|
459 |
// txtWidth.setValue((int) Math.round(envelope.getLength(DIMENSIONS.X) / pixelSizeX));
|
460 |
// txtHeight.setValue((int) Math.round(envelope.getLength(DIMENSIONS.Y) / pixelSizeY));
|
461 |
updateSize(); |
462 |
} |
463 |
|
464 |
protected void doChangeUpdateCellHeight() { |
465 |
if(updatingResolution){
|
466 |
return;
|
467 |
} |
468 |
updatingResolution = true;
|
469 |
Double pixelSizeY = ((Number) txtCellHeight.getValue()).doubleValue(); |
470 |
if (pixelSizeY != null) { |
471 |
Envelope envelope = this.envelope; //calculateEnvelope(); |
472 |
double ratio = layerPixelSizeX/layerPixelSizeY;
|
473 |
double pixelSizeX = pixelSizeY*ratio;
|
474 |
txtCellWidth.setValue(pixelSizeX); |
475 |
txtWidth.setValue((int) Math.round(envelope.getLength(DIMENSIONS.X) / pixelSizeX)); |
476 |
txtHeight.setValue((int) Math.round(envelope.getLength(DIMENSIONS.Y) / pixelSizeY)); |
477 |
} |
478 |
updatingResolution = false;
|
479 |
} |
480 |
|
481 |
protected void doChangeUpdateCellWidth() { |
482 |
|
483 |
if (updatingResolution) {
|
484 |
return;
|
485 |
} |
486 |
updatingResolution = true;
|
487 |
Double pixelSizeX = ((Number) txtCellWidth.getValue()).doubleValue(); |
488 |
if (pixelSizeX != null) { |
489 |
Envelope envelope = this.envelope; // calculateEnvelope(); |
490 |
double ratio = layerPixelSizeX / layerPixelSizeY;
|
491 |
double pixelSizeY = pixelSizeX / ratio;
|
492 |
txtCellHeight.setValue(pixelSizeY); |
493 |
txtWidth.setValue((int) Math.round(envelope.getLength(DIMENSIONS.X) / pixelSizeX)); |
494 |
txtHeight.setValue((int) Math.round(envelope.getLength(DIMENSIONS.Y) / pixelSizeY)); |
495 |
} |
496 |
updatingResolution = false;
|
497 |
} |
498 |
|
499 |
protected void doChangeUpdateHeight() { |
500 |
if(updatingResolution){
|
501 |
return;
|
502 |
} |
503 |
updatingResolution = true;
|
504 |
Integer value = (Integer) txtHeight.getValue(); |
505 |
Envelope envelope = this.envelope; //calculateEnvelope(); |
506 |
double pixelSizeY = envelope.getLength(DIMENSIONS.Y) / value;
|
507 |
double ratio = layerPixelSizeX/layerPixelSizeY;
|
508 |
double pixelSizeX = pixelSizeY*ratio;
|
509 |
txtCellWidth.setValue(pixelSizeX); |
510 |
txtCellHeight.setValue(pixelSizeY); |
511 |
txtWidth.setValue((int)Math.round(envelope.getLength(DIMENSIONS.X) / pixelSizeX)); |
512 |
updatingResolution = false;
|
513 |
} |
514 |
|
515 |
protected void doChangeUpdateWidth() { |
516 |
if(updatingResolution){
|
517 |
return;
|
518 |
} |
519 |
updatingResolution = true;
|
520 |
Integer value = (Integer) txtWidth.getValue(); |
521 |
Envelope envelope = this.envelope; //calculateEnvelope(); |
522 |
double pixelSizeX = envelope.getLength(DIMENSIONS.X) / value;
|
523 |
double ratio = layerPixelSizeX/layerPixelSizeY;
|
524 |
double pixelSizeY = pixelSizeX/ratio;
|
525 |
txtCellWidth.setValue(pixelSizeX); |
526 |
txtCellHeight.setValue(pixelSizeY); |
527 |
txtHeight.setValue((int)Math.round(envelope.getLength(DIMENSIONS.Y) / pixelSizeY)); |
528 |
updatingResolution = false;
|
529 |
} |
530 |
|
531 |
protected void doImportROIsEnvelope() { |
532 |
try {
|
533 |
RasterStore rasterStore = this.layer.getRasterStore();
|
534 |
// FIXME: Ver qu? hacemos con las ROIs y coger el envelope
|
535 |
Envelope envelope = GeometryLocator.getGeometryManager().createEnvelope(SUBTYPES.GEOM2D); |
536 |
setEnvelope(envelope); |
537 |
RasterQuery query = rasterStore.createRasterQuery().setClip(envelope); |
538 |
RasterSet rasterSet = rasterStore.getRasterSet(query); |
539 |
setPixels(0, 0, rasterSet.getColumns() - 1, rasterSet.getRows() - 1); |
540 |
} catch (LocatorException | CreateEnvelopeException e1) {
|
541 |
LOG.warn("Can't get the envelope of the rois of the layer", e1);
|
542 |
// TODO Gestionar la excepci?n ?mostrar di?logo de advertencia?
|
543 |
} catch (DataException e1) {
|
544 |
LOG.warn("Can't get the raster set of the envelope of the ROIs of the layer", e1);
|
545 |
// TODO Gestionar la excepci?n ?mostrar di?logo de advertencia?
|
546 |
} |
547 |
updateResolution(false);
|
548 |
} |
549 |
|
550 |
protected void doLoadEnvelope() { |
551 |
Envelope lastEnvelopeSaved = RasterToolsSwingLocator.getSwingManager().getLastClipEnvelopeSaved(); |
552 |
if (lastEnvelopeSaved == null) { |
553 |
ThreadSafeDialogsManager dlgManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
554 |
String message = "_there_is_no_previously_saved_envelope"; |
555 |
String title = "_error_creating_clip"; |
556 |
dlgManager.messageDialog(message, title, JOptionPane.WARNING_MESSAGE);
|
557 |
} else {
|
558 |
if (lastEnvelopeSaved.intersects(ClipPanelController.this.layerEnvelope)) {
|
559 |
Envelope intersection = null;
|
560 |
try {
|
561 |
intersection = |
562 |
(lastEnvelopeSaved.getGeometry().intersection(ClipPanelController.this.layerEnvelope |
563 |
.getGeometry())).getEnvelope(); |
564 |
} catch (GeometryOperationNotSupportedException | GeometryOperationException e) {
|
565 |
LOG.warn("Can't gets intersection between last envelope saved and the layer's envelope", e);
|
566 |
} |
567 |
|
568 |
if (intersection != null) { |
569 |
this.setEnvelope(intersection);
|
570 |
this.updatePixelsFromEnvelope();
|
571 |
} |
572 |
} |
573 |
} |
574 |
} |
575 |
|
576 |
protected void doSaveEnvelope() { |
577 |
try {
|
578 |
RasterToolsSwingLocator.getSwingManager().setLastClipEnvelopeSaved((Envelope) this.envelope.clone());
|
579 |
// this.lastEnvelopeSaved = (Envelope) this.envelope.clone();
|
580 |
} catch (CloneNotSupportedException e1) { |
581 |
LOG.warn("Can't clone the envelope", e1);
|
582 |
} |
583 |
} |
584 |
|
585 |
protected void doImportViewSelection() { |
586 |
|
587 |
if (!CLIP_TOOL_NAME.equalsIgnoreCase(this.mapControl.getCurrentTool())) { |
588 |
this.previousTool = this.mapControl.getCurrentTool(); |
589 |
} |
590 |
|
591 |
RectangleBehavior behavior = new RectangleBehavior(new RectangleListener() { |
592 |
|
593 |
@Override
|
594 |
public Image getImageCursor() { |
595 |
return IconThemeHelper.getImage("cursor-select-by-rectangle"); |
596 |
} |
597 |
|
598 |
@Override
|
599 |
public boolean cancelDrawing() { |
600 |
return false; |
601 |
} |
602 |
|
603 |
@Override
|
604 |
public void rectangle(EnvelopeEvent event) throws BehaviorException { |
605 |
Envelope selectedEnvelope = event.getWorldCoordRect(); |
606 |
if (selectedEnvelope.intersects(ClipPanelController.this.layerEnvelope)) {
|
607 |
Envelope intersection = null;
|
608 |
try {
|
609 |
intersection = |
610 |
(selectedEnvelope.getGeometry().intersection(ClipPanelController.this.layerEnvelope |
611 |
.getGeometry())).getEnvelope(); |
612 |
} catch (GeometryOperationNotSupportedException | GeometryOperationException e) {
|
613 |
LOG.warn("Can't gets intersection between selected envelope and the layer's envelope", e);
|
614 |
} |
615 |
|
616 |
if (intersection != null) { |
617 |
ClipPanelController.this.setEnvelope(intersection); |
618 |
updatingPixels = true;
|
619 |
if (ClipPanelController.this.updatePixelsFromEnvelope()) {
|
620 |
updateSize(); |
621 |
} |
622 |
; |
623 |
updatingPixels = false;
|
624 |
|
625 |
} |
626 |
} |
627 |
ClipPanelController.this.returnMapControlToPreviousTool(); |
628 |
} |
629 |
}); |
630 |
|
631 |
// if(!this.mapControl.hasTool(CLIP_TOOL_NAME)){
|
632 |
this.mapControl.addBehavior(CLIP_TOOL_NAME, behavior);
|
633 |
// }
|
634 |
this.mapControl.setTool(CLIP_TOOL_NAME);
|
635 |
} |
636 |
|
637 |
protected void doPixelsRound() { |
638 |
if (updateEnvelopeFromPixels()) {
|
639 |
updateSize(); |
640 |
} |
641 |
} |
642 |
|
643 |
protected void doRestore() { |
644 |
updateResolution(true);
|
645 |
} |
646 |
|
647 |
protected void doSelectFolder() { |
648 |
// FIXME:
|
649 |
JFileChooser fc = null; |
650 |
if (!txtFolder.getText().isEmpty()) {
|
651 |
fc = new JFileChooser(txtFolder.getText()); |
652 |
} else {
|
653 |
fc = new JFileChooser(); |
654 |
} |
655 |
|
656 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
657 |
fc.setMultiSelectionEnabled(false);
|
658 |
int result = fc.showOpenDialog(this); |
659 |
if (result == JFileChooser.APPROVE_OPTION) { |
660 |
File folder = fc.getSelectedFile();
|
661 |
txtFolder.setText(folder.getAbsolutePath()); |
662 |
BufferLocator.getBufferManager().setLastFolderUsedToSaveRaster(folder); |
663 |
} |
664 |
} |
665 |
|
666 |
protected void doCheckSaveToFolder() { |
667 |
boolean selected = chkSaveTo.isSelected();
|
668 |
txtFolder.setEnabled(selected); |
669 |
btnFolderChooser.setEnabled(selected); |
670 |
lblFolder.setEnabled(selected); |
671 |
} |
672 |
|
673 |
protected void doImportFullLayerEnvelope() { |
674 |
setFullEnvelope(); |
675 |
updateResolution(true);
|
676 |
} |
677 |
|
678 |
protected void doImportViewExtentEnvelope() { |
679 |
setEnvelope(mapControl.getViewPort().getAdjustedEnvelope()); |
680 |
updatePixelsFromEnvelope(); |
681 |
doImportCellWidthFromView(); |
682 |
} |
683 |
|
684 |
protected void doSelectModeSize() { |
685 |
lblCellHeight.setEnabled(rbtnCellSize.isSelected()); |
686 |
txtCellWidth.setEnabled(rbtnCellSize.isSelected()); |
687 |
lblCellWidth.setEnabled(rbtnCellSize.isSelected()); |
688 |
txtCellHeight.setEnabled(rbtnCellSize.isSelected()); |
689 |
|
690 |
lblRasterWidth.setEnabled(rbtnRasterSize.isSelected()); |
691 |
txtWidth.setEnabled(rbtnRasterSize.isSelected()); |
692 |
lblRasterHeight.setEnabled(rbtnRasterSize.isSelected()); |
693 |
txtHeight.setEnabled(rbtnRasterSize.isSelected()); |
694 |
} |
695 |
|
696 |
protected void doDownBand() { |
697 |
SelectableBandDescriptorsTableModel bandsTableModel = (SelectableBandDescriptorsTableModel) tblBands.getModel(); |
698 |
int selectedRow = tblBands.getSelectedRow();
|
699 |
bandsTableModel.down(selectedRow); |
700 |
tblBands.getSelectionModel().setSelectionInterval(selectedRow + 1, selectedRow + 1); |
701 |
} |
702 |
|
703 |
protected void doUpBand() { |
704 |
SelectableBandDescriptorsTableModel bandsTableModel = (SelectableBandDescriptorsTableModel) tblBands.getModel(); |
705 |
int selectedRow = tblBands.getSelectedRow();
|
706 |
bandsTableModel.up(selectedRow); |
707 |
tblBands.getSelectionModel().setSelectionInterval(selectedRow - 1, selectedRow - 1); |
708 |
} |
709 |
|
710 |
|
711 |
private void translate() { |
712 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
713 |
|
714 |
lblPixelCoord.setText(i18nManager.getTranslation(lblPixelCoord.getText())); |
715 |
lblRealCoord.setText(i18nManager.getTranslation(lblRealCoord.getText())); |
716 |
for (int i = 0; i < tabClip.getTabCount(); i++) { |
717 |
tabClip.setTitleAt(i, i18nManager.getTranslation(tabClip.getTitleAt(i))); |
718 |
} |
719 |
|
720 |
lblPix1X.setText(i18nManager.getTranslation(lblPix1X.getText())); |
721 |
lblPix1Y.setText(i18nManager.getTranslation(lblPix1Y.getText())); |
722 |
lblPix2X.setText(i18nManager.getTranslation(lblPix2X.getText())); |
723 |
lblPix2Y.setText(i18nManager.getTranslation(lblPix2Y.getText())); |
724 |
|
725 |
btnViewSelection.setText(""); //i18nManager.getTranslation(btnViewSelection.getText())); |
726 |
btnViewSelection.setToolTipText(i18nManager.getTranslation(btnViewSelection.getToolTipText())); |
727 |
|
728 |
btnFullLayer.setText(""); //i18nManager.getTranslation(btnFullLayer.getText())); |
729 |
btnFullLayer.setToolTipText(i18nManager.getTranslation(btnFullLayer.getToolTipText())); |
730 |
|
731 |
btnView.setText(""); //i18nManager.getTranslation(btnView.getText())); |
732 |
btnView.setToolTipText(i18nManager.getTranslation(btnView.getToolTipText())); |
733 |
|
734 |
btnPixelsRound.setText(""); //i18nManager.getTranslation(btnPixelsRound.getText())); |
735 |
btnPixelsRound.setToolTipText(i18nManager.getTranslation(btnPixelsRound.getToolTipText())); |
736 |
|
737 |
btnLoad.setText(""); //i18nManager.getTranslation(btnLoad.getText())); |
738 |
btnLoad.setToolTipText(i18nManager.getTranslation(btnLoad.getToolTipText())); |
739 |
|
740 |
btnSave.setText(""); //i18nManager.getTranslation(btnSave.getText())); |
741 |
btnSave.setToolTipText(i18nManager.getTranslation(btnSave.getToolTipText())); |
742 |
|
743 |
btnRois.setText(""); //i18nManager.getTranslation(btnRois.getText())); |
744 |
btnRois.setToolTipText(i18nManager.getTranslation(btnRois.getToolTipText())); |
745 |
|
746 |
lblRasterWidth.setText(i18nManager.getTranslation(lblRasterWidth.getText())); |
747 |
lblCellWidth.setText(i18nManager.getTranslation(lblCellWidth.getText())); |
748 |
lblCellHeight.setText(i18nManager.getTranslation(lblCellHeight.getText())); |
749 |
lblRasterHeight.setText(i18nManager.getTranslation(lblRasterHeight.getText())); |
750 |
|
751 |
lblResolutionMode.setText(i18nManager.getTranslation(lblResolutionMode.getText())); |
752 |
lblInterpolation.setText(i18nManager.getTranslation(lblInterpolation.getText())); |
753 |
|
754 |
btnRestore.setText(i18nManager.getTranslation(btnRestore.getText())); |
755 |
btnRestore.setToolTipText(i18nManager.getTranslation(btnRestore.getToolTipText())); |
756 |
|
757 |
btnImportCellWidthFromView.setText(i18nManager.getTranslation(btnImportCellWidthFromView.getText())); |
758 |
btnImportCellWidthFromView.setToolTipText(i18nManager.getTranslation(btnImportCellWidthFromView.getToolTipText())); |
759 |
|
760 |
rbtnCellSize.setText(i18nManager.getTranslation(rbtnCellSize.getText())); |
761 |
rbtnCellSize.setToolTipText(i18nManager.getTranslation(rbtnCellSize.getToolTipText())); |
762 |
|
763 |
rbtnRasterSize.setText(i18nManager.getTranslation(rbtnRasterSize.getText())); |
764 |
rbtnRasterSize.setToolTipText(i18nManager.getTranslation(rbtnRasterSize.getToolTipText())); |
765 |
|
766 |
lblLayerNames.setText(i18nManager.getTranslation(lblLayerNames.getText())); |
767 |
txtLayerNames.setText(i18nManager.getTranslation("_newlayer"));
|
768 |
|
769 |
chkOnePerBand.setText(i18nManager.getTranslation(chkOnePerBand.getText())); |
770 |
chkOnePerBand.setToolTipText(i18nManager.getTranslation(chkOnePerBand.getToolTipText())); |
771 |
|
772 |
chkSaveTo.setText(i18nManager.getTranslation(chkSaveTo.getText())); |
773 |
chkSaveTo.setToolTipText(i18nManager.getTranslation(chkSaveTo.getToolTipText())); |
774 |
|
775 |
lblFolder.setText(i18nManager.getTranslation(lblFolder.getText())); |
776 |
|
777 |
btnFolderChooser.setText(i18nManager.getTranslation(btnFolderChooser.getText())); |
778 |
btnFolderChooser.setToolTipText(i18nManager.getTranslation(btnFolderChooser.getToolTipText())); |
779 |
|
780 |
btnUpBand.setText(""); //i18nManager.getTranslation(btnUpBand.getText())); |
781 |
btnUpBand.setToolTipText(i18nManager.getTranslation(btnUpBand.getToolTipText())); |
782 |
|
783 |
btnDownBand.setText(""); //i18nManager.getTranslation(btnDownBand.getText())); |
784 |
btnDownBand.setToolTipText(i18nManager.getTranslation(btnDownBand.getToolTipText())); |
785 |
|
786 |
cmbInterpolationMethod.removeAllItems(); |
787 |
|
788 |
for (int i = 0; i < interpolationMethods.length; i++) { |
789 |
cmbInterpolationMethod.addItem(i18nManager.getTranslation(interpolationMethods[i])); |
790 |
} |
791 |
|
792 |
|
793 |
NumberFormat numberInstance = NumberFormat.getNumberInstance(); |
794 |
numberInstance.setGroupingUsed(false);
|
795 |
numberInstance.setMaximumFractionDigits(Integer.MAX_VALUE);
|
796 |
NumberFormatter numberFormatter = new NumberFormatter(numberInstance); |
797 |
DefaultFormatterFactory tf = new DefaultFormatterFactory( |
798 |
numberFormatter, |
799 |
numberFormatter, |
800 |
numberFormatter, |
801 |
numberFormatter); |
802 |
txtReal1X.setFormatterFactory(tf); |
803 |
|
804 |
txtReal1Y.setFormatterFactory(tf); |
805 |
txtReal2X.setFormatterFactory(tf); |
806 |
txtReal2Y.setFormatterFactory(tf); |
807 |
txtCellWidth.setFormatterFactory(tf); |
808 |
txtCellHeight.setFormatterFactory(tf); |
809 |
|
810 |
NumberFormat integerInstance = NumberFormat.getIntegerInstance(); |
811 |
integerInstance.setGroupingUsed(false);
|
812 |
numberFormatter = new NumberFormatter(integerInstance); |
813 |
numberFormatter.setMinimum(0);
|
814 |
numberFormatter.setMaximum(layerColumns-1);
|
815 |
tf = new DefaultFormatterFactory( |
816 |
numberFormatter, |
817 |
numberFormatter, |
818 |
numberFormatter, |
819 |
numberFormatter); |
820 |
txtPix1X.setFormatterFactory(tf); |
821 |
|
822 |
numberFormatter = new NumberFormatter(integerInstance); |
823 |
numberFormatter.setMinimum(0);
|
824 |
numberFormatter.setMaximum(layerRows-1);
|
825 |
tf = new DefaultFormatterFactory( |
826 |
numberFormatter, |
827 |
numberFormatter, |
828 |
numberFormatter, |
829 |
numberFormatter); |
830 |
txtPix1Y.setFormatterFactory(tf); |
831 |
numberFormatter = new NumberFormatter(integerInstance); |
832 |
numberFormatter.setMinimum(0);
|
833 |
numberFormatter.setMaximum(layerColumns-1);
|
834 |
tf = new DefaultFormatterFactory( |
835 |
numberFormatter, |
836 |
numberFormatter, |
837 |
numberFormatter, |
838 |
numberFormatter); |
839 |
txtPix2X.setFormatterFactory(tf); |
840 |
numberFormatter = new NumberFormatter(integerInstance); |
841 |
numberFormatter.setMinimum(0);
|
842 |
numberFormatter.setMaximum(layerRows-1);
|
843 |
tf = new DefaultFormatterFactory( |
844 |
numberFormatter, |
845 |
numberFormatter, |
846 |
numberFormatter, |
847 |
numberFormatter); |
848 |
txtPix2Y.setFormatterFactory(tf); |
849 |
|
850 |
numberFormatter = new NumberFormatter(integerInstance); |
851 |
numberFormatter.setMinimum(0);
|
852 |
tf = new DefaultFormatterFactory( |
853 |
numberFormatter, |
854 |
numberFormatter, |
855 |
numberFormatter, |
856 |
numberFormatter); |
857 |
txtWidth.setFormatterFactory(tf); |
858 |
txtHeight.setFormatterFactory(tf); |
859 |
|
860 |
} |
861 |
|
862 |
/**
|
863 |
* @param locale
|
864 |
*
|
865 |
*/
|
866 |
public void setLocate(Locale locale) { |
867 |
Locale l = super.getLocale(); |
868 |
if (!l.equals(locale)) {
|
869 |
translate(); |
870 |
} |
871 |
super.setLocale(locale);
|
872 |
} |
873 |
|
874 |
private void doSelectionTblBandsChanged() { |
875 |
if (tblBands.getSelectedRowCount() == 1) { |
876 |
if (tblBands.getSelectedRow() > 0) { |
877 |
btnUpBand.setEnabled(true);
|
878 |
} else {
|
879 |
btnUpBand.setEnabled(false);
|
880 |
} |
881 |
if (tblBands.getSelectedRow() < tblBands.getRowCount() - 1) { |
882 |
btnDownBand.setEnabled(true);
|
883 |
} else {
|
884 |
btnDownBand.setEnabled(false);
|
885 |
} |
886 |
} else {
|
887 |
btnUpBand.setEnabled(false);
|
888 |
btnDownBand.setEnabled(false);
|
889 |
} |
890 |
} |
891 |
|
892 |
private void returnMapControlToPreviousTool() { |
893 |
mapControl.setTool(this.previousTool);
|
894 |
} |
895 |
|
896 |
/**
|
897 |
*
|
898 |
*/
|
899 |
private void setFullEnvelope() { |
900 |
this.envelope = this.layerEnvelope; |
901 |
setPixels(0, 0, layerColumns - 1, layerRows - 1); |
902 |
setEnvelope(envelope); |
903 |
} |
904 |
|
905 |
|
906 |
public void fetch(RasterClip rasterClip) { |
907 |
rasterClip.setLayer(this.layer);
|
908 |
|
909 |
rasterClip.setEnvelope(calculateEnvelope()); |
910 |
rasterClip.setPixelSizeX(getCellWidth()); |
911 |
rasterClip.setPixelSizeY(getCellHeight()); |
912 |
rasterClip.setInterpolationMethod(getInterpolationMethod()); |
913 |
rasterClip.setRows(getResolutionHeight()); |
914 |
rasterClip.setColumns(getResolutionWidth()); |
915 |
|
916 |
String layerNamePrefix = txtLayerNames.getText();
|
917 |
if(layerNamePrefix.isEmpty()){
|
918 |
layerNamePrefix = DEFAULT_LAYER_NAME; |
919 |
} |
920 |
rasterClip.setLayerNamePrefix(layerNamePrefix); |
921 |
rasterClip.setCreateOneLayerPerBand(chkOnePerBand.isSelected()); |
922 |
rasterClip.setSaveToNewRasterFile(chkSaveTo.isSelected()); |
923 |
|
924 |
List<Integer> bands = ((SelectableBandDescriptorsTableModel)tblBands.getModel()).getSelectedBands(); |
925 |
|
926 |
rasterClip.setBands(bands); |
927 |
|
928 |
boolean saveToNewRasterFile = chkSaveTo.isSelected();
|
929 |
rasterClip.setSaveToNewRasterFile(saveToNewRasterFile); |
930 |
if(saveToNewRasterFile){
|
931 |
File folder = new File(txtFolder.getText()); |
932 |
rasterClip.setFolder(folder); |
933 |
} |
934 |
} |
935 |
|
936 |
private void updateResolution(boolean updatePixelSize) { |
937 |
updatingResolution=true;
|
938 |
txtWidth.setValue(calculateColumns()); |
939 |
txtHeight.setValue(calculateRows()); |
940 |
if(updatePixelSize){
|
941 |
txtCellWidth.setValue(calculatePixelSizeX()); |
942 |
txtCellHeight.setValue(calculatePixelSizeY()); |
943 |
} |
944 |
updatingResolution=false;
|
945 |
} |
946 |
|
947 |
private Integer calculateColumns() { |
948 |
Integer x1 = (Integer) txtPix1X.getValue(); |
949 |
Integer x2 = (Integer) txtPix2X.getValue(); |
950 |
return x2 - x1 + 1; |
951 |
} |
952 |
|
953 |
private Integer calculateRows() { |
954 |
Integer y1 = (Integer) txtPix1Y.getValue(); |
955 |
Integer y2 = (Integer) txtPix2Y.getValue(); |
956 |
return y2 - y1 + 1; |
957 |
} |
958 |
|
959 |
private Double calculatePixelSizeX() { |
960 |
return this.envelope.getLength(DIMENSIONS.X) / calculateColumns(); |
961 |
} |
962 |
|
963 |
private Double calculatePixelSizeY() { |
964 |
return this.envelope.getLength(DIMENSIONS.Y) / calculateRows(); |
965 |
} |
966 |
|
967 |
private double getCellWidth() { |
968 |
return ((Number) txtCellWidth.getValue()).doubleValue(); |
969 |
} |
970 |
|
971 |
private double getCellHeight() { |
972 |
return ((Number) txtCellHeight.getValue()).doubleValue(); |
973 |
} |
974 |
|
975 |
private int getResolutionWidth() { |
976 |
return ((Integer) txtWidth.getValue()).intValue(); |
977 |
} |
978 |
|
979 |
private int getResolutionHeight() { |
980 |
return ((Integer) txtHeight.getValue()).intValue(); |
981 |
} |
982 |
|
983 |
private void setEnvelope(Envelope envelope) { |
984 |
updatingEnvelope = true;
|
985 |
this.envelope = envelope;
|
986 |
txtReal1X.setValue(envelope.getMinimum(DIMENSIONS.X)); |
987 |
txtReal1Y.setValue(envelope.getMaximum(DIMENSIONS.Y)); |
988 |
txtReal2X.setValue(envelope.getMaximum(DIMENSIONS.X)); |
989 |
txtReal2Y.setValue(envelope.getMinimum(DIMENSIONS.Y)); |
990 |
updatingEnvelope = false;
|
991 |
} |
992 |
|
993 |
private void setPixels(int x1, int y1, int x2, int y2) { |
994 |
updatingPixels = true;
|
995 |
txtPix1X.setValue(new Integer(x1)); |
996 |
txtPix1Y.setValue(new Integer(y1)); |
997 |
txtPix2X.setValue(new Integer(x2)); |
998 |
txtPix2Y.setValue(new Integer(y2)); |
999 |
updatingPixels = false;
|
1000 |
} |
1001 |
|
1002 |
private int getInterpolationMethod() { |
1003 |
return cmbInterpolationMethod.getSelectedIndex() + 1; |
1004 |
} |
1005 |
|
1006 |
/*
|
1007 |
* Creates an envelope from the data of the corresponding text fields.
|
1008 |
*/
|
1009 |
private Envelope calculateEnvelope() {
|
1010 |
// Coercion coercion = new CoerceToDouble();
|
1011 |
boolean fail = false; |
1012 |
Double x1 = ((Number) txtReal1X.getValue()).doubleValue(); |
1013 |
Double y1 = ((Number) txtReal1Y.getValue()).doubleValue(); |
1014 |
Double x2 = ((Number) txtReal2X.getValue()).doubleValue(); |
1015 |
Double y2 = ((Number) txtReal2Y.getValue()).doubleValue(); |
1016 |
try {
|
1017 |
if (x1 != null && y1 != null && x2 != null && y2 != null && x1 != null && x2 >= x1 && y2 <= y1) { |
1018 |
this.envelope = GeometryLocator.getGeometryManager().createEnvelope(x1, y2, x2, y1, SUBTYPES.GEOM2D);
|
1019 |
} else {
|
1020 |
fail = true;
|
1021 |
} |
1022 |
} catch (Exception e2) { |
1023 |
fail = true;
|
1024 |
} |
1025 |
|
1026 |
if (fail) {
|
1027 |
ThreadSafeDialogsManager dlgManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
1028 |
String message =
|
1029 |
"_cant_create_the_envelope_with_this_coordinates_XcolonX_XparenthesisX_XUL1X_XUL2X_XdashX_XDR1X_XDR2X_XparenthesisX";
|
1030 |
String title = "_error_updating_envelope"; |
1031 |
dlgManager.messageDialog(message, |
1032 |
new String[] { txtReal1X.getText(), txtReal2Y.getText(), txtReal2X.getText(), txtReal1Y.getText() }, |
1033 |
title, JOptionPane.WARNING_MESSAGE);
|
1034 |
LOG.warn(message); |
1035 |
} |
1036 |
return this.envelope; |
1037 |
} |
1038 |
|
1039 |
private void updateSize() { |
1040 |
double pixelSizeX = ((Number)txtCellWidth.getValue()).doubleValue(); |
1041 |
double ratio = layerPixelSizeX/layerPixelSizeY;
|
1042 |
|
1043 |
txtWidth.setValue((int)Math.round(this.envelope.getLength(DIMENSIONS.X) / pixelSizeX)); |
1044 |
txtHeight.setValue((int)Math.round(this.envelope.getLength(DIMENSIONS.Y) / (pixelSizeX/ratio))); |
1045 |
} |
1046 |
|
1047 |
private boolean updatePixelsFromEnvelope() { |
1048 |
updatingPixels = true;
|
1049 |
Double real1X = ((Number) txtReal1X.getValue()).doubleValue(); |
1050 |
Double real2X = ((Number) txtReal2X.getValue()).doubleValue(); |
1051 |
Double real1Y = ((Number) txtReal1Y.getValue()).doubleValue(); |
1052 |
Double real2Y = ((Number) txtReal2Y.getValue()).doubleValue(); |
1053 |
if (real1X == null || real2X < real1X || real1X < layerEnvelope.getMinimum(DIMENSIONS.X)) { |
1054 |
real1X = layerEnvelope.getMinimum(DIMENSIONS.X); |
1055 |
} |
1056 |
if (real1Y == null || real2Y > real1Y || real1Y > layerEnvelope.getMaximum(DIMENSIONS.Y)) { |
1057 |
real1Y = layerEnvelope.getMaximum(DIMENSIONS.Y); |
1058 |
} |
1059 |
if (real2X == null || real2X < real1X || real2X > layerEnvelope.getMaximum(DIMENSIONS.X)) { |
1060 |
real2X = layerEnvelope.getMaximum(DIMENSIONS.X); |
1061 |
} |
1062 |
if (real2Y == null || real2Y > real1Y || real2Y < layerEnvelope.getMinimum(DIMENSIONS.Y)) { |
1063 |
real2Y = layerEnvelope.getMinimum(DIMENSIONS.Y); |
1064 |
} |
1065 |
|
1066 |
setPixels((int) Math.round((real1X - layerEnvelope.getMinimum(DIMENSIONS.X)) / layerPixelSizeX), |
1067 |
(int) Math.round((layerEnvelope.getMaximum(DIMENSIONS.Y) - real1Y) / layerPixelSizeY), |
1068 |
(int) Math.round((real2X - layerEnvelope.getMinimum(DIMENSIONS.X)) / layerPixelSizeX) - 1, |
1069 |
(int) Math.round((layerEnvelope.getMaximum(DIMENSIONS.Y) - real2Y) / layerPixelSizeY) - 1); |
1070 |
updatingPixels = false;
|
1071 |
return true; |
1072 |
} |
1073 |
|
1074 |
|
1075 |
private boolean updateEnvelopeFromPixels() { |
1076 |
updatingEnvelope = true;
|
1077 |
|
1078 |
Integer pix1X = null; |
1079 |
pix1X = (Integer) txtPix1X.getValue();
|
1080 |
Integer pix2X = null; |
1081 |
pix2X = (Integer) txtPix2X.getValue();
|
1082 |
Integer pix1Y = null; |
1083 |
pix1Y = (Integer) txtPix1Y.getValue();
|
1084 |
Integer pix2Y = null; |
1085 |
pix2Y = (Integer) txtPix2Y.getValue();
|
1086 |
if (pix1X == null || pix1X < 0 || pix2X < pix1X) { |
1087 |
pix1X = 0;
|
1088 |
} |
1089 |
if (pix1Y == null || pix1Y < 0 || pix2Y < pix1Y) { |
1090 |
pix1Y = 0;
|
1091 |
} |
1092 |
if (pix2X == null || pix2X < pix1X || pix2X >= layerColumns) { |
1093 |
pix2X = layerColumns - 1;
|
1094 |
} |
1095 |
if (pix2Y == null || pix2Y < pix1Y || pix2Y >= layerRows) { |
1096 |
pix2Y = layerRows - 1;
|
1097 |
} |
1098 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
1099 |
try {
|
1100 |
setEnvelope(geomManager.createEnvelope( |
1101 |
pix1X * layerPixelSizeX + layerEnvelope.getMinimum(DIMENSIONS.X), |
1102 |
layerEnvelope.getMaximum(DIMENSIONS.Y) - ((pix2Y + 1) * layerPixelSizeY) ,
|
1103 |
(pix2X + 1) * layerPixelSizeX + layerEnvelope.getMinimum(DIMENSIONS.X),
|
1104 |
layerEnvelope.getMaximum(DIMENSIONS.Y) - (pix1Y * layerPixelSizeY) , |
1105 |
SUBTYPES.GEOM2D)); |
1106 |
updatingEnvelope = false;
|
1107 |
return true; |
1108 |
} catch (CreateEnvelopeException e) {
|
1109 |
LOG.debug("Can't create the envelope", e);
|
1110 |
updatingEnvelope = false;
|
1111 |
return false; |
1112 |
} |
1113 |
} |
1114 |
|
1115 |
private class RealCoordinatesDocumentListener implements DocumentListener { |
1116 |
|
1117 |
@Override
|
1118 |
public void insertUpdate(DocumentEvent e) { |
1119 |
changedUpdate(e); |
1120 |
} |
1121 |
|
1122 |
@Override
|
1123 |
public void removeUpdate(DocumentEvent e) { |
1124 |
changedUpdate(e); |
1125 |
} |
1126 |
|
1127 |
@Override
|
1128 |
public void changedUpdate(DocumentEvent e) { |
1129 |
doChangedUpdateRealCoordinates(e); |
1130 |
} |
1131 |
|
1132 |
} |
1133 |
|
1134 |
private void doChangedUpdateRealCoordinates(DocumentEvent e) { |
1135 |
if(updatingEnvelope){
|
1136 |
return;
|
1137 |
} |
1138 |
if(txtReal1X.getValue()==null || txtReal2X.getValue()==null || txtReal1Y.getValue()==null || txtReal2Y.getValue()==null){ |
1139 |
return;
|
1140 |
} |
1141 |
updatingPixels = true;
|
1142 |
if(updatePixelsFromEnvelope()){
|
1143 |
updateSize(); |
1144 |
}; |
1145 |
updatingPixels = false;
|
1146 |
} |
1147 |
|
1148 |
private class PixelCoordinatesDocumentListener implements DocumentListener { |
1149 |
|
1150 |
@Override
|
1151 |
public void insertUpdate(DocumentEvent e) { |
1152 |
changedUpdate(e); |
1153 |
} |
1154 |
|
1155 |
@Override
|
1156 |
public void removeUpdate(DocumentEvent e) { |
1157 |
changedUpdate(e); |
1158 |
} |
1159 |
|
1160 |
@Override
|
1161 |
public void changedUpdate(DocumentEvent e) { |
1162 |
doChangedUpdatePixelCoordinates(e); |
1163 |
} |
1164 |
|
1165 |
} |
1166 |
|
1167 |
private void doChangedUpdatePixelCoordinates(DocumentEvent e) { |
1168 |
if(updatingPixels){
|
1169 |
return;
|
1170 |
} |
1171 |
if(txtPix1X.getValue()==null || txtPix2X.getValue()==null || txtPix1Y.getValue()==null || txtPix2Y.getValue()==null){ |
1172 |
return;
|
1173 |
} |
1174 |
updatingEnvelope = true;
|
1175 |
if(updateEnvelopeFromPixels()){
|
1176 |
updateSize(); |
1177 |
}; |
1178 |
updatingEnvelope = false;
|
1179 |
} |
1180 |
} |