root / branches / v2_0_0_prep / extensions / org.gvsig.hyperlink.app / org.gvsig.hyperlink.app.extension / src / main / java / org / gvsig / hyperlink / app / extension / actions / LoadVectorLayer.java @ 33402
History | View | Annotate | Download (8.68 KB)
1 |
/* 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 |
|
23 |
package org.gvsig.hyperlink.app.extension.actions; |
24 |
|
25 |
import java.io.File; |
26 |
import java.io.IOException; |
27 |
import java.io.Serializable; |
28 |
import java.net.MalformedURLException; |
29 |
import java.net.URI; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
33 |
import org.gvsig.app.project.documents.view.gui.IView; |
34 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider; |
35 |
import org.gvsig.fmap.dal.DALLocator; |
36 |
import org.gvsig.fmap.dal.DataStoreParameters; |
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
38 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
39 |
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider; |
40 |
import org.gvsig.fmap.dal.store.dxf.DXFStoreProvider; |
41 |
import org.gvsig.fmap.dal.store.raster.RasterStoreProvider; |
42 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
43 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
44 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
45 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
46 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
47 |
import org.gvsig.hyperlink.app.extension.AbstractActionManager; |
48 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
49 |
import org.gvsig.tools.locator.LocatorException; |
50 |
|
51 |
import com.sun.media.jai.rmi.ShapeState; |
52 |
|
53 |
public class LoadVectorLayer extends AbstractActionManager implements |
54 |
Serializable {
|
55 |
|
56 |
private static final long serialVersionUID = 1L; |
57 |
public static final String actionCode = "Load_Vector_Layer"; |
58 |
|
59 |
public AbstractHyperLinkPanel createPanel(URI doc) throws UnsupportedOperationException { |
60 |
throw new UnsupportedOperationException(); |
61 |
} |
62 |
|
63 |
public String getActionCode() { |
64 |
return actionCode;
|
65 |
} |
66 |
|
67 |
public boolean hasPanel() { |
68 |
return false; |
69 |
} |
70 |
|
71 |
public void showDocument(URI doc) { |
72 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
73 |
if (activeWindow instanceof IView) { |
74 |
IView view = (IView) activeWindow; |
75 |
String fileName = null; |
76 |
if (doc.isAbsolute()) {
|
77 |
try {
|
78 |
fileName = new File(doc).getCanonicalPath(); |
79 |
} catch (MalformedURLException e) { |
80 |
PluginServices.getLogger() |
81 |
.warn("Hyperlink - Malformed URL", e);
|
82 |
} catch (IOException e) { |
83 |
PluginServices.getLogger() |
84 |
.warn("Hyperlink - Malformed URL", e);
|
85 |
} |
86 |
} |
87 |
if (fileName == null || fileName.equals("")) { |
88 |
return;
|
89 |
} |
90 |
String viewName =
|
91 |
PluginServices.getMDIManager() |
92 |
.getWindowInfo(activeWindow) |
93 |
.getTitle(); |
94 |
try {
|
95 |
// assume that layer has same projection as view, because the
|
96 |
// user has no opportunity to choose the projection
|
97 |
FLayer newLayer = null;
|
98 |
DataStoreParameters parameters = null;
|
99 |
if (fileName.toLowerCase().endsWith(".shp")) { |
100 |
// newLayer = LayerFactory.createLayer(fileName,
|
101 |
// "gvSIG shp driver",
|
102 |
// new File(fileName), view.getProjection());
|
103 |
parameters = |
104 |
DALLocator.getDataManager() |
105 |
.createStoreParameters(SHPStoreProvider.NAME); |
106 |
parameters.setDynValue("shpfile", fileName);
|
107 |
// parameters.setDynValue("shxfile", fileName);
|
108 |
parameters.setDynValue("CRS", view.getViewDocument()
|
109 |
.getMapContext() |
110 |
.getProjection()); // ???????
|
111 |
} else
|
112 |
if (fileName.toLowerCase().endsWith(".dgn")) { |
113 |
// newLayer = LayerFactory.createLayer(fileName,
|
114 |
// "gvSIG DGN Memory Driver",
|
115 |
// new File(fileName), view.getProjection());
|
116 |
parameters = |
117 |
DALLocator.getDataManager() |
118 |
.createStoreParameters(DGNStoreProvider.NAME); |
119 |
parameters.setDynValue("file", fileName);
|
120 |
parameters.setDynValue("CRS", view.getViewDocument()
|
121 |
.getMapContext() |
122 |
.getProjection()); // ???????
|
123 |
} else
|
124 |
if (fileName.toLowerCase().endsWith(".dwg")) { |
125 |
// newLayer = LayerFactory.createLayer(fileName,
|
126 |
// "gvSIG DWG Memory Driver",
|
127 |
// new File(fileName), view.getProjection());
|
128 |
parameters = |
129 |
DALLocator.getDataManager() |
130 |
.createStoreParameters(DWGStoreProvider.NAME); |
131 |
parameters.setDynValue("file", fileName);
|
132 |
parameters.setDynValue("CRS",
|
133 |
view.getViewDocument() |
134 |
.getMapContext() |
135 |
.getProjection()); // ???????
|
136 |
} else
|
137 |
if (fileName.toLowerCase().endsWith(".dxf")) { |
138 |
// newLayer = LayerFactory.createLayer(fileName,
|
139 |
// "gvSIG DXF Memory Driver",
|
140 |
// new File(fileName), view.getProjection());
|
141 |
parameters = |
142 |
DALLocator.getDataManager() |
143 |
.createStoreParameters(DXFStoreProvider.NAME); |
144 |
parameters.setDynValue("File", fileName);
|
145 |
parameters.setDynValue("CRS",
|
146 |
view.getViewDocument() |
147 |
.getMapContext() |
148 |
.getProjection()); // ???????
|
149 |
} |
150 |
// TODO:
|
151 |
// else if (fileName.toLowerCase().endsWith(".gml")) {
|
152 |
// // newLayer = LayerFactory.createLayer(fileName,
|
153 |
// "gvSIG GML Memory Driver",
|
154 |
// // new File(fileName), view.getProjection());
|
155 |
// }
|
156 |
// else if (fileName.toLowerCase().endsWith(".kml")) {
|
157 |
// // newLayer = LayerFactory.createLayer(fileName,
|
158 |
// "gvSIG KML Memory Driver",
|
159 |
// // new File(fileName), view.getProjection());
|
160 |
// }
|
161 |
if (parameters != null) { |
162 |
newLayer = |
163 |
MapContextLocator.getMapContextManager() |
164 |
.createLayer(fileName, parameters); |
165 |
} |
166 |
|
167 |
if (newLayer != null) { |
168 |
view.getMapControl() |
169 |
.getMapContext() |
170 |
.getLayers() |
171 |
.addLayer(newLayer); |
172 |
} |
173 |
} catch (InitializeException e) {
|
174 |
PluginServices.getLogger() |
175 |
.warn("Hyperlink - Error loading vector layer", e);
|
176 |
} catch (ProviderNotRegisteredException e) {
|
177 |
PluginServices.getLogger() |
178 |
.warn("Hyperlink - Error loading vector layer", e);
|
179 |
} catch (LocatorException e) {
|
180 |
PluginServices.getLogger() |
181 |
.warn("Hyperlink - Error loading vector layer", e);
|
182 |
} catch (LoadLayerException e) {
|
183 |
PluginServices.getLogger() |
184 |
.warn("Hyperlink - Error loading vector layer", e);
|
185 |
} |
186 |
} |
187 |
} |
188 |
|
189 |
public String getDescription() { |
190 |
return PluginServices.getText(this, "Loads_vector_layers_in_gvSIG"); |
191 |
} |
192 |
|
193 |
public String getName() { |
194 |
return PluginServices.getText(this, "Load_Vector_Layer"); |
195 |
} |
196 |
} |