gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.lib / org.gvsig.geoprocess.lib.sextante / src / main / java / org / gvsig / geoprocess / lib / sextante / core / DefaultInputFactory.java @ 237
History | View | Annotate | Download (7.38 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007,2012 gvSIG Association.
|
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 |
package org.gvsig.geoprocess.lib.sextante.core; |
22 |
|
23 |
import java.awt.geom.Rectangle2D; |
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import es.unex.sextante.core.AbstractInputFactory; |
28 |
import es.unex.sextante.core.NamedExtent; |
29 |
import es.unex.sextante.dataObjects.I3DRasterLayer; |
30 |
import es.unex.sextante.dataObjects.IDataObject; |
31 |
|
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.app.extension.ProjectExtension; |
34 |
import org.gvsig.app.project.Project; |
35 |
import org.gvsig.app.project.documents.Document; |
36 |
import org.gvsig.app.project.documents.table.TableDocument; |
37 |
import org.gvsig.app.project.documents.table.TableManager; |
38 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
39 |
import org.gvsig.app.project.documents.view.ViewManager; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
41 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
42 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
43 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
44 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FileTools; |
45 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterReadOnlyIRasterLayer; |
46 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.TableDocumentITable; |
47 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
48 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
49 |
|
50 |
public class DefaultInputFactory extends AbstractInputFactory { |
51 |
|
52 |
public void createDataObjects() { |
53 |
|
54 |
final List<IDataObject> list = new ArrayList<IDataObject>(); |
55 |
|
56 |
final Project project =
|
57 |
((ProjectExtension) PluginServices |
58 |
.getExtension(ProjectExtension.class)).getProject(); |
59 |
final List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
60 |
for (int i = 0; i < views.size(); i++) { |
61 |
final DefaultViewDocument view = (DefaultViewDocument) views.get(i);
|
62 |
final FLayers layers = view.getMapContext().getLayers();
|
63 |
final LayersIterator iter = new LayersIterator(layers); |
64 |
while (iter.hasNext()) {
|
65 |
final FLayer layer = iter.nextLayer();
|
66 |
if (layer instanceof FLyrRaster) { |
67 |
final FLyrRasterReadOnlyIRasterLayer rasterLayer =
|
68 |
new FLyrRasterReadOnlyIRasterLayer();
|
69 |
rasterLayer.create((FLyrRaster) layer); |
70 |
list.add(rasterLayer); |
71 |
} else
|
72 |
if (layer instanceof FLyrVect) { |
73 |
final FlyrVectIVectorLayer vectorLayer = new FlyrVectIVectorLayer(); |
74 |
vectorLayer.create((FLyrVect) layer); |
75 |
list.add(vectorLayer); |
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
final List<Document> tables = |
81 |
project.getDocuments(TableManager.TYPENAME); |
82 |
for (int i = 0; i < tables.size(); i++) { |
83 |
final TableDocumentITable table = new TableDocumentITable(); |
84 |
table.create((TableDocument) tables.get(i)); |
85 |
list.add(table); |
86 |
} |
87 |
|
88 |
m_Objects = list.toArray(new IDataObject[list.size()]);
|
89 |
} |
90 |
|
91 |
public NamedExtent[] getPredefinedExtents() { |
92 |
|
93 |
final Project project =
|
94 |
((ProjectExtension) PluginServices |
95 |
.getExtension(ProjectExtension.class)).getProject(); |
96 |
final List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
97 |
final NamedExtent ne[] = new NamedExtent[views.size()]; |
98 |
for (int i = 0; i < views.size(); i++) { |
99 |
final DefaultViewDocument view = (DefaultViewDocument) views.get(i);
|
100 |
final Rectangle2D extent = |
101 |
view.getMapContext().getViewPort().getExtent(); |
102 |
final String sName = view.getName(); |
103 |
ne[i] = new NamedExtent(sName, extent);
|
104 |
} |
105 |
|
106 |
return ne;
|
107 |
} |
108 |
|
109 |
public String[] getRasterLayerInputExtensions() { |
110 |
|
111 |
return FileTools.RASTER_EXT_IN;
|
112 |
|
113 |
} |
114 |
|
115 |
public String[] get3DRasterLayerInputExtensions() { |
116 |
|
117 |
return FileTools.RASTER3D_EXT_IN;
|
118 |
|
119 |
} |
120 |
|
121 |
public String[] getVectorLayerInputExtensions() { |
122 |
|
123 |
return FileTools.VECTOR_EXT_IN;
|
124 |
|
125 |
} |
126 |
|
127 |
public String[] getTableInputExtensions() { |
128 |
|
129 |
return FileTools.TABLE_EXT;
|
130 |
|
131 |
} |
132 |
|
133 |
public IDataObject openDataObjectFromFile(final String sFilename) { |
134 |
|
135 |
final Object object = FileTools.open(sFilename); |
136 |
|
137 |
if (object == null) { |
138 |
return null; |
139 |
} else
|
140 |
if (object instanceof FLyrRaster) { |
141 |
final FLyrRasterReadOnlyIRasterLayer layer = new FLyrRasterReadOnlyIRasterLayer(); |
142 |
layer.create((FLyrRaster) object); |
143 |
return layer;
|
144 |
} else
|
145 |
if (object instanceof FLyrVect) { |
146 |
final FlyrVectIVectorLayer layer = new FlyrVectIVectorLayer(); |
147 |
layer.create((FLyrVect) object); |
148 |
return layer;
|
149 |
} else
|
150 |
if (object instanceof I3DRasterLayer) { |
151 |
return (I3DRasterLayer) object;
|
152 |
} else {
|
153 |
return null; |
154 |
} |
155 |
|
156 |
} |
157 |
|
158 |
public void close(final String sName) { |
159 |
|
160 |
final IDataObject dataObject = this.getInputFromName(sName); |
161 |
|
162 |
final Object obj = dataObject.getBaseDataObject(); |
163 |
if (obj instanceof FLayer) { |
164 |
removeLayer((FLayer) obj); |
165 |
} else {
|
166 |
final Project project =
|
167 |
((ProjectExtension) PluginServices |
168 |
.getExtension(ProjectExtension.class)).getProject(); |
169 |
project.remove((Document) obj);
|
170 |
} |
171 |
|
172 |
} |
173 |
|
174 |
private static void removeLayer(final FLayer baseLayer) { |
175 |
|
176 |
final Project project =
|
177 |
((ProjectExtension) PluginServices |
178 |
.getExtension(ProjectExtension.class)).getProject(); |
179 |
final List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
180 |
for (int i = 0; i < views.size(); i++) { |
181 |
final DefaultViewDocument view = (DefaultViewDocument) views.get(i);
|
182 |
final FLayers layers = view.getMapContext().getLayers();
|
183 |
final LayersIterator iter = new LayersIterator(layers); |
184 |
while (iter.hasNext()) {
|
185 |
final FLayer layer = iter.nextLayer();
|
186 |
if (layer.equals(baseLayer)) {
|
187 |
layers.removeLayer(baseLayer); |
188 |
return;
|
189 |
} |
190 |
} |
191 |
|
192 |
} |
193 |
|
194 |
} |
195 |
|
196 |
@Override
|
197 |
public I3DRasterLayer[] get3DRasterLayers() { |
198 |
|
199 |
return new I3DRasterLayer[0]; |
200 |
|
201 |
} |
202 |
|
203 |
} |