Statistics
| Revision:

root / trunk / extensions / extHyperlink / src / org / gvsig / hyperlink / actions / LoadRasterLayer.java @ 28132

History | View | Annotate | Download (2.29 KB)

1
package org.gvsig.hyperlink.actions;
2

    
3
import java.io.File;
4
import java.io.IOException;
5
import java.io.Serializable;
6
import java.net.MalformedURLException;
7
import java.net.URI;
8

    
9
import org.gvsig.hyperlink.AbstractActionManager;
10
import org.gvsig.hyperlink.AbstractHyperLinkPanel;
11

    
12
import com.iver.andami.PluginServices;
13
import com.iver.andami.ui.mdiManager.IWindow;
14
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
15
import com.iver.cit.gvsig.fmap.layers.FLayer;
16
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
17
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
18

    
19

    
20
public class LoadRasterLayer extends AbstractActionManager implements Serializable{
21
        protected static final String actionCode = "Load_Raster_Layer";
22

    
23
        public AbstractHyperLinkPanel createPanel(URI doc)
24
                        throws UnsupportedOperationException {
25
                throw new UnsupportedOperationException();
26
        }
27

    
28
        public String getActionCode() {
29
                return actionCode;
30
        }
31

    
32
        public boolean hasPanel() {
33
                return false;
34
        }
35

    
36
        public void showDocument(URI doc) {
37
                IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
38
                if (activeWindow instanceof BaseView) {
39
                        BaseView view = (BaseView) activeWindow;
40
                        String fileName = null;
41
                        if (doc.isAbsolute()) {
42
                                try {
43
                                        fileName = new File(doc).getCanonicalPath();
44
                                } catch (MalformedURLException e) {
45
                                        PluginServices.getLogger().warn("Hyperlink - Malformed URL", e);
46
                                } catch (IOException e) {
47
                                        PluginServices.getLogger().warn("Hyperlink - Malformed URL", e);
48
                                }
49
                        }
50
                        if (fileName==null || fileName.equals("")) {
51
                                return;
52
                        }
53
                        String viewName = PluginServices.getMDIManager().getWindowInfo(activeWindow).getTitle();
54
                        try {
55
                                // assume that Raster projection has same projection as view, because the user has no opportunity to choose the projection
56
                                FLayer newLayer = LayerFactory.createLayer(fileName, "gvSIG Image Driver",
57
                                                new File(fileName), view.getProjection());
58
                                view.getMapControl().getMapContext().getLayers().addLayer(newLayer);
59
                        } catch (LoadLayerException e) {
60
                                PluginServices.getLogger().warn("Hyperlink - Error loading raster layer", e);
61
                        }
62
                }
63
        }
64

    
65
        public String getDescription() {
66
                return PluginServices.getText(this, "Loads_raster_layers_in_gvSIG");
67
        }
68

    
69
        public String getName() {
70
                return PluginServices.getText(this, "Load_Raster_Layer");
71
        }
72
}