Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / AddToLocatorExtension.java @ 42448

History | View | Annotate | Download (4.28 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.app.extension;
24

    
25
import java.awt.Component;
26
import java.io.File;
27
import java.lang.reflect.InvocationTargetException;
28
import java.util.ArrayList;
29
import java.util.List;
30

    
31
import javax.swing.JOptionPane;
32

    
33
import org.cresques.cts.ICoordTrans;
34
import org.cresques.cts.IProjection;
35
import org.gvsig.andami.IconThemeHelper;
36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.andami.plugins.Extension;
38
import org.gvsig.app.ApplicationLocator;
39
import org.gvsig.app.ApplicationManager;
40
import org.gvsig.app.addlayer.AddLayerDialog;
41
import org.gvsig.app.gui.WizardPanel;
42
import org.gvsig.app.project.documents.view.MapOverview;
43
import org.gvsig.app.project.documents.view.ViewDocument;
44
import org.gvsig.app.project.documents.view.gui.IView;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerAddLayerWizardPanel;
46
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel;
47
import org.gvsig.fmap.mapcontext.MapContext;
48
import org.gvsig.fmap.mapcontext.ViewPort;
49
import org.gvsig.fmap.mapcontext.layers.CancelationException;
50
import org.gvsig.fmap.mapcontext.layers.FLayer;
51
import org.gvsig.fmap.mapcontext.layers.FLayers;
52
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
53
import org.gvsig.fmap.mapcontrol.MapControl;
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
56

    
57
/**
58
 * Extensi?n que a?ade una capa al locator
59
 *
60
 */
61
public class AddToLocatorExtension extends Extension {
62
    private static final Logger logger = LoggerFactory.getLogger(AddToLocatorExtension.class);
63

    
64

    
65
    public boolean isVisible() {
66
        ApplicationManager application = ApplicationLocator.getManager();
67

    
68
        if (application.getActiveComponent(ViewDocument.class) != null){
69
            IView view = (IView) application.getActiveComponent(ViewDocument.class);
70
            if (view == null) {
71
                return false;
72
            }
73
            FLayer[] layers = view.getMapControl().getMapContext().getLayers().getActives();
74
            return layers!=null&&layers.length>0;
75
        }
76
        return false;
77
    }
78

    
79
    public void postInitialize() {
80
        super.postInitialize();
81
    }
82

    
83
    public void execute(String actionCommand) {
84
        this.execute(actionCommand, null);
85
    }
86

    
87
    public void execute(String command, Object[] args) {
88
        ApplicationManager application = ApplicationLocator.getManager();
89

    
90
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
91
        if (view == null) {
92
            return;
93
        }
94
        FLayer[] layers = view.getMapControl().getMapContext().getLayers().getActives();
95
        ViewDocument document = view.getViewDocument();
96

    
97
        for (int i= 0; i < layers.length;i++){
98
            try {
99
                FLayer layer = layers[i];
100
                MapOverview mapOverview =view.getMapOverview();
101
                mapOverview.getMapContext().getLayers().addLayer(layer.cloneLayer());
102
                mapOverview.refreshExtent();
103
                document.setModified(true);
104

    
105
            } catch (CancelationException e1) {
106
                e1.printStackTrace();
107
            } catch (Exception e) {
108
                // TODO Auto-generated catch block
109
                e.printStackTrace();
110
            }
111
        }
112
    }
113

    
114
    public boolean isEnabled() {
115
        return true;
116
    }
117

    
118
    public void initialize() {
119
        IconThemeHelper.registerIcon("action", "add-to-locator", this);
120
    }
121
}