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 / LoadRasterLayer.java @ 33402
History | View | Annotate | Download (5.38 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.cresques.cts.IProjection; |
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
34 |
import org.gvsig.app.project.documents.view.gui.IView; |
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.raster.RasterStoreParameters; |
40 |
import org.gvsig.fmap.dal.store.raster.RasterStoreProvider; |
41 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
42 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
43 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
45 |
import org.gvsig.hyperlink.app.extension.AbstractActionManager; |
46 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel; |
47 |
import org.gvsig.tools.locator.LocatorException; |
48 |
|
49 |
public class LoadRasterLayer extends AbstractActionManager implements |
50 |
Serializable {
|
51 |
|
52 |
public static final String actionCode = "Load_Raster_Layer"; |
53 |
|
54 |
public AbstractHyperLinkPanel createPanel(URI doc) throws UnsupportedOperationException { |
55 |
throw new UnsupportedOperationException(); |
56 |
} |
57 |
|
58 |
public String getActionCode() { |
59 |
return actionCode;
|
60 |
} |
61 |
|
62 |
public boolean hasPanel() { |
63 |
return false; |
64 |
} |
65 |
|
66 |
public void showDocument(URI doc) { |
67 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
68 |
if (activeWindow instanceof IView) { |
69 |
IView view = (IView) activeWindow; |
70 |
String fileName = null; |
71 |
if (doc.isAbsolute()) {
|
72 |
try {
|
73 |
fileName = new File(doc).getCanonicalPath(); |
74 |
} catch (MalformedURLException e) { |
75 |
PluginServices.getLogger() |
76 |
.warn("Hyperlink - Malformed URL", e);
|
77 |
} catch (IOException e) { |
78 |
PluginServices.getLogger() |
79 |
.warn("Hyperlink - Malformed URL", e);
|
80 |
} |
81 |
} |
82 |
if (fileName == null || fileName.equals("")) { |
83 |
return;
|
84 |
} |
85 |
String viewName =
|
86 |
PluginServices.getMDIManager() |
87 |
.getWindowInfo(activeWindow) |
88 |
.getTitle(); |
89 |
try {
|
90 |
// assume that Raster projection has same projection as view,
|
91 |
// because the user has no opportunity to choose the projection
|
92 |
// FLayer newLayer = LayerFactory.createLayer(fileName,
|
93 |
// "gvSIG Image Driver",
|
94 |
// new File(fileName), view.getProjection());
|
95 |
DataStoreParameters parameters = |
96 |
DALLocator.getDataManager() |
97 |
.createStoreParameters(RasterStoreProvider.NAME); |
98 |
parameters.setDynValue("filename", fileName);
|
99 |
parameters.setDynValue("srs", view.getViewDocument()
|
100 |
.getMapContext() |
101 |
.getProjection()); // ???????
|
102 |
FLayer newLayer = |
103 |
MapContextLocator.getMapContextManager() |
104 |
.createLayer(fileName, parameters); |
105 |
// FLayer newLayer = FLyrRasterSE.createLayer(fileName,
|
106 |
// fileName,
|
107 |
// view.getProjection());
|
108 |
view.getMapControl() |
109 |
.getMapContext() |
110 |
.getLayers() |
111 |
.addLayer(newLayer); |
112 |
} catch (LoadLayerException e) {
|
113 |
PluginServices.getLogger() |
114 |
.warn("Hyperlink - Error loading raster layer", e);
|
115 |
} catch (InitializeException e) {
|
116 |
PluginServices.getLogger() |
117 |
.warn("Hyperlink - Error loading raster layer", e);
|
118 |
} catch (ProviderNotRegisteredException e) {
|
119 |
PluginServices.getLogger() |
120 |
.warn("Hyperlink - Error loading raster layer", e);
|
121 |
} catch (LocatorException e) {
|
122 |
PluginServices.getLogger() |
123 |
.warn("Hyperlink - Error loading raster layer", e);
|
124 |
} |
125 |
} |
126 |
} |
127 |
|
128 |
public String getDescription() { |
129 |
return PluginServices.getText(this, "Loads_raster_layers_in_gvSIG"); |
130 |
} |
131 |
|
132 |
public String getName() { |
133 |
return PluginServices.getText(this, "Load_Raster_Layer"); |
134 |
} |
135 |
} |