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