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 / InfoToolExtension.java @ 43510

History | View | Annotate | Download (3.27 KB)

1 40558 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 41248 jjdelcerro
 * 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 40558 jjdelcerro
 *
11 41248 jjdelcerro
 * 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 40558 jjdelcerro
 *
16 41248 jjdelcerro
 * 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 40558 jjdelcerro
 *
20 41248 jjdelcerro
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22 40558 jjdelcerro
 */
23 40435 jjdelcerro
package org.gvsig.app.extension;
24
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.app.ApplicationLocator;
28 41248 jjdelcerro
import org.gvsig.app.ApplicationManager;
29
import org.gvsig.app.project.documents.view.ViewDocument;
30 40435 jjdelcerro
import org.gvsig.app.project.documents.view.gui.IView;
31
import org.gvsig.fmap.mapcontext.MapContext;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontrol.MapControl;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36
37
/**
38
 * Extension that handles the info by point tool for a selected layer set
39 41248 jjdelcerro
 *
40 40435 jjdelcerro
 */
41
public class InfoToolExtension extends Extension {
42 41248 jjdelcerro
43 40435 jjdelcerro
    private static final Logger logger = LoggerFactory
44
            .getLogger(InfoToolExtension.class);
45
46
    public void initialize() {
47 41248 jjdelcerro
        IconThemeHelper.registerIcon("action", "layer-info-by-point", this);
48 40435 jjdelcerro
    }
49
50 41248 jjdelcerro
    public void execute(String s) {
51
        ApplicationManager application = ApplicationLocator.getManager();
52
53 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
54
        if (view == null) {
55 41248 jjdelcerro
            return;
56 40435 jjdelcerro
        }
57 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
58
59 41248 jjdelcerro
        if (s.compareTo("layer-info-by-point") == 0) {
60
            MapControl mapCtrl = view.getMapControl();
61
            mapCtrl.setTool("info");
62 41264 jjdelcerro
            document.setModified(true);
63 41248 jjdelcerro
        }
64
    }
65 40435 jjdelcerro
66 41248 jjdelcerro
    public boolean isEnabled() {
67
        ApplicationManager application = ApplicationLocator.getManager();
68 40435 jjdelcerro
69 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
70
        if (view == null) {
71 41248 jjdelcerro
            return false;
72
        }
73 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
74 41248 jjdelcerro
        MapContext mapa = document.getMapContext();
75
        FLayer[] layers = mapa.getLayers().getActives();
76
        for (int i = 0; i < layers.length; i++) {
77
            if (layers[i].isAvailable()) {
78
                return true;
79
            }
80
        }
81
        return false;
82
    }
83 40435 jjdelcerro
84 41248 jjdelcerro
    public boolean isVisible() {
85
        ApplicationManager application = ApplicationLocator.getManager();
86 40435 jjdelcerro
87 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
88
        if (view == null) {
89 40435 jjdelcerro
            return false;
90
        }
91 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
92 41248 jjdelcerro
        MapContext mapa = document.getMapContext();
93
        return mapa.getLayers().getLayersCount() > 0;
94
    }
95 40435 jjdelcerro
96
}