Revision 616
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.derivedgeometries.swing</artifactId> |
|
6 |
<version>1.0.113</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.derivedgeometries.swing.impl</artifactId> |
|
9 |
<name>org.gvsig.derivedgeometries.swing.impl</name> |
|
10 |
<dependencies> |
|
11 |
<dependency> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
14 |
<scope>compile</scope> |
|
15 |
</dependency> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
19 |
<scope>runtime</scope> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.derivedgeometries.swing.api</artifactId> |
|
24 |
</dependency> |
|
25 |
<dependency> |
|
26 |
<groupId>org.gvsig</groupId> |
|
27 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.fmap.dal.swing.api</artifactId> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.fmap.dal.file.shp</artifactId> |
|
36 |
</dependency> |
|
37 |
<dependency> |
|
38 |
<groupId>org.gvsig</groupId> |
|
39 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
40 |
<scope>runtime</scope> |
|
41 |
</dependency> |
|
42 |
<dependency> |
|
43 |
<groupId>org.gvsig</groupId> |
|
44 |
<artifactId>org.gvsig.fmap.dal.file.dbf</artifactId> |
|
45 |
</dependency> |
|
46 |
<dependency> |
|
47 |
<groupId>org.gvsig</groupId> |
|
48 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
49 |
</dependency> |
|
50 |
</dependencies> |
|
51 |
</project> |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.derivedgeometries.swing.impl.DefaultDerivedGeometriesLibrary |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/DefaultDerivedGeometriesLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl; |
|
24 |
|
|
25 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLibrary; |
|
26 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLocator; |
|
27 |
import org.gvsig.fmap.dal.DALLibrary; |
|
28 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
29 |
import org.gvsig.tools.library.AbstractLibrary; |
|
30 |
import org.gvsig.tools.library.LibraryException; |
|
31 |
|
|
32 |
/** |
|
33 |
* Library for default swing implementation initialization and configuration. |
|
34 |
* |
|
35 |
* @author gvSIG team |
|
36 |
* @version $Id$ |
|
37 |
*/ |
|
38 |
public class DefaultDerivedGeometriesLibrary extends AbstractLibrary { |
|
39 |
|
|
40 |
@Override |
|
41 |
public void doRegistration() { |
|
42 |
registerAsImplementationOf(DerivedGeometriesLibrary.class); |
|
43 |
require(DALLibrary.class); |
|
44 |
require(GeometryLibrary.class); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void doInitialize() throws LibraryException { |
|
49 |
DerivedGeometriesLocator |
|
50 |
.registerManager(DefaultDerivedGeometriesManager.class); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
protected void doPostInitialize() throws LibraryException { |
|
55 |
// Do nothing |
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/panels/DefaultLayerAndProcessSelectionPanel.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl.panels; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
import java.io.File; |
|
28 |
import java.util.Vector; |
|
29 |
|
|
30 |
import javax.swing.JComponent; |
|
31 |
import javax.swing.JFileChooser; |
|
32 |
import javax.swing.JOptionPane; |
|
33 |
|
|
34 |
import org.apache.commons.io.FilenameUtils; |
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
38 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLocator; |
|
39 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters; |
|
40 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesProcess.TYPE; |
|
41 |
import org.gvsig.derivedgeometries.swing.api.exceptions.ValidateSourceLayerException; |
|
42 |
import org.gvsig.derivedgeometries.swing.api.panels.LayerAndProcessSelectionPanel; |
|
43 |
import org.gvsig.derivedgeometries.swing.impl.views.LayerAndProcessSelectionPanelView; |
|
44 |
import org.gvsig.fmap.dal.DALLocator; |
|
45 |
import org.gvsig.fmap.dal.DataManager; |
|
46 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
47 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
48 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
49 |
import org.gvsig.fmap.dal.exception.DataException; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
51 |
import org.gvsig.fmap.geom.Geometry; |
|
52 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
53 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
54 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
55 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
|
56 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
57 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
58 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
|
59 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
|
60 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
|
61 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
62 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
63 |
import org.gvsig.tools.ToolsLocator; |
|
64 |
import org.gvsig.tools.i18n.I18nManager; |
|
65 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
66 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
67 |
import org.gvsig.utils.GenericFileFilter; |
|
68 |
|
|
69 |
public class DefaultLayerAndProcessSelectionPanel extends |
|
70 |
LayerAndProcessSelectionPanelView implements LayerAndProcessSelectionPanel { |
|
71 |
|
|
72 |
private static final long serialVersionUID = 1032294236575442328L; |
|
73 |
|
|
74 |
private static final Logger LOG = LoggerFactory |
|
75 |
.getLogger(DefaultLayerAndProcessSelectionPanel.class); |
|
76 |
|
|
77 |
private final String[] SHAPE_EXTENSIONS = { "shp", "SHP", "Shp", "sHp", |
|
78 |
"SHp", "shP", "ShP", "sHP" }; |
|
79 |
|
|
80 |
private MapControl mapControl; |
|
81 |
|
|
82 |
private DerivedGeometriesParameters parameters; |
|
83 |
|
|
84 |
public DefaultLayerAndProcessSelectionPanel(MapControl mapControl) { |
|
85 |
super(); |
|
86 |
|
|
87 |
this.mapControl = mapControl; |
|
88 |
|
|
89 |
initSourceLayerCombo(); |
|
90 |
initProcessCombo(); |
|
91 |
initSelectPathButton(); |
|
92 |
|
|
93 |
addVectorialLayers(); |
|
94 |
|
|
95 |
initMapControlListeners(); |
|
96 |
} |
|
97 |
|
|
98 |
@SuppressWarnings("unchecked") |
|
99 |
private void addVectorialLayers() { |
|
100 |
getLayersComboBox().removeAllItems(); |
|
101 |
FLayers flayers = mapControl.getMapContext().getLayers(); |
|
102 |
for (FLyrVect layer : getVectorialLayers(flayers)) { |
|
103 |
getLayersComboBox().addItem(layer); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
public JComponent asJComponent() { |
|
108 |
return this; |
|
109 |
} |
|
110 |
|
|
111 |
public void closePanel() { |
|
112 |
setVisible(false); |
|
113 |
} |
|
114 |
|
|
115 |
private void deleteShapeFiles(FLyrVect sourceLayer, String outputLayerPath) { |
|
116 |
DataManager dataManager = DALLocator.getDataManager(); |
|
117 |
|
|
118 |
try { |
|
119 |
DataServerExplorerParameters eparams = |
|
120 |
dataManager |
|
121 |
.createServerExplorerParameters("FilesystemExplorer"); |
|
122 |
eparams.setDynValue("initialpath", "/data"); |
|
123 |
|
|
124 |
DataServerExplorer serverExplorer = |
|
125 |
dataManager.openServerExplorer(eparams.getExplorerName(), |
|
126 |
eparams); |
|
127 |
|
|
128 |
DataStoreParameters dataStoreParams = |
|
129 |
dataManager.createStoreParameters("Shape"); |
|
130 |
|
|
131 |
dataStoreParams.setDynValue("shpfile", outputLayerPath); |
|
132 |
dataStoreParams.setDynValue("CRS", sourceLayer.getProjection()); |
|
133 |
dataStoreParams.setDynValue("useNullGeometry", false); |
|
134 |
dataStoreParams.validate(); |
|
135 |
|
|
136 |
serverExplorer.remove(dataStoreParams); |
|
137 |
} catch (Exception e) { |
|
138 |
e.printStackTrace(); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
public void doAccept() { |
|
143 |
FLyrVect sourceLayer = (FLyrVect) getLayersComboBox().getSelectedItem(); |
|
144 |
String outputLayerName = getOutputLayerName().getText(); |
|
145 |
String outputLayerPath = getOutputLayerPath().getText(); |
|
146 |
String type = (String) getOutputShapeTypeCombo().getSelectedItem(); |
|
147 |
|
|
148 |
File outputLayer = new File(outputLayerPath); |
|
149 |
// If file exist, it will delete shape files to overwrite shape. |
|
150 |
if (exist(outputLayer)) { |
|
151 |
deleteShapeFiles(sourceLayer, outputLayerPath); |
|
152 |
} |
|
153 |
|
|
154 |
int outputLayerType = 0; |
|
155 |
if (type.equalsIgnoreCase("Multicurve")) { |
|
156 |
outputLayerType = TYPES.MULTICURVE; |
|
157 |
} else if (type.equalsIgnoreCase("Surface")) { |
|
158 |
outputLayerType = TYPES.SURFACE; |
|
159 |
} |
|
160 |
|
|
161 |
TYPE processType = (TYPE) getProcessCombo().getSelectedItem(); |
|
162 |
|
|
163 |
parameters = |
|
164 |
DerivedGeometriesLocator.getManager() |
|
165 |
.createDerivedGeometriesParameters(mapControl, sourceLayer, |
|
166 |
outputLayerName, outputLayerPath, outputLayerType, |
|
167 |
processType); |
|
168 |
} |
|
169 |
|
|
170 |
public void doCancel() { |
|
171 |
closePanel(); |
|
172 |
} |
|
173 |
|
|
174 |
public DerivedGeometriesParameters getParameters() { |
|
175 |
return parameters; |
|
176 |
} |
|
177 |
|
|
178 |
private boolean exist(File file) { |
|
179 |
|
|
180 |
String pathWithoutExtension = |
|
181 |
FilenameUtils.removeExtension(file.getAbsolutePath()); |
|
182 |
|
|
183 |
for (int i = 0; i < SHAPE_EXTENSIONS.length; i++) { |
|
184 |
String path = pathWithoutExtension + "." + SHAPE_EXTENSIONS[i]; |
|
185 |
File tmpFile = new File(path); |
|
186 |
if (tmpFile.exists()) { |
|
187 |
return true; |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
return false; |
|
192 |
} |
|
193 |
|
|
194 |
private Vector<FLyrVect> getVectorialLayers(FLayers flayers) { |
|
195 |
Vector<FLyrVect> vectorialLayers = new Vector<FLyrVect>(); |
|
196 |
for (int i = 0; i < flayers.getLayersCount(); i++) { |
|
197 |
if (flayers.getLayer(i) instanceof FLyrVect) { |
|
198 |
vectorialLayers.add((FLyrVect) flayers.getLayer(i)); |
|
199 |
|
|
200 |
} else if (flayers.getLayer(i) instanceof FLayers) { |
|
201 |
FLayers group = ((FLayers) flayers.getLayer(i)); |
|
202 |
vectorialLayers.addAll(getVectorialLayers(group)); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
return vectorialLayers; |
|
207 |
} |
|
208 |
|
|
209 |
private void initMapControlListeners() { |
|
210 |
|
|
211 |
MapContext context = mapControl.getMapContext(); |
|
212 |
FLayers layers = context.getLayers(); |
|
213 |
|
|
214 |
layers.addLayerCollectionListener(new LayerCollectionListener() { |
|
215 |
|
|
216 |
public void layerAdded(LayerCollectionEvent e) { |
|
217 |
FLayer layer = e.getAffectedLayer(); |
|
218 |
if (layer instanceof FLyrVect) { |
|
219 |
getLayersComboBox().addItem(layer); |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
public void layerAdding(LayerCollectionEvent e) |
|
224 |
throws CancelationException { |
|
225 |
} |
|
226 |
|
|
227 |
public void layerMoved(LayerPositionEvent e) { |
|
228 |
} |
|
229 |
|
|
230 |
public void layerMoving(LayerPositionEvent e) |
|
231 |
throws CancelationException { |
|
232 |
} |
|
233 |
|
|
234 |
public void layerRemoved(LayerCollectionEvent e) { |
|
235 |
FLayer layer = e.getAffectedLayer(); |
|
236 |
if (layer instanceof FLyrVect) { |
|
237 |
getLayersComboBox().removeItem(layer); |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
public void layerRemoving(LayerCollectionEvent e) |
|
242 |
throws CancelationException { |
|
243 |
} |
|
244 |
|
|
245 |
public void visibilityChanged(LayerCollectionEvent e) |
|
246 |
throws CancelationException { |
|
247 |
} |
|
248 |
}); |
|
249 |
} |
|
250 |
|
|
251 |
private void initProcessCombo() { |
|
252 |
getProcessCombo().addActionListener(new ActionListener() { |
|
253 |
|
|
254 |
@SuppressWarnings("unchecked") |
|
255 |
public void actionPerformed(ActionEvent e) { |
|
256 |
// Update the other comboBox |
|
257 |
TYPE processType = (TYPE) getProcessCombo().getSelectedItem(); |
|
258 |
if (processType != null) { |
|
259 |
switch (processType) { |
|
260 |
case POINTS_TO_LINE: |
|
261 |
getOutputShapeTypeCombo().removeAllItems(); |
|
262 |
getOutputShapeTypeCombo().addItem("Multicurve"); |
|
263 |
break; |
|
264 |
case POINTS_TO_POLYGON: |
|
265 |
getOutputShapeTypeCombo().removeAllItems(); |
|
266 |
getOutputShapeTypeCombo().addItem("Surface"); |
|
267 |
break; |
|
268 |
default: |
|
269 |
break; |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
}); |
|
274 |
} |
|
275 |
|
|
276 |
private void initSelectPathButton() { |
|
277 |
getJButtonSelectPath().addActionListener( |
|
278 |
new java.awt.event.ActionListener() { |
|
279 |
|
|
280 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
281 |
ThreadSafeDialogsManager dlgManager = |
|
282 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
283 |
|
|
284 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
285 |
|
|
286 |
File[] files = |
|
287 |
dlgManager.showChooserDialog( |
|
288 |
i18nManager |
|
289 |
.getTranslation("shape_file"), |
|
290 |
JFileChooser.OPEN_DIALOG, |
|
291 |
JFileChooser.FILES_ONLY, |
|
292 |
false, |
|
293 |
new File(System.getProperty("user.home")), |
|
294 |
new GenericFileFilter(SHAPE_EXTENSIONS, i18nManager |
|
295 |
.getTranslation("shape_file") + " (*.shp)"), |
|
296 |
true); |
|
297 |
|
|
298 |
if (files == null) { |
|
299 |
return; |
|
300 |
} |
|
301 |
|
|
302 |
if (files.length == 1) { |
|
303 |
File file = files[0]; |
|
304 |
|
|
305 |
String extension = |
|
306 |
FilenameUtils.getExtension(file.getAbsolutePath()); |
|
307 |
|
|
308 |
if (extension == "") { |
|
309 |
StringBuilder stb = new StringBuilder(); |
|
310 |
stb.append(file.getAbsolutePath()); |
|
311 |
stb.append("."); |
|
312 |
stb.append(SHAPE_EXTENSIONS[0]); |
|
313 |
|
|
314 |
file = new File(stb.toString()); |
|
315 |
} |
|
316 |
|
|
317 |
if (exist(file)) { |
|
318 |
|
|
319 |
String title = |
|
320 |
i18nManager |
|
321 |
.getTranslation("_file_already_exist"); |
|
322 |
String message = |
|
323 |
i18nManager |
|
324 |
.getTranslation("_file_already_exist_override_it"); |
|
325 |
|
|
326 |
int answer = |
|
327 |
dlgManager.confirmDialog(message, title, |
|
328 |
JOptionPane.YES_NO_OPTION, |
|
329 |
JOptionPane.INFORMATION_MESSAGE); |
|
330 |
|
|
331 |
if (answer == JOptionPane.YES_OPTION) { |
|
332 |
getOutputLayerPath().setText( |
|
333 |
file.getAbsolutePath()); |
|
334 |
} else { |
|
335 |
return; |
|
336 |
} |
|
337 |
|
|
338 |
} else { |
|
339 |
getOutputLayerPath() |
|
340 |
.setText(file.getAbsolutePath()); |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
}); |
|
345 |
} |
|
346 |
|
|
347 |
private void initSourceLayerCombo() { |
|
348 |
getLayersComboBox().addActionListener(new ActionListener() { |
|
349 |
|
|
350 |
@SuppressWarnings("unchecked") |
|
351 |
public void actionPerformed(ActionEvent e) { |
|
352 |
|
|
353 |
FLyrVect selectedLayer = |
|
354 |
(FLyrVect) getLayersComboBox().getSelectedItem(); |
|
355 |
GeometryType featureGeomType = null; |
|
356 |
|
|
357 |
getOutputShapeTypeCombo().removeAllItems(); |
|
358 |
getProcessCombo().removeAllItems(); |
|
359 |
|
|
360 |
if (selectedLayer != null) { |
|
361 |
FeatureStore featureStore = selectedLayer.getFeatureStore(); |
|
362 |
try { |
|
363 |
featureGeomType = |
|
364 |
featureStore.getDefaultFeatureType() |
|
365 |
.getDefaultGeometryAttribute().getGeomType(); |
|
366 |
} catch (DataException ex) { |
|
367 |
String message = |
|
368 |
String.format("Error getting feature type of %1", |
|
369 |
featureStore); |
|
370 |
LOG.info(message, ex); |
|
371 |
return; |
|
372 |
} |
|
373 |
|
|
374 |
if (featureGeomType.isTypeOf(Geometry.TYPES.POINT) |
|
375 |
|| featureGeomType.isTypeOf(Geometry.TYPES.MULTIPOINT)) { |
|
376 |
setSelectableComponentsEnabled(true); |
|
377 |
getOutputShapeTypeCombo().addItem("Multicurve"); |
|
378 |
getProcessCombo().addItem(TYPE.POINTS_TO_LINE); |
|
379 |
getProcessCombo().addItem(TYPE.POINTS_TO_POLYGON); |
|
380 |
|
|
381 |
} else if (featureGeomType |
|
382 |
.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
383 |
setSelectableComponentsEnabled(true); |
|
384 |
getOutputShapeTypeCombo().addItem("Surface"); |
|
385 |
getProcessCombo() |
|
386 |
.addItem(TYPE.LINES_TO_CLOSED_POLYLINE); |
|
387 |
|
|
388 |
} else { |
|
389 |
setSelectableComponentsEnabled(false); |
|
390 |
getOutputLayerName().setText(""); |
|
391 |
getOutputLayerPath().setText(""); |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
}); |
|
396 |
} |
|
397 |
|
|
398 |
public void setMapControl(MapControl mapControl) { |
|
399 |
this.mapControl = mapControl; |
|
400 |
} |
|
401 |
|
|
402 |
private void setSelectableComponentsEnabled(boolean b) { |
|
403 |
getOutputLayerPath().setEnabled(b); |
|
404 |
getOutputLayerName().setEnabled(b); |
|
405 |
getOutputShapeTypeCombo().setEnabled(b); |
|
406 |
getJButtonSelectPath().setEnabled(b); |
|
407 |
getProcessCombo().setEnabled(b); |
|
408 |
} |
|
409 |
|
|
410 |
public boolean validateFields() { |
|
411 |
FLyrVect sourceLayer = (FLyrVect) getLayersComboBox().getSelectedItem(); |
|
412 |
String outputLayerName = getOutputLayerName().getText(); |
|
413 |
String outputLayerPath = getOutputLayerPath().getText(); |
|
414 |
|
|
415 |
if (sourceLayer != null && outputLayerName.length() > 0 |
|
416 |
&& outputLayerPath.length() > 0) { |
|
417 |
return true; |
|
418 |
} else { |
|
419 |
return false; |
|
420 |
} |
|
421 |
} |
|
422 |
|
|
423 |
public boolean validateSourceLayer() throws ValidateSourceLayerException { |
|
424 |
FLyrVect sourceLayer = (FLyrVect) getLayersComboBox().getSelectedItem(); |
|
425 |
FeatureStore featureStore = sourceLayer.getFeatureStore(); |
|
426 |
GeometryType featureGeomType; |
|
427 |
try { |
|
428 |
featureGeomType = |
|
429 |
featureStore.getDefaultFeatureType() |
|
430 |
.getDefaultGeometryAttribute().getGeomType(); |
|
431 |
} catch (DataException e) { |
|
432 |
String message = |
|
433 |
String.format( |
|
434 |
"Error validating %1. Can't get feature geometry type", |
|
435 |
sourceLayer); |
|
436 |
throw new ValidateSourceLayerException(message, e); |
|
437 |
} |
|
438 |
if (featureGeomType.isTypeOf(Geometry.TYPES.POINT) |
|
439 |
|| featureGeomType.isTypeOf(Geometry.TYPES.MULTIPOINT) |
|
440 |
|| featureGeomType.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
|
441 |
return true; |
|
442 |
} |
|
443 |
return false; |
|
444 |
} |
|
445 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/panels/DefaultDerivedGeometriesPanel.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl.panels; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import javax.swing.JComponent; |
|
29 |
import javax.swing.JOptionPane; |
|
30 |
|
|
31 |
import org.slf4j.Logger; |
|
32 |
import org.slf4j.LoggerFactory; |
|
33 |
|
|
34 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters; |
|
35 |
import org.gvsig.derivedgeometries.swing.api.exceptions.DerivedGeometriesException; |
|
36 |
import org.gvsig.derivedgeometries.swing.api.exceptions.ValidateSourceLayerException; |
|
37 |
import org.gvsig.derivedgeometries.swing.api.panels.DerivedGeometriesPanel; |
|
38 |
import org.gvsig.derivedgeometries.swing.impl.views.DerivedGeometriesPanelView; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
41 |
import org.gvsig.tools.ToolsLocator; |
|
42 |
import org.gvsig.tools.i18n.I18nManager; |
|
43 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
44 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
45 |
|
|
46 |
public class DefaultDerivedGeometriesPanel extends DerivedGeometriesPanelView |
|
47 |
implements DerivedGeometriesPanel { |
|
48 |
|
|
49 |
private static final long serialVersionUID = -2874430817496441084L; |
|
50 |
|
|
51 |
private static final Logger LOG = LoggerFactory |
|
52 |
.getLogger(DefaultDerivedGeometriesPanel.class); |
|
53 |
|
|
54 |
public DefaultDerivedGeometriesPanel(MapControl theMapControl) { |
|
55 |
super(theMapControl); |
|
56 |
|
|
57 |
initNextButton(); |
|
58 |
initCancelButton(); |
|
59 |
} |
|
60 |
|
|
61 |
public JComponent asJComponent() { |
|
62 |
return this; |
|
63 |
} |
|
64 |
|
|
65 |
private void closeWindow() { |
|
66 |
setVisible(false); |
|
67 |
} |
|
68 |
|
|
69 |
private void initCancelButton() { |
|
70 |
getCancelButton().addActionListener(new ActionListener() { |
|
71 |
|
|
72 |
public void actionPerformed(ActionEvent e) { |
|
73 |
|
|
74 |
DerivedGeometriesParameters parameters = null; |
|
75 |
|
|
76 |
if (getLayerAndProcessSelectionPanel().asJComponent() |
|
77 |
.isVisible()) { |
|
78 |
|
|
79 |
parameters = |
|
80 |
getLayerAndProcessSelectionPanel().getParameters(); |
|
81 |
|
|
82 |
} else if (getFeaturesControlPanel().asJComponent().isVisible()) { |
|
83 |
|
|
84 |
parameters = getFeaturesControlPanel().getParameters(); |
|
85 |
} |
|
86 |
|
|
87 |
if(parameters != null){ |
|
88 |
FeatureStore featureStore = parameters.getFeatureStore(); |
|
89 |
if (featureStore != null) { |
|
90 |
featureStore.dispose(); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
closeWindow(); |
|
95 |
} |
|
96 |
}); |
|
97 |
} |
|
98 |
|
|
99 |
private void initNextButton() { |
|
100 |
getNextButton().addActionListener(new ActionListener() { |
|
101 |
|
|
102 |
public void actionPerformed(ActionEvent e) { |
|
103 |
|
|
104 |
ThreadSafeDialogsManager dlgManager = |
|
105 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
106 |
|
|
107 |
if (getLayerAndProcessSelectionPanel().asJComponent() |
|
108 |
.isVisible()) { |
|
109 |
|
|
110 |
// If selected source layer is not valid shows a dialog and |
|
111 |
// finish method |
|
112 |
try { |
|
113 |
if (!validateSelectedSourceLayer()) { |
|
114 |
|
|
115 |
String title = "_no_valid_source_layer"; |
|
116 |
String message = "_cant_process_this_type_of_layer"; |
|
117 |
dlgManager.messageDialog(message, title, |
|
118 |
JOptionPane.ERROR_MESSAGE); |
|
119 |
return; |
|
120 |
|
|
121 |
} |
|
122 |
} catch (DerivedGeometriesException ex) { |
|
123 |
LOG.warn("Error validating source layer", ex); |
|
124 |
return; |
|
125 |
} |
|
126 |
|
|
127 |
if (validateLayerAndOutputLayerFields()) { |
|
128 |
|
|
129 |
getLayerAndProcessSelectionPanel().doAccept(); |
|
130 |
|
|
131 |
DerivedGeometriesParameters parameters = |
|
132 |
getLayerAndProcessSelectionPanel().getParameters(); |
|
133 |
|
|
134 |
getLayerAndProcessSelectionPanel().asJComponent() |
|
135 |
.setVisible(false); |
|
136 |
|
|
137 |
getFeaturesControlPanel().setParameters(parameters); |
|
138 |
getFeaturesControlPanel().asJComponent().setVisible( |
|
139 |
true); |
|
140 |
|
|
141 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
142 |
getCancelButton().setText( |
|
143 |
i18nManager.getTranslation("finish")); |
|
144 |
getNextButton().setText( |
|
145 |
i18nManager.getTranslation("generate")); |
|
146 |
|
|
147 |
} else { |
|
148 |
|
|
149 |
// If data fields is no valid shows a dialog and finish |
|
150 |
// method |
|
151 |
String title = "_no_valid_data"; |
|
152 |
String message = |
|
153 |
"_no_valid_data_make_sure_data_are_valid"; |
|
154 |
dlgManager.messageDialog(message, title, |
|
155 |
JOptionPane.ERROR_MESSAGE); |
|
156 |
return; |
|
157 |
|
|
158 |
} |
|
159 |
} else if (getFeaturesControlPanel().asJComponent().isVisible()) { |
|
160 |
|
|
161 |
if (validateFeaturesControlPanelFields()) { |
|
162 |
|
|
163 |
getFeaturesControlPanel().doAction(); |
|
164 |
|
|
165 |
} else { |
|
166 |
|
|
167 |
// If data fields is no valid shows a dialog and finish |
|
168 |
// method |
|
169 |
String title = "_no_valid_data"; |
|
170 |
String message = |
|
171 |
"_no_valid_data_make_sure_data_are_valid"; |
|
172 |
dlgManager.messageDialog(message, title, |
|
173 |
JOptionPane.ERROR_MESSAGE); |
|
174 |
return; |
|
175 |
|
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
}); |
|
180 |
} |
|
181 |
|
|
182 |
private boolean validateLayerAndOutputLayerFields() { |
|
183 |
return getLayerAndProcessSelectionPanel().validateFields(); |
|
184 |
} |
|
185 |
|
|
186 |
private boolean validateFeaturesControlPanelFields() { |
|
187 |
return getFeaturesControlPanel().validateFields(); |
|
188 |
} |
|
189 |
|
|
190 |
private boolean validateSelectedSourceLayer() |
|
191 |
throws ValidateSourceLayerException { |
|
192 |
return getLayerAndProcessSelectionPanel().validateSourceLayer(); |
|
193 |
} |
|
194 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/panels/DefaultFeaturesControlPanel.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl.panels; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import javax.swing.JComponent; |
|
31 |
import javax.swing.JOptionPane; |
|
32 |
import javax.swing.ListSelectionModel; |
|
33 |
import javax.swing.event.ListSelectionEvent; |
|
34 |
import javax.swing.event.ListSelectionListener; |
|
35 |
|
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLocator; |
|
40 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesManager; |
|
41 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters; |
|
42 |
import org.gvsig.derivedgeometries.swing.api.exceptions.DerivedGeometriesException; |
|
43 |
import org.gvsig.derivedgeometries.swing.api.exceptions.FetaureTableModelException; |
|
44 |
import org.gvsig.derivedgeometries.swing.api.panels.FeaturesControlPanel; |
|
45 |
import org.gvsig.derivedgeometries.swing.api.tablemodels.DerivedGeometriesSelectionModel; |
|
46 |
import org.gvsig.derivedgeometries.swing.impl.views.FeaturesControlPanelView; |
|
47 |
import org.gvsig.derivedgeometries.swing.impl.views.SelectedFeaturesTableModel; |
|
48 |
import org.gvsig.fmap.dal.exception.DataException; |
|
49 |
import org.gvsig.fmap.dal.feature.Feature; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
53 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
54 |
import org.gvsig.fmap.geom.Geometry; |
|
55 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
56 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
57 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
58 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
59 |
|
|
60 |
public class DefaultFeaturesControlPanel extends FeaturesControlPanelView |
|
61 |
implements FeaturesControlPanel { |
|
62 |
|
|
63 |
private static final long serialVersionUID = -2215258264697623544L; |
|
64 |
|
|
65 |
private static final Logger LOG = LoggerFactory |
|
66 |
.getLogger(DefaultFeaturesControlPanel.class); |
|
67 |
|
|
68 |
private List<FeatureReference> features; |
|
69 |
|
|
70 |
private DerivedGeometriesParameters parameters; |
|
71 |
|
|
72 |
public DefaultFeaturesControlPanel() { |
|
73 |
super(); |
|
74 |
features = new ArrayList<FeatureReference>(); |
|
75 |
|
|
76 |
initAddAllButton(); |
|
77 |
initRemoveAllButton(); |
|
78 |
initAddButton(); |
|
79 |
initRemoveButton(); |
|
80 |
initMoveUpButton(); |
|
81 |
initMoveDownButton(); |
|
82 |
} |
|
83 |
|
|
84 |
public JComponent asJComponent() { |
|
85 |
return this; |
|
86 |
} |
|
87 |
|
|
88 |
public void doAction() { |
|
89 |
getParameters().setSelectedFeatures(features); |
|
90 |
|
|
91 |
DerivedGeometriesManager manager = |
|
92 |
DerivedGeometriesLocator.getManager(); |
|
93 |
|
|
94 |
manager.startDerivedGeometriesProcess(parameters); |
|
95 |
|
|
96 |
getSelectedFeaturesTableModel().clear(); |
|
97 |
features.clear(); |
|
98 |
} |
|
99 |
|
|
100 |
public DerivedGeometriesParameters getParameters() { |
|
101 |
return this.parameters; |
|
102 |
} |
|
103 |
|
|
104 |
private int[] getSelectedIndexs() { |
|
105 |
if (features == null || features.size() == 0) { |
|
106 |
return new int[-1]; |
|
107 |
} |
|
108 |
return getSelectedFeaturesTable().getSelectedRows(); |
|
109 |
} |
|
110 |
|
|
111 |
private boolean hasMoreThanOneGeometry(Feature feature) { |
|
112 |
Geometry geom = feature.getDefaultGeometry(); |
|
113 |
if (geom instanceof Aggregate) { |
|
114 |
if (((Aggregate) geom).getPrimitivesNumber() > 1) { |
|
115 |
return true; |
|
116 |
} |
|
117 |
} |
|
118 |
return false; |
|
119 |
} |
|
120 |
|
|
121 |
private void initAddAllButton() { |
|
122 |
getAddAllButton().addActionListener(new ActionListener() { |
|
123 |
|
|
124 |
public void actionPerformed(ActionEvent e) { |
|
125 |
|
|
126 |
FeatureStore featureStore = |
|
127 |
getParameters().getSourceLayer().getFeatureStore(); |
|
128 |
final List<FeatureReference> tmpFeatures = |
|
129 |
new ArrayList<FeatureReference>(); |
|
130 |
boolean showWarningDialog = false; |
|
131 |
DisposableIterator it = null; |
|
132 |
FeatureSet featureSet = null; |
|
133 |
|
|
134 |
try { |
|
135 |
featureSet = featureStore.getFeatureSet(); |
|
136 |
it = featureSet.fastIterator(); |
|
137 |
} catch (DataException ex) { |
|
138 |
String message = |
|
139 |
String.format( |
|
140 |
"Error getting feature set or fast iterator of %1", |
|
141 |
featureStore); |
|
142 |
LOG.info(message, ex); |
|
143 |
return; |
|
144 |
} |
|
145 |
|
|
146 |
while (it.hasNext()) { |
|
147 |
Feature feature = (Feature) it.next(); |
|
148 |
if (hasMoreThanOneGeometry(feature) |
|
149 |
|| feature.getDefaultGeometry() == null) { |
|
150 |
showWarningDialog = true; |
|
151 |
} else { |
|
152 |
tmpFeatures.add(feature.getCopy().getReference()); |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
156 |
|
|
157 |
it.dispose(); |
|
158 |
featureSet.dispose(); |
|
159 |
|
|
160 |
if (showWarningDialog) { |
|
161 |
showWarningDialog(); |
|
162 |
} |
|
163 |
|
|
164 |
features = tmpFeatures; |
|
165 |
|
|
166 |
try { |
|
167 |
getSelectedFeaturesTableModel().loadData(features); |
|
168 |
} catch (DerivedGeometriesException ex) { |
|
169 |
LOG.info("Error loading features", ex); |
|
170 |
} |
|
171 |
|
|
172 |
} |
|
173 |
}); |
|
174 |
} |
|
175 |
|
|
176 |
private void initAddButton() { |
|
177 |
getAddButton().addActionListener(new ActionListener() { |
|
178 |
|
|
179 |
public void actionPerformed(ActionEvent e) { |
|
180 |
FeatureStore featureStore = |
|
181 |
getParameters().getSourceLayer().getFeatureStore(); |
|
182 |
boolean showWarningDialog = false; |
|
183 |
|
|
184 |
DerivedGeometriesSelectionModel selectionModel = null; |
|
185 |
try { |
|
186 |
selectionModel = |
|
187 |
(DerivedGeometriesSelectionModel) getAllFeaturesTable( |
|
188 |
featureStore).getSelectionModel(); |
|
189 |
} catch (FetaureTableModelException e1) { |
|
190 |
// TODO Auto-generated catch block |
|
191 |
e1.printStackTrace(); |
|
192 |
} |
|
193 |
|
|
194 |
if (showWarningDialog) { |
|
195 |
showWarningDialog(); |
|
196 |
} |
|
197 |
|
|
198 |
features.addAll(selectionModel.getSelectedFeatures()); |
|
199 |
selectionModel.getSelectedFeatures().clear(); |
|
200 |
|
|
201 |
try { |
|
202 |
getSelectedFeaturesTableModel().loadData(features); |
|
203 |
} catch (DerivedGeometriesException ex) { |
|
204 |
LOG.info("Error loading features", ex); |
|
205 |
} |
|
206 |
|
|
207 |
} |
|
208 |
}); |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
private void initMoveDownButton() { |
|
213 |
getMoveDownButton().addActionListener(new ActionListener() { |
|
214 |
|
|
215 |
public void actionPerformed(ActionEvent e) { |
|
216 |
int[] currIndexs = getSelectedIndexs(); |
|
217 |
// If selected is the last row, do nothing |
|
218 |
if (currIndexs.length <= 0 |
|
219 |
|| currIndexs[currIndexs.length - 1] >= features.size() - 1) { |
|
220 |
return; // nothing to do |
|
221 |
} |
|
222 |
|
|
223 |
List<FeatureReference> selectedFeatures = |
|
224 |
new ArrayList<FeatureReference>(); |
|
225 |
for (int i = 0; i < currIndexs.length; i++) { |
|
226 |
FeatureReference selected = null; |
|
227 |
selected = features.get(currIndexs[i]); |
|
228 |
selectedFeatures.add(selected); |
|
229 |
} |
|
230 |
if (!selectedFeatures.isEmpty()) { |
|
231 |
features.removeAll(selectedFeatures); |
|
232 |
for (int i = 0; i < selectedFeatures.size(); i++) { |
|
233 |
FeatureReference selected = selectedFeatures.get(i); |
|
234 |
features.add(currIndexs[i] + 1, selected); |
|
235 |
} |
|
236 |
|
|
237 |
try { |
|
238 |
// Reload table |
|
239 |
getSelectedFeaturesTableModel().loadData(features); |
|
240 |
} catch (DerivedGeometriesException ex) { |
|
241 |
LOG.info("Error loading features", ex); |
|
242 |
return; |
|
243 |
} |
|
244 |
|
|
245 |
// Keeps rows selected. We have to add one due to |
|
246 |
// displacement. |
|
247 |
for (int i = 0; i < currIndexs.length; i++) { |
|
248 |
getSelectedFeaturesTable().addRowSelectionInterval( |
|
249 |
currIndexs[i] + 1, currIndexs[i] + 1); |
|
250 |
} |
|
251 |
} |
|
252 |
} |
|
253 |
}); |
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
private void initMoveUpButton() { |
|
258 |
getMoveUpButton().addActionListener(new ActionListener() { |
|
259 |
|
|
260 |
public void actionPerformed(ActionEvent e) { |
|
261 |
int[] currIndexs = getSelectedIndexs(); |
|
262 |
// If selected is the first row, do nothing |
|
263 |
if (currIndexs.length <= 0 || currIndexs[0] == 0) { |
|
264 |
return; |
|
265 |
} |
|
266 |
|
|
267 |
List<FeatureReference> selectedFeatures = |
|
268 |
new ArrayList<FeatureReference>(); |
|
269 |
for (int i = 0; i < currIndexs.length; i++) { |
|
270 |
FeatureReference selected = null; |
|
271 |
try { |
|
272 |
selected = |
|
273 |
features.get(currIndexs[i]).getFeature() |
|
274 |
.getReference(); |
|
275 |
} catch (DataException ex) { |
|
276 |
LOG.info("Error getting feature", ex); |
|
277 |
return; |
|
278 |
} |
|
279 |
selectedFeatures.add(selected); |
|
280 |
} |
|
281 |
if (!selectedFeatures.isEmpty()) { |
|
282 |
features.removeAll(selectedFeatures); |
|
283 |
for (int i = 0; i < selectedFeatures.size(); i++) { |
|
284 |
FeatureReference selected = selectedFeatures.get(i); |
|
285 |
features.add(currIndexs[i] - 1, selected); |
|
286 |
} |
|
287 |
|
|
288 |
// Reload table |
|
289 |
try { |
|
290 |
getSelectedFeaturesTableModel().loadData(features); |
|
291 |
} catch (DerivedGeometriesException ex) { |
|
292 |
LOG.info("Error loading features", ex); |
|
293 |
return; |
|
294 |
} |
|
295 |
|
|
296 |
// Keeps rows selected. We have to subtract one due to |
|
297 |
// displacement. |
|
298 |
for (int i = 0; i < currIndexs.length; i++) { |
|
299 |
getSelectedFeaturesTable().addRowSelectionInterval( |
|
300 |
currIndexs[i] - 1, currIndexs[i] - 1); |
|
301 |
} |
|
302 |
} |
|
303 |
} |
|
304 |
}); |
|
305 |
|
|
306 |
} |
|
307 |
|
|
308 |
private void initRemoveAllButton() { |
|
309 |
getRemoveAllButton().addActionListener(new ActionListener() { |
|
310 |
|
|
311 |
public void actionPerformed(ActionEvent e) { |
|
312 |
if (!features.isEmpty()) { |
|
313 |
getSelectedFeaturesTableModel().clear(); |
|
314 |
features.clear(); |
|
315 |
} |
|
316 |
} |
|
317 |
}); |
|
318 |
|
|
319 |
} |
|
320 |
|
|
321 |
private void initRemoveButton() { |
|
322 |
getRemoveButton().addActionListener(new ActionListener() { |
|
323 |
|
|
324 |
public void actionPerformed(ActionEvent e) { |
|
325 |
int[] selectedRows = |
|
326 |
getSelectedFeaturesTable().getSelectedRows(); |
|
327 |
|
|
328 |
for (int i = 0; i < selectedRows.length; i++) { |
|
329 |
features.remove(selectedRows[i]); |
|
330 |
} |
|
331 |
|
|
332 |
try { |
|
333 |
getSelectedFeaturesTableModel().loadData(features); |
|
334 |
} catch (DerivedGeometriesException ex) { |
|
335 |
LOG.info("Error loading features", ex); |
|
336 |
return; |
|
337 |
} |
|
338 |
} |
|
339 |
}); |
|
340 |
|
|
341 |
} |
|
342 |
|
|
343 |
private void initSelectionListener() { |
|
344 |
ListSelectionModel selectionModel = |
|
345 |
getSelectedFeaturesTable().getSelectionModel(); |
|
346 |
selectionModel.addListSelectionListener(new ListSelectionListener() { |
|
347 |
|
|
348 |
public void valueChanged(ListSelectionEvent e) { |
|
349 |
|
|
350 |
FeatureStore featureStore = |
|
351 |
getParameters().getSourceLayer().getFeatureStore(); |
|
352 |
try { |
|
353 |
FeatureSelection selection = |
|
354 |
(FeatureSelection) featureStore.getSelection(); |
|
355 |
selection.deselectAll(); |
|
356 |
int[] selectedRows = getSelectedIndexs(); |
|
357 |
for (int i = 0; i < selectedRows.length; i++) { |
|
358 |
selection.select(features.get(selectedRows[i])); |
|
359 |
} |
|
360 |
} catch (DataException ex) { |
|
361 |
LOG.info("Error selecting features", ex); |
|
362 |
return; |
|
363 |
} |
|
364 |
} |
|
365 |
}); |
|
366 |
} |
|
367 |
|
|
368 |
private void refreshDataView(DerivedGeometriesParameters parameters) { |
|
369 |
|
|
370 |
// Set information of summary panel |
|
371 |
getSourceLayerNameTextField().setText( |
|
372 |
parameters.getSourceLayer().getName()); |
|
373 |
getOutputLayerNameTextField().setText(parameters.getOutPutLayerName()); |
|
374 |
|
|
375 |
// Load features table |
|
376 |
FeatureStore featureStore = |
|
377 |
parameters.getSourceLayer().getFeatureStore(); |
|
378 |
try { |
|
379 |
getAllFeaturesScrollPane().setViewportView( |
|
380 |
getAllFeaturesTable(featureStore)); |
|
381 |
} catch (DerivedGeometriesException e) { |
|
382 |
LOG.info("Error getting feature table", e); |
|
383 |
return; |
|
384 |
} |
|
385 |
|
|
386 |
getSelectedFeaturesTable().setModel( |
|
387 |
new SelectedFeaturesTableModel(featureStore)); |
|
388 |
getSelectedFeaturesScrollPane().setViewportView( |
|
389 |
getSelectedFeaturesTable()); |
|
390 |
|
|
391 |
} |
|
392 |
|
|
393 |
public void setParameters(DerivedGeometriesParameters theParameters) { |
|
394 |
this.parameters = theParameters; |
|
395 |
|
|
396 |
// Refresh view with new data |
|
397 |
refreshDataView(parameters); |
|
398 |
|
|
399 |
// Initialize selection listener. We do here because |
|
400 |
// selectedFeaturesTable needs source layer feature store to be created |
|
401 |
initSelectionListener(); |
|
402 |
} |
|
403 |
|
|
404 |
private void showWarningDialog() { |
|
405 |
String title = "_warning_adding_features"; |
|
406 |
String message = |
|
407 |
"_warning_there_are_features_with_more_than_one_geometry_or_without_geometry"; |
|
408 |
ThreadSafeDialogsManager dlgManager = |
|
409 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
410 |
dlgManager.messageDialog(message, title, JOptionPane.WARNING_MESSAGE); |
|
411 |
} |
|
412 |
|
|
413 |
public boolean validateFields() { |
|
414 |
return !features.isEmpty(); |
|
415 |
} |
|
416 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/DefaultDerivedGeometriesManager.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl; |
|
24 |
|
|
25 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesManager; |
|
26 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters; |
|
27 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesProcess; |
|
28 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesProcess.TYPE; |
|
29 |
import org.gvsig.derivedgeometries.swing.api.panels.DerivedGeometriesPanel; |
|
30 |
import org.gvsig.derivedgeometries.swing.api.panels.FeaturesControlPanel; |
|
31 |
import org.gvsig.derivedgeometries.swing.api.panels.LayerAndProcessSelectionPanel; |
|
32 |
import org.gvsig.derivedgeometries.swing.impl.panels.DefaultDerivedGeometriesPanel; |
|
33 |
import org.gvsig.derivedgeometries.swing.impl.panels.DefaultFeaturesControlPanel; |
|
34 |
import org.gvsig.derivedgeometries.swing.impl.panels.DefaultLayerAndProcessSelectionPanel; |
|
35 |
import org.gvsig.derivedgeometries.swing.impl.processes.LineToClosedPolylineDerivedGeometriesProcess; |
|
36 |
import org.gvsig.derivedgeometries.swing.impl.processes.PointToLineDerivedGeometriesProcess; |
|
37 |
import org.gvsig.derivedgeometries.swing.impl.processes.PointToPolygonDerivedGeometriesProcess; |
|
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
39 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
40 |
|
|
41 |
public class DefaultDerivedGeometriesManager implements |
|
42 |
DerivedGeometriesManager { |
|
43 |
|
|
44 |
public DerivedGeometriesParameters createDerivedGeometriesParameters( |
|
45 |
MapControl mapControl, FLyrVect sourceLayer, String outputLayerName, |
|
46 |
String outputLayerPath, int outputLayerType, TYPE processType) { |
|
47 |
|
|
48 |
return new DefaultDerivedGeometriesParameters(mapControl, sourceLayer, |
|
49 |
outputLayerName, outputLayerPath, outputLayerType, processType); |
|
50 |
} |
|
51 |
|
|
52 |
public DerivedGeometriesParameters createDerivedGeometriesParameters() { |
|
53 |
return new DefaultDerivedGeometriesParameters(); |
|
54 |
} |
|
55 |
|
|
56 |
public LayerAndProcessSelectionPanel getLayerAndProcessSelectionPanel( |
|
57 |
MapControl mapControl) { |
|
58 |
return new DefaultLayerAndProcessSelectionPanel(mapControl); |
|
59 |
} |
|
60 |
|
|
61 |
public FeaturesControlPanel getFeaturesControlPanel() { |
|
62 |
return new DefaultFeaturesControlPanel(); |
|
63 |
} |
|
64 |
|
|
65 |
public DerivedGeometriesPanel getDerivedGeometriesPanel( |
|
66 |
MapControl mapControl) { |
|
67 |
return new DefaultDerivedGeometriesPanel(mapControl); |
|
68 |
} |
|
69 |
|
|
70 |
public void startDerivedGeometriesProcess( |
|
71 |
DerivedGeometriesParameters parameters) { |
|
72 |
TYPE processType = parameters.getProcessType(); |
|
73 |
DerivedGeometriesProcess newProcess = null; |
|
74 |
|
|
75 |
switch (processType) { |
|
76 |
case POINTS_TO_LINE: |
|
77 |
newProcess = new PointToLineDerivedGeometriesProcess(parameters); |
|
78 |
break; |
|
79 |
case POINTS_TO_POLYGON: |
|
80 |
newProcess = new PointToPolygonDerivedGeometriesProcess(parameters); |
|
81 |
break; |
|
82 |
case LINES_TO_CLOSED_POLYLINE: |
|
83 |
newProcess = |
|
84 |
new LineToClosedPolylineDerivedGeometriesProcess(parameters); |
|
85 |
break; |
|
86 |
default: |
|
87 |
break; |
|
88 |
} |
|
89 |
|
|
90 |
newProcess.start(); |
|
91 |
|
|
92 |
} |
|
93 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.113/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/processes/LineToClosedPolylineDerivedGeometriesProcess.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl.processes; |
|
24 |
|
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
import javax.swing.JOptionPane; |
|
28 |
|
|
29 |
import org.cresques.cts.IProjection; |
|
30 |
import org.slf4j.Logger; |
|
31 |
import org.slf4j.LoggerFactory; |
|
32 |
|
|
33 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters; |
|
34 |
import org.gvsig.derivedgeometries.swing.impl.AbstractDerivedGeometriesProcess; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
42 |
import org.gvsig.fmap.geom.primitive.Point; |
|
43 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
44 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
46 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
47 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
48 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
49 |
|
|
50 |
public class LineToClosedPolylineDerivedGeometriesProcess extends |
|
51 |
AbstractDerivedGeometriesProcess { |
|
52 |
|
|
53 |
private static final Logger logger = LoggerFactory |
|
54 |
.getLogger(LineToClosedPolylineDerivedGeometriesProcess.class); |
|
55 |
|
|
56 |
public LineToClosedPolylineDerivedGeometriesProcess( |
|
57 |
DerivedGeometriesParameters parameters) { |
|
58 |
super("Line to polyline process", parameters); |
|
59 |
} |
|
60 |
|
|
61 |
public void run() { |
|
62 |
SimpleTaskStatus status = null; |
|
63 |
|
|
64 |
try { |
|
65 |
status = (SimpleTaskStatus) this.getTaskStatus(); |
|
66 |
|
|
67 |
if (status.isCancellationRequested()) { |
|
68 |
|
|
69 |
status.cancel(); |
|
70 |
return; |
|
71 |
} |
|
72 |
|
|
73 |
// Get data process |
|
74 |
DerivedGeometriesParameters parameters = super.getParameters(); |
|
75 |
String outputLayerName = parameters.getOutPutLayerName(); |
|
76 |
String outputLayerPath = parameters.getOutPutLayerPath(); |
|
77 |
int outputLayerType = parameters.getOutPutLayerType(); |
|
78 |
boolean addLayer = parameters.getAddLayer(); |
|
79 |
boolean createNewFeatureStore = |
|
80 |
parameters.getCreateNewFeatureStore(); |
|
81 |
FLyrVect sourceLayer = parameters.getSourceLayer(); |
|
82 |
IProjection projection = sourceLayer.getProjection(); |
|
83 |
FeatureType sourceFeatureType = |
|
84 |
sourceLayer.getFeatureStore().getDefaultFeatureType(); |
|
85 |
List<FeatureReference> selectedFeatures = |
|
86 |
parameters.getSelectedFeatures(); |
|
87 |
|
|
88 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
89 |
GeometryType sourceGeomType = |
|
90 |
sourceLayer.getFeatureStore().getDefaultFeatureType() |
|
91 |
.getDefaultGeometryAttribute().getGeomType(); |
|
92 |
Polygon polygon = |
|
93 |
geomManager.createPolygon(sourceGeomType.getSubType()); |
|
94 |
Point vertexAnt = null; |
|
95 |
|
|
96 |
status.setRangeOfValues(1, selectedFeatures.size()); |
|
97 |
|
|
98 |
// Iterate over features getting geometries to create polygon |
|
99 |
for (int i = 0; i < selectedFeatures.size(); i++) { |
|
100 |
|
|
101 |
// Si ha sido solicitada la cancelacion de la tarea |
|
102 |
// la marcamos como cancelada y salimos del proceso. |
|
103 |
if (status.isCancellationRequested()) { |
|
104 |
|
|
105 |
status.cancel(); |
|
106 |
return; |
|
107 |
} |
|
108 |
|
|
109 |
// Informamos del progreso de la tarea |
|
110 |
status.setCurValue(i); |
|
111 |
|
|
112 |
FeatureReference featureReference = selectedFeatures.get(i); |
|
113 |
Geometry geom = |
|
114 |
featureReference.getFeature().getDefaultGeometry(); |
|
115 |
for (int j = 0; j < ((Curve) geom).getNumVertices(); j++) { |
|
116 |
Point point = ((Curve) geom).getVertex(j); |
|
117 |
|
|
118 |
if (vertexAnt == null || !vertexAnt.equals(point)) { |
|
119 |
polygon.addVertex(point); |
|
120 |
vertexAnt = point; |
|
121 |
} |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
} |
|
126 |
|
|
127 |
// Close polygon if it is necessary |
|
128 |
closeSurfaceIfNecessary(polygon); |
|
129 |
|
|
130 |
if (status.isCancellationRequested()) { |
|
131 |
status.cancel(); |
|
132 |
|
|
133 |
return; |
|
134 |
} |
|
135 |
|
|
136 |
if (createNewFeatureStore) { |
|
137 |
// Creating new feature store |
|
138 |
createNewFeatureStore(sourceFeatureType, outputLayerType, |
|
139 |
outputLayerPath, projection); |
|
140 |
|
|
141 |
// Set createNewFeatureStore false to avoid create new feature |
|
142 |
// if process is started again |
|
143 |
parameters.setCreateNewFeatureStore(false); |
|
144 |
} |
|
145 |
|
|
146 |
// Open the new feature store |
|
147 |
FeatureStore featureStore = parameters.getFeatureStore(); |
|
148 |
if (featureStore == null) { |
|
149 |
featureStore = getFeatureStore(outputLayerPath, projection); |
|
150 |
} |
|
151 |
|
|
152 |
// Set feature store in edit mode |
|
153 |
setEditingMode(featureStore); |
|
154 |
|
|
155 |
// Add line |
|
156 |
insertGeometryIntoFeauteStore(featureStore, polygon); |
|
157 |
|
|
158 |
// Save changes and finish editing |
|
159 |
endEditingMode(featureStore); |
|
160 |
|
|
161 |
if (status.isCancellationRequested()) { |
|
162 |
status.cancel(); |
|
163 |
|
|
164 |
return; |
|
165 |
} |
|
166 |
|
|
167 |
if (addLayer) { |
|
168 |
// Dispose feature store to liberate resources |
|
169 |
featureStore.dispose(); |
|
170 |
|
|
171 |
// Add layer to MapControl |
|
172 |
featureStore = |
|
173 |
addLayerToMapContex(outputLayerName, outputLayerPath, |
|
174 |
projection); |
|
175 |
parameters.setAddLayer(false); |
|
176 |
parameters.setFeatureStore(featureStore); |
|
177 |
} |
|
178 |
|
|
179 |
this.postProcess(); |
|
180 |
|
|
181 |
} catch (Exception e) { |
|
182 |
ThreadSafeDialogsManager dlgManager = |
|
183 |
ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
184 |
|
|
185 |
dlgManager.messageDialog("_process_error", "_error", |
|
186 |
JOptionPane.ERROR_MESSAGE); |
|
187 |
|
|
188 |
logger.info("Error in line to closed process", e); |
|
189 |
if (status != null) { |
|
190 |
status.abort(); |
|
191 |
} |
|
192 |
|
|
193 |
} finally { |
|
194 |
if (status != null) { |
|
195 |
// Mark process as terminate if it is running. |
|
196 |
if (status.isRunning()) { |
|
197 |
status.terminate(); |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
} |
Also available in: Unified diff