Statistics
| Revision:

gvsig-lrs / org.gvsig.lrs / trunk / org.gvsig.lrs / org.gvsig.lrs.app / org.gvsig.lrs.app.mainplugin / src / main / java / org / gvsig / lrs / app / showmeasures / WiperMeasuresExtension.java @ 69

History | View | Annotate | Download (3.92 KB)

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

    
25
import org.apache.commons.lang3.StringUtils;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

    
29
import org.gvsig.andami.IconThemeHelper;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.app.ApplicationLocator;
32
import org.gvsig.app.ApplicationManager;
33
import org.gvsig.app.project.documents.view.ViewDocument;
34
import org.gvsig.app.project.documents.view.gui.IView;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer;
39
import org.gvsig.lrs.swing.impl.JLrsShowMeasuresParamsController;
40

    
41
/**
42
 * @author dmartinez
43
 *
44
 */
45
public class WiperMeasuresExtension extends Extension {
46

    
47
    private static final Logger logger = LoggerFactory.getLogger(WiperMeasuresExtension.class);
48

    
49
    private JLrsShowMeasuresParamsController panel;
50

    
51

    
52
    /*
53
     * (non-Javadoc)
54
     *
55
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
56
     */
57
    public void execute(String actionCommand) {
58
        if (StringUtils.equalsIgnoreCase(actionCommand, "wiper-measures")) {
59
            IView view = getActiveView();
60
            final MapContext mapContext = view.getMapControl().getMapContext();
61
            final GraphicLayer graphics = mapContext.getGraphicsLayer();
62

    
63
            graphics.removeGraphics(ShowMeasuresExtension.SHOW_MEASURES_GRAPHICS_ID);
64
            mapContext.invalidate();
65

    
66
        }
67
    }
68

    
69
    /*
70
     * (non-Javadoc)
71
     *
72
     * @see org.gvsig.andami.plugins.IExtension#initialize()
73
     */
74
    public void initialize() {
75
        registerIcons();
76
    }
77

    
78
    /*
79
     * (non-Javadoc)
80
     *
81
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
82
     */
83
    public boolean isEnabled() {
84
        IView view = getActiveView();
85
        FLyrVect activeLayer = getActiveLayer(view);
86
        if (panel == null && activeLayer != null) {
87
            return true;
88
        }
89
        return false;
90
    }
91

    
92
    /*
93
     * (non-Javadoc)
94
     *
95
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
96
     */
97
    public boolean isVisible() {
98
        ApplicationManager application = ApplicationLocator.getManager();
99

    
100
        return application.getActiveComponent(ViewDocument.class) != null;
101
    }
102

    
103
    private void registerIcons() {
104
        IconThemeHelper.registerIcon("lrs", "wiper", this);
105
    }
106

    
107
    private IView getActiveView() {
108
        ApplicationManager application = ApplicationLocator.getManager();
109
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
110
        return view;
111
    }
112

    
113
    private FLyrVect getActiveLayer(IView vista) {
114
        if (vista != null) {
115
            ViewDocument viewDocument = vista.getViewDocument();
116
            FLayer[] actives = viewDocument.getMapContext().getLayers().getActives();
117

    
118
            if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) {
119
                return (FLyrVect) actives[0];
120
            }
121
        }
122
        return null;
123
    }
124
}