svn-gvsig-desktop / 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 / SelectByBufferExtension.java @ 46277
History | View | Annotate | Download (5.16 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
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 |
*
|
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 |
*
|
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.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.selectiontools.app.extension; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
27 |
|
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import org.slf4j.Logger; |
31 |
import org.slf4j.LoggerFactory; |
32 |
|
33 |
import org.gvsig.andami.IconThemeHelper; |
34 |
import org.gvsig.andami.plugins.Extension; |
35 |
import org.gvsig.app.ApplicationLocator; |
36 |
import org.gvsig.app.ApplicationManager; |
37 |
import org.gvsig.app.project.documents.view.ViewDocument; |
38 |
import org.gvsig.app.project.documents.view.gui.IView; |
39 |
import org.gvsig.fmap.dal.exception.DataException; |
40 |
import org.gvsig.fmap.mapcontext.MapContext; |
41 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
42 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
43 |
import org.gvsig.selectiontools.app.extension.tools.buffer.gui.BufferConfigurationPanel; |
44 |
|
45 |
/**
|
46 |
* Extension to add support for selecting the geometries of the active vector
|
47 |
* layers that intersect with a buffer around their previously selected
|
48 |
* geometries.
|
49 |
*/
|
50 |
public class SelectByBufferExtension extends Extension { |
51 |
|
52 |
private static Logger logger |
53 |
= LoggerFactory.getLogger(SelectByBufferExtension.class); |
54 |
public static final String BUFFER_SELECTION_TOOL_NAME = "bufferSelection"; |
55 |
|
56 |
public void initialize() { |
57 |
IconThemeHelper.registerIcon("action", "selection-select-by-buffer", this); |
58 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-buffer", this); |
59 |
} |
60 |
|
61 |
public void execute(String actionCommand) { |
62 |
ApplicationManager application = ApplicationLocator.getManager(); |
63 |
|
64 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
65 |
if (view == null) { |
66 |
return;
|
67 |
} |
68 |
ViewDocument document = view.getViewDocument(); |
69 |
|
70 |
if (actionCommand.equals("SELBUFFER")) { |
71 |
MapContext mapContext = document.getMapContext(); |
72 |
|
73 |
FLayer layers[] = mapContext.getLayers().getActives();
|
74 |
FLayer layer; |
75 |
List<FLyrVect> usefulLayers = new ArrayList<FLyrVect>(); |
76 |
int emptySelectionLayers = 0; |
77 |
|
78 |
for (int i = 0; i < layers.length; i++) { |
79 |
layer = layers[i]; |
80 |
if ((layer instanceof FLyrVect) && layer.isAvailable() && layer.isActive()) { |
81 |
FLyrVect layervect = (FLyrVect) layer; |
82 |
usefulLayers.add(layervect); |
83 |
if (layervect.getFeatureStore().isFeatureSelectionEmpty()) {
|
84 |
emptySelectionLayers++; |
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
if (usefulLayers.isEmpty() || emptySelectionLayers == usefulLayers.size()) {
|
90 |
application.messageDialog( |
91 |
application.translate("_There_are_no_geometries_selected"),
|
92 |
application.translate("Warning"),
|
93 |
JOptionPane.WARNING_MESSAGE);
|
94 |
return;
|
95 |
} |
96 |
|
97 |
// Creates and displays the configuration panel
|
98 |
application.getUIManager().addWindow( |
99 |
new BufferConfigurationPanel(usefulLayers, view));
|
100 |
} |
101 |
|
102 |
} |
103 |
|
104 |
public boolean isVisible() { |
105 |
ApplicationManager application = ApplicationLocator.getManager(); |
106 |
|
107 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
108 |
if (view == null) { |
109 |
return false; |
110 |
} |
111 |
ViewDocument document = view.getViewDocument(); |
112 |
MapContext mapa = document.getMapContext(); |
113 |
return mapa.getLayers().getLayersCount() > 0; |
114 |
} |
115 |
|
116 |
public boolean isEnabled() { |
117 |
ApplicationManager application = ApplicationLocator.getManager(); |
118 |
|
119 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
120 |
if (view == null) { |
121 |
return false; |
122 |
} |
123 |
ViewDocument document = view.getViewDocument(); |
124 |
MapContext mapa = document.getMapContext(); |
125 |
|
126 |
FLayer layers[] = mapa.getLayers().getActives();
|
127 |
FLayer layer; |
128 |
for (int i = 0; i < layers.length; i++) { |
129 |
layer = layers[i]; |
130 |
if ((layer instanceof FLyrVect) && layer.isAvailable() && layer.isActive()) { |
131 |
FLyrVect layervect = (FLyrVect) layer; |
132 |
if (!layervect.getFeatureStore().isFeatureSelectionEmpty()) {
|
133 |
return true; |
134 |
} |
135 |
} |
136 |
} |
137 |
return false; |
138 |
} |
139 |
} |