Revision 569
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/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.lrs</artifactId> |
|
6 |
<version>1.0.99</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.lrs.app</artifactId> |
|
9 |
<packaging>pom</packaging> |
|
10 |
<name>${project.artifactId}</name> |
|
11 |
<modules> |
|
12 |
<module>org.gvsig.lrs.app.mainplugin</module> |
|
13 |
</modules> |
|
14 |
|
|
15 |
</project> |
|
0 | 16 |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2013 gvSIG |
|
2 |
Association. This program is free software; you can redistribute it and/or modify |
|
3 |
it under the terms of the GNU General Public License as published by the Free Software |
|
4 |
Foundation; either version 3 of the License, or (at your option) any later version. |
|
5 |
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|
6 |
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
7 |
PURPOSE. See the GNU General Public License for more details. You should have received |
|
8 |
a copy of the GNU General Public License along with this program; if not, write to |
|
9 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
|
10 |
USA. For any additional information, do not hesitate to contact us at info AT gvsig.com, |
|
11 |
or visit our website www.gvsig.com. --> |
|
12 |
<assembly> |
|
13 |
<id>gvsig-plugin-package</id> |
|
14 |
<formats> |
|
15 |
<format>zip</format> |
|
16 |
</formats> |
|
17 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
18 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
19 |
<files> |
|
20 |
<file> |
|
21 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
22 |
<outputDirectory>lib</outputDirectory> |
|
23 |
</file> |
|
24 |
<file> |
|
25 |
<source>target/package.info</source> |
|
26 |
</file> |
|
27 |
</files> |
|
28 |
|
|
29 |
<fileSets> |
|
30 |
<fileSet> |
|
31 |
<directory>src/main/resources-plugin</directory> |
|
32 |
<outputDirectory>.</outputDirectory> |
|
33 |
</fileSet> |
|
34 |
</fileSets> |
|
35 |
|
|
36 |
|
|
37 |
<dependencySets> |
|
38 |
<dependencySet> |
|
39 |
<useProjectArtifact>false</useProjectArtifact> |
|
40 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
41 |
<outputDirectory>lib</outputDirectory> |
|
42 |
<includes> |
|
43 |
<include>org.gvsig:org.gvsig.lrs.lib.api</include> |
|
44 |
<include>org.gvsig:org.gvsig.lrs.lib.impl</include> |
|
45 |
<include>org.gvsig:org.gvsig.lrs.swing.api</include> |
|
46 |
<include>org.gvsig:org.gvsig.lrs.swing.impl</include> |
|
47 |
</includes> |
|
48 |
</dependencySet> |
|
49 |
</dependencySets> |
|
50 |
|
|
51 |
</assembly> |
|
52 |
|
|
0 | 53 |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/editroutecalibration/EditRouteCalibrationExtension.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 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.lrs.app.editroutecalibration; |
|
24 |
|
|
25 |
import java.awt.Component; |
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
import java.awt.event.ComponentEvent; |
|
29 |
import java.awt.event.ComponentListener; |
|
30 |
import java.text.MessageFormat; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import javax.swing.JOptionPane; |
|
34 |
|
|
35 |
import org.apache.commons.lang3.StringUtils; |
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
import org.gvsig.andami.IconThemeHelper; |
|
40 |
import org.gvsig.andami.plugins.Extension; |
|
41 |
import org.gvsig.app.ApplicationLocator; |
|
42 |
import org.gvsig.app.ApplicationManager; |
|
43 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
44 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
45 |
import org.gvsig.fmap.dal.exception.DataException; |
|
46 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
47 |
import org.gvsig.fmap.dal.feature.Feature; |
|
48 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
49 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
51 |
import org.gvsig.fmap.geom.Geometry; |
|
52 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
53 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
54 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
55 |
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationAlgorithmParams; |
|
56 |
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationSelectIdRouteAlgorithmParams; |
|
57 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
|
58 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
59 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
60 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
61 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
62 |
import org.gvsig.lrs.swing.impl.JLrsEditRouteCalibrationController; |
|
63 |
import org.gvsig.lrs.swing.impl.JLrsEditRouteCalibrationSelectIdRouteController; |
|
64 |
import org.gvsig.lrs.swing.impl.JLrsUtils; |
|
65 |
import org.gvsig.tools.ToolsLocator; |
|
66 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
67 |
import org.gvsig.tools.i18n.I18nManager; |
|
68 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
69 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
70 |
|
|
71 |
|
|
72 |
/** |
|
73 |
* @author dmartinez |
|
74 |
* |
|
75 |
*/ |
|
76 |
public class EditRouteCalibrationExtension extends Extension implements ComponentListener { |
|
77 |
|
|
78 |
private static final Logger logger = LoggerFactory.getLogger(EditRouteCalibrationExtension.class); |
|
79 |
|
|
80 |
private JLrsEditRouteCalibrationSelectIdRouteController panelSelectId; |
|
81 |
|
|
82 |
private JLrsEditRouteCalibrationController panelController; |
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
/* (non-Javadoc) |
|
87 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
88 |
*/ |
|
89 |
public void execute(String actionCommand) { |
|
90 |
if (StringUtils.equalsIgnoreCase(actionCommand, "edit-route-calibration")) { |
|
91 |
IView view = getActiveView(); |
|
92 |
final FLyrVect activeLayer; |
|
93 |
if (view!=null){ |
|
94 |
activeLayer = getActiveLayer(view); |
|
95 |
}else{ |
|
96 |
activeLayer = null; |
|
97 |
} |
|
98 |
|
|
99 |
final MapContext mapContext = view.getMapControl().getMapContext(); |
|
100 |
|
|
101 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
102 |
|
|
103 |
final LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
104 |
|
|
105 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
106 |
|
|
107 |
try { |
|
108 |
panelSelectId = (JLrsEditRouteCalibrationSelectIdRouteController)manager.createJLrsEditRouteCalibrationSelectIdRouteAlgorithmParameters(activeLayer, null); |
|
109 |
panelSelectId.addComponentListener(this); |
|
110 |
} catch (LrsNeededParameterException e2) { |
|
111 |
logger.error("Error creating panel", e2); |
|
112 |
JOptionPane.showMessageDialog( |
|
113 |
null, |
|
114 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
115 |
.append(":").append(e2.getLocalizedMessage()), |
|
116 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
117 |
return; |
|
118 |
} |
|
119 |
panelSelectId.setVisibleAceptCancel(true); |
|
120 |
panelSelectId.addActionListener(new ActionListener() { |
|
121 |
|
|
122 |
public void actionPerformed(ActionEvent e) { |
|
123 |
JLrsAlgorithmParams panel = (JLrsAlgorithmParams) e.getSource(); |
|
124 |
if (panel.isCanceled()) { |
|
125 |
return; |
|
126 |
} |
|
127 |
LrsEditRouteCalibrationSelectIdRouteAlgorithmParams params = null; |
|
128 |
try { |
|
129 |
params = (LrsEditRouteCalibrationSelectIdRouteAlgorithmParams)panel.getParams(); |
|
130 |
} catch (LrsGettingParametersException e1) { |
|
131 |
logger.error("Error getting parameters", e1); |
|
132 |
JOptionPane.showMessageDialog( |
|
133 |
null, |
|
134 |
new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
135 |
.append(":").append(e1.getLocalizedMessage()), |
|
136 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
137 |
return; |
|
138 |
} catch (LrsNeededParameterException e1) { |
|
139 |
logger.warn("Error getting parameters", e1); |
|
140 |
JOptionPane.showMessageDialog( |
|
141 |
null, |
|
142 |
i18nManager.getTranslation(e1.getMessage()), |
|
143 |
i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
144 |
return; |
|
145 |
} |
|
146 |
|
|
147 |
try { |
|
148 |
panelController = (JLrsEditRouteCalibrationController)manager.createJLrsEditRouteCalibrationAlgorithmParameters(activeLayer, mapContext, params.getIdRouteField(), null); |
|
149 |
panelController.addComponentListener(EditRouteCalibrationExtension.this); |
|
150 |
} catch (Exception e2) { |
|
151 |
logger.error("Error creating panel", e2); |
|
152 |
JOptionPane.showMessageDialog( |
|
153 |
null, |
|
154 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
155 |
.append(":").append(e2.getLocalizedMessage()), |
|
156 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
157 |
return; |
|
158 |
} |
|
159 |
panelController.setVisibleAceptCancel(true); |
|
160 |
panelController.addActionListener(new ActionListener() { |
|
161 |
public void actionPerformed(ActionEvent e) { |
|
162 |
JLrsEditRouteCalibrationController panel = (JLrsEditRouteCalibrationController) e.getSource(); |
|
163 |
if (panel.isCanceled()) { |
|
164 |
return; |
|
165 |
} |
|
166 |
|
|
167 |
if (panel.hasWarnings()){ |
|
168 |
boolean acceptedWarnings=showWarnings(panel.getWarnings()); |
|
169 |
if (acceptedWarnings){ |
|
170 |
panel.close(); |
|
171 |
}else{ |
|
172 |
return; |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
final LrsEditRouteCalibrationAlgorithmParams params; |
|
177 |
try { |
|
178 |
params = (LrsEditRouteCalibrationAlgorithmParams)panel.getParams(); |
|
179 |
} catch (LrsGettingParametersException e1) { |
|
180 |
logger.error("Error getting parameters", e1); |
|
181 |
JOptionPane.showMessageDialog( |
|
182 |
null, |
|
183 |
new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
184 |
.append(":").append(e1.getLocalizedMessage()), |
|
185 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
186 |
return; |
|
187 |
} catch (LrsNeededParameterException e1) { |
|
188 |
logger.warn("Error getting parameters", e1); |
|
189 |
JOptionPane.showMessageDialog( |
|
190 |
null, |
|
191 |
i18nManager.getTranslation(e1.getMessage()), |
|
192 |
i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
193 |
return; |
|
194 |
} |
|
195 |
|
|
196 |
if (params!=null){ |
|
197 |
saveLayer(activeLayer,params); |
|
198 |
} |
|
199 |
|
|
200 |
panel.close(); |
|
201 |
} |
|
202 |
|
|
203 |
}); |
|
204 |
winManager.showWindow(panelController.asJComponent(), i18nManager.getTranslation("edit_route_calibration"), |
|
205 |
WindowManager.MODE.WINDOW); |
|
206 |
} |
|
207 |
}); |
|
208 |
winManager.showWindow(panelSelectId.asJComponent(), i18nManager.getTranslation("edit_route_calibration"), |
|
209 |
WindowManager.MODE.WINDOW); |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/* (non-Javadoc) |
|
214 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
215 |
*/ |
|
216 |
public void initialize() { |
|
217 |
registerIcons(); |
|
218 |
} |
|
219 |
|
|
220 |
/* (non-Javadoc) |
|
221 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
222 |
*/ |
|
223 |
public boolean isEnabled() { |
|
224 |
IView view = getActiveView(); |
|
225 |
if (view!=null){ |
|
226 |
FLyrVect activeLayer = getActiveLayer(view); |
|
227 |
if (panelSelectId == null && panelController == null && activeLayer!=null && activeLayer.isEditing()){ |
|
228 |
return JLrsUtils.isMlayerWithNonGeomField(activeLayer); |
|
229 |
} |
|
230 |
} |
|
231 |
return false; |
|
232 |
} |
|
233 |
|
|
234 |
/* (non-Javadoc) |
|
235 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
236 |
*/ |
|
237 |
public boolean isVisible() { |
|
238 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
239 |
|
|
240 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
241 |
} |
|
242 |
|
|
243 |
private void registerIcons() { |
|
244 |
IconThemeHelper.registerIcon("lrs", "pk_cian", this); |
|
245 |
} |
|
246 |
|
|
247 |
|
|
248 |
private IView getActiveView() { |
|
249 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
250 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
251 |
return view; |
|
252 |
} |
|
253 |
|
|
254 |
private FLyrVect getActiveLayer(IView vista) { |
|
255 |
if (vista != null) { |
|
256 |
ViewDocument viewDocument = vista.getViewDocument(); |
|
257 |
FLayer[] actives = |
|
258 |
viewDocument.getMapContext().getLayers().getActives(); |
|
259 |
|
|
260 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
|
261 |
return (FLyrVect) actives[0]; |
|
262 |
} |
|
263 |
} |
|
264 |
return null; |
|
265 |
} |
|
266 |
|
|
267 |
private boolean showWarnings(List<String> warnings){ |
|
268 |
final int MAXWARNINGSSHOWED=15; |
|
269 |
|
|
270 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
271 |
logger.debug("Warnings found accepting edit route panel"); |
|
272 |
StringBuilder messageBuilder= new StringBuilder().append(i18nManager.getTranslation("warnings_in_edit_route")); |
|
273 |
String newLine=System.getProperty("line.separator"); |
|
274 |
messageBuilder.append(newLine); |
|
275 |
for (int i=0;(i<=MAXWARNINGSSHOWED&&i<warnings.size());i++){ |
|
276 |
if(i<MAXWARNINGSSHOWED){ |
|
277 |
String warning=warnings.get(i); |
|
278 |
messageBuilder.append(newLine); |
|
279 |
messageBuilder.append(warning); |
|
280 |
} |
|
281 |
if (i==MAXWARNINGSSHOWED&&warnings.size()>MAXWARNINGSSHOWED){ |
|
282 |
messageBuilder.append(newLine); |
|
283 |
int warningsNotShowed=warnings.size()-MAXWARNINGSSHOWED; |
|
284 |
messageBuilder.append(MessageFormat.format( |
|
285 |
i18nManager.getTranslation("more_warnings_found"), warningsNotShowed)); |
|
286 |
} |
|
287 |
} |
|
288 |
messageBuilder.append(newLine); |
|
289 |
messageBuilder.append(newLine).append(i18nManager.getTranslation("accept_warnings_question")); |
|
290 |
int result =JOptionPane.showConfirmDialog( |
|
291 |
null, |
|
292 |
messageBuilder, |
|
293 |
i18nManager.getTranslation("warnings_dialog"), JOptionPane.YES_NO_OPTION); |
|
294 |
if (result==JOptionPane.YES_OPTION)return true; |
|
295 |
else return false; |
|
296 |
} |
|
297 |
|
|
298 |
private void saveLayer(FLyrVect activeLayer,LrsEditRouteCalibrationAlgorithmParams params){ |
|
299 |
FeatureAttributeDescriptor fieldRoute=params.getIdRouteField(); |
|
300 |
String routeName=params.getSelectedRouteName(); |
|
301 |
Geometry modifiedGeometry=params.getModifiedGeometry(); |
|
302 |
|
|
303 |
FeatureStore featureStore=activeLayer.getFeatureStore(); |
|
304 |
if (!featureStore.isEditing()){ |
|
305 |
throw new IllegalArgumentException(); |
|
306 |
} |
|
307 |
DisposableIterator it=null; |
|
308 |
EditableFeature editableFeature=null; |
|
309 |
try { |
|
310 |
FeatureSet selectedFeatures=featureStore.getFeatureSet(); |
|
311 |
it=selectedFeatures.fastIterator(); |
|
312 |
while (it.hasNext()&&editableFeature==null) { |
|
313 |
Feature feature = (Feature) it.next(); |
|
314 |
if (feature.get(fieldRoute.getName()) instanceof String && |
|
315 |
routeName.equals((String)feature.get(fieldRoute.getName()))){ |
|
316 |
editableFeature=feature.getEditable(); |
|
317 |
} |
|
318 |
} |
|
319 |
if (editableFeature==null){ |
|
320 |
throw new IllegalArgumentException(); |
|
321 |
}else{ |
|
322 |
editableFeature.setDefaultGeometry(modifiedGeometry); |
|
323 |
featureStore.update(editableFeature); |
|
324 |
} |
|
325 |
|
|
326 |
} catch (DataException e) { |
|
327 |
logger.error("Error saving modified layer",e); |
|
328 |
}finally{ |
|
329 |
if (it!=null){ |
|
330 |
it.dispose(); |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
|
|
335 |
/* (non-Javadoc) |
|
336 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent) |
|
337 |
*/ |
|
338 |
public void componentResized(ComponentEvent e) { |
|
339 |
// TODO Auto-generated method stub |
|
340 |
|
|
341 |
} |
|
342 |
|
|
343 |
/* (non-Javadoc) |
|
344 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent) |
|
345 |
*/ |
|
346 |
public void componentMoved(ComponentEvent e) { |
|
347 |
// TODO Auto-generated method stub |
|
348 |
|
|
349 |
} |
|
350 |
|
|
351 |
/* (non-Javadoc) |
|
352 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent) |
|
353 |
*/ |
|
354 |
public void componentShown(ComponentEvent e) { |
|
355 |
// TODO Auto-generated method stub |
|
356 |
|
|
357 |
} |
|
358 |
|
|
359 |
/* (non-Javadoc) |
|
360 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent) |
|
361 |
*/ |
|
362 |
public void componentHidden(ComponentEvent e) { |
|
363 |
Component component = e.getComponent(); |
|
364 |
if (component == panelSelectId) { |
|
365 |
panelSelectId = null; |
|
366 |
} else if (component == panelController) { |
|
367 |
panelController = null; |
|
368 |
} else { |
|
369 |
if (panelSelectId != null && panelSelectId.getParent() == component) { |
|
370 |
panelSelectId = null; |
|
371 |
} else if (panelController != null && panelController.getParent() == component) { |
|
372 |
panelController.close(); |
|
373 |
panelController = null; |
|
374 |
|
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
} |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/generatedynamicsegmentation/GenerateDynamicSegmentationExtension.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 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.lrs.app.generatedynamicsegmentation; |
|
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.JOptionPane; |
|
31 |
|
|
32 |
import org.apache.commons.lang3.StringUtils; |
|
33 |
import org.slf4j.Logger; |
|
34 |
import org.slf4j.LoggerFactory; |
|
35 |
|
|
36 |
import org.gvsig.andami.IconThemeHelper; |
|
37 |
import org.gvsig.andami.plugins.Extension; |
|
38 |
import org.gvsig.app.ApplicationLocator; |
|
39 |
import org.gvsig.app.ApplicationManager; |
|
40 |
import org.gvsig.app.project.documents.Document; |
|
41 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
42 |
import org.gvsig.app.project.documents.table.TableManager; |
|
43 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
44 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
46 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
|
47 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
48 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
49 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
50 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
51 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
|
52 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
53 |
import org.gvsig.lrs.lib.api.LrsAlgorithm; |
|
54 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
|
55 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
|
56 |
import org.gvsig.lrs.lib.api.LrsGenerateDynamicSegmentationAlgorithmParams; |
|
57 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
|
58 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
59 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
60 |
import org.gvsig.lrs.swing.api.JLrsProgressDialog; |
|
61 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
62 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
63 |
import org.gvsig.lrs.swing.impl.JLrsGenerateDynamicSegmentationParamsController; |
|
64 |
import org.gvsig.lrs.swing.impl.JLrsUtils; |
|
65 |
import org.gvsig.tools.ToolsLocator; |
|
66 |
import org.gvsig.tools.i18n.I18nManager; |
|
67 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
68 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
69 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
70 |
|
|
71 |
|
|
72 |
/** |
|
73 |
* @author dmartinez |
|
74 |
* |
|
75 |
*/ |
|
76 |
public class GenerateDynamicSegmentationExtension extends Extension { |
|
77 |
|
|
78 |
private static final Logger logger = LoggerFactory.getLogger(GenerateDynamicSegmentationExtension.class); |
|
79 |
|
|
80 |
/* (non-Javadoc) |
|
81 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
82 |
*/ |
|
83 |
public void execute(String actionCommand) { |
|
84 |
if (StringUtils.equalsIgnoreCase(actionCommand, "generate-dynamic-segmentation")) { |
|
85 |
IView view = getActiveView(); |
|
86 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
|
87 |
List<FeatureStore> tables=getTables(); |
|
88 |
|
|
89 |
|
|
90 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
91 |
|
|
92 |
final LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
93 |
|
|
94 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
95 |
|
|
96 |
JLrsGenerateDynamicSegmentationParamsController panel; |
|
97 |
try { |
|
98 |
panel = (JLrsGenerateDynamicSegmentationParamsController)manager.createJLrsGenerateDynamicSegmentationAlgorithmParameters(layers,tables, null); |
|
99 |
} catch (LrsNeededParameterException e2) { |
|
100 |
logger.error("Error creating panel", e2); |
|
101 |
JOptionPane.showMessageDialog( |
|
102 |
null, |
|
103 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
104 |
.append(":").append(e2.getLocalizedMessage()), |
|
105 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
106 |
return; |
|
107 |
} |
|
108 |
panel.setVisibleAceptCancel(true); |
|
109 |
panel.addActionListener(new ActionListener() { |
|
110 |
|
|
111 |
public void actionPerformed(ActionEvent e) { |
|
112 |
JLrsAlgorithmParams panel = (JLrsAlgorithmParams) e.getSource(); |
|
113 |
if (panel.isCanceled()) { |
|
114 |
return; |
|
115 |
} |
|
116 |
LrsGenerateDynamicSegmentationAlgorithmParams params = null; |
|
117 |
try { |
|
118 |
params = (LrsGenerateDynamicSegmentationAlgorithmParams)panel.getParams(); |
|
119 |
} catch (LrsGettingParametersException e1) { |
|
120 |
logger.error("Error getting parameters", e1); |
|
121 |
JOptionPane.showMessageDialog( |
|
122 |
null, |
|
123 |
new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
124 |
.append(":").append(e1.getLocalizedMessage()), |
|
125 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
126 |
return; |
|
127 |
} catch (LrsNeededParameterException e1) { |
|
128 |
logger.warn("Error getting parameters", e1); |
|
129 |
JOptionPane.showMessageDialog( |
|
130 |
null, |
|
131 |
i18nManager.getTranslation(e1.getMessage()), |
|
132 |
i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
133 |
return; |
|
134 |
} |
|
135 |
|
|
136 |
LrsAlgorithmsManager algorithmsManager = LrsAlgorithmsLocator.getLrsAlgorithmsManager(); |
|
137 |
final LrsAlgorithm algorithm = algorithmsManager.createLrsAlgorithm(params); |
|
138 |
final SHPNewStoreParameters shpParams=(SHPNewStoreParameters)params.getNewFeatureStoreParameters(); |
|
139 |
|
|
140 |
final SimpleTaskStatus taskStatus = |
|
141 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(i18nManager.getTranslation("progress")); |
|
142 |
|
|
143 |
final JLrsProgressDialog progressDialog = manager.createJLrsProgressDialog(taskStatus); |
|
144 |
|
|
145 |
winManager.showWindow(progressDialog.asJComponent(), i18nManager.getTranslation("generate_dynamic_segmentation"), |
|
146 |
WindowManager.MODE.WINDOW); |
|
147 |
|
|
148 |
Thread task = new Thread(new Runnable() { |
|
149 |
|
|
150 |
public void run() { |
|
151 |
try { |
|
152 |
algorithm.execute(taskStatus); |
|
153 |
int resultLoadLayer =JOptionPane.showConfirmDialog( |
|
154 |
null, |
|
155 |
i18nManager.getTranslation("load_layer_question"), |
|
156 |
i18nManager.getTranslation("load_layer_question_title"), JOptionPane.YES_NO_OPTION); |
|
157 |
if (resultLoadLayer==JOptionPane.YES_OPTION){ |
|
158 |
loadLayer(shpParams); |
|
159 |
} |
|
160 |
|
|
161 |
} catch (Exception e) { |
|
162 |
logger.error("Error generating dynamic segmentation ", e); |
|
163 |
String message = e.getMessage(); |
|
164 |
if (e.getCause() != null) { |
|
165 |
message = e.getCause().getMessage(); |
|
166 |
} |
|
167 |
JOptionPane.showMessageDialog( |
|
168 |
progressDialog.asJComponent(), |
|
169 |
message, |
|
170 |
i18nManager.getTranslation("generate_dynamic_segmentation"), |
|
171 |
JOptionPane.ERROR_MESSAGE |
|
172 |
); |
|
173 |
} |
|
174 |
} |
|
175 |
}); |
|
176 |
task.start(); |
|
177 |
|
|
178 |
} |
|
179 |
}); |
|
180 |
winManager.showWindow(panel.asJComponent(), i18nManager.getTranslation("generate_dynamic_segmentation"), |
|
181 |
WindowManager.MODE.WINDOW); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
/* (non-Javadoc) |
|
186 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
187 |
*/ |
|
188 |
public void initialize() { |
|
189 |
registerIcons(); |
|
190 |
} |
|
191 |
|
|
192 |
/* (non-Javadoc) |
|
193 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
194 |
*/ |
|
195 |
public boolean isEnabled() { |
|
196 |
IView view = getActiveView(); |
|
197 |
if (view!=null){ |
|
198 |
ViewDocument viewDocument = view.getViewDocument(); |
|
199 |
LayerCollection layers = viewDocument.getMapContext().getLayers(); |
|
200 |
if (JLrsUtils.validateMLayerWithNonGeomField(layers)){ |
|
201 |
List<FeatureStore> tables=getTables(); |
|
202 |
if (tables!=null&&tables.size()>0){ |
|
203 |
return JLrsUtils.validateStoreWithFieldsAndOneNumeric(tables); |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
return false; |
|
208 |
} |
|
209 |
|
|
210 |
/* (non-Javadoc) |
|
211 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
212 |
*/ |
|
213 |
public boolean isVisible() { |
|
214 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
215 |
|
|
216 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
217 |
} |
|
218 |
|
|
219 |
private void registerIcons() { |
|
220 |
IconThemeHelper.registerIcon("lrs", "pk_yellow", this); |
|
221 |
} |
|
222 |
|
|
223 |
private List<FeatureStore> getTables(){ |
|
224 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
225 |
List<Document> documents=application.getCurrentProject().getDocuments(TableManager.TYPENAME); |
|
226 |
List<FeatureStore> tables=new ArrayList<FeatureStore>(); |
|
227 |
if (documents!=null){ |
|
228 |
for (int i = 0; i < documents.size(); i++) { |
|
229 |
TableDocument tableDocument=(TableDocument)documents.get(i); |
|
230 |
tables.add(tableDocument.getStore()); |
|
231 |
} |
|
232 |
} |
|
233 |
return tables; |
|
234 |
} |
|
235 |
|
|
236 |
private IView getActiveView() { |
|
237 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
238 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
239 |
return view; |
|
240 |
} |
|
241 |
|
|
242 |
private void loadLayer(SHPNewStoreParameters shpParams){ |
|
243 |
if (shpParams!=null ){ |
|
244 |
String name=shpParams.getFile().getName(); |
|
245 |
if (name.contains(".shp")){ |
|
246 |
name=name.substring(0,name.lastIndexOf(".shp")); |
|
247 |
} |
|
248 |
MapContextManager mapContextManager =MapContextLocator.getMapContextManager(); |
|
249 |
|
|
250 |
FLyrVect newLayer=null; |
|
251 |
try { |
|
252 |
newLayer = (FLyrVect) mapContextManager.createLayer(name,shpParams); |
|
253 |
} catch (LoadLayerException e) { |
|
254 |
logger.warn("Couldn't load layer",e); |
|
255 |
} |
|
256 |
getActiveView().getMapControl().getMapContext().getLayers().addLayer(newLayer); |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
} |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/createroute/CreateRouteExtension.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 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.lrs.app.createroute; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import javax.swing.JOptionPane; |
|
29 |
|
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.bouncycastle.util.Store; |
|
32 |
import org.cresques.cts.IProjection; |
|
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.DALLocator; |
|
40 |
import org.gvsig.fmap.dal.DataManager; |
|
41 |
import org.gvsig.fmap.dal.DataStore; |
|
42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
43 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
44 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
45 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
46 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
48 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
|
49 |
import org.gvsig.fmap.geom.Geometry; |
|
50 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
51 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
52 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
53 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
54 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
55 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
56 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
57 |
import org.gvsig.lrs.lib.api.LrsAlgorithm; |
|
58 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
|
59 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
|
60 |
import org.gvsig.lrs.lib.api.LrsCreateRouteAlgorithmParams; |
|
61 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
|
62 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
63 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
64 |
import org.gvsig.lrs.swing.api.JLrsProgressDialog; |
|
65 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
66 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
67 |
import org.gvsig.lrs.swing.impl.JLrsCreateRouteParamsController; |
|
68 |
import org.gvsig.lrs.swing.impl.JLrsUtils; |
|
69 |
import org.gvsig.tools.ToolsLocator; |
|
70 |
import org.gvsig.tools.i18n.I18nManager; |
|
71 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
72 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
73 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
74 |
import org.slf4j.Logger; |
|
75 |
import org.slf4j.LoggerFactory; |
|
76 |
|
|
77 |
|
|
78 |
/** |
|
79 |
* @author fdiaz |
|
80 |
* |
|
81 |
*/ |
|
82 |
public class CreateRouteExtension extends Extension { |
|
83 |
|
|
84 |
private static final Logger logger = LoggerFactory.getLogger(CreateRouteExtension.class); |
|
85 |
|
|
86 |
/* (non-Javadoc) |
|
87 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
88 |
*/ |
|
89 |
public void execute(String actionCommand) { |
|
90 |
if (StringUtils.equalsIgnoreCase(actionCommand, "create-routes")) { |
|
91 |
IView view = getActiveView(); |
|
92 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
|
93 |
|
|
94 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
95 |
|
|
96 |
final LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
97 |
|
|
98 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
99 |
|
|
100 |
JLrsCreateRouteParamsController panel; |
|
101 |
try { |
|
102 |
panel = (JLrsCreateRouteParamsController)manager.createJLrsCreateRouteAlgorithmParameters(layers, null); |
|
103 |
} catch (LrsNeededParameterException e2) { |
|
104 |
logger.error("Error creating panel", e2); |
|
105 |
JOptionPane.showMessageDialog( |
|
106 |
null, |
|
107 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
108 |
.append(":").append(e2.getLocalizedMessage()), |
|
109 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
110 |
return; |
|
111 |
} |
|
112 |
panel.setVisibleAceptCancel(true); |
|
113 |
panel.addActionListener(new ActionListener() { |
|
114 |
|
|
115 |
public void actionPerformed(ActionEvent e) { |
|
116 |
JLrsAlgorithmParams panel = (JLrsAlgorithmParams) e.getSource(); |
|
117 |
if (panel.isCanceled()) { |
|
118 |
return; |
|
119 |
} |
|
120 |
LrsCreateRouteAlgorithmParams params = null; |
|
121 |
try { |
|
122 |
params = (LrsCreateRouteAlgorithmParams)panel.getParams(); |
|
123 |
} catch (LrsGettingParametersException e1) { |
|
124 |
logger.error("Error getting parameters", e1); |
|
125 |
JOptionPane.showMessageDialog( |
|
126 |
null, |
|
127 |
new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
128 |
.append(":").append(e1.getLocalizedMessage()), |
|
129 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
130 |
return; |
|
131 |
} catch (LrsNeededParameterException e1) { |
|
132 |
logger.warn("Error getting parameters", e1); |
|
133 |
JOptionPane.showMessageDialog( |
|
134 |
null, |
|
135 |
i18nManager.getTranslation(e1.getMessage()), |
|
136 |
i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
137 |
return; |
|
138 |
} |
|
139 |
LrsAlgorithmsManager algorithmsManager = LrsAlgorithmsLocator.getLrsAlgorithmsManager(); |
|
140 |
final LrsAlgorithm algorithm = algorithmsManager.createLrsAlgorithm(params); |
|
141 |
final SHPNewStoreParameters shpParams=(SHPNewStoreParameters)params.getNewFeatureStoreParameters(); |
|
142 |
|
|
143 |
final SimpleTaskStatus taskStatus = |
|
144 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(i18nManager.getTranslation("progress")); |
|
145 |
|
|
146 |
final JLrsProgressDialog progressDialog = manager.createJLrsProgressDialog(taskStatus); |
|
147 |
|
|
148 |
winManager.showWindow(progressDialog.asJComponent(), i18nManager.getTranslation("create_routes"), |
|
149 |
WindowManager.MODE.WINDOW); |
|
150 |
|
|
151 |
Thread task = new Thread(new Runnable() { |
|
152 |
|
|
153 |
public void run() { |
|
154 |
try { |
|
155 |
algorithm.execute(taskStatus); |
|
156 |
int resultLoadLayer =JOptionPane.showConfirmDialog( |
|
157 |
null, |
|
158 |
i18nManager.getTranslation("load_layer_question"), |
|
159 |
i18nManager.getTranslation("load_layer_question_title"), JOptionPane.YES_NO_OPTION); |
|
160 |
if (resultLoadLayer==JOptionPane.YES_OPTION){ |
|
161 |
loadLayer(shpParams); |
|
162 |
} |
|
163 |
} catch (Exception e) { |
|
164 |
logger.error("Error creating routes", e); |
|
165 |
String message = e.getMessage(); |
|
166 |
if (e.getCause() != null) { |
|
167 |
message = e.getCause().getMessage(); |
|
168 |
} |
|
169 |
JOptionPane.showMessageDialog( |
|
170 |
progressDialog.asJComponent(), |
|
171 |
message, |
|
172 |
i18nManager.getTranslation("create_routes"), |
|
173 |
JOptionPane.ERROR_MESSAGE |
|
174 |
); |
|
175 |
} |
|
176 |
} |
|
177 |
}); |
|
178 |
task.start(); |
|
179 |
} |
|
180 |
}); |
|
181 |
winManager.showWindow(panel.asJComponent(), i18nManager.getTranslation("create_routes"), |
|
182 |
WindowManager.MODE.WINDOW); |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
/* (non-Javadoc) |
|
187 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
188 |
*/ |
|
189 |
public void initialize() { |
|
190 |
registerIcons(); |
|
191 |
} |
|
192 |
|
|
193 |
/* (non-Javadoc) |
|
194 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
195 |
*/ |
|
196 |
public boolean isEnabled() { |
|
197 |
IView view = getActiveView(); |
|
198 |
if (view!=null){ |
|
199 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
|
200 |
return JLrsUtils.validateOneCurveLyrOneNonGeomField(layers); |
|
201 |
}else return false; |
|
202 |
|
|
203 |
} |
|
204 |
|
|
205 |
/* (non-Javadoc) |
|
206 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
207 |
*/ |
|
208 |
public boolean isVisible() { |
|
209 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
210 |
|
|
211 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
212 |
} |
|
213 |
|
|
214 |
private void registerIcons() { |
|
215 |
IconThemeHelper.registerIcon("lrs", "pk_red", this); |
|
216 |
IconThemeHelper.registerIcon("lrs", "pk_m", this); |
|
217 |
} |
|
218 |
|
|
219 |
|
|
220 |
private IView getActiveView() { |
|
221 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
222 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
223 |
return view; |
|
224 |
} |
|
225 |
|
|
226 |
private void loadLayer(SHPNewStoreParameters shpParams){ |
|
227 |
if (shpParams!=null ){ |
|
228 |
String name=shpParams.getFile().getName(); |
|
229 |
if (name.contains(".shp")){ |
|
230 |
name=name.substring(0,name.lastIndexOf(".shp")); |
|
231 |
} |
|
232 |
MapContextManager mapContextManager =MapContextLocator.getMapContextManager(); |
|
233 |
|
|
234 |
FLyrVect newLayer=null; |
|
235 |
try { |
|
236 |
newLayer = (FLyrVect) mapContextManager.createLayer(name,shpParams); |
|
237 |
} catch (LoadLayerException e) { |
|
238 |
logger.warn("Couldn't load layer",e); |
|
239 |
} |
|
240 |
getActiveView().getMapControl().getMapContext().getLayers().addLayer(newLayer); |
|
241 |
} |
|
242 |
} |
|
243 |
|
|
244 |
} |
|
0 | 245 |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/calibrateroute/CalibrateRouteExtension.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 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.lrs.app.calibrateroute; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import javax.swing.JOptionPane; |
|
29 |
|
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.gvsig.andami.IconThemeHelper; |
|
32 |
import org.gvsig.andami.PluginServices; |
|
33 |
import org.gvsig.andami.PluginsLocator; |
|
34 |
import org.gvsig.andami.PluginsManager; |
|
35 |
import org.gvsig.andami.plugins.Extension; |
|
36 |
import org.gvsig.app.ApplicationLocator; |
|
37 |
import org.gvsig.app.ApplicationManager; |
|
38 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
39 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
40 |
import org.gvsig.fmap.dal.exception.DataException; |
|
41 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
42 |
import org.gvsig.fmap.dal.feature.Feature; |
|
43 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
45 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
|
46 |
import org.gvsig.fmap.geom.Geometry; |
|
47 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
48 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
49 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
50 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
51 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
52 |
import org.gvsig.lrs.lib.api.LrsAlgorithm; |
|
53 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
|
54 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
|
55 |
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams; |
|
56 |
import org.gvsig.lrs.lib.api.MeasuresCalculator; |
|
57 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
|
58 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
59 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
60 |
import org.gvsig.lrs.swing.api.JLrsLastUsedValues; |
|
61 |
import org.gvsig.lrs.swing.api.JLrsProgressDialog; |
|
62 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
63 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
64 |
import org.gvsig.lrs.swing.impl.JLrsCalibrateRouteParamsController; |
|
65 |
import org.gvsig.lrs.swing.impl.JLrsUtils; |
|
66 |
import org.gvsig.tools.ToolsLocator; |
|
67 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
68 |
import org.gvsig.tools.dynobject.DynObject; |
|
69 |
import org.gvsig.tools.i18n.I18nManager; |
|
70 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
71 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
72 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
73 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
74 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
75 |
import org.slf4j.Logger; |
|
76 |
import org.slf4j.LoggerFactory; |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* @author fdiaz |
|
81 |
* |
|
82 |
*/ |
|
83 |
public class CalibrateRouteExtension extends Extension { |
|
84 |
|
|
85 |
private static final Logger logger = LoggerFactory.getLogger(CalibrateRouteExtension.class); |
|
86 |
|
|
87 |
/* (non-Javadoc) |
|
88 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
89 |
*/ |
|
90 |
public void execute(String actionCommand) { |
|
91 |
if (StringUtils.equalsIgnoreCase(actionCommand, "calibrate-routes")) { |
|
92 |
IView view = getActiveView(); |
|
93 |
FLayers layers = view.getMapControl().getMapContext().getLayers(); |
|
94 |
|
|
95 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
96 |
|
|
97 |
final LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
98 |
|
|
99 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
100 |
|
|
101 |
JLrsCalibrateRouteParamsController panel; |
|
102 |
try { |
|
103 |
panel = (JLrsCalibrateRouteParamsController)manager.createJLrsCalibrateRouteAlgorithmParameters(layers, null); |
|
104 |
} catch (LrsNeededParameterException e2) { |
|
105 |
logger.error("Error creating panel", e2); |
|
106 |
JOptionPane.showMessageDialog( |
|
107 |
null, |
|
108 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
109 |
.append(":").append(e2.getLocalizedMessage()), |
|
110 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
111 |
return; |
|
112 |
} |
|
113 |
panel.setVisibleAceptCancel(true); |
|
114 |
panel.addActionListener(new ActionListener() { |
|
115 |
|
|
116 |
public void actionPerformed(ActionEvent e) { |
|
117 |
JLrsAlgorithmParams panel = (JLrsAlgorithmParams) e.getSource(); |
|
118 |
if (panel.isCanceled()) { |
|
119 |
return; |
|
120 |
} |
|
121 |
LrsCalibrateRouteAlgorithmParams params = null; |
|
122 |
try { |
|
123 |
params = (LrsCalibrateRouteAlgorithmParams)panel.getParams(); |
|
124 |
} catch (LrsGettingParametersException e1) { |
|
125 |
logger.error("Error getting parameters", e1); |
|
126 |
JOptionPane.showMessageDialog( |
|
127 |
null, |
|
128 |
new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
129 |
.append(":").append(e1.getLocalizedMessage()), |
|
130 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
131 |
return; |
|
132 |
} catch (LrsNeededParameterException e1) { |
|
133 |
logger.warn("Error getting parameters", e1); |
|
134 |
JOptionPane.showMessageDialog( |
|
135 |
null, |
|
136 |
i18nManager.getTranslation(e1.getMessage()), |
|
137 |
i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
138 |
return; |
|
139 |
} |
|
140 |
LrsAlgorithmsManager algorithmsManager = LrsAlgorithmsLocator.getLrsAlgorithmsManager(); |
|
141 |
final LrsAlgorithm algorithm = algorithmsManager.createLrsAlgorithm(params); |
|
142 |
final SHPNewStoreParameters shpParams=(SHPNewStoreParameters)params.getNewFeatureStoreParameters(); |
|
143 |
|
|
144 |
final SimpleTaskStatus taskStatus = |
|
145 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(i18nManager.getTranslation("progress")); |
|
146 |
|
|
147 |
final JLrsProgressDialog progressDialog = manager.createJLrsProgressDialog(taskStatus); |
|
148 |
|
|
149 |
winManager.showWindow(progressDialog.asJComponent(), i18nManager.getTranslation("calibrate_routes"), |
|
150 |
WindowManager.MODE.WINDOW); |
|
151 |
|
|
152 |
Thread task = new Thread(new Runnable() { |
|
153 |
|
|
154 |
public void run() { |
|
155 |
try { |
|
156 |
algorithm.execute(taskStatus); |
|
157 |
int resultLoadLayer =JOptionPane.showConfirmDialog( |
|
158 |
null, |
|
159 |
i18nManager.getTranslation("load_layer_question"), |
|
160 |
i18nManager.getTranslation("load_layer_question_title"), JOptionPane.YES_NO_OPTION); |
|
161 |
if (resultLoadLayer==JOptionPane.YES_OPTION){ |
|
162 |
loadLayer(shpParams); |
|
163 |
} |
|
164 |
} catch (Exception e) { |
|
165 |
logger.error("Error calibrating route", e); |
|
166 |
String message = e.getMessage(); |
|
167 |
if (e.getCause() != null) { |
|
168 |
message = e.getCause().getMessage(); |
|
169 |
} |
|
170 |
JOptionPane.showMessageDialog( |
|
171 |
progressDialog.asJComponent(), |
|
172 |
message, |
|
173 |
i18nManager.getTranslation("calibrate_routes"), |
|
174 |
JOptionPane.ERROR_MESSAGE |
|
175 |
); |
|
176 |
} |
|
177 |
} |
|
178 |
}); |
|
179 |
task.start(); |
|
180 |
|
|
181 |
} |
|
182 |
}); |
|
183 |
winManager.showWindow(panel.asJComponent(), i18nManager.getTranslation("calibrate_routes"), |
|
184 |
WindowManager.MODE.WINDOW); |
|
185 |
} |
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
/* (non-Javadoc) |
|
190 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
191 |
*/ |
|
192 |
public void initialize() { |
|
193 |
registerIcons(); |
|
194 |
} |
|
195 |
|
|
196 |
/* (non-Javadoc) |
|
197 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
198 |
*/ |
|
199 |
public boolean isEnabled() { |
|
200 |
IView view = getActiveView(); |
|
201 |
//FLyrVect activeLayer = getActiveLayer(view); |
|
202 |
if (view!=null){ |
|
203 |
ViewDocument viewDocument = view.getViewDocument(); |
|
204 |
FLayers layers = viewDocument.getMapContext().getLayers(); |
|
205 |
return JLrsUtils.validatedMCurveAndPointLayer(layers); |
|
206 |
} |
|
207 |
|
|
208 |
return false; |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
/* (non-Javadoc) |
|
213 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
214 |
*/ |
|
215 |
public boolean isVisible() { |
|
216 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
217 |
|
|
218 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
219 |
} |
|
220 |
|
|
221 |
private void registerIcons() { |
|
222 |
IconThemeHelper.registerIcon("lrs", "pk_blue", this); |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
private IView getActiveView() { |
|
227 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
228 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
229 |
return view; |
|
230 |
} |
|
231 |
|
|
232 |
private void loadLayer(SHPNewStoreParameters shpParams){ |
|
233 |
if (shpParams!=null ){ |
|
234 |
String name=shpParams.getFile().getName(); |
|
235 |
if (name.contains(".shp")){ |
|
236 |
name=name.substring(0,name.lastIndexOf(".shp")); |
|
237 |
} |
|
238 |
MapContextManager mapContextManager =MapContextLocator.getMapContextManager(); |
|
239 |
|
|
240 |
FLyrVect newLayer=null; |
|
241 |
try { |
|
242 |
newLayer = (FLyrVect) mapContextManager.createLayer(name,shpParams); |
|
243 |
} catch (LoadLayerException e) { |
|
244 |
logger.warn("Couldn't load layer",e); |
|
245 |
} |
|
246 |
getActiveView().getMapControl().getMapContext().getLayers().addLayer(newLayer); |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
} |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/calibrateroute/MeasureCalculatorRouteExtension.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 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.lrs.app.calibrateroute; |
|
24 |
|
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import org.apache.commons.lang3.StringUtils; |
|
29 |
import org.gvsig.andami.IconThemeHelper; |
|
30 |
import org.gvsig.andami.PluginServices; |
|
31 |
import org.gvsig.andami.PluginsLocator; |
|
32 |
import org.gvsig.andami.PluginsManager; |
|
33 |
import org.gvsig.andami.plugins.Extension; |
|
34 |
import org.gvsig.app.ApplicationLocator; |
|
35 |
import org.gvsig.app.ApplicationManager; |
|
36 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
37 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
38 |
import org.gvsig.fmap.dal.exception.DataException; |
|
39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
40 |
import org.gvsig.fmap.dal.feature.Feature; |
|
41 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
43 |
import org.gvsig.fmap.geom.Geometry; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
46 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
|
47 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
|
48 |
import org.gvsig.lrs.lib.api.MeasuresCalculator; |
|
49 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
50 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
51 |
import org.gvsig.lrs.swing.api.JLrsLastUsedValues; |
|
52 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
53 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
54 |
import org.gvsig.tools.ToolsLocator; |
|
55 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
56 |
import org.gvsig.tools.dynobject.DynObject; |
|
57 |
import org.gvsig.tools.i18n.I18nManager; |
|
58 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
59 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
60 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
61 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
62 |
import org.slf4j.Logger; |
|
63 |
import org.slf4j.LoggerFactory; |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* @author jbadia |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class MeasureCalculatorRouteExtension extends Extension { |
|
71 |
|
|
72 |
private static final Logger logger = LoggerFactory.getLogger(MeasureCalculatorRouteExtension.class); |
|
73 |
|
|
74 |
/* (non-Javadoc) |
|
75 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
76 |
*/ |
|
77 |
public void execute(String actionCommand) { |
|
78 |
|
|
79 |
if (StringUtils.equalsIgnoreCase(actionCommand, "calculate-m-routes")) { |
|
80 |
IView view = getActiveView(); |
|
81 |
FLyrVect layer = view.getMapControl().getMapContext().getLayers().getFirstActiveVectorLayer(); |
|
82 |
|
|
83 |
|
|
84 |
LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
85 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
86 |
|
|
87 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
|
88 |
PluginServices plugin = pluginsManager.getPlugin(this); |
|
89 |
DynObject pluginProperties = plugin.getPluginProperties(); |
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
JLrsAlgorithmParams panel; |
|
94 |
try { |
|
95 |
JLrsLastUsedValues params = manager.getJLrsLastUsedValues(pluginProperties); |
|
96 |
panel = manager.createJLrsCalculateMRoutePanel(layer, params); |
|
97 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
98 |
|
|
99 |
final Dialog dialog = winManager.createDialog(panel.asJComponent(), |
|
100 |
i18nManager.getTranslation("m-coordinate-selector"), "", WindowManager_v2.BUTTONS_OK_CANCEL); |
|
101 |
dialog.addActionListener(new ActionListener() { |
|
102 |
public void actionPerformed(ActionEvent e) { |
|
103 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK) { |
|
104 |
LrsAlgorithmsManager lrsAlgMng = LrsAlgorithmsLocator.getLrsAlgorithmsManager(); |
|
105 |
LrsAlgorithmsSwingManager lrsAlgSwingMng = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
106 |
|
|
107 |
JLrsLastUsedValues prms = lrsAlgSwingMng.getJLrsLastUsedValues(); |
|
108 |
if(prms != null && !StringUtils.isBlank(prms.getPkInicial()) && !StringUtils.isBlank(prms.getPkFinal())){ |
|
109 |
|
|
110 |
FLyrVect lyrVect = (FLyrVect) getActiveView().getMapControl().getMapContext().getLayers().getFirstActiveVectorLayer(); |
|
111 |
FeatureStore featStore = lyrVect.getFeatureStore(); |
|
112 |
try { |
|
113 |
featStore.edit(FeatureStore.MODE_FULLEDIT); |
|
114 |
|
|
115 |
FeatureSelection selection = featStore.getFeatureSelection(); |
|
116 |
DisposableIterator it = selection.fastIterator(); |
|
117 |
while(it.hasNext()){ |
|
118 |
Feature feat = (Feature) it.next(); |
|
119 |
EditableFeature editfeat = feat.getEditable(); |
|
120 |
|
|
121 |
MeasuresCalculator mcalc = lrsAlgMng.createMeasuresCalculator(editfeat.getDefaultGeometry(), false); |
|
122 |
mcalc.setFirstMeasure(editfeat.getDouble(prms.getPkInicial())); |
|
123 |
mcalc.setLastMeasure(editfeat.getDouble(prms.getPkFinal())); |
|
124 |
mcalc.calculate(); |
|
125 |
Geometry mgeom = mcalc.getResult(); |
|
126 |
|
|
127 |
editfeat.setDefaultGeometry(mgeom); |
|
128 |
editfeat.validate(EditableFeature.CHECK_RULES_AT_FINISH); |
|
129 |
featStore.update(editfeat); |
|
130 |
} |
|
131 |
|
|
132 |
featStore.finishEditing(); |
|
133 |
} catch (DataException e1) { |
|
134 |
logger.debug("Error creating the M coordinate: ", e1); |
|
135 |
} |
|
136 |
}else{ |
|
137 |
|
|
138 |
} |
|
139 |
|
|
140 |
} |
|
141 |
} |
|
142 |
}); |
|
143 |
dialog.show(WindowManager.MODE.WINDOW); |
|
144 |
} catch (LrsNeededParameterException e1) { |
|
145 |
// TODO Auto-generated catch block |
|
146 |
e1.printStackTrace(); |
|
147 |
} |
|
148 |
|
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
/* (non-Javadoc) |
|
153 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
154 |
*/ |
|
155 |
public void initialize() { |
|
156 |
registerIcons(); |
|
157 |
} |
|
158 |
|
|
159 |
/* (non-Javadoc) |
|
160 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
161 |
*/ |
|
162 |
public boolean isEnabled() { |
|
163 |
IView view = getActiveView(); |
|
164 |
if (view!=null){ |
|
165 |
ViewDocument viewDocument = view.getViewDocument(); |
|
166 |
FLayer[] layers = viewDocument.getMapContext().getLayers().getActives(); |
|
167 |
return layers.length > 0; |
|
168 |
} |
|
169 |
|
|
170 |
return false; |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
/* (non-Javadoc) |
|
175 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
176 |
*/ |
|
177 |
public boolean isVisible() { |
|
178 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
179 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
180 |
} |
|
181 |
|
|
182 |
private void registerIcons() { |
|
183 |
IconThemeHelper.registerIcon("lrs", "pk_blue", this); |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
private IView getActiveView() { |
|
188 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
189 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
190 |
return view; |
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
} |
|
0 | 195 |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.99/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/showmeasures/WiperMeasuresExtension.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
Also available in: Unified diff