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/SelectByCircleExtension.java

View differences:

SelectByCircleExtension.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 25
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28 26
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.andami.ui.mdiManager.IWindow;
27
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
30 29
import org.gvsig.app.project.documents.view.ViewDocument;
31 30
import org.gvsig.app.project.documents.view.gui.IView;
32 31
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
33 32
import org.gvsig.fmap.mapcontext.MapContext;
34
import org.gvsig.fmap.mapcontext.layers.FLayer;
35
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
36 33
import org.gvsig.fmap.mapcontrol.MapControl;
37 34
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
38 35
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
39 36
import org.gvsig.selectiontools.app.extension.tools.CircleSelectListener;
40 37
import org.gvsig.selectiontools.app.extension.tools.behavior.CircleSelectionBehavior;
41 38

  
42
/* gvSIG. Geographic Information System of the Valencian Government
43
 *
44
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
45
 * of the Valencian Government (CIT)
46
 * 
47
 * This program is free software; you can redistribute it and/or
48
 * modify it under the terms of the GNU General Public License
49
 * as published by the Free Software Foundation; either version 2
50
 * of the License, or (at your option) any later version.
51
 * 
52
 * This program is distributed in the hope that it will be useful,
53
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55
 * GNU General Public License for more details.
56
 *  
57
 * You should have received a copy of the GNU General Public License
58
 * along with this program; if not, write to the Free Software
59
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
60
 * MA  02110-1301, USA.
61
 * 
62
 */
63

  
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 circle defined by the user.
68
 * </p>
69
 * 
70
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
71 42
 */
72 43
public class SelectByCircleExtension extends Extension {
73 44

  
74 45
    public static final String CIRCLE_SELECTION_TOOL_NAME = "circleSelection";
75 46

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

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

  
97
                // If current's view MapControl doesn't have the
98
                // "CircleSelection" tool, adds it
99
                if (!mc.getNamesMapTools()
100
                    .containsKey(CIRCLE_SELECTION_TOOL_NAME)) {
101
                    CircleSelectListener circleSelListener =
102
                        new CircleSelectListener(mc);
103
                    mc.addBehavior(CIRCLE_SELECTION_TOOL_NAME, new Behavior[] {
104
                        new CircleSelectionBehavior(circleSelListener),
105
                        new MouseMovementBehavior(new StatusBarListener(mc)) });
106
                }
107

  
108
                mc.setTool(CIRCLE_SELECTION_TOOL_NAME);
55
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
56
        if (view == null) {
57
            return;
58
        }
59
        if (actionCommand.equals("SELCIRCLE")) {
60
            MapControl mc = view.getMapControl();
61
            /*
62
             If current's view MapControl doesn't have the
63
             "CircleSelection" tool, adds it
64
             */
65
            if (!mc.getNamesMapTools().containsKey(CIRCLE_SELECTION_TOOL_NAME)) {
66
                CircleSelectListener circleSelListener = new CircleSelectListener(mc);
67
                mc.addBehavior(
68
                        CIRCLE_SELECTION_TOOL_NAME,
69
                        new Behavior[]{
70
                            new CircleSelectionBehavior(circleSelListener),
71
                            new MouseMovementBehavior(new StatusBarListener(mc))
72
                        });
109 73
            }
74
            mc.setTool(CIRCLE_SELECTION_TOOL_NAME);
110 75
        }
111 76
    }
112 77

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

  
119
        if (f == null) {
81
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
82
        if (view == null) {
120 83
            return false;
121 84
        }
122

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

  
128
            return mapa.getLayers().getLayersCount() > 0;
129
        }
130

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

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

  
140
        if (f == null) {
93
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
94
        if (view == null) {
141 95
            return false;
142 96
        }
143

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

  
149
            FLayer layers[] = mapa.getLayers().getActives();
150
            FLayer layer;
151

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

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

  
161
        return false;
97
        ViewDocument document = view.getViewDocument();
98
        return document.getMapContext().hasActiveVectorLayers();
162 99
    }
163 100
}

Also available in: Unified diff