Statistics
| Revision:

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 @ 37828

History | View | Annotate | Download (5.2 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.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.InitializeException;
37
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
38
import org.gvsig.fmap.mapcontext.MapContextLocator;
39
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
40
import org.gvsig.fmap.mapcontext.layers.FLayer;
41
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
42
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
43
import org.gvsig.tools.locator.LocatorException;
44

    
45
public class LoadRasterLayer extends AbstractActionManager implements
46
    Serializable {
47

    
48
    public static final String actionCode = "Load_Raster_Layer";
49

    
50
    public AbstractHyperLinkPanel createPanel(URI doc) throws UnsupportedOperationException {
51
        throw new UnsupportedOperationException();
52
    }
53

    
54
    public String getActionCode() {
55
        return actionCode;
56
    }
57

    
58
    public boolean hasPanel() {
59
        return false;
60
    }
61

    
62
    public void showDocument(URI doc) {
63
        IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
64
        if (activeWindow instanceof IView) {
65
            IView view = (IView) activeWindow;
66
            String fileName = null;
67
            if (doc.isAbsolute()) {
68
                try {
69
                    fileName = new File(doc).getCanonicalPath();
70
                } catch (MalformedURLException e) {
71
                    PluginServices.getLogger()
72
                        .warn("Hyperlink - Malformed URL", e);
73
                } catch (IOException e) {
74
                    PluginServices.getLogger()
75
                        .warn("Hyperlink - Malformed URL", e);
76
                }
77
            }
78
            if (fileName == null || fileName.equals("")) {
79
                return;
80
            }
81
            String viewName =
82
                PluginServices.getMDIManager()
83
                    .getWindowInfo(activeWindow)
84
                    .getTitle();
85
            try {
86
                // assume that Raster projection has same projection as view,
87
                // because the user has no opportunity to choose the projection
88
                // FLayer newLayer = LayerFactory.createLayer(fileName,
89
                // "gvSIG Image Driver",
90
                // new File(fileName), view.getProjection());
91
                DataStoreParameters parameters =
92
                    DALLocator.getDataManager()
93
                        .createStoreParameters("RasterStore");
94
                parameters.setDynValue("filename", fileName);
95
                parameters.setDynValue("srs", view.getViewDocument()
96
                    .getMapContext()
97
                    .getProjection()); // ???????
98
                FLayer newLayer =
99
                    MapContextLocator.getMapContextManager()
100
                        .createLayer(fileName, parameters);
101
                // FLayer newLayer = FLyrRasterSE.createLayer(fileName,
102
                // fileName,
103
                // view.getProjection());
104
                view.getMapControl()
105
                    .getMapContext()
106
                    .getLayers()
107
                    .addLayer(newLayer);
108
                newLayer.dispose();
109
            } catch (LoadLayerException e) {
110
                PluginServices.getLogger()
111
                    .warn("Hyperlink - Error loading raster layer", e);
112
            } catch (InitializeException e) {
113
                PluginServices.getLogger()
114
                    .warn("Hyperlink - Error loading raster layer", e);
115
            } catch (ProviderNotRegisteredException e) {
116
                PluginServices.getLogger()
117
                    .warn("Hyperlink - Error loading raster layer", e);
118
            } catch (LocatorException e) {
119
                PluginServices.getLogger()
120
                    .warn("Hyperlink - Error loading raster layer", e);
121
            }
122
        }
123
    }
124

    
125
    public String getDescription() {
126
        return PluginServices.getText(this, "Loads_raster_layers_in_gvSIG");
127
    }
128

    
129
    public String getName() {
130
        return PluginServices.getText(this, "Load_Raster_Layer");
131
    }
132
}