root / tags / v2_0_0_Build_2057 / extensions / org.gvsig.selectiontools.app / org.gvsig.selectiontools.app.extension / src / main / java / org / gvsig / selectiontools / app / extension / SelectByCircleExtension.java @ 39192
History | View | Annotate | Download (4.81 KB)
1 |
package org.gvsig.selectiontools.app.extension; |
---|---|
2 |
|
3 |
import org.gvsig.andami.IconThemeHelper; |
4 |
import org.gvsig.andami.PluginServices; |
5 |
import org.gvsig.andami.plugins.Extension; |
6 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
7 |
import org.gvsig.app.project.documents.view.ViewDocument; |
8 |
import org.gvsig.app.project.documents.view.gui.IView; |
9 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
10 |
import org.gvsig.fmap.mapcontext.MapContext; |
11 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
12 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
13 |
import org.gvsig.fmap.mapcontrol.MapControl; |
14 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
15 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
16 |
import org.gvsig.selectiontools.app.extension.tools.CircleSelectListener; |
17 |
import org.gvsig.selectiontools.app.extension.tools.behavior.CircleSelectionBehavior; |
18 |
|
19 |
/* gvSIG. Geographic Information System of the Valencian Government
|
20 |
*
|
21 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
22 |
* of the Valencian Government (CIT)
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* as published by the Free Software Foundation; either version 2
|
27 |
* of the License, or (at your option) any later version.
|
28 |
*
|
29 |
* This program is distributed in the hope that it will be useful,
|
30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
* GNU General Public License for more details.
|
33 |
*
|
34 |
* You should have received a copy of the GNU General Public License
|
35 |
* along with this program; if not, write to the Free Software
|
36 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
37 |
* MA 02110-1301, USA.
|
38 |
*
|
39 |
*/
|
40 |
|
41 |
/**
|
42 |
* <p>
|
43 |
* Extension to add support for selecting the geometries of the active vector
|
44 |
* layers that intersect with a circle defined by the user.
|
45 |
* </p>
|
46 |
*
|
47 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
48 |
*/
|
49 |
public class SelectByCircleExtension extends Extension { |
50 |
|
51 |
public static final String CIRCLE_SELECTION_TOOL_NAME = "circleSelection"; |
52 |
|
53 |
/*
|
54 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
55 |
*/
|
56 |
public void initialize() { |
57 |
IconThemeHelper.registerIcon("action", "selection-select-by-circle", this); |
58 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-circle", this); |
59 |
} |
60 |
|
61 |
/*
|
62 |
* (non-Javadoc)
|
63 |
*
|
64 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
65 |
*/
|
66 |
public void execute(String actionCommand) { |
67 |
if (actionCommand.equals("SELCIRCLE")) { |
68 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
69 |
if (window instanceof IView) { |
70 |
IView view = (IView) window; |
71 |
// Selection by circle
|
72 |
MapControl mc = view.getMapControl(); |
73 |
|
74 |
// If current's view MapControl doesn't have the
|
75 |
// "CircleSelection" tool, adds it
|
76 |
if (!mc.getNamesMapTools()
|
77 |
.containsKey(CIRCLE_SELECTION_TOOL_NAME)) { |
78 |
CircleSelectListener circleSelListener = |
79 |
new CircleSelectListener(mc);
|
80 |
mc.addBehavior(CIRCLE_SELECTION_TOOL_NAME, new Behavior[] { |
81 |
new CircleSelectionBehavior(circleSelListener),
|
82 |
new MouseMovementBehavior(new StatusBarListener(mc)) }); |
83 |
} |
84 |
|
85 |
mc.setTool(CIRCLE_SELECTION_TOOL_NAME); |
86 |
} |
87 |
} |
88 |
} |
89 |
|
90 |
/*
|
91 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
92 |
*/
|
93 |
public boolean isVisible() { |
94 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
95 |
|
96 |
if (f == null) { |
97 |
return false; |
98 |
} |
99 |
|
100 |
if (f instanceof IView) { |
101 |
IView vista = (IView) f; |
102 |
ViewDocument model = vista.getViewDocument(); |
103 |
MapContext mapa = model.getMapContext(); |
104 |
|
105 |
return mapa.getLayers().getLayersCount() > 0; |
106 |
} |
107 |
|
108 |
return false; |
109 |
} |
110 |
|
111 |
/*
|
112 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
113 |
*/
|
114 |
public boolean isEnabled() { |
115 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
116 |
|
117 |
if (f == null) { |
118 |
return false; |
119 |
} |
120 |
|
121 |
if (f instanceof IView) { |
122 |
IView vista = (IView) f; |
123 |
ViewDocument model = vista.getViewDocument(); |
124 |
MapContext mapa = model.getMapContext(); |
125 |
|
126 |
FLayer layers[] = mapa.getLayers().getActives();
|
127 |
FLayer layer; |
128 |
|
129 |
for (int i = 0; i < layers.length; i++) { |
130 |
layer = layers[i]; |
131 |
|
132 |
if ((layer instanceof FLyrVect) && (layer.isAvailable()) |
133 |
&& (layer.isActive())) |
134 |
return true; |
135 |
} |
136 |
} |
137 |
|
138 |
return false; |
139 |
} |
140 |
} |