Revision 41264 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

View differences:

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

  
26
/* gvSIG. Geographic Information System of the Valencian Government
27
 *
28
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
29
 * of the Valencian Government (CIT)
30
 * 
31
 * This program is free software; you can redistribute it and/or
32
 * modify it under the terms of the GNU General Public License
33
 * as published by the Free Software Foundation; either version 2
34
 * of the License, or (at your option) any later version.
35
 * 
36
 * This program is distributed in the hope that it will be useful,
37
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
 * GNU General Public License for more details.
40
 *  
41
 * You should have received a copy of the GNU General Public License
42
 * along with this program; if not, write to the Free Software
43
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
44
 * MA  02110-1301, USA.
45
 * 
46
 */
47

  
48 25
import org.gvsig.andami.IconThemeHelper;
49
import org.gvsig.andami.PluginServices;
50 26
import org.gvsig.andami.plugins.Extension;
51
import org.gvsig.andami.ui.mdiManager.IWindow;
27
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
52 29
import org.gvsig.app.project.documents.view.ViewDocument;
53 30
import org.gvsig.app.project.documents.view.gui.IView;
54 31
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
55 32
import org.gvsig.fmap.mapcontext.MapContext;
56
import org.gvsig.fmap.mapcontext.layers.FLayer;
57
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
58 33
import org.gvsig.fmap.mapcontrol.MapControl;
59 34
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
60 35
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
......
62 37
import org.gvsig.selectiontools.app.extension.tools.PolyLineSelectListener;
63 38

  
64 39
/**
65
 * <p>
66 40
 * Extension to add support for selecting the geometries of the active vector
67 41
 * layers that intersect with a polyline defined by the user.
68
 * </p>
69
 * 
70
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
71 42
 */
72 43
public class SelectByPolylineExtension extends Extension {
73 44

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

  
77
    /*
78
     * @see com.iver.andami.plugins.IExtension#initialize()
79
     */
80 48
    public void initialize() {
81
    	IconThemeHelper.registerIcon("action", "selection-select-by-polyline", this);
82
    	IconThemeHelper.registerIcon("cursor", "cursor-select-by-polyline", this);
49
        IconThemeHelper.registerIcon("action", "selection-select-by-polyline", this);
50
        IconThemeHelper.registerIcon("cursor", "cursor-select-by-polyline", this);
83 51
    }
84 52

  
85
    /*
86
     * (non-Javadoc)
87
     * 
88
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
89
     */
90 53
    public void execute(String actionCommand) {
91
        if (actionCommand.equals("SELPOLYLINE")) {
92
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
93
            if (window instanceof IView) {
94
                IView view = (IView) window;
95
                // Selection by polyline
96
                MapControl mc = view.getMapControl();
54
        ApplicationManager application = ApplicationLocator.getManager();
97 55

  
98
                // If current's view MapControl doesn't have the
99
                // "CircleSelection" tool, adds it
100
                if (!mc.getNamesMapTools()
101
                    .containsKey(POLYLINE_SELECTION_TOOL_NAME)) {
102
                    PolyLineSelectListener polylineSelListener =
103
                        new PolyLineSelectListener(mc);
104
                    mc.addBehavior(POLYLINE_SELECTION_TOOL_NAME,
105
                        new Behavior[] {
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[]{
106 71
                            new PolylineBehavior(polylineSelListener),
107
                            new MouseMovementBehavior(new StatusBarListener(mc)) });
108
                }
109

  
110
                mc.setTool(POLYLINE_SELECTION_TOOL_NAME);
72
                            new MouseMovementBehavior(new StatusBarListener(mc))
73
                        });
111 74
            }
75
            mc.setTool(POLYLINE_SELECTION_TOOL_NAME);
112 76
        }
113 77
    }
114 78

  
115
    /*
116
     * @see com.iver.andami.plugins.IExtension#isVisible()
117
     */
118 79
    public boolean isVisible() {
119
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
80
        ApplicationManager application = ApplicationLocator.getManager();
120 81

  
121
        if (f == null) {
82
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
83
        if (view == null) {
122 84
            return false;
123 85
        }
124

  
125
        if (f instanceof IView) {
126
            IView vista = (IView) f;
127
            ViewDocument model = vista.getViewDocument();
128
            MapContext mapa = model.getMapContext();
129

  
130
            return mapa.getLayers().getLayersCount() > 0;
131
        }
132

  
133
        return false;
86
        ViewDocument document = view.getViewDocument();
87
        MapContext mapa = document.getMapContext();
88
        return mapa.getLayers().getLayersCount() > 0;
134 89
    }
135 90

  
136
    /*
137
     * @see com.iver.andami.plugins.IExtension#isEnabled()
138
     */
139 91
    public boolean isEnabled() {
140
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
92
        ApplicationManager application = ApplicationLocator.getManager();
141 93

  
142
        if (f == null) {
94
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
95
        if (view == null) {
143 96
            return false;
144 97
        }
145

  
146
        if (f instanceof IView) {
147
            IView vista = (IView) f;
148
            ViewDocument model = vista.getViewDocument();
149
            MapContext mapa = model.getMapContext();
150

  
151
            FLayer layers[] = mapa.getLayers().getActives();
152
            FLayer layer;
153

  
154
            for (int i = 0; i < layers.length; i++) {
155
                layer = layers[i];
156

  
157
                if ((layer instanceof FLyrVect) && (layer.isAvailable())
158
                    && (layer.isActive()))
159
                    return true;
160
            }
161
        }
162

  
163
        return false;
98
        ViewDocument document = view.getViewDocument();
99
        return document.getMapContext().hasActiveVectorLayers();
164 100
    }
165 101
}

Also available in: Unified diff