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 / ViewSelectionControls.java @ 44601

History | View | Annotate | Download (3.91 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.util.List;
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.app.ApplicationLocator;
29
import org.gvsig.app.ApplicationManager;
30
import org.gvsig.app.project.documents.view.ViewDocument;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontext.layers.FLayers;
34
import org.gvsig.fmap.mapcontrol.MapControl;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

    
38
/**
39
 * Extension that handles the selection tools, selection tools have sense on
40
 * vectorial layers only.
41
 *
42
 */
43
public class ViewSelectionControls extends Extension {
44

    
45
    private static final Logger logger = LoggerFactory
46
            .getLogger(ViewSelectionControls.class);
47

    
48
    @Override
49
    public void initialize() {
50
        registerIcons();
51
    }
52

    
53
    private void registerIcons() {
54
        IconThemeHelper.registerIcon("action", "selection-select-by-rectangle", this);
55
        IconThemeHelper.registerIcon("action", "selection-select-by-polygon", this);
56
        IconThemeHelper.registerIcon("action", "selection-clear", this);
57
    }
58

    
59
    @Override
60
    public void execute(String actionCommand) {
61
        ApplicationManager application = ApplicationLocator.getManager();
62

    
63
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
64
        if (view == null) {
65
            return;
66
        }
67
        ViewDocument document = view.getViewDocument();
68
        MapControl mapCtrl = view.getMapControl();
69

    
70
        if (actionCommand.equalsIgnoreCase("selection-select-by-rectangle-view")) {
71
            mapCtrl.setTool("rectSelection");
72
            document.setModified(true);
73

    
74
        } else if (actionCommand.equalsIgnoreCase("selection-select-by-polygon")) {
75
            mapCtrl.setTool("polSelection");
76
            document.setModified(true);
77

    
78
        }
79
    }
80

    
81
    @Override
82
    public boolean isEnabled() {
83
        ApplicationManager application = ApplicationLocator.getManager();
84

    
85
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
86
        if (view == null) {
87
            return false;
88
        }
89
        ViewDocument document = view.getViewDocument();
90
        if( document == null ) {
91
            return false;
92
        }
93
        List<FLayer> layers = document.getMapContext().getLayers().getLayers(
94
                FLayers.LAYER_ACTIVE
95
                        .and(FLayers.LAYER_AVALAIBLE)
96
                        .and(FLayers.LAYER_SELECTION_AVAILABLE)
97
        );
98
        if (layers.size()>=1) {
99
            return true;
100
        }
101
        return false;
102
    }
103

    
104
    @Override
105
    public boolean isVisible() {
106
        ApplicationManager application = ApplicationLocator.getManager();
107

    
108
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
109
        if (view == null) {
110
            return false;
111
        }
112
        ViewDocument document = view.getViewDocument();
113
        return document.getMapContext().hasVectorLayers();
114
    }
115

    
116
}