Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.selectiontools.app / org.gvsig.selectiontools.app.mainplugin / src / main / java / org / gvsig / selectiontools / app / extension / SelectByPolylineExtension.java @ 46277

History | View | Annotate | Download (4.01 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.selectiontools.app.extension;
24

    
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
29
import org.gvsig.app.project.documents.view.ViewDocument;
30
import org.gvsig.app.project.documents.view.gui.IView;
31
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
32
import org.gvsig.fmap.mapcontext.MapContext;
33
import org.gvsig.fmap.mapcontrol.MapControl;
34
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
35
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
36
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior;
37
import org.gvsig.selectiontools.app.extension.tools.PolyLineSelectListener;
38

    
39
/**
40
 * Extension to add support for selecting the geometries of the active vector
41
 * layers that intersect with a polyline defined by the user.
42
 */
43
public class SelectByPolylineExtension extends Extension {
44

    
45
    public static final String POLYLINE_SELECTION_TOOL_NAME
46
            = "polylineSelection";
47

    
48
    public void initialize() {
49
        IconThemeHelper.registerIcon("action", "selection-select-by-polyline", this);
50
        IconThemeHelper.registerIcon("cursor", "cursor-select-by-polyline", this);
51
    }
52

    
53
    public void execute(String actionCommand) {
54
        ApplicationManager application = ApplicationLocator.getManager();
55

    
56
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
57
        if (view == null) {
58
            return;
59
        }
60
        if (actionCommand.equals("SELPOLYLINE")) {
61
            MapControl mc = view.getMapControl();
62
            /*
63
             If current's view MapControl doesn't have the
64
             "polylineSelection" tool, adds it
65
             */
66
            if (!mc.getNamesMapTools().containsKey(POLYLINE_SELECTION_TOOL_NAME)) {
67
                PolyLineSelectListener polylineSelListener = new PolyLineSelectListener(mc);
68
                mc.addBehavior(
69
                        POLYLINE_SELECTION_TOOL_NAME,
70
                        new Behavior[]{
71
                            new PolylineBehavior(polylineSelListener),
72
                            new MouseMovementBehavior(new StatusBarListener(mc))
73
                        });
74
            }
75
            mc.setTool(POLYLINE_SELECTION_TOOL_NAME);
76
        }
77
    }
78

    
79
    public boolean isVisible() {
80
        ApplicationManager application = ApplicationLocator.getManager();
81

    
82
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
83
        if (view == null) {
84
            return false;
85
        }
86
        ViewDocument document = view.getViewDocument();
87
        MapContext mapa = document.getMapContext();
88
        return mapa.getLayers().getLayersCount() > 0;
89
    }
90

    
91
    public boolean isEnabled() {
92
        ApplicationManager application = ApplicationLocator.getManager();
93

    
94
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
95
        if (view == null) {
96
            return false;
97
        }
98
        ViewDocument document = view.getViewDocument();
99
        return document.getMapContext().hasActiveVectorLayers();
100
    }
101
}