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 40556 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 41264 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 40556 jjdelcerro
 *
11 41264 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 40556 jjdelcerro
 *
16 41264 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 40556 jjdelcerro
 *
20 41264 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 40556 jjdelcerro
 */
23 40435 jjdelcerro
package org.gvsig.selectiontools.app.extension;
24
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.plugins.Extension;
27 41264 jjdelcerro
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
29 40435 jjdelcerro
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 41264 jjdelcerro
    public static final String POLYLINE_SELECTION_TOOL_NAME
46
            = "polylineSelection";
47 40435 jjdelcerro
48
    public void initialize() {
49 41264 jjdelcerro
        IconThemeHelper.registerIcon("action", "selection-select-by-polyline", this);
50
        IconThemeHelper.registerIcon("cursor", "cursor-select-by-polyline", this);
51 40435 jjdelcerro
    }
52
53
    public void execute(String actionCommand) {
54 41264 jjdelcerro
        ApplicationManager application = ApplicationLocator.getManager();
55 40435 jjdelcerro
56 41264 jjdelcerro
        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 40435 jjdelcerro
                            new PolylineBehavior(polylineSelListener),
72 41264 jjdelcerro
                            new MouseMovementBehavior(new StatusBarListener(mc))
73
                        });
74 40435 jjdelcerro
            }
75 41264 jjdelcerro
            mc.setTool(POLYLINE_SELECTION_TOOL_NAME);
76 40435 jjdelcerro
        }
77
    }
78
79
    public boolean isVisible() {
80 41264 jjdelcerro
        ApplicationManager application = ApplicationLocator.getManager();
81 40435 jjdelcerro
82 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
83
        if (view == null) {
84 40435 jjdelcerro
            return false;
85
        }
86 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
87
        MapContext mapa = document.getMapContext();
88
        return mapa.getLayers().getLayersCount() > 0;
89 40435 jjdelcerro
    }
90
91
    public boolean isEnabled() {
92 41264 jjdelcerro
        ApplicationManager application = ApplicationLocator.getManager();
93 40435 jjdelcerro
94 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
95
        if (view == null) {
96 40435 jjdelcerro
            return false;
97
        }
98 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
99
        return document.getMapContext().hasActiveVectorLayers();
100 40435 jjdelcerro
    }
101
}