Revision 867
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.157/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Wed Mar 01 22:03:56 CET 2023 |
|
2 |
buildNumber=160 |
|
0 | 3 |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.157/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.157/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.157/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 |
} |
|
0 | 251 |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.157/org.gvsig.lrs.app/org.gvsig.lrs.app.mainplugin/src/main/java/org/gvsig/lrs/app/showmeasures/ShowMeasuresExtension.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.showmeasures; |
|
24 |
|
|
25 |
import java.awt.Color; |
|
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.DecimalFormat; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Iterator; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import javax.swing.JOptionPane; |
|
36 |
|
|
37 |
import org.apache.commons.lang3.StringUtils; |
|
38 |
import org.cresques.cts.ICoordTrans; |
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
|
|
42 |
import org.gvsig.andami.IconThemeHelper; |
|
43 |
import org.gvsig.andami.plugins.Extension; |
|
44 |
import org.gvsig.app.ApplicationLocator; |
|
45 |
import org.gvsig.app.ApplicationManager; |
|
46 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
47 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
48 |
import org.gvsig.fmap.dal.DataSet; |
|
49 |
import org.gvsig.fmap.dal.exception.DataException; |
|
50 |
import org.gvsig.fmap.dal.feature.Feature; |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
53 |
import org.gvsig.fmap.geom.Geometry; |
|
54 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
55 |
import org.gvsig.fmap.geom.GeometryManager; |
|
56 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
57 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
58 |
import org.gvsig.fmap.geom.primitive.Line; |
|
59 |
import org.gvsig.fmap.geom.primitive.Point; |
|
60 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
61 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
62 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
63 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
|
65 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
66 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
67 |
import org.gvsig.gui.beans.ProgressDialog; |
|
68 |
import org.gvsig.lrs.lib.api.LrsAlgorithm; |
|
69 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
|
70 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
|
71 |
import org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams; |
|
72 |
import static org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams.LRS_SHOWMEASURES_KILOMETER; |
|
73 |
import static org.gvsig.lrs.lib.api.LrsShowMeasuresAlgorithmParams.LRS_SHOWMEASURES_METER; |
|
74 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
|
75 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
76 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
77 |
import org.gvsig.lrs.swing.api.JLrsProgressDialog; |
|
78 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
79 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
80 |
import org.gvsig.lrs.swing.impl.JLrsShowMeasuresParamsController; |
|
81 |
import org.gvsig.lrs.swing.impl.JLrsUtils; |
|
82 |
import org.gvsig.symbology.SymbologyLocator; |
|
83 |
import org.gvsig.symbology.SymbologyManager; |
|
84 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
|
85 |
import org.gvsig.tools.ToolsLocator; |
|
86 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
87 |
import org.gvsig.tools.i18n.I18nManager; |
|
88 |
import org.gvsig.tools.locator.LocatorException; |
|
89 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
90 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
91 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
92 |
|
|
93 |
/** |
|
94 |
* @author dmartinez |
|
95 |
* |
|
96 |
*/ |
|
97 |
public class ShowMeasuresExtension extends Extension implements ComponentListener { |
|
98 |
|
|
99 |
private static final Logger logger = LoggerFactory.getLogger(ShowMeasuresExtension.class); |
|
100 |
|
|
101 |
public static final String SHOW_MEASURES_GRAPHICS_ID = "ShowMeasures"; |
|
102 |
|
|
103 |
private JLrsShowMeasuresParamsController panel; |
|
104 |
|
|
105 |
|
|
106 |
/* |
|
107 |
* (non-Javadoc) |
|
108 |
* |
|
109 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
110 |
*/ |
|
111 |
public void execute(String actionCommand) { |
|
112 |
if (StringUtils.equalsIgnoreCase(actionCommand, "show-measures")) { |
|
113 |
IView view = getActiveView(); |
|
114 |
final MapContext mapContext = view.getMapControl().getMapContext(); |
|
115 |
final GraphicLayer graphics = mapContext.getGraphicsLayer(); |
|
116 |
|
|
117 |
final FLyrVect activeLayer = getActiveLayer(view); |
|
118 |
|
|
119 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
120 |
|
|
121 |
final LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
122 |
|
|
123 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
124 |
|
|
125 |
try { |
|
126 |
panel = |
|
127 |
(JLrsShowMeasuresParamsController) manager.createJLrsShowMeasuresAlgorithmParameters(activeLayer, |
|
128 |
null); |
|
129 |
panel.addComponentListener(this); |
|
130 |
} catch (LrsNeededParameterException e2) { |
|
131 |
logger.error("Error creating panel", e2); |
|
132 |
JOptionPane.showMessageDialog( |
|
133 |
null, |
|
134 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")).append(":") |
|
135 |
.append(e2.getLocalizedMessage()), i18nManager.getTranslation("error"), |
|
136 |
JOptionPane.ERROR_MESSAGE); |
|
137 |
return; |
|
138 |
} |
|
139 |
panel.setVisibleAceptCancel(true); |
|
140 |
panel.addActionListener(new ActionListener() { |
|
141 |
|
|
142 |
public void actionPerformed(ActionEvent e) { |
|
143 |
JLrsAlgorithmParams panel = (JLrsAlgorithmParams) e.getSource(); |
|
144 |
if (panel.isCanceled()) { |
|
145 |
return; |
|
146 |
} |
|
147 |
LrsShowMeasuresAlgorithmParams params = null; |
|
148 |
try { |
|
149 |
params = (LrsShowMeasuresAlgorithmParams) panel.getParams(); |
|
150 |
} catch (LrsGettingParametersException e1) { |
|
151 |
logger.error("Error getting parameters", e1); |
|
152 |
JOptionPane.showMessageDialog( |
|
153 |
null, |
|
154 |
new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
155 |
.append(":").append(e1.getLocalizedMessage()), i18nManager.getTranslation("error"), |
|
156 |
JOptionPane.ERROR_MESSAGE); |
|
157 |
return; |
|
158 |
} catch (LrsNeededParameterException e1) { |
|
159 |
logger.warn("Error getting parameters", e1); |
|
160 |
JOptionPane.showMessageDialog(null, i18nManager.getTranslation(e1.getMessage()), |
|
161 |
i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
162 |
return; |
|
163 |
} |
|
164 |
final SimpleTaskStatus taskStatus = |
|
165 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus( |
|
166 |
i18nManager.getTranslation("progress")); |
|
167 |
|
|
168 |
final JLrsProgressDialog progressDialog = manager.createJLrsProgressDialog(taskStatus); |
|
169 |
|
|
170 |
winManager.showWindow(progressDialog.asJComponent(), i18nManager.getTranslation("show_measures"), |
|
171 |
WindowManager.MODE.WINDOW); |
|
172 |
|
|
173 |
final double distance = params.getDistance(); |
|
174 |
final int units = params.getUnits(); |
|
175 |
|
|
176 |
Thread task = new Thread(new Runnable() { |
|
177 |
|
|
178 |
public void run() { |
|
179 |
try { |
|
180 |
showMeasures(graphics, activeLayer, distance, units, taskStatus); |
|
181 |
mapContext.invalidate(); |
|
182 |
if(!taskStatus.isRunning() && progressDialog.asJComponent().isVisible()){ |
|
183 |
progressDialog.asJComponent().setVisible(false); |
|
184 |
} |
|
185 |
} catch (Exception e) { |
|
186 |
logger.error("Error showing measures", e); |
|
187 |
String message = e.getMessage(); |
|
188 |
if (e.getCause() != null) { |
|
189 |
message = e.getCause().getMessage(); |
|
190 |
} |
|
191 |
JOptionPane.showMessageDialog(progressDialog.asJComponent(), message, |
|
192 |
i18nManager.getTranslation("show_measures"), JOptionPane.ERROR_MESSAGE); |
|
193 |
} |
|
194 |
} |
|
195 |
}); |
|
196 |
task.start(); |
|
197 |
|
|
198 |
} |
|
199 |
}); |
|
200 |
winManager.showWindow(panel.asJComponent(), i18nManager.getTranslation("show_measures"), |
|
201 |
WindowManager.MODE.WINDOW); |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
/* |
|
206 |
* (non-Javadoc) |
|
207 |
* |
|
208 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
209 |
*/ |
|
210 |
public void initialize() { |
|
211 |
registerIcons(); |
|
212 |
} |
|
213 |
|
|
214 |
/* |
|
215 |
* (non-Javadoc) |
|
216 |
* |
|
217 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
218 |
*/ |
|
219 |
public boolean isEnabled() { |
|
220 |
IView view = getActiveView(); |
|
221 |
FLyrVect activeLayer = getActiveLayer(view); |
|
222 |
if (panel == null && activeLayer != null) { |
|
223 |
return JLrsUtils.hasMLayersWithSelectedFeatures(activeLayer); |
|
224 |
} |
|
225 |
return false; |
|
226 |
} |
|
227 |
|
|
228 |
/* |
|
229 |
* (non-Javadoc) |
|
230 |
* |
|
231 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
232 |
*/ |
|
233 |
public boolean isVisible() { |
|
234 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
235 |
|
|
236 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
237 |
} |
|
238 |
|
|
239 |
private void registerIcons() { |
|
240 |
IconThemeHelper.registerIcon("lrs", "pk_green", this); |
|
241 |
} |
|
242 |
|
|
243 |
/* |
|
244 |
* Shows measurements along the selected features in a layer with a fixed spacing |
|
245 |
* |
|
246 |
*/ |
|
247 |
private void showMeasures(GraphicLayer graphics, FLyrVect layer, double distance, int units, SimpleTaskStatus taskStatus) |
|
248 |
throws DataException, CreateGeometryException, LocatorException { |
|
249 |
FeatureStore featureStore = layer.getFeatureStore(); |
|
250 |
FeatureSelection selection = featureStore.getFeatureSelection(); |
|
251 |
if (selection != null && !selection.isEmpty()) { |
|
252 |
long range = getRange(selection); |
|
253 |
taskStatus.setRangeOfValues(0, range); |
|
254 |
long curValue = 0; |
|
255 |
taskStatus.setCurValue(curValue); |
|
256 |
DisposableIterator it = selection.fastIterator(); |
|
257 |
ICoordTrans ct = layer.getCoordTrans(); |
|
258 |
while (it.hasNext()) { |
|
259 |
Feature feature = (Feature) it.next(); |
|
260 |
Geometry geometry = feature.getDefaultGeometry(); |
|
261 |
if (geometry instanceof Line) { |
|
262 |
curValue = showLineMeasures(graphics, curValue, (Line) geometry, distance, units, ct); |
|
263 |
taskStatus.setCurValue(curValue); |
|
264 |
} else if (geometry instanceof MultiLine) { |
|
265 |
MultiLine multiLine = (MultiLine) geometry; |
|
266 |
int primitives = multiLine.getPrimitivesNumber(); |
|
267 |
for (int i = 0; i < primitives; i++) { |
|
268 |
curValue = showLineMeasures(graphics, curValue, (Line) multiLine.getPrimitiveAt(i), distance, units, ct); |
|
269 |
taskStatus.setCurValue(curValue); |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
it.dispose(); |
|
274 |
} |
|
275 |
taskStatus.terminate(); |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* Shows measurements along a line with a fixed spacing |
|
280 |
* |
|
281 |
* @param curValue |
|
282 |
* @param ct2 |
|
283 |
* @param taskStatus |
|
284 |
* @param geometry |
|
285 |
* @return |
|
286 |
* @throws LocatorException |
|
287 |
* @throws CreateGeometryException |
|
288 |
*/ |
|
289 |
private long showLineMeasures(GraphicLayer graphics, long curValue, Line line, Double distance, int units, ICoordTrans ct) throws CreateGeometryException, LocatorException { |
|
290 |
long value = curValue; |
|
291 |
for (int i = 0; i < line.getNumVertices() - 1; i++) { |
|
292 |
value++; |
|
293 |
Point vertex = (Point) line.getVertex(i); |
|
294 |
double m0 = vertex.getCoordinateAt(vertex.getDimension() - 1); |
|
295 |
|
|
296 |
double div = m0 / distance; |
|
297 |
if (isMultiple(m0, distance)) { |
|
298 |
showMeasure(graphics, vertex, m0, units, ct); |
|
299 |
} |
|
300 |
Point nextVertex = line.getVertex(i + 1); |
|
301 |
double m1 = nextVertex.getCoordinateAt(vertex.getDimension() - 1); |
|
302 |
List<Double> multiples = calculateMultiplesBetweenTwoValues(distance, m0, m1); |
|
303 |
for (Iterator iterator = multiples.iterator(); iterator.hasNext();) { |
|
304 |
Double m = (Double) iterator.next(); |
|
305 |
Point point = getPointWithMBetweenTwoVertex(m, vertex, nextVertex); |
|
306 |
showMeasure(graphics, point, m, units, ct); |
|
307 |
} |
|
308 |
} |
|
309 |
value++; |
|
310 |
return value; |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Show the m in the point p on the graphicLayer |
|
315 |
* |
|
316 |
* @param m |
|
317 |
* @param ct |
|
318 |
*/ |
|
319 |
private void showMeasure(GraphicLayer graphics, Point p, double m, int units, ICoordTrans ct) { |
|
320 |
|
|
321 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
322 |
SymbolManager symbolManager = MapContextLocator.getSymbolManager(); |
|
323 |
|
|
324 |
ISymbol markerSymbol = symbolManager.createSymbol(Geometry.TYPES.POINT, Color.RED); |
|
325 |
ISimpleTextSymbol textSymbol = getTextSymbol(); |
|
326 |
DecimalFormat formato = new DecimalFormat("0.000"); |
|
327 |
double theMeasure = m; |
|
328 |
if(units == LRS_SHOWMEASURES_METER){ |
|
329 |
theMeasure = m/1000; |
|
330 |
} |
|
331 |
|
|
332 |
String text = formato.format(theMeasure); |
|
333 |
if(units == LRS_SHOWMEASURES_METER || units == LRS_SHOWMEASURES_KILOMETER){ |
|
334 |
text = text.replace(",", " + "); |
|
335 |
} |
|
336 |
|
|
337 |
textSymbol.setText(text); |
|
338 |
int idMarkerSymbol = graphics.addSymbol(markerSymbol); |
|
339 |
int idTextSymbol = graphics.addSymbol(textSymbol); |
|
340 |
Point clonedPoint = (Point) p.cloneGeometry(); |
|
341 |
clonedPoint.reProject(ct); |
|
342 |
graphics.addGraphic(SHOW_MEASURES_GRAPHICS_ID, clonedPoint, idTextSymbol); |
|
343 |
graphics.addGraphic(SHOW_MEASURES_GRAPHICS_ID, clonedPoint, idMarkerSymbol); |
|
344 |
} |
|
345 |
|
|
346 |
/* |
|
347 |
* Creates a text symbol to be used in showMeasure |
|
348 |
*/ |
|
349 |
private ISimpleTextSymbol getTextSymbol(){ |
|
350 |
SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager(); |
|
351 |
ISimpleTextSymbol textSymbol = symbologyManager.createSimpleTextSymbol(); |
|
352 |
textSymbol.setFontSize(10); |
|
353 |
return textSymbol; |
|
354 |
} |
|
355 |
|
|
356 |
/** |
|
357 |
* Dados dos puntos con coordenada M, calcula el punto correspondiente a la m dada. |
|
358 |
* |
|
359 |
* @param m |
|
360 |
* @param vertex |
|
361 |
* @param nextVertex |
|
362 |
* @return |
|
363 |
* @throws LocatorException |
|
364 |
* @throws CreateGeometryException |
|
365 |
*/ |
|
366 |
private Point getPointWithMBetweenTwoVertex(Double m, Point vertex, Point nextVertex) throws CreateGeometryException, LocatorException { |
|
367 |
Point point = (Point)GeometryLocator.getGeometryManager().create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
368 |
point.setX( |
|
369 |
getCoordinateBetweenTwoValues( |
|
370 |
m, |
|
371 |
vertex.getCoordinateAt(vertex.getDimension()-1), |
|
372 |
nextVertex.getCoordinateAt(vertex.getDimension()-1), |
|
373 |
vertex.getX(), |
|
374 |
nextVertex.getX())); |
|
375 |
point.setY( |
|
376 |
getCoordinateBetweenTwoValues( |
|
377 |
m, |
|
378 |
vertex.getCoordinateAt(vertex.getDimension()-1), |
|
379 |
nextVertex.getCoordinateAt(vertex.getDimension()-1), |
|
380 |
vertex.getY(), |
|
381 |
nextVertex.getY())); |
|
382 |
|
|
383 |
return point; |
|
384 |
} |
|
385 |
|
|
386 |
/** |
|
387 |
* Dados los valores en una dimensi?n de dos puntos y sus "m" correspondientes, |
|
388 |
* calcula el valor en esa dimensi?n correspondiente a la "m" dada. |
|
389 |
* |
|
390 |
* @param m |
|
391 |
* @param m1 |
|
392 |
* @param m2 |
|
393 |
* @param v1 |
|
394 |
* @param v2 |
|
395 |
* @return |
|
396 |
*/ |
|
397 |
private double getCoordinateBetweenTwoValues(double m, double m1, double m2, double v1, double v2) { |
|
398 |
if (v1==v2){ |
|
399 |
return Double.POSITIVE_INFINITY; |
|
400 |
} |
|
401 |
return ((v2-v1)*(m-m1)/(m2-m1))+v1; |
|
402 |
} |
|
403 |
|
|
404 |
/** |
|
405 |
* Calcula los m?ltiplos de "distance" que existen entre los valores "value0" y "value1" |
|
406 |
* |
|
407 |
* @param distance |
|
408 |
* @param value0 |
|
409 |
* @param value1 |
|
410 |
* @return |
|
411 |
*/ |
|
412 |
private List<Double> calculateMultiplesBetweenTwoValues(Double distance, double value0, double value1) { |
|
413 |
List<Double> result = new ArrayList<Double>(); |
|
414 |
|
|
415 |
double v0; |
|
416 |
double v1; |
|
417 |
if(value0<=value1){ |
|
418 |
v0 = value0; |
|
419 |
v1 = value1; |
|
420 |
} else { |
|
421 |
v0 = value1; |
|
422 |
v1 = value0; |
|
423 |
} |
|
424 |
|
|
425 |
int factor1 = (int) Math.ceil(v0/distance); |
|
426 |
int factor2 = (int) Math.floor(v1/distance); |
|
427 |
for (int factor = factor1; factor <= factor2; factor++) { |
|
428 |
double m = factor * distance; |
|
429 |
if(m>=v0 && m<=v1){ |
|
430 |
result.add(m); |
|
431 |
} |
|
432 |
} |
|
433 |
return result; |
|
434 |
} |
|
435 |
|
|
436 |
|
|
437 |
/** |
|
438 |
* Calcula si el valor del par?metro n es m?ltiplo del valor del par?metro d |
|
439 |
* @param n |
|
440 |
* @param d |
|
441 |
*/ |
|
442 |
private boolean isMultiple(double n, double d) { |
|
443 |
double div = n / d; |
|
444 |
return ((div - (int) div) < 0.000001); |
|
445 |
} |
|
446 |
|
|
447 |
/** |
|
448 |
* @param selection |
|
449 |
* @throws DataException |
|
450 |
*/ |
|
451 |
private long getRange(FeatureSelection selection) throws DataException { |
|
452 |
long range = 0; |
|
453 |
DisposableIterator it = selection.fastIterator(); |
|
454 |
while (it.hasNext()) { |
|
455 |
Feature feature = (Feature) it.next(); |
|
456 |
Geometry geometry = feature.getDefaultGeometry(); |
|
457 |
if (geometry instanceof Line) { |
|
458 |
range += ((Line) geometry).getNumVertices(); |
|
459 |
} else if (geometry instanceof MultiLine) { |
|
460 |
MultiLine multiLine = (MultiLine) geometry; |
|
461 |
int primitives = multiLine.getPrimitivesNumber(); |
|
462 |
for (int i = 0; i < primitives; i++) { |
|
463 |
range += ((Line) multiLine.getPrimitiveAt(i)).getNumVertices(); |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
it.dispose(); |
|
468 |
return range; |
|
469 |
} |
|
470 |
|
|
471 |
private IView getActiveView() { |
|
472 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
473 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
474 |
return view; |
|
475 |
} |
|
476 |
|
|
477 |
private FLyrVect getActiveLayer(IView vista) { |
|
478 |
if (vista != null) { |
|
479 |
ViewDocument viewDocument = vista.getViewDocument(); |
|
480 |
FLayer[] actives = viewDocument.getMapContext().getLayers().getActives(); |
|
481 |
|
|
482 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
|
483 |
return (FLyrVect) actives[0]; |
|
484 |
} |
|
485 |
} |
|
486 |
return null; |
|
487 |
} |
|
488 |
|
|
489 |
/* |
|
490 |
* (non-Javadoc) |
|
491 |
* |
|
492 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event. |
|
493 |
* ComponentEvent) |
|
494 |
*/ |
|
495 |
public void componentResized(ComponentEvent e) { |
|
496 |
// TODO Auto-generated method stub |
|
497 |
|
|
498 |
} |
|
499 |
|
|
500 |
/* |
|
501 |
* (non-Javadoc) |
|
502 |
* |
|
503 |
* @see |
|
504 |
* java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent |
|
505 |
* ) |
|
506 |
*/ |
|
507 |
public void componentMoved(ComponentEvent e) { |
|
508 |
// TODO Auto-generated method stub |
|
509 |
|
|
510 |
} |
|
511 |
|
|
512 |
/* |
|
513 |
* (non-Javadoc) |
|
514 |
* |
|
515 |
* @see |
|
516 |
* java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent |
|
517 |
* ) |
|
518 |
*/ |
|
519 |
public void componentShown(ComponentEvent e) { |
|
520 |
// TODO Auto-generated method stub |
|
521 |
|
|
522 |
} |
|
523 |
|
|
524 |
/* |
|
525 |
* (non-Javadoc) |
|
526 |
* |
|
527 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event. |
|
528 |
* ComponentEvent) |
|
529 |
*/ |
|
530 |
public void componentHidden(ComponentEvent e) { |
|
531 |
panel = null; |
|
532 |
} |
|
533 |
} |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.157/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 |
|
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.showmeasures; |
|
24 |
|
|
25 |
import org.apache.commons.lang3.StringUtils; |
|
26 |
import org.slf4j.Logger; |
|
27 |
import org.slf4j.LoggerFactory; |
|
28 |
|
|
29 |
import org.gvsig.andami.IconThemeHelper; |
|
30 |
import org.gvsig.andami.plugins.Extension; |
|
31 |
import org.gvsig.app.ApplicationLocator; |
|
32 |
import org.gvsig.app.ApplicationManager; |
|
33 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
34 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
35 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
|
39 |
import org.gvsig.lrs.swing.impl.JLrsShowMeasuresParamsController; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author dmartinez |
|
43 |
* |
|
44 |
*/ |
|
45 |
public class WiperMeasuresExtension extends Extension { |
|
46 |
|
|
47 |
private static final Logger logger = LoggerFactory.getLogger(WiperMeasuresExtension.class); |
|
48 |
|
|
49 |
private JLrsShowMeasuresParamsController panel; |
|
50 |
|
|
51 |
|
|
52 |
/* |
|
53 |
* (non-Javadoc) |
|
54 |
* |
|
55 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String) |
|
56 |
*/ |
|
57 |
public void execute(String actionCommand) { |
|
58 |
if (StringUtils.equalsIgnoreCase(actionCommand, "wiper-measures")) { |
|
59 |
IView view = getActiveView(); |
|
60 |
final MapContext mapContext = view.getMapControl().getMapContext(); |
|
61 |
final GraphicLayer graphics = mapContext.getGraphicsLayer(); |
|
62 |
|
|
63 |
graphics.removeGraphics(ShowMeasuresExtension.SHOW_MEASURES_GRAPHICS_ID); |
|
64 |
mapContext.invalidate(); |
|
65 |
|
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
/* |
|
70 |
* (non-Javadoc) |
|
71 |
* |
|
72 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
73 |
*/ |
|
74 |
public void initialize() { |
|
75 |
registerIcons(); |
|
76 |
} |
|
77 |
|
|
78 |
/* |
|
79 |
* (non-Javadoc) |
|
80 |
* |
|
81 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
82 |
*/ |
|
83 |
public boolean isEnabled() { |
|
84 |
IView view = getActiveView(); |
|
85 |
FLyrVect activeLayer = getActiveLayer(view); |
|
86 |
if (panel == null && activeLayer != null) { |
|
87 |
return true; |
|
88 |
} |
|
89 |
return false; |
|
90 |
} |
|
91 |
|
|
92 |
/* |
|
93 |
* (non-Javadoc) |
|
94 |
* |
|
95 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
96 |
*/ |
|
97 |
public boolean isVisible() { |
|
98 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
99 |
|
|
100 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
101 |
} |
|
102 |
|
|
103 |
private void registerIcons() { |
|
104 |
IconThemeHelper.registerIcon("lrs", "wiper", this); |
|
105 |
} |
|
106 |
|
|
107 |
private IView getActiveView() { |
|
108 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
109 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
110 |
return view; |
|
111 |
} |
|
112 |
|
|
113 |
private FLyrVect getActiveLayer(IView vista) { |
|
114 |
if (vista != null) { |
|
115 |
ViewDocument viewDocument = vista.getViewDocument(); |
|
116 |
FLayer[] actives = viewDocument.getMapContext().getLayers().getActives(); |
|
117 |
|
|
118 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
|
119 |
return (FLyrVect) actives[0]; |
|
120 |
} |
|
121 |
} |
|
122 |
return null; |
|
123 |
} |
|
124 |
} |
org.gvsig.lrs/tags/org.gvsig.lrs-1.0.157/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 |
import java.util.Map; |
|
33 |
import javax.swing.JOptionPane; |
|
34 |
import org.apache.commons.lang3.StringUtils; |
|
35 |
import org.gvsig.andami.IconThemeHelper; |
|
36 |
import org.gvsig.andami.plugins.Extension; |
|
37 |
import org.gvsig.app.ApplicationLocator; |
|
38 |
import org.gvsig.app.ApplicationManager; |
|
39 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
40 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
|
42 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
43 |
import org.gvsig.fmap.dal.feature.Feature; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
47 |
import org.gvsig.fmap.geom.Geometry; |
|
48 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
49 |
import org.gvsig.fmap.geom.primitive.Line; |
|
50 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
51 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
52 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
53 |
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationAlgorithmParams; |
|
54 |
import org.gvsig.lrs.lib.api.LrsEditRouteCalibrationSelectIdRouteAlgorithmParams; |
|
55 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
|
56 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
|
57 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
|
58 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingLocator; |
|
59 |
import org.gvsig.lrs.swing.api.LrsAlgorithmsSwingManager; |
|
60 |
import org.gvsig.lrs.swing.impl.JLrsEditRouteCalibrationController; |
|
61 |
import org.gvsig.lrs.swing.impl.JLrsEditRouteCalibrationSelectIdRouteController; |
|
62 |
import org.gvsig.lrs.swing.impl.JLrsUtils; |
|
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.windowmanager.WindowManager; |
|
67 |
import org.slf4j.Logger; |
|
68 |
import org.slf4j.LoggerFactory; |
|
69 |
|
|
70 |
|
|
71 |
/** |
|
72 |
* @author dmartinez |
|
73 |
* |
|
74 |
*/ |
|
75 |
public class EditRouteCalibrationExtension extends Extension implements ComponentListener { |
|
76 |
|
|
77 |
private static final Logger logger = LoggerFactory.getLogger(EditRouteCalibrationExtension.class); |
|
78 |
|
|
79 |
private JLrsEditRouteCalibrationSelectIdRouteController panelSelectId; |
|
80 |
|
|
81 |
private JLrsEditRouteCalibrationController panelController; |
|
82 |
|
|
83 |
@Override |
|
84 |
public void execute(String actionCommand) { |
|
85 |
if (StringUtils.equalsIgnoreCase(actionCommand, "edit-route-calibration")) { |
|
86 |
IView view = getActiveView(); |
|
87 |
final FLyrVect activeLayer; |
|
88 |
if (view!=null){ |
|
89 |
activeLayer = getActiveLayer(view); |
|
90 |
}else{ |
|
91 |
activeLayer = null; |
|
92 |
} |
|
93 |
|
|
94 |
final MapContext mapContext = view.getMapControl().getMapContext(); |
|
95 |
|
|
96 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
97 |
|
|
98 |
final LrsAlgorithmsSwingManager manager = LrsAlgorithmsSwingLocator.getLrsAlgorithmsSwingManager(); |
|
99 |
|
|
100 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
101 |
|
|
102 |
try { |
|
103 |
panelSelectId = (JLrsEditRouteCalibrationSelectIdRouteController)manager.createJLrsEditRouteCalibrationSelectIdRouteAlgorithmParameters(activeLayer, null); |
|
104 |
panelSelectId.addComponentListener(this); |
|
105 |
} catch (LrsNeededParameterException e2) { |
|
106 |
logger.error("Error creating panel", e2); |
|
107 |
JOptionPane.showMessageDialog( |
|
108 |
null, |
|
109 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
110 |
.append(":").append(e2.getLocalizedMessage()), |
|
111 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
112 |
return; |
|
113 |
} |
|
114 |
panelSelectId.setVisibleAceptCancel(true); |
|
115 |
panelSelectId.addActionListener((ActionEvent e) -> { |
|
116 |
JLrsAlgorithmParams panel = (JLrsAlgorithmParams) e.getSource(); |
|
117 |
if (panel.isCanceled()) { |
|
118 |
return; |
|
119 |
} |
|
120 |
LrsEditRouteCalibrationSelectIdRouteAlgorithmParams params = null; |
|
121 |
try { |
|
122 |
params = (LrsEditRouteCalibrationSelectIdRouteAlgorithmParams)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 |
} try { |
|
139 |
panelController = (JLrsEditRouteCalibrationController)manager.createJLrsEditRouteCalibrationAlgorithmParameters(activeLayer, mapContext, params.getIdRouteField(), null); |
|
140 |
panelController.addComponentListener(EditRouteCalibrationExtension.this); |
|
141 |
} catch (Exception e2) { |
|
142 |
logger.error("Error creating panel", e2); |
|
143 |
JOptionPane.showMessageDialog( |
|
144 |
null, |
|
145 |
new StringBuilder().append(i18nManager.getTranslation("error_creating_panel")) |
|
146 |
.append(":").append(e2.getLocalizedMessage()), |
|
147 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
148 |
return; |
|
149 |
} |
|
150 |
panelController.setVisibleAceptCancel(true); |
|
151 |
panelController.addActionListener((ActionEvent e1) -> { |
|
152 |
JLrsEditRouteCalibrationController panel1 = (JLrsEditRouteCalibrationController) e1.getSource(); |
|
153 |
if (panel1.isCanceled()) { |
|
154 |
return; |
|
155 |
} |
|
156 |
if (panel1.hasWarnings()) { |
|
157 |
boolean acceptedWarnings = showWarnings(panel1.getWarnings()); |
|
158 |
if (acceptedWarnings) { |
|
159 |
panel1.close(); |
|
160 |
} else { |
|
161 |
return; |
|
162 |
} |
|
163 |
} |
|
164 |
final LrsEditRouteCalibrationAlgorithmParams params1; |
|
165 |
try { |
|
166 |
params1 = (LrsEditRouteCalibrationAlgorithmParams) panel1.getParams(); |
|
167 |
} catch (LrsGettingParametersException e2) { |
|
168 |
logger.error("Error getting parameters", e2); |
|
169 |
JOptionPane.showMessageDialog(null, new StringBuilder().append(i18nManager.getTranslation("error_getting_parameters")) |
|
170 |
.append(":").append(e2.getLocalizedMessage()), i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
|
171 |
return; |
|
172 |
} catch (LrsNeededParameterException e3) { |
|
173 |
logger.warn("Error getting parameters", e3); |
|
174 |
JOptionPane.showMessageDialog(null, i18nManager.getTranslation(e3.getMessage()), i18nManager.getTranslation("warning"), JOptionPane.WARNING_MESSAGE); |
|
175 |
return; |
|
176 |
} |
|
177 |
if (params1 != null) { |
|
178 |
saveLayer(activeLayer, params1); |
|
179 |
} |
|
180 |
panel1.close(); |
|
181 |
}); |
|
182 |
winManager.showWindow(panelController.asJComponent(), i18nManager.getTranslation("edit_route_calibration"), |
|
183 |
WindowManager.MODE.WINDOW); |
|
184 |
}); |
|
185 |
winManager.showWindow(panelSelectId.asJComponent(), i18nManager.getTranslation("edit_route_calibration"), |
|
186 |
WindowManager.MODE.WINDOW); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
public void initialize() { |
|
191 |
registerIcons(); |
|
192 |
} |
|
193 |
|
|
194 |
public boolean isEnabled() { |
|
195 |
IView view = getActiveView(); |
|
196 |
if (view!=null){ |
|
197 |
FLyrVect activeLayer = getActiveLayer(view); |
|
198 |
if (panelSelectId == null && panelController == null && activeLayer!=null && activeLayer.isEditing()){ |
|
199 |
return JLrsUtils.isMlayerWithNonGeomField(activeLayer); |
|
200 |
} |
|
201 |
} |
|
202 |
return false; |
|
203 |
} |
|
204 |
|
|
205 |
public boolean isVisible() { |
|
206 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
207 |
|
|
208 |
return application.getActiveComponent(ViewDocument.class) != null; |
|
209 |
} |
|
210 |
|
|
211 |
private void registerIcons() { |
|
212 |
IconThemeHelper.registerIcon("lrs", "pk_cian", this); |
|
213 |
} |
|
214 |
|
|
215 |
|
|
216 |
private IView getActiveView() { |
|
217 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
218 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
219 |
return view; |
|
220 |
} |
|
221 |
|
|
222 |
private FLyrVect getActiveLayer(IView vista) { |
|
223 |
if (vista != null) { |
|
224 |
ViewDocument viewDocument = vista.getViewDocument(); |
|
225 |
FLayer[] actives = |
|
226 |
viewDocument.getMapContext().getLayers().getActives(); |
|
227 |
|
|
228 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
|
229 |
return (FLyrVect) actives[0]; |
|
230 |
} |
|
231 |
} |
|
232 |
return null; |
|
233 |
} |
|
234 |
|
|
235 |
private boolean showWarnings(List<String> warnings){ |
|
236 |
final int MAXWARNINGSSHOWED=15; |
|
237 |
|
|
238 |
final I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
239 |
logger.debug("Warnings found accepting edit route panel"); |
|
240 |
StringBuilder messageBuilder= new StringBuilder().append(i18nManager.getTranslation("warnings_in_edit_route")); |
|
241 |
String newLine=System.getProperty("line.separator"); |
|
242 |
messageBuilder.append(newLine); |
|
243 |
for (int i=0;(i<=MAXWARNINGSSHOWED&&i<warnings.size());i++){ |
|
244 |
if(i<MAXWARNINGSSHOWED){ |
|
245 |
String warning=warnings.get(i); |
|
246 |
messageBuilder.append(newLine); |
|
247 |
messageBuilder.append(warning); |
|
248 |
} |
|
249 |
if (i==MAXWARNINGSSHOWED&&warnings.size()>MAXWARNINGSSHOWED){ |
|
250 |
messageBuilder.append(newLine); |
|
251 |
int warningsNotShowed=warnings.size()-MAXWARNINGSSHOWED; |
|
252 |
messageBuilder.append(MessageFormat.format( |
|
253 |
i18nManager.getTranslation("more_warnings_found"), warningsNotShowed)); |
|
254 |
} |
|
255 |
} |
|
256 |
messageBuilder.append(newLine); |
|
257 |
messageBuilder.append(newLine).append(i18nManager.getTranslation("accept_warnings_question")); |
|
258 |
int result =JOptionPane.showConfirmDialog( |
|
259 |
null, |
|
260 |
messageBuilder, |
|
261 |
i18nManager.getTranslation("warnings_dialog"), JOptionPane.YES_NO_OPTION); |
|
262 |
return (result==JOptionPane.YES_OPTION); |
|
263 |
} |
|
264 |
|
|
265 |
private void saveLayer(FLyrVect activeLayer,LrsEditRouteCalibrationAlgorithmParams params){ |
|
266 |
FeatureAttributeDescriptor fieldRoute=params.getIdRouteField(); |
|
267 |
String routeName=params.getSelectedRouteName(); |
|
268 |
Map<FeatureReference, List<Double>> modifiedMCoordinates = params.getModifiedMCoordinates(); |
|
269 |
|
|
270 |
|
|
271 |
FeatureStore featureStore=activeLayer.getFeatureStore(); |
|
272 |
if (!featureStore.isEditing()){ |
|
273 |
throw new IllegalArgumentException(); |
|
274 |
} |
|
275 |
try { |
|
276 |
for (Map.Entry<FeatureReference, List<Double>> entry : modifiedMCoordinates.entrySet()) { |
|
277 |
FeatureReference fref = entry.getKey(); |
|
278 |
List<Double> mCoordinates = entry.getValue(); |
|
279 |
Feature f = fref.getFeature(); |
|
280 |
Geometry geom = f.getDefaultGeometry().cloneGeometry(); |
|
281 |
int k = 0; |
Also available in: Unified diff