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