gvsig-raster / org.gvsig.raster.mosaic / trunk / org.gvsig.raster.mosaic / org.gvsig.raster.mosaic.app / src / main / java / org / gvsig / raster / mosaic / app / MainDialogActions.java @ 2191
History | View | Annotate | Download (4.77 KB)
1 |
package org.gvsig.raster.mosaic.app; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import org.gvsig.andami.PluginServices; |
6 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
7 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
8 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
9 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
10 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
11 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
12 |
import org.gvsig.fmap.dal.exception.InitializeException; |
13 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
14 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
15 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
16 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
17 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
18 |
import org.gvsig.raster.mosaic.swing.main.AddFilesEvent; |
19 |
import org.gvsig.raster.mosaic.swing.main.AddFilesListener; |
20 |
import org.gvsig.raster.mosaic.swing.main.AddFilesPanel; |
21 |
import org.gvsig.tools.locator.LocatorException; |
22 |
import org.slf4j.Logger; |
23 |
import org.slf4j.LoggerFactory; |
24 |
|
25 |
public class MainDialogActions implements AddFilesListener { |
26 |
private Logger log = LoggerFactory.getLogger(MainDialogActions.class); |
27 |
private String file = null; |
28 |
private String folder = null; |
29 |
private AddFilesPanel addFilesPanel = null; |
30 |
private AbstractViewPanel selectedView = null; |
31 |
|
32 |
public MainDialogActions(AddFilesPanel panel, String file, String folder) { |
33 |
this.file = file;
|
34 |
this.folder = folder;
|
35 |
this.addFilesPanel = panel;
|
36 |
} |
37 |
|
38 |
private void loadLayerInView(RasterDataStore mainRasterStore) throws LoadLayerException { |
39 |
MapContextManager mcm = MapContextLocator.getMapContextManager(); |
40 |
FLyrRaster lyr = (FLyrRaster) mcm.createLayer(file, mainRasterStore); |
41 |
lyr.reload(); |
42 |
|
43 |
getView().getMapControl().getMapContext().beginAtomicEvent(); |
44 |
getView().getMapControl().getMapContext().getLayers().addLayer(lyr); |
45 |
getView().getMapControl().getMapContext().invalidate(); |
46 |
getView().getMapControl().getMapContext().endAtomicEvent(); |
47 |
} |
48 |
|
49 |
private AbstractViewPanel getView() {
|
50 |
if(selectedView == null) { |
51 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
52 |
for (int i = 0; i < wList.length; i++) { |
53 |
if(wList[i] instanceof AbstractViewPanel) |
54 |
selectedView = (AbstractViewPanel)wList[i]; |
55 |
} |
56 |
} |
57 |
return selectedView;
|
58 |
} |
59 |
|
60 |
public void actionAddFiles(AddFilesEvent e) { |
61 |
File[] fList = e.getFileList(); |
62 |
for (int i = 0; i < fList.length; i++) { |
63 |
try {
|
64 |
RasterDataStore store = RasterLocator.getManager().getProviderServices().open(fList[i].getAbsolutePath()); |
65 |
if(store != null) |
66 |
addFilesPanel.addDstFile( |
67 |
store, |
68 |
getLayerNameFromFileName(store.getFullName()), |
69 |
store.getBandCount(), |
70 |
store.getDataType()[0]);
|
71 |
} catch (RasterDriverException e1) {
|
72 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
73 |
} catch (InitializeException e1) {
|
74 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
75 |
} catch (ProviderNotRegisteredException e1) {
|
76 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
77 |
} catch (LocatorException e1) {
|
78 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
79 |
} catch (NotSupportedExtensionException e1) {
|
80 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
81 |
} |
82 |
} |
83 |
} |
84 |
|
85 |
public void actionAddFolder(AddFilesEvent e) { |
86 |
File[] folderList = e.getFileList(); |
87 |
for (int i = 0; i < folderList.length; i++) { |
88 |
try {
|
89 |
RasterDataStore store = RasterLocator.getManager().getProviderServices().open(folderList[i].getAbsolutePath()); |
90 |
if(store != null) |
91 |
addFilesPanel.addDstFile( |
92 |
store, |
93 |
getLayerNameFromFileName(store.getFullName()), |
94 |
store.getBandCount(), |
95 |
store.getDataType()[0]);
|
96 |
} catch (RasterDriverException e1) {
|
97 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
98 |
} catch (InitializeException e1) {
|
99 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
100 |
} catch (ProviderNotRegisteredException e1) {
|
101 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
102 |
} catch (LocatorException e1) {
|
103 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
104 |
} catch (NotSupportedExtensionException e1) {
|
105 |
log.debug("Error loading a RasterDataStore from the list", e1);
|
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
private String getLayerNameFromFileName(String fullName) { |
111 |
if(fullName.contains(File.separator)) { |
112 |
int index = fullName.lastIndexOf(File.separator); |
113 |
fullName = fullName.substring(index + 1);
|
114 |
} |
115 |
|
116 |
/*if(fullName.contains(".")) {
|
117 |
int index = fullName.lastIndexOf(".");
|
118 |
fullName = fullName.substring(0, index);
|
119 |
}*/
|
120 |
return fullName;
|
121 |
} |
122 |
} |