Revision 38310
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/buildNumber.properties | ||
---|---|---|
1 |
#maven.buildNumber.plugin properties file |
|
2 |
#Tue May 29 16:41:48 CEST 2012 |
|
3 |
buildNumber=2047 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
|
0 | 9 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
org.gvsig.tools packages. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.selectiontools"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="INFO" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
|
0 | 38 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/AboutSelectionToolsExtension.java | ||
---|---|---|
1 |
package org.gvsig.selectiontools.app.extension; |
|
2 |
|
|
3 |
import org.gvsig.about.AboutManager; |
|
4 |
import org.gvsig.about.AboutParticipant; |
|
5 |
import org.gvsig.andami.plugins.Extension; |
|
6 |
import org.gvsig.app.ApplicationLocator; |
|
7 |
import org.gvsig.app.ApplicationManager; |
|
8 |
|
|
9 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
10 |
* |
|
11 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
12 |
* of the Valencian Government (CIT) |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
27 |
* MA 02110-1301, USA. |
|
28 |
* |
|
29 |
*/ |
|
30 |
|
|
31 |
/** |
|
32 |
* <p> |
|
33 |
* Some selection tools for gvSIG of the <i>Consejer?a de Medio Ambiente de la |
|
34 |
* Junta de Castilla y Le?n.</i> |
|
35 |
* </p> |
|
36 |
* project. |
|
37 |
* |
|
38 |
* @author Vicente Caballero Navarro (vicente.caballero@iver.es) |
|
39 |
* @author Jaume Dom?nguez Faus (jaume.dominguez@iver.es) |
|
40 |
* @author C?sar Mart?nez Izquierdo (cesar.martinez@iver.es) |
|
41 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
42 |
* @author Jos? Manuel Viv? Arnal (josemanuel.vivo@iver.es) |
|
43 |
*/ |
|
44 |
public class AboutSelectionToolsExtension extends Extension { |
|
45 |
|
|
46 |
/* |
|
47 |
* (non-Javadoc) |
|
48 |
* |
|
49 |
* @see com.iver.andami.plugins.IExtension#initialize() |
|
50 |
*/ |
|
51 |
public void initialize() { |
|
52 |
} |
|
53 |
|
|
54 |
public void postInitialize() { |
|
55 |
// Register the about panel |
|
56 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
57 |
|
|
58 |
AboutManager about = application.getAbout(); |
|
59 |
|
|
60 |
about.addDeveloper("IVER", this.getClass().getClassLoader() |
|
61 |
.getResource("iver.html"), 1); |
|
62 |
|
|
63 |
AboutParticipant participant = about.getDeveloper("IVER"); |
|
64 |
participant.addContribution("SelectionToolsExtension", |
|
65 |
"Selection tools", 2009, 1, 1, 2009, 12, 31); |
|
66 |
|
|
67 |
about.addSponsor("Junta de Castilla y Le?n", // Junta de Castilla y Le?n |
|
68 |
getClass().getClassLoader().getResource("jcyl.html"), 2); |
|
69 |
} |
|
70 |
|
|
71 |
/* |
|
72 |
* (non-Javadoc) |
|
73 |
* |
|
74 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String) |
|
75 |
*/ |
|
76 |
public void execute(String actionCommand) { |
|
77 |
} |
|
78 |
|
|
79 |
/* |
|
80 |
* (non-Javadoc) |
|
81 |
* |
|
82 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
|
83 |
*/ |
|
84 |
public boolean isEnabled() { |
|
85 |
return false; |
|
86 |
} |
|
87 |
|
|
88 |
/* |
|
89 |
* (non-Javadoc) |
|
90 |
* |
|
91 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
|
92 |
*/ |
|
93 |
public boolean isVisible() { |
|
94 |
return false; |
|
95 |
} |
|
96 |
} |
|
0 | 97 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/PolyLineSelectListener.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.selectiontools.app.extension.tools; |
|
24 |
|
|
25 |
import org.gvsig.andami.PluginServices; |
|
26 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
27 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
28 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @version 06/04/2009 |
|
33 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
34 |
*/ |
|
35 |
public class PolyLineSelectListener extends PolyLineSelectionListener { |
|
36 |
|
|
37 |
public PolyLineSelectListener(MapControl mc) { |
|
38 |
super(mc); |
|
39 |
} |
|
40 |
|
|
41 |
public void polylineFinished(MeasureEvent event) throws BehaviorException { |
|
42 |
super.polylineFinished(event); |
|
43 |
PluginServices.getMainFrame().enableControls(); |
|
44 |
} |
|
45 |
} |
|
0 | 46 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/CircleSelectListener.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.selectiontools.app.extension.tools; |
|
24 |
|
|
25 |
import org.gvsig.andami.PluginServices; |
|
26 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
27 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
28 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @version 06/04/2009 |
|
33 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
34 |
*/ |
|
35 |
public class CircleSelectListener extends CircleSelectionListener { |
|
36 |
|
|
37 |
public CircleSelectListener(MapControl mc) { |
|
38 |
super(mc); |
|
39 |
} |
|
40 |
|
|
41 |
public void circle(MeasureEvent event) throws BehaviorException { |
|
42 |
super.circle(event); |
|
43 |
PluginServices.getMainFrame().enableControls(); |
|
44 |
} |
|
45 |
} |
|
0 | 46 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/PolyLineSelectionListener.java | ||
---|---|---|
1 |
package org.gvsig.selectiontools.app.extension.tools; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
import java.awt.Cursor; |
|
26 |
import java.awt.Image; |
|
27 |
import java.awt.Point; |
|
28 |
import java.awt.Toolkit; |
|
29 |
|
|
30 |
import javax.swing.ImageIcon; |
|
31 |
|
|
32 |
import org.gvsig.andami.PluginServices; |
|
33 |
import org.gvsig.andami.messages.NotificationManager; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
36 |
import org.gvsig.fmap.geom.Geometry; |
|
37 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
38 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
42 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
43 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
46 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
47 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
48 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
49 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener; |
|
50 |
|
|
51 |
/** |
|
52 |
* <p> |
|
53 |
* Listener that selects all features of the active and vector layers which |
|
54 |
* intersect with the defined polyline in the associated {@link MapControl |
|
55 |
* MapControl} object. |
|
56 |
* </p> |
|
57 |
* |
|
58 |
* <p> |
|
59 |
* The selection will be produced after user finishes the creation of the |
|
60 |
* polyline. |
|
61 |
* </p> |
|
62 |
* |
|
63 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
64 |
*/ |
|
65 |
public class PolyLineSelectionListener implements PolylineListener { |
|
66 |
|
|
67 |
/** |
|
68 |
* The image to display when the cursor is active. |
|
69 |
*/ |
|
70 |
private final Image img = new ImageIcon(this.getClass() |
|
71 |
.getClassLoader() |
|
72 |
.getResource("images/polyline-cursor-icon.png")).getImage(); |
|
73 |
|
|
74 |
/** |
|
75 |
* The cursor used to work with this tool listener. |
|
76 |
* |
|
77 |
* @see #getCursor() |
|
78 |
*/ |
|
79 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img, |
|
80 |
new Point(16, 16), |
|
81 |
""); |
|
82 |
|
|
83 |
/** |
|
84 |
* Reference to the <code>MapControl</code> object that uses. |
|
85 |
*/ |
|
86 |
private MapControl mapCtrl; |
|
87 |
|
|
88 |
/** |
|
89 |
* <p> |
|
90 |
* Creates a new <code>PolygonSelectionListener</code> object. |
|
91 |
* </p> |
|
92 |
* |
|
93 |
* @param mc |
|
94 |
* the <code>MapControl</code> where is drawn the polyline |
|
95 |
*/ |
|
96 |
public PolyLineSelectionListener(MapControl mc) { |
|
97 |
this.mapCtrl = mc; |
|
98 |
} |
|
99 |
|
|
100 |
/* |
|
101 |
* (non-Javadoc) |
|
102 |
* |
|
103 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
104 |
*/ |
|
105 |
public Cursor getCursor() { |
|
106 |
return cur; |
|
107 |
} |
|
108 |
|
|
109 |
/* |
|
110 |
* (non-Javadoc) |
|
111 |
* |
|
112 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
113 |
*/ |
|
114 |
public boolean cancelDrawing() { |
|
115 |
return false; |
|
116 |
} |
|
117 |
|
|
118 |
/* |
|
119 |
* (non-Javadoc) |
|
120 |
* |
|
121 |
* @see |
|
122 |
* com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#points(com.iver |
|
123 |
* .cit.gvsig.fmap.tools.Events.MeasureEvent) |
|
124 |
*/ |
|
125 |
public void points(MeasureEvent event) throws BehaviorException { |
|
126 |
} |
|
127 |
|
|
128 |
/* |
|
129 |
* (non-Javadoc) |
|
130 |
* |
|
131 |
* @see |
|
132 |
* com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#pointFixed(com |
|
133 |
* .iver.cit.gvsig.fmap.tools.Events.MeasureEvent) |
|
134 |
*/ |
|
135 |
public void pointFixed(MeasureEvent event) throws BehaviorException { |
|
136 |
} |
|
137 |
|
|
138 |
/* |
|
139 |
* (non-Javadoc) |
|
140 |
* |
|
141 |
* @see |
|
142 |
* com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished |
|
143 |
* (com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent) |
|
144 |
*/ |
|
145 |
public void polylineFinished(MeasureEvent event) throws BehaviorException { |
|
146 |
try { |
|
147 |
GeneralPathX gp = event.getGP(); |
|
148 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
149 |
Geometry geom = null; |
|
150 |
Surface surface = null; |
|
151 |
try { |
|
152 |
surface = |
|
153 |
(Surface) manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
|
154 |
surface.setGeneralPath(gp); |
|
155 |
geom = surface; |
|
156 |
} catch (CreateGeometryException e1) { |
|
157 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
158 |
"Failed_creating_geometry"), |
|
159 |
e1); |
|
160 |
} |
|
161 |
if (geom == null) |
|
162 |
return; |
|
163 |
|
|
164 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives(); |
|
165 |
|
|
166 |
for (int i = 0; i < actives.length; i++) { |
|
167 |
if (actives[i] instanceof FLyrVect) { |
|
168 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
|
169 |
FeatureSet newSelection = null; |
|
170 |
|
|
171 |
newSelection = |
|
172 |
lyrVect.queryByGeometry(geom, lyrVect.getFeatureStore() |
|
173 |
.getDefaultFeatureType()); |
|
174 |
|
|
175 |
if (event.getEvent().isControlDown()) { |
|
176 |
((FeatureSelection) lyrVect.getDataStore() |
|
177 |
.getSelection()).select(newSelection); |
|
178 |
} else { |
|
179 |
lyrVect.getFeatureStore().setSelection(newSelection); |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
} catch (com.vividsolutions.jts.geom.TopologyException topEx) { |
|
184 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
185 |
"Failed_selecting_geometries_by_polyline_topology_exception_explanation"), |
|
186 |
topEx); |
|
187 |
} catch (Exception ex) { |
|
188 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
189 |
"Failed_selecting_geometries"), ex); |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
public Image getImageCursor() { |
|
194 |
return img; |
|
195 |
} |
|
196 |
} |
|
0 | 197 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/buffer/gui/BufferConfigurationPanel.java | ||
---|---|---|
1 |
package org.gvsig.selectiontools.app.extension.tools.buffer.gui; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.FlowLayout; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
import java.awt.event.ComponentAdapter; |
|
30 |
import java.awt.event.ComponentEvent; |
|
31 |
import java.text.DecimalFormat; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Arrays; |
|
34 |
import java.util.Iterator; |
|
35 |
|
|
36 |
import javax.swing.BorderFactory; |
|
37 |
import javax.swing.JCheckBox; |
|
38 |
import javax.swing.JLabel; |
|
39 |
import javax.swing.JPanel; |
|
40 |
import javax.swing.text.NumberFormatter; |
|
41 |
|
|
42 |
import org.gvsig.andami.PluginServices; |
|
43 |
import org.gvsig.andami.messages.NotificationManager; |
|
44 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
45 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
46 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
47 |
import org.gvsig.fmap.dal.exception.DataException; |
|
48 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
49 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
50 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
|
51 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
52 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
|
53 |
import org.gvsig.gui.beans.specificcaretposition.JFormattedTextFieldSCP; |
|
54 |
import org.gvsig.selectiontools.app.extension.tools.buffer.process.BufferSelectionProcess; |
|
55 |
import org.gvsig.utils.swing.JComboBox; |
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
* |
|
60 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
61 |
*/ |
|
62 |
public class BufferConfigurationPanel extends JPanel implements IWindow { |
|
63 |
|
|
64 |
private WindowInfo viewInfo = null; |
|
65 |
private final short Window_Width = 354; |
|
66 |
private final short Window_Height = 315; // 35; |
|
67 |
private JFormattedTextFieldSCP distanceTextField = null; |
|
68 |
private JComboBox distanceUnitsCombo = null; |
|
69 |
private JComboBox polygonSidesCombo = null; |
|
70 |
private JComboBox lineSidesCombo = null; |
|
71 |
private JComboBox pointSidesCombo = null; |
|
72 |
private JComboBox multiPointSidesCombo = null; |
|
73 |
private JLabel distanceUnitsLabel = null; |
|
74 |
private JLabel polygonSideLabel = null; |
|
75 |
private JLabel lineSideLabel = null; |
|
76 |
private JLabel pointSideLabel = null; |
|
77 |
private JLabel multiPointSideLabel = null; |
|
78 |
private JPanel polygonSidePanel = null; |
|
79 |
private JPanel lineSidePanel = null; |
|
80 |
private JPanel pointSidePanel = null; |
|
81 |
private JPanel multiPointSidePanel = null; |
|
82 |
private JLabel widthLabel = null; |
|
83 |
private JPanel widthPanel = null; |
|
84 |
// private JPanel distanceUnits = null; |
|
85 |
private JPanel sidePanel = null; |
|
86 |
private JPanel optionsPanel = null; |
|
87 |
private AdaptedAcceptCancelPanel acceptCancelPanel = null; |
|
88 |
private FLyrVect[] layers; |
|
89 |
private MapControl mapControl; |
|
90 |
private IView view; |
|
91 |
private JCheckBox multiLayerSelectionCBox; |
|
92 |
private SideInfo outside, inside, out_in_side; |
|
93 |
|
|
94 |
/** |
|
95 |
* <p> |
|
96 |
* Creates a new form where user can define the option of the buffer. |
|
97 |
* </p> |
|
98 |
*/ |
|
99 |
public BufferConfigurationPanel(FLyrVect[] array, IView view) { |
|
100 |
super(); |
|
101 |
|
|
102 |
layers = array; |
|
103 |
this.view = view; |
|
104 |
mapControl = view.getMapControl(); |
|
105 |
|
|
106 |
initialize(); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* <p> |
|
111 |
* Initializes this component. |
|
112 |
* </p> |
|
113 |
*/ |
|
114 |
private void initialize() { |
|
115 |
outside = |
|
116 |
new SideInfo(BufferSelectionProcess.BUFFER_OUTSIDE_POLY, |
|
117 |
PluginServices.getText(null, "Outside")); |
|
118 |
inside = |
|
119 |
new SideInfo(BufferSelectionProcess.BUFFER_INSIDE_POLY, |
|
120 |
PluginServices.getText(null, "Inside")); |
|
121 |
out_in_side = |
|
122 |
new SideInfo(BufferSelectionProcess.BUFFER_INSIDE_OUTSIDE_POLY, |
|
123 |
PluginServices.getText(null, "Both")); |
|
124 |
|
|
125 |
setLayout(new FlowLayout()); |
|
126 |
add(getWidthPanel()); |
|
127 |
add(getSidePanel()); |
|
128 |
add(getOptionsPanel()); |
|
129 |
add(getAdaptedAcceptCancelPanel()); |
|
130 |
} |
|
131 |
|
|
132 |
private JPanel getOptionsPanel() { |
|
133 |
if (optionsPanel == null) { |
|
134 |
optionsPanel = new JPanel(); |
|
135 |
optionsPanel.setLayout(new FlowLayout()); |
|
136 |
optionsPanel.setPreferredSize(new Dimension(344, 80)); // 106)); |
|
137 |
optionsPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(optionsPanel, |
|
138 |
"Options"))); |
|
139 |
optionsPanel.add(getMultiLayerSelectionCBox()); |
|
140 |
} |
|
141 |
|
|
142 |
return optionsPanel; |
|
143 |
} |
|
144 |
|
|
145 |
private JCheckBox getMultiLayerSelectionCBox() { |
|
146 |
if (multiLayerSelectionCBox == null) { |
|
147 |
multiLayerSelectionCBox = new JCheckBox(); |
|
148 |
multiLayerSelectionCBox.setPreferredSize(new Dimension(330, 22)); |
|
149 |
multiLayerSelectionCBox.setText(PluginServices.getText(multiLayerSelectionCBox, |
|
150 |
"multiLayer_selection")); |
|
151 |
multiLayerSelectionCBox.setSelected(true); |
|
152 |
multiLayerSelectionCBox.setToolTipText(PluginServices.getText(null, |
|
153 |
"multiLayerSelection_checkbox_TOOLTIP_HTML_explanation")); |
|
154 |
} |
|
155 |
|
|
156 |
return multiLayerSelectionCBox; |
|
157 |
} |
|
158 |
|
|
159 |
private JPanel getWidthPanel() { |
|
160 |
if (widthPanel == null) { |
|
161 |
widthPanel = new JPanel(); |
|
162 |
widthPanel.setPreferredSize(new Dimension(344, 55)); |
|
163 |
widthPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(widthPanel, |
|
164 |
"Width"))); |
|
165 |
widthPanel.setLayout(new FlowLayout()); |
|
166 |
widthPanel.add(getWidthLabel()); |
|
167 |
widthPanel.add(getWidthTextField()); |
|
168 |
widthPanel.add(getDistanceUnitsLabel()); |
|
169 |
widthPanel.add(getDistanceUnitsCombo()); |
|
170 |
} |
|
171 |
|
|
172 |
return widthPanel; |
|
173 |
} |
|
174 |
|
|
175 |
private JLabel getWidthLabel() { |
|
176 |
if (widthLabel == null) { |
|
177 |
widthLabel = new JLabel(); |
|
178 |
widthLabel.setPreferredSize(new Dimension(68, 22)); |
|
179 |
widthLabel.setText(PluginServices.getText(widthLabel, "Width")); |
|
180 |
widthLabel.setToolTipText(PluginServices.getText(null, |
|
181 |
"bufferWidth_TOOLTIP_HTML_explanation")); |
|
182 |
} |
|
183 |
|
|
184 |
return widthLabel; |
|
185 |
} |
|
186 |
|
|
187 |
private JFormattedTextFieldSCP getWidthTextField() { |
|
188 |
if (distanceTextField == null) { |
|
189 |
DecimalFormat decimalFormat = new DecimalFormat(); |
|
190 |
decimalFormat.setDecimalSeparatorAlwaysShown(true); |
|
191 |
decimalFormat.setMaximumIntegerDigits(12); |
|
192 |
decimalFormat.setMinimumIntegerDigits(1); |
|
193 |
decimalFormat.setMinimumFractionDigits(2); |
|
194 |
decimalFormat.setMaximumFractionDigits(4); |
|
195 |
|
|
196 |
NumberFormatter numberFormatter = new NumberFormatter(); |
|
197 |
numberFormatter.setAllowsInvalid(false); |
|
198 |
numberFormatter.setOverwriteMode(false); |
|
199 |
numberFormatter.setCommitsOnValidEdit(true); |
|
200 |
numberFormatter.setMinimum(new Double(0)); |
|
201 |
numberFormatter.setFormat(decimalFormat); |
|
202 |
|
|
203 |
// numberFormatter.setFormat(new |
|
204 |
// DecimalFormat("([+]|[-])?[0-9]+([.][0-9]+)?")); |
|
205 |
|
|
206 |
distanceTextField = new JFormattedTextFieldSCP(numberFormatter); |
|
207 |
distanceTextField.setPreferredSize(new Dimension(85, 22)); |
|
208 |
distanceTextField.setValue(new Double(100.00)); |
|
209 |
distanceTextField.setToolTipText(PluginServices.getText(null, |
|
210 |
"bufferWidth_TOOLTIP_HTML_explanation")); |
|
211 |
} |
|
212 |
|
|
213 |
return distanceTextField; |
|
214 |
} |
|
215 |
|
|
216 |
private JLabel getDistanceUnitsLabel() { |
|
217 |
if (distanceUnitsLabel == null) { |
|
218 |
distanceUnitsLabel = |
|
219 |
new JLabel(PluginServices.getText(distanceUnitsLabel, "Unit")); |
|
220 |
distanceUnitsLabel.setAlignmentX(JLabel.RIGHT_ALIGNMENT); |
|
221 |
distanceUnitsLabel.setPreferredSize(new Dimension(68, 22)); |
|
222 |
distanceUnitsLabel.setToolTipText(PluginServices.getText(null, |
|
223 |
"distanceUnitsLabel_TOOLTIP_HTML_explanation")); |
|
224 |
} |
|
225 |
|
|
226 |
return distanceUnitsLabel; |
|
227 |
} |
|
228 |
|
|
229 |
private JComboBox getDistanceUnitsCombo() { |
|
230 |
if (distanceUnitsCombo == null) { |
|
231 |
distanceUnitsCombo = new JComboBox(); |
|
232 |
distanceUnitsCombo.setPreferredSize(new Dimension(85, 22)); |
|
233 |
distanceUnitsCombo.addItem("km"); |
|
234 |
distanceUnitsCombo.addItem("m"); |
|
235 |
distanceUnitsCombo.addItem("cm"); |
|
236 |
distanceUnitsCombo.addItem("mm"); |
|
237 |
distanceUnitsCombo.addItem("mi"); |
|
238 |
distanceUnitsCombo.addItem("Ya"); |
|
239 |
distanceUnitsCombo.addItem("ft"); |
|
240 |
distanceUnitsCombo.addItem("in"); |
|
241 |
distanceUnitsCombo.addItem("?"); |
|
242 |
distanceUnitsCombo.setSelectedIndex(1); // By default in meters |
|
243 |
distanceUnitsCombo.setToolTipText(PluginServices.getText(null, |
|
244 |
"distanceUnitsLabel_TOOLTIP_HTML_explanation")); |
|
245 |
} |
|
246 |
|
|
247 |
return distanceUnitsCombo; |
|
248 |
} |
|
249 |
|
|
250 |
private JPanel getSidePanel() { |
|
251 |
if (sidePanel == null) { |
|
252 |
sidePanel = new JPanel(); |
|
253 |
sidePanel.setLayout(new FlowLayout()); |
|
254 |
sidePanel.setPreferredSize(new Dimension(344, 166)); |
|
255 |
sidePanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(sidePanel, |
|
256 |
"Side"))); |
|
257 |
sidePanel.setToolTipText(PluginServices.getText(null, |
|
258 |
"sideLabel_TOOLTIP_HTML_explanation")); |
|
259 |
sidePanel.add(getPolygonSidePanel()); |
|
260 |
sidePanel.add(getLineSidePanel()); |
|
261 |
sidePanel.add(getPointSidePanel()); |
|
262 |
sidePanel.add(getMultiPointSidePanel()); |
|
263 |
} |
|
264 |
|
|
265 |
return sidePanel; |
|
266 |
} |
|
267 |
|
|
268 |
private JPanel getPolygonSidePanel() { |
|
269 |
if (polygonSidePanel == null) { |
|
270 |
polygonSidePanel = new JPanel(); |
|
271 |
polygonSidePanel.setPreferredSize(new Dimension(336, 28)); |
|
272 |
polygonSidePanel.add(getPolygonSideLabel()); |
|
273 |
polygonSidePanel.add(getPolygonSidesCombo()); |
|
274 |
} |
|
275 |
|
|
276 |
return polygonSidePanel; |
|
277 |
} |
|
278 |
|
|
279 |
private JLabel getPolygonSideLabel() { |
|
280 |
if (polygonSideLabel == null) { |
|
281 |
polygonSideLabel = |
|
282 |
new JLabel(PluginServices.getText(polygonSideLabel, "Polygon")); |
|
283 |
polygonSideLabel.setPreferredSize(new Dimension(90, 22)); |
|
284 |
polygonSideLabel.setToolTipText(PluginServices.getText(null, |
|
285 |
"polygonSideLabel_TOOLTIP_HTML_explanation")); |
|
286 |
} |
|
287 |
|
|
288 |
return polygonSideLabel; |
|
289 |
} |
|
290 |
|
|
291 |
private JComboBox getPolygonSidesCombo() { |
|
292 |
if (polygonSidesCombo == null) { |
|
293 |
polygonSidesCombo = new JComboBox(); |
|
294 |
polygonSidesCombo.setPreferredSize(new Dimension(230, 22)); |
|
295 |
polygonSidesCombo.addItem(outside); |
|
296 |
polygonSidesCombo.addItem(inside); |
|
297 |
// polygonSidesCombo.addItem(out_in_side); // Disabled because fails |
|
298 |
// quite often |
|
299 |
polygonSidesCombo.setToolTipText(PluginServices.getText(null, |
|
300 |
"polygonSideLabel_TOOLTIP_HTML_explanation")); |
|
301 |
} |
|
302 |
|
|
303 |
return polygonSidesCombo; |
|
304 |
} |
|
305 |
|
|
306 |
private JPanel getLineSidePanel() { |
|
307 |
if (lineSidePanel == null) { |
|
308 |
lineSidePanel = new JPanel(); |
|
309 |
lineSidePanel.setPreferredSize(new Dimension(336, 28)); |
|
310 |
lineSidePanel.add(getLineSideLabel()); |
|
311 |
lineSidePanel.add(getLineSidesCombo()); |
|
312 |
} |
|
313 |
|
|
314 |
return lineSidePanel; |
|
315 |
} |
|
316 |
|
|
317 |
private JLabel getLineSideLabel() { |
|
318 |
if (lineSideLabel == null) { |
|
319 |
lineSideLabel = |
|
320 |
new JLabel(PluginServices.getText(lineSideLabel, "Line")); |
|
321 |
lineSideLabel.setPreferredSize(new Dimension(90, 22)); |
|
322 |
lineSideLabel.setToolTipText(PluginServices.getText(null, |
|
323 |
"lineSideLabel_TOOLTIP_HTML_explanation")); |
|
324 |
} |
|
325 |
|
|
326 |
return lineSideLabel; |
|
327 |
} |
|
328 |
|
|
329 |
private JComboBox getLineSidesCombo() { |
|
330 |
if (lineSidesCombo == null) { |
|
331 |
lineSidesCombo = new JComboBox(); |
|
332 |
lineSidesCombo.setPreferredSize(new Dimension(230, 22)); |
|
333 |
lineSidesCombo.addItem(outside); |
|
334 |
lineSidesCombo.setToolTipText(PluginServices.getText(null, |
|
335 |
"lineSideLabel_TOOLTIP_HTML_explanation")); |
|
336 |
} |
|
337 |
|
|
338 |
return lineSidesCombo; |
|
339 |
} |
|
340 |
|
|
341 |
private JPanel getPointSidePanel() { |
|
342 |
if (pointSidePanel == null) { |
|
343 |
pointSidePanel = new JPanel(); |
|
344 |
pointSidePanel.setPreferredSize(new Dimension(336, 28)); |
|
345 |
pointSidePanel.add(getPointSideLabel()); |
|
346 |
pointSidePanel.add(getPointSidesCombo()); |
|
347 |
} |
|
348 |
|
|
349 |
return pointSidePanel; |
|
350 |
} |
|
351 |
|
|
352 |
private JLabel getPointSideLabel() { |
|
353 |
if (pointSideLabel == null) { |
|
354 |
pointSideLabel = |
|
355 |
new JLabel(PluginServices.getText(pointSideLabel, "Point")); |
|
356 |
pointSideLabel.setPreferredSize(new Dimension(90, 22)); |
|
357 |
pointSideLabel.setToolTipText(PluginServices.getText(null, |
|
358 |
"pointSideLabel_TOOLTIP_HTML_explanation")); |
|
359 |
} |
|
360 |
|
|
361 |
return pointSideLabel; |
|
362 |
} |
|
363 |
|
|
364 |
private JComboBox getPointSidesCombo() { |
|
365 |
if (pointSidesCombo == null) { |
|
366 |
pointSidesCombo = new JComboBox(); |
|
367 |
pointSidesCombo.setPreferredSize(new Dimension(230, 22)); |
|
368 |
pointSidesCombo.addItem(outside); |
|
369 |
pointSidesCombo.setToolTipText(PluginServices.getText(null, |
|
370 |
"pointSideLabel_TOOLTIP_HTML_explanation")); |
|
371 |
} |
|
372 |
|
|
373 |
return pointSidesCombo; |
|
374 |
} |
|
375 |
|
|
376 |
private JPanel getMultiPointSidePanel() { |
|
377 |
if (multiPointSidePanel == null) { |
|
378 |
multiPointSidePanel = new JPanel(); |
|
379 |
multiPointSidePanel.setPreferredSize(new Dimension(336, 28)); |
|
380 |
multiPointSidePanel.add(getMultiPointSideLabel()); |
|
381 |
multiPointSidePanel.add(getMultiPointSidesCombo()); |
|
382 |
} |
|
383 |
|
|
384 |
return multiPointSidePanel; |
|
385 |
} |
|
386 |
|
|
387 |
private JLabel getMultiPointSideLabel() { |
|
388 |
if (multiPointSideLabel == null) { |
|
389 |
multiPointSideLabel = |
|
390 |
new JLabel(PluginServices.getText(multiPointSideLabel, |
|
391 |
"MultiPoint")); |
|
392 |
multiPointSideLabel.setPreferredSize(new Dimension(90, 22)); |
|
393 |
multiPointSideLabel.setToolTipText(PluginServices.getText(null, |
|
394 |
"multiPointSideLabel_TOOLTIP_HTML_explanation")); |
|
395 |
} |
|
396 |
|
|
397 |
return multiPointSideLabel; |
|
398 |
} |
|
399 |
|
|
400 |
private JComboBox getMultiPointSidesCombo() { |
|
401 |
if (multiPointSidesCombo == null) { |
|
402 |
multiPointSidesCombo = new JComboBox(); |
|
403 |
multiPointSidesCombo.setPreferredSize(new Dimension(230, 22)); |
|
404 |
multiPointSidesCombo.addItem(outside); |
|
405 |
multiPointSidesCombo.setToolTipText(PluginServices.getText(null, |
|
406 |
"multiPointSideLabel_TOOLTIP_HTML_explanation")); |
|
407 |
} |
|
408 |
|
|
409 |
return multiPointSidesCombo; |
|
410 |
} |
|
411 |
|
|
412 |
/** |
|
413 |
* <p> |
|
414 |
* This method initializes acceptCancelPanel. |
|
415 |
* </p> |
|
416 |
* |
|
417 |
* @return an adapted {@link AcceptCancelPanel AcceptCancelPanel} |
|
418 |
*/ |
|
419 |
private AdaptedAcceptCancelPanel getAdaptedAcceptCancelPanel() { |
|
420 |
if (acceptCancelPanel == null) { |
|
421 |
acceptCancelPanel = new AdaptedAcceptCancelPanel(); |
|
422 |
} |
|
423 |
|
|
424 |
return acceptCancelPanel; |
|
425 |
} |
|
426 |
|
|
427 |
/* |
|
428 |
* (non-Javadoc) |
|
429 |
* |
|
430 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo() |
|
431 |
*/ |
|
432 |
public WindowInfo getWindowInfo() { |
|
433 |
if (viewInfo == null) { |
|
434 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG); |
|
435 |
viewInfo.setTitle(PluginServices.getText(this, "configuration")); |
|
436 |
viewInfo.setWidth(Window_Width); |
|
437 |
viewInfo.setHeight(Window_Height); |
|
438 |
} |
|
439 |
|
|
440 |
return viewInfo; |
|
441 |
} |
|
442 |
|
|
443 |
/** |
|
444 |
* <p> |
|
445 |
* Adapts {@link AcceptCancelPanel AcceptCancelPanel} to be used as a |
|
446 |
* component of the <code>BufferConfigurationPanel</code> panel. |
|
447 |
* </p> |
|
448 |
* |
|
449 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
450 |
*/ |
|
451 |
private class AdaptedAcceptCancelPanel extends AcceptCancelPanel { |
|
452 |
|
|
453 |
public AdaptedAcceptCancelPanel() { |
|
454 |
super(); |
|
455 |
|
|
456 |
addOkButtonActionListener(getOKAction()); |
|
457 |
addCancelButtonActionListener(getCancelAction()); |
|
458 |
setPreferredSize(new Dimension(350, 30)); |
|
459 |
} |
|
460 |
|
|
461 |
/** |
|
462 |
* <p> |
|
463 |
* Create the action that will be executed when user pressed the |
|
464 |
* <i>ok</i> button. |
|
465 |
* </p> |
|
466 |
* |
|
467 |
* @return action that will be executed when user pressed the |
|
468 |
* <i>cancel</i> |
|
469 |
* button |
|
470 |
*/ |
|
471 |
private ActionListener getOKAction() { |
|
472 |
// OK button action |
|
473 |
return new ActionListener() { |
|
474 |
|
|
475 |
/* |
|
476 |
* @see |
|
477 |
* java.awt.event.ActionListener#actionPerformed(java.awt.event |
|
478 |
* .ActionEvent) |
|
479 |
*/ |
|
480 |
public void actionPerformed(ActionEvent e) { |
|
481 |
/* 1- Closes this window */ |
|
482 |
closeThis(); |
|
483 |
|
|
484 |
/* 2- Validates the buffer width */ |
|
485 |
double width; |
|
486 |
|
|
487 |
try { |
|
488 |
width = |
|
489 |
Double.parseDouble(getWidthTextField().getText() |
|
490 |
.replaceAll("(\\.)?", "") |
|
491 |
.replace(",", ".")); // Formats the decimal |
|
492 |
// number to be parsed |
|
493 |
} catch (Exception ex) { |
|
494 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
495 |
"Invalid_width"), |
|
496 |
ex); |
|
497 |
return; |
|
498 |
} |
|
499 |
|
|
500 |
/* 3- Creates the process */ |
|
501 |
// checks layers to proccess if multilayer is not selected |
|
502 |
ArrayList<FLyrVect> tmpLayersToProccess = |
|
503 |
new ArrayList<FLyrVect>(layers.length); |
|
504 |
tmpLayersToProccess.addAll(Arrays.asList(layers)); |
|
505 |
if (!multiLayerSelectionCBox.isSelected()) { |
|
506 |
Iterator<FLyrVect> iter = |
|
507 |
tmpLayersToProccess.iterator(); |
|
508 |
FLyrVect curLayer; |
|
509 |
while (iter.hasNext()) { |
|
510 |
curLayer = (FLyrVect) iter.next(); |
|
511 |
try { |
|
512 |
if (curLayer.getFeatureStore() |
|
513 |
.getFeatureSelection() |
|
514 |
.isEmpty()) { |
|
515 |
iter.remove(); |
|
516 |
} |
|
517 |
} catch (DataException e1) { |
|
518 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
519 |
"Failed_selecting_layer"), |
|
520 |
e1); |
|
521 |
return; |
|
522 |
|
|
523 |
} |
|
524 |
} |
|
525 |
} |
|
526 |
FLyrVect[] layersToProcess = |
|
527 |
(FLyrVect[]) tmpLayersToProccess.toArray(new FLyrVect[tmpLayersToProccess.size()]); |
|
528 |
|
|
529 |
BufferSelectionProcess iprocess = |
|
530 |
new BufferSelectionProcess(PluginServices.getText(this, |
|
531 |
"Selection_by_buffer_process"), |
|
532 |
PluginServices.getText(this, |
|
533 |
"Ongoing_process_please_wait"), |
|
534 |
mapControl, |
|
535 |
((SideInfo) getPolygonSidesCombo().getSelectedItem()).getSide(), |
|
536 |
((SideInfo) getLineSidesCombo().getSelectedItem()).getSide(), |
|
537 |
((SideInfo) getPointSidesCombo().getSelectedItem()).getSide(), |
|
538 |
((SideInfo) getMultiPointSidesCombo().getSelectedItem()).getSide(), |
|
539 |
width, |
|
540 |
(short) getDistanceUnitsCombo().getSelectedIndex(), |
|
541 |
layersToProcess, |
|
542 |
getMultiLayerSelectionCBox().isSelected());// getAddBufferLayersCBox().isSelected(), |
|
543 |
// getAddInfluenceAreaLayersCBox().isSelected(), |
|
544 |
// getMultiLayerSelectionCBox().isSelected()); |
|
545 |
IncrementableTask iTask = |
|
546 |
new IncrementableTask(iprocess, |
|
547 |
new ProgressPanel(false)); |
|
548 |
iTask.addIncrementableListener(iprocess); |
|
549 |
iprocess.setIncrementableTask(iTask); |
|
550 |
final BufferSelectionProcess f_iprocess = iprocess; |
|
551 |
final IncrementableTask f_iTask = iTask; |
|
552 |
|
|
553 |
iTask.getProgressPanel() |
|
554 |
.addComponentListener(new ComponentAdapter() { |
|
555 |
|
|
556 |
/* |
|
557 |
* (non-Javadoc) |
|
558 |
* |
|
559 |
* @see |
|
560 |
* java.awt.event.ComponentAdapter#componentHidden |
|
561 |
* (java.awt.event.ComponentEvent) |
|
562 |
*/ |
|
563 |
public void componentHidden(ComponentEvent e) { |
|
564 |
/* |
|
565 |
* 5- If the process has failed, tries to reload |
|
566 |
* the layers |
|
567 |
*/ |
|
568 |
if (f_iprocess.getPercent() < 100) { |
|
569 |
/* 5.1- Forces to reload the active layers */ |
|
570 |
mapControl.drawMap(false); |
|
571 |
f_iTask.getProgressPanel().dispose(); |
|
572 |
|
|
573 |
for (int i = 0; i < layers.length; i++) { |
|
574 |
try { |
|
575 |
layers[i].reload(); |
|
576 |
} catch (Exception ex) { |
|
577 |
try { |
|
578 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
579 |
"Failed_reloading_the_layer") |
|
580 |
+ " " + layers[i].getName(), |
|
581 |
ex); |
|
582 |
} catch (Exception ex2) { |
|
583 |
NotificationManager.showMessageError(PluginServices.getText(null, |
|
584 |
"Undefined_layer"), |
|
585 |
ex); |
|
586 |
} |
|
587 |
} |
|
588 |
} |
|
589 |
|
|
590 |
view.getTOC().setVisible(false); |
|
591 |
view.getTOC().setVisible(true); |
|
592 |
} |
|
593 |
|
|
594 |
/* |
|
595 |
* 6- Writes in the gvSIG log the results of the |
|
596 |
* process |
|
597 |
*/ |
|
598 |
String text = |
|
599 |
"\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" |
|
600 |
+ PluginServices.getText(this, |
|
601 |
"Summary_of_the_process_of_selecting_by_buffer") |
|
602 |
+ ":\n" |
|
603 |
+ f_iprocess.getLog() |
|
604 |
+ "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"; |
|
605 |
PluginServices.getLogger().info(text); |
|
606 |
} |
|
607 |
}); |
|
608 |
|
|
609 |
/* 4- Starts the process */ |
|
610 |
iprocess.start(); |
|
611 |
iTask.start(); |
|
612 |
} |
|
613 |
}; |
|
614 |
} |
|
615 |
|
|
616 |
/** |
|
617 |
* <p> |
|
618 |
* Create the action that will be executed when user pressed the |
|
619 |
* <i>cancel</i> button. |
|
620 |
* </p> |
|
621 |
* |
|
622 |
* @return action that will be executed when user pressed the |
|
623 |
* <i>cancel</i> |
|
624 |
* button |
|
625 |
*/ |
|
626 |
private ActionListener getCancelAction() { |
|
627 |
// Cancel button action |
|
628 |
return new ActionListener() { |
|
629 |
|
|
630 |
/* |
|
631 |
* @see |
|
632 |
* java.awt.event.ActionListener#actionPerformed(java.awt.event |
|
633 |
* .ActionEvent) |
|
634 |
*/ |
|
635 |
public void actionPerformed(ActionEvent e) { |
|
636 |
closeThis(); |
|
637 |
} |
|
638 |
}; |
|
639 |
} |
|
640 |
} |
|
641 |
|
|
642 |
/** |
|
643 |
* <p> |
|
644 |
* Closes this window. |
|
645 |
* </p> |
|
646 |
*/ |
|
647 |
private void closeThis() { |
|
648 |
PluginServices.getMDIManager().closeWindow(this); |
|
649 |
} |
|
650 |
|
|
651 |
/** |
|
652 |
* |
|
653 |
* |
|
654 |
* |
|
655 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
656 |
*/ |
|
657 |
private class SideInfo { |
|
658 |
|
|
659 |
private byte side; |
|
660 |
private String name; |
|
661 |
|
|
662 |
public SideInfo(byte side, String name) { |
|
663 |
this.side = side; |
|
664 |
this.name = name; |
|
665 |
} |
|
666 |
|
|
667 |
public String toString() { |
|
668 |
return name; |
|
669 |
} |
|
670 |
|
|
671 |
public String getName() { |
|
672 |
return name; |
|
673 |
} |
|
674 |
|
|
675 |
public byte getSide() { |
|
676 |
return side; |
|
677 |
} |
|
678 |
} |
|
679 |
|
|
680 |
public Object getWindowProfile() { |
|
681 |
return WindowInfo.DIALOG_PROFILE; |
|
682 |
} |
|
683 |
} |
|
0 | 684 |
tags/v2_0_0_Build_2047/extensions/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.extension/src/main/java/org/gvsig/selectiontools/app/extension/tools/buffer/process/BufferSelectionProcess.java | ||
---|---|---|
1 |
package org.gvsig.selectiontools.app.extension.tools.buffer.process; |
|
2 |
|
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
6 |
* of the Valencian Government (CIT) |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
* MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
import java.awt.event.MouseAdapter; |
|
26 |
import java.awt.event.MouseEvent; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Iterator; |
|
29 |
|
|
30 |
import javax.swing.JButton; |
|
31 |
|
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
import org.gvsig.andami.PluginServices; |
|
34 |
import org.gvsig.andami.messages.NotificationManager; |
|
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
36 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
37 |
import org.gvsig.fmap.dal.feature.Feature; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
40 |
import org.gvsig.fmap.geom.Geometry; |
|
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
42 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
43 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
44 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
|
45 |
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess; |
|
46 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
47 |
import org.gvsig.selectiontools.app.extension.tools.buffer.gui.BufferConfigurationPanel; |
|
48 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
49 |
|
|
50 |
/** |
|
51 |
* |
|
52 |
* |
|
53 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
|
54 |
*/ |
|
55 |
public class BufferSelectionProcess extends IncrementableProcess { |
|
56 |
|
|
57 |
// private boolean layerWasBeingEdited = false; |
|
58 |
|
|
59 |
private MapControl mapControl = null; |
|
60 |
private byte pol_side = -1; |
|
61 |
private byte line_side = -1; |
|
62 |
private byte point_side = -1; |
|
63 |
private byte multi_point_side = -1; |
|
64 |
private short selectedDistanceUnit = -1; |
|
65 |
private FLyrVect[] layers = null; |
|
66 |
private final double f_width; |
|
67 |
private boolean multiLayerSelection = false; |
|
68 |
|
|
69 |
/** |
|
70 |
* For polygonal buffers, only compute interior buffers |
|
71 |
*/ |
|
72 |
public static final byte BUFFER_INSIDE_POLY = 0; |
|
73 |
|
|
74 |
/** |
|
75 |
* For polygonal buffers, only compute exterior buffers (is the default |
|
76 |
* operation, it applies to any geometry type) |
|
77 |
*/ |
|
78 |
public static final byte BUFFER_OUTSIDE_POLY = 1; |
|
79 |
|
|
80 |
/** |
|
81 |
* For polygonal buffers, compute interior and exterior buffers |
|
82 |
*/ |
|
83 |
public static final byte BUFFER_INSIDE_OUTSIDE_POLY = 2; |
|
84 |
|
|
85 |
/** |
|
86 |
* Buffer with square cap |
|
87 |
*/ |
|
88 |
public static final byte CAP_SQUARE = 0; |
|
89 |
/** |
|
90 |
* Buffer with round cap |
|
91 |
*/ |
|
92 |
public static final byte CAP_ROUND = 1; |
|
93 |
|
|
94 |
/** |
|
95 |
* flag that represents buffer computing with one only buffer distance. |
|
96 |
*/ |
|
97 |
public static final byte CONSTANT_DISTANCE_STRATEGY = 0; |
|
98 |
|
|
99 |
/** |
|
100 |
* buffer computing with variable buffer distance in function of feature |
|
101 |
* attribute value |
|
102 |
*/ |
|
103 |
public static final byte ATTRIBUTE_DISTANCE_STRATEGY = 1; |
|
104 |
|
|
105 |
/** |
|
106 |
* Creates a new |
|
107 |
* <p> |
|
108 |
* BufferSelectionProcess |
|
109 |
* </p> |
|
110 |
* . |
|
111 |
* |
|
112 |
* @param title |
|
113 |
* of the progress dialog |
|
114 |
* @param label |
|
115 |
* the label that explains the process |
|
116 |
* @param mapControl |
|
117 |
* reference to the current active view's <code>MapControl</code> |
|
118 |
* . |
|
119 |
* @param pol_side |
|
120 |
* side of the buffer in a polyline layer: |
|
121 |
* {@link BufferConfigurationPanel#OUTSIDE |
|
122 |
* BufferConfigurationPanel#OUTSIDE}, |
|
123 |
* {@link BufferConfigurationPanel#INSIDE |
|
124 |
* BufferConfigurationPanel#INSIDE}, or |
|
125 |
* {@link BufferConfigurationPanel#OUTSIDE_AND_INSIDE |
|
126 |
* BufferConfigurationPanel#OUTSIDE_AND_INSIDE} |
|
127 |
* @param line_side |
|
128 |
* side of the buffer in a line layer: |
|
129 |
* {@link BufferConfigurationPanel#OUTSIDE_AND_INSIDE |
|
130 |
* BufferConfigurationPanel#OUTSIDE_AND_INSIDE} |
|
131 |
* @param point_side |
|
132 |
* side of the buffer in a point layer: |
|
133 |
* {@link BufferConfigurationPanel#OUTSIDE |
|
134 |
* BufferConfigurationPanel#OUTSIDE} |
|
135 |
* @param multi_point_side |
|
136 |
* side of the buffer in a multi point layer: |
|
137 |
* {@link BufferConfigurationPanel#OUTSIDE |
|
138 |
* BufferConfigurationPanel#OUTSIDE} |
|
139 |
* @param width |
|
140 |
* buffer's width |
|
141 |
* @param selectedDistanceUnit |
|
142 |
* distance unit selected |
|
143 |
* @param activeLayers |
|
144 |
* current active view's active layers |
|
145 |
* @param showBufferLayers |
|
146 |
* determines if will show the layers with the buffers as new |
|
147 |
* temporal layers |
|
148 |
* @param multiLayerSelection |
|
149 |
* determines if the selection in each active layer affects the |
|
150 |
* other |
|
151 |
*/ |
|
152 |
public BufferSelectionProcess(String title, |
|
153 |
String label, |
|
154 |
MapControl mapControl, |
|
155 |
byte pol_side, |
|
156 |
byte line_side, |
|
157 |
byte point_side, |
|
158 |
byte multi_point_side, |
|
159 |
double width, |
|
160 |
short selectedDistanceUnit, |
|
161 |
FLyrVect[] activeLayers, |
|
162 |
boolean multiLayerSelection) { |
|
163 |
super(title); |
|
164 |
|
|
165 |
this.label = label; |
|
166 |
this.mapControl = mapControl; |
|
167 |
this.pol_side = pol_side; |
|
168 |
this.line_side = line_side; |
|
169 |
this.point_side = point_side; |
|
170 |
this.multi_point_side = multi_point_side; |
|
171 |
this.f_width = width; |
|
172 |
this.selectedDistanceUnit = selectedDistanceUnit; |
|
173 |
this.layers = activeLayers; |
|
174 |
this.multiLayerSelection = multiLayerSelection; |
|
175 |
this.isPausable = true; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Sets the object that will display the evolution of this loading process |
|
180 |
* as a progress dialog. |
|
181 |
* |
|
182 |
* @param iTask |
|
183 |
* the object that will display the evolution of this loading |
|
184 |
* process |
|
185 |
*/ |
|
186 |
public void setIncrementableTask(IncrementableTask iTask) { |
|
187 |
this.iTask = iTask; |
|
188 |
iTask.setAskCancel(true); |
|
189 |
iTask.getButtonsPanel().addAccept(); |
|
190 |
iTask.getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_ACCEPT, false); |
|
191 |
|
|
192 |
JButton jButton = |
|
193 |
iTask.getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT); |
|
194 |
jButton.addMouseListener(new MouseAdapter() { |
|
195 |
|
|
196 |
/* |
|
197 |
* (non-Javadoc) |
|
198 |
* |
|
199 |
* @see |
|
200 |
* java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent |
|
201 |
* ) |
|
202 |
*/ |
|
203 |
public void mouseClicked(MouseEvent e) { |
|
204 |
processFinalize(); |
|
205 |
} |
|
206 |
}); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Importation process. |
|
211 |
* |
|
212 |
* @throws InterruptedException |
|
213 |
* if fails the process |
|
214 |
*/ |
|
215 |
public void process() throws InterruptedException { |
|
216 |
percentage = 5; |
|
217 |
double inc = 0; |
|
218 |
FeatureSelection selections[] = new FeatureSelection[layers.length]; |
|
219 |
ArrayList<Geometry> buffer[] = new ArrayList[layers.length]; |
|
220 |
try { |
|
221 |
|
|
222 |
/* 2- Gets the distance relation */ |
|
223 |
percentage = 6; |
|
224 |
|
|
225 |
/* 3- Stores the new selections */ |
|
226 |
FLyrVect layer = null; |
|
227 |
|
|
228 |
// int size; |
|
229 |
|
|
230 |
percentage = 9; |
|
231 |
|
|
232 |
/* 4- Gets the buffer and intersects to select new geometries */ |
|
233 |
double width = 1; // default value (not used) |
|
234 |
byte side; |
|
235 |
|
|
236 |
percentage = 11; |
|
237 |
|
|
238 |
boolean isProjected = false; |
|
239 |
|
|
240 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
241 |
if (f instanceof IView) { |
|
242 |
IView vista = (IView) f; |
|
243 |
|
|
244 |
// Sets projection |
|
245 |
IProjection proj = |
|
246 |
vista.getMapControl().getViewPort().getProjection(); |
|
247 |
|
|
248 |
// Sets distance units |
|
249 |
isProjected = proj.isProjected(); |
|
250 |
} |
|
251 |
// Sets map units |
|
252 |
int mapUnits = -1; |
|
253 |
if (isProjected) { |
|
254 |
mapUnits = |
|
255 |
((IView) PluginServices.getMDIManager().getActiveWindow()).getMapControl() |
|
256 |
.getViewPort() |
|
257 |
.getMapUnits(); |
|
258 |
} else { |
|
259 |
mapUnits = 1; |
|
260 |
} |
|
261 |
|
|
262 |
percentage = 14; |
|
263 |
|
|
264 |
inc = (100 - percentage) / layers.length; |
|
265 |
|
|
266 |
/* 4.1- For each vector layer with geometries selected */ |
|
267 |
for (int i = 0; i < layers.length; i++) { |
|
268 |
try { |
|
269 |
if (cancelProcess.isCanceled()) { |
|
270 |
throw new InterruptedException(); |
|
271 |
} |
|
272 |
|
|
273 |
layer = layers[i]; |
|
274 |
FeatureSelection selection = |
|
275 |
(FeatureSelection) layer.getFeatureStore() |
|
276 |
.getFeatureSelection() |
|
277 |
.clone(); |
|
278 |
selections[i] = selection; |
|
279 |
|
|
280 |
log.addLine(PluginServices.getText(null, |
|
281 |
"Starting_selection_of_layer") |
|
282 |
+ " \"" |
|
283 |
+ layer.getName() + "\""); |
|
284 |
|
|
285 |
switch (layer.getShapeType()) { |
|
286 |
case Geometry.TYPES.POINT: |
|
287 |
side = point_side; |
|
288 |
break; |
|
289 |
case Geometry.TYPES.CURVE: |
|
290 |
case Geometry.TYPES.MULTICURVE: |
|
291 |
side = line_side; |
|
292 |
break; |
|
293 |
case Geometry.TYPES.SURFACE: |
|
294 |
case Geometry.TYPES.MULTISURFACE: |
|
295 |
side = pol_side; |
|
296 |
break; |
|
297 |
case Geometry.TYPES.MULTIPOINT: |
|
298 |
side = multi_point_side; |
|
299 |
break; |
Also available in: Unified diff