Revision 10626 trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/wizards/SelectFilePanel.java
SelectFilePanel.java | ||
---|---|---|
44 | 44 |
import com.hardcode.driverManager.DriverLoadException; |
45 | 45 |
import com.iver.andami.PluginServices; |
46 | 46 |
import com.iver.andami.messages.NotificationManager; |
47 |
import com.iver.cit.gvsig.fmap.DriverException;
|
|
47 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
|
|
48 | 48 |
import com.iver.cit.gvsig.fmap.ViewPort; |
49 | 49 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
50 | 50 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
... | ... | |
58 | 58 |
|
59 | 59 |
/** |
60 | 60 |
* Esta clase gestiona la carga de ficheros a georreferenciar mostrando un |
61 |
* wizard para su selecci?n.
|
|
62 |
*
|
|
63 |
* NO SE USA!!!!!
|
|
64 |
*
|
|
61 |
* wizard para su selecci?n. |
|
62 |
* |
|
63 |
* NO SE USA!!!!! |
|
64 |
* |
|
65 | 65 |
* @author Nacho Brodin (brodin_ign@gva.es) |
66 | 66 |
* |
67 | 67 |
*/ |
... | ... | |
82 | 82 |
* Nombre del fichero seleccionado |
83 | 83 |
*/ |
84 | 84 |
private String fName = ""; |
85 |
|
|
85 |
|
|
86 | 86 |
/** |
87 | 87 |
* Nombre de la capa |
88 | 88 |
*/ |
... | ... | |
93 | 93 |
private String lastPath = "./"; |
94 | 94 |
private GeoreferencingDialog parent = null; |
95 | 95 |
private FLyrGeoRaster lyrGeoRaster = null; |
96 |
|
|
96 |
|
|
97 | 97 |
private JPanel pCheckUseGeoref = null; |
98 | 98 |
private JCheckBox cbUseGeoref = null; |
99 | 99 |
private JLabel lUseGeoref = null; |
100 | 100 |
public double widthPxImg, heightPxImg; |
101 |
|
|
101 |
|
|
102 | 102 |
/** |
103 | 103 |
* This is the default constructor |
104 | 104 |
*/ |
... | ... | |
110 | 110 |
|
111 | 111 |
/** |
112 | 112 |
* This method initializes this |
113 |
*
|
|
113 |
* |
|
114 | 114 |
* @return void |
115 | 115 |
*/ |
116 | 116 |
private void initialize() { |
... | ... | |
126 | 126 |
} |
127 | 127 |
|
128 | 128 |
/** |
129 |
* This method initializes jPanel
|
|
130 |
*
|
|
131 |
* @return javax.swing.JPanel
|
|
129 |
* This method initializes jPanel |
|
130 |
* |
|
131 |
* @return javax.swing.JPanel |
|
132 | 132 |
*/ |
133 | 133 |
private JPanel getPGeneral() { |
134 | 134 |
if (pGeneral == null) { |
... | ... | |
152 | 152 |
} |
153 | 153 |
|
154 | 154 |
/** |
155 |
* This method initializes jPanel
|
|
156 |
*
|
|
157 |
* @return javax.swing.JPanel
|
|
155 |
* This method initializes jPanel |
|
156 |
* |
|
157 |
* @return javax.swing.JPanel |
|
158 | 158 |
*/ |
159 | 159 |
private JPanel getPFileSelection() { |
160 | 160 |
if (pFileSelection == null) { |
... | ... | |
187 | 187 |
} |
188 | 188 |
return pControls; |
189 | 189 |
} |
190 |
|
|
190 |
|
|
191 | 191 |
/** |
192 |
* This method initializes jTextField
|
|
193 |
*
|
|
194 |
* @return javax.swing.JTextField
|
|
192 |
* This method initializes jTextField |
|
193 |
* |
|
194 |
* @return javax.swing.JTextField |
|
195 | 195 |
*/ |
196 | 196 |
private JTextField getTFile() { |
197 | 197 |
if (tFile == null) { |
... | ... | |
202 | 202 |
} |
203 | 203 |
|
204 | 204 |
/** |
205 |
* This method initializes jButton
|
|
206 |
*
|
|
207 |
* @return javax.swing.JButton
|
|
205 |
* This method initializes jButton |
|
206 |
* |
|
207 |
* @return javax.swing.JButton |
|
208 | 208 |
*/ |
209 | 209 |
private JButton getBSelectFile() { |
210 | 210 |
if (bSelectFile == null) { |
... | ... | |
213 | 213 |
} |
214 | 214 |
return bSelectFile; |
215 | 215 |
} |
216 |
|
|
216 |
|
|
217 | 217 |
/** |
218 |
* This method initializes jPanel
|
|
219 |
*
|
|
220 |
* @return javax.swing.JPanel
|
|
221 |
*/
|
|
218 |
* This method initializes jPanel |
|
219 |
* |
|
220 |
* @return javax.swing.JPanel |
|
221 |
*/ |
|
222 | 222 |
private CRSSelectPanel getPProyection() { |
223 | 223 |
if (pProyection == null) { |
224 | 224 |
pProyection = CRSSelectPanel.getPanel(GeoreferencingDialog.getLastProjection()); |
225 |
pProyection.addActionListener(new java.awt.event.ActionListener() {
|
|
225 |
pProyection.addActionListener(new java.awt.event.ActionListener() { |
|
226 | 226 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
227 | 227 |
if (pProyection.isOkPressed()) { |
228 | 228 |
FOpenDialog.setLastProjection(pProyection.getCurProj()); |
... | ... | |
234 | 234 |
} |
235 | 235 |
|
236 | 236 |
/** |
237 |
* Crea una capa Raster a partir del nombre driver, fichero y proyecci?n y
|
|
238 |
* coordenadas de georeferenciaci?n. Esta funci?n es para georeferenciar
|
|
237 |
* Crea una capa Raster a partir del nombre driver, fichero y proyecci?n y |
|
238 |
* coordenadas de georeferenciaci?n. Esta funci?n es para georeferenciar |
|
239 | 239 |
* capas raster. Para imagenes que no tienen georeferenciaci?n hay que asignarle |
240 | 240 |
* una temporal, normalmente a partir de la vista activa. |
241 | 241 |
* |
... | ... | |
246 | 246 |
* @param extent Extent de la vista activa |
247 | 247 |
* |
248 | 248 |
* @return Nueva capa de tipo raster. |
249 |
* @throws LoadLayerException |
|
249 | 250 |
* |
250 | 251 |
* @throws DriverIOException |
251 | 252 |
*/ |
252 | 253 |
private FLyrGeoRaster createLayer(String layerName, RasterDriver d, |
253 |
File f, IProjection proj) throws DriverException {
|
|
254 |
File f, IProjection proj) throws LoadLayerException{
|
|
254 | 255 |
RasterAdapter adapter = new RasterFileAdapter(f); |
255 | 256 |
adapter.setDriver(d); |
256 | 257 |
GeoPointPersistence geoPointPersistence = new GeoPointPersistence(); |
257 | 258 |
StackZoom zoom = new StackZoom(); |
258 | 259 |
FLyrGeoRaster capa = new FLyrGeoRaster(geoPointPersistence, zoom); |
259 | 260 |
geoPointPersistence.setLyrPoints(capa.getFLyrPoints()); |
260 |
|
|
261 |
|
|
261 | 262 |
if (capa != null) { |
262 | 263 |
capa.setName(layerName); |
263 | 264 |
capa.setSource(adapter); |
264 | 265 |
capa.setProjection(proj); |
265 |
try { |
|
266 |
capa.load(); |
|
267 |
} catch (DriverIOException e) { |
|
268 |
throw new DriverException(e); |
|
269 |
} |
|
270 |
|
|
266 |
capa.load(); |
|
267 |
|
|
271 | 268 |
capa.setVisible(true); |
272 |
}else
|
|
269 |
}else |
|
273 | 270 |
return null; |
274 | 271 |
return capa; |
275 | 272 |
} |
276 |
|
|
273 |
|
|
277 | 274 |
/** |
278 | 275 |
* Calcula un extent posible para la imagen a partir del extent de la vista. |
279 | 276 |
* En este caso centra la imagen en la vista. |
... | ... | |
282 | 279 |
* @return Extent para la imagen |
283 | 280 |
*/ |
284 | 281 |
protected Extent calcTempExtent(String file, ViewPort vp, IProjection proj){ |
285 |
|
|
282 |
|
|
286 | 283 |
//Obtenemos el ancho y alto de la imagen y obtenemos un extent a partir |
287 | 284 |
//del viewport. |
288 | 285 |
Extent tempExtent = null; |
... | ... | |
297 | 294 |
}else |
298 | 295 |
tempExtent = new Extent(vp.getAdjustedExtent()); |
299 | 296 |
grf.close(); |
300 |
|
|
301 |
|
|
297 |
|
|
298 |
|
|
302 | 299 |
double ulX = 0D, ulY = 0D, lrX = 0D, lrY = 0D; |
303 | 300 |
if(widthPxImg > heightPxImg){ |
304 | 301 |
double widthView = tempExtent.maxX() - tempExtent.minX(); |
... | ... | |
319 | 316 |
} |
320 | 317 |
return new Extent(ulX, ulY, lrX, lrY); |
321 | 318 |
} |
322 |
|
|
319 |
|
|
323 | 320 |
/** |
324 | 321 |
* Evento de pulsado del bot?n de seleccionar fichero |
325 | 322 |
* @param e |
326 | 323 |
*/ |
327 | 324 |
private void acceptButtonActionPerformed(ActionEvent e) { |
328 | 325 |
//Selector de Fichero que se quiere georeferenciar |
329 |
|
|
326 |
|
|
330 | 327 |
if( e.getSource().equals(this.getBSelectFile())){ |
331 | 328 |
JFileChooser chooser = new JFileChooser(lastPath); |
332 | 329 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero")); |
... | ... | |
341 | 338 |
FileFilter filter = chooser.getFileFilter(); |
342 | 339 |
this.getTFile().setText(fName); |
343 | 340 |
lastPath = chooser.getCurrentDirectory().getAbsolutePath(); |
344 |
|
|
341 |
|
|
345 | 342 |
if (PluginServices.getMainFrame() == null) { |
346 | 343 |
((JDialog) (getParent().getParent().getParent() |
347 | 344 |
.getParent())).dispose(); |
... | ... | |
355 | 352 |
}catch(ClassCastException exc){ |
356 | 353 |
return; |
357 | 354 |
} |
358 |
|
|
355 |
|
|
359 | 356 |
com.hardcode.driverManager.Driver driver = LayerFactory.getDM().getDriver("gvSIG Image Driver"); |
360 |
|
|
357 |
|
|
361 | 358 |
File fich = new File(fName); |
362 |
|
|
359 |
|
|
363 | 360 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
364 |
|
|
365 |
Extent ext = calcTempExtent(fName,
|
|
366 |
viewPort,
|
|
361 |
|
|
362 |
Extent ext = calcTempExtent(fName, |
|
363 |
viewPort, |
|
367 | 364 |
proj); |
368 |
|
|
365 |
|
|
369 | 366 |
this.setLyrName("*"+fName.substring(fName.lastIndexOf(File.separator)+1)); |
370 | 367 |
lyrGeoRaster = this.createLayer("*"+fName.substring(fName.lastIndexOf(File.separator)+1, fName.length()), |
371 | 368 |
(RasterDriver) driver, fich, proj); |
372 |
|
|
369 |
|
|
373 | 370 |
if(!this.getCbUseGeoref().isSelected()) |
374 |
lyrGeoRaster.setAssignExtent(ext);
|
|
375 |
|
|
376 |
|
|
377 |
if(lyrGeoRaster != null){
|
|
371 |
lyrGeoRaster.setAssignExtent(ext); |
|
372 |
|
|
373 |
|
|
374 |
if(lyrGeoRaster != null){ |
|
378 | 375 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
379 | 376 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyrGeoRaster); |
380 | 377 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
381 | 378 |
lyrGeoRaster.getStackZoom().setInitExtent(ext, true); |
382 | 379 |
lyrGeoRaster.setActive(true); |
383 | 380 |
} |
384 |
|
|
381 |
|
|
385 | 382 |
}catch(DriverLoadException exc){ |
386 | 383 |
NotificationManager.addError("No se pudo acceder a los drivers", exc); |
387 |
}catch(DriverException exc){
|
|
384 |
} catch (LoadLayerException exc) {
|
|
388 | 385 |
NotificationManager.addError("El driver ha producido un error", exc); |
389 |
}
|
|
390 |
|
|
386 |
}
|
|
387 |
|
|
391 | 388 |
} |
392 | 389 |
} |
393 |
}
|
|
394 |
|
|
390 |
} |
|
391 |
|
|
395 | 392 |
} |
396 |
|
|
393 |
|
|
397 | 394 |
/** |
398 | 395 |
* @return Returns the lyrRaster. |
399 | 396 |
*/ |
... | ... | |
407 | 404 |
public void setFLyrGeoRaster(FLyrGeoRaster lyrGeoRaster) { |
408 | 405 |
this.lyrGeoRaster = lyrGeoRaster; |
409 | 406 |
} |
410 |
|
|
407 |
|
|
411 | 408 |
/** |
412 |
*
|
|
409 |
* |
|
413 | 410 |
* @author Nacho Brodin (brodin_ign@gva.es) |
414 | 411 |
* |
415 | 412 |
*/ |
416 | 413 |
class SelectFileFilter extends javax.swing.filechooser.FileFilter { |
417 |
|
|
414 |
|
|
418 | 415 |
private JFileChooser chooser = null; |
419 | 416 |
private String file = null; |
420 |
|
|
417 |
|
|
421 | 418 |
public SelectFileFilter(JFileChooser ch, String file){ |
422 | 419 |
this.chooser = ch; |
423 | 420 |
this.file = file; |
424 | 421 |
} |
425 |
|
|
422 |
|
|
426 | 423 |
public boolean accept(File f) { |
427 | 424 |
|
428 | 425 |
return f.isDirectory() || f.getName().toLowerCase().endsWith("."+file); |
429 | 426 |
} |
430 |
|
|
427 |
|
|
431 | 428 |
public String getDescription() { |
432 | 429 |
return file; |
433 | 430 |
} |
434 |
|
|
431 |
|
|
435 | 432 |
} |
436 |
|
|
433 |
|
|
437 | 434 |
/** |
438 | 435 |
* @return Returns the fName. |
439 | 436 |
*/ |
... | ... | |
447 | 444 |
lyrName = name; |
448 | 445 |
} |
449 | 446 |
/** |
450 |
* This method initializes jPanel
|
|
451 |
*
|
|
452 |
* @return javax.swing.JPanel
|
|
453 |
*/
|
|
447 |
* This method initializes jPanel |
|
448 |
* |
|
449 |
* @return javax.swing.JPanel |
|
450 |
*/ |
|
454 | 451 |
private JPanel getPCheckUseGeoref() { |
455 | 452 |
if (pCheckUseGeoref == null) { |
456 | 453 |
FlowLayout flowLayout1 = new FlowLayout(); |
... | ... | |
466 | 463 |
return pCheckUseGeoref; |
467 | 464 |
} |
468 | 465 |
/** |
469 |
* This method initializes jCheckBox
|
|
470 |
*
|
|
471 |
* @return javax.swing.JCheckBox
|
|
472 |
*/
|
|
466 |
* This method initializes jCheckBox |
|
467 |
* |
|
468 |
* @return javax.swing.JCheckBox |
|
469 |
*/ |
|
473 | 470 |
private JCheckBox getCbUseGeoref() { |
474 | 471 |
if (cbUseGeoref == null) { |
475 | 472 |
cbUseGeoref = new JCheckBox(); |
Also available in: Unified diff