Revision 8265
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.204/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.symbology.library.DotDensityLibrary |
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.204/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
|
8 |
modify it under the terms of the GNU General Public License |
|
9 |
as published by the Free Software Foundation; either version 3 |
|
10 |
of the License, or (at your option) any later version. |
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
GNU General Public License for more details. |
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
|
18 |
along with this program; if not, write to the Free Software |
|
19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-plugin-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
32 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
33 |
<files> |
|
34 |
<file> |
|
35 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
36 |
<outputDirectory>lib</outputDirectory> |
|
37 |
</file> |
|
38 |
<file> |
|
39 |
<source>target/package.info</source> |
|
40 |
</file> |
|
41 |
</files> |
|
42 |
|
|
43 |
<fileSets> |
|
44 |
<fileSet> |
|
45 |
<directory>src/main/resources-plugin</directory> |
|
46 |
<outputDirectory>.</outputDirectory> |
|
47 |
</fileSet> |
|
48 |
</fileSets> |
|
49 |
|
|
50 |
<!-- No dependencies |
|
51 |
<dependencySets> |
|
52 |
<dependencySet> |
|
53 |
<useProjectArtifact>false</useProjectArtifact> |
|
54 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
55 |
<outputDirectory>lib</outputDirectory> |
|
56 |
<includes> |
|
57 |
<include>...</include> |
|
58 |
</includes> |
|
59 |
</dependencySet> |
|
60 |
</dependencySets> |
|
61 |
--> |
|
62 |
|
|
63 |
</assembly> |
|
64 |
|
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.204/src/main/java/org/gvsig/symbology/fmap/symbols/DotDensityFillSymbol.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id: DotDensityFillSymbol.java 13953 2007-09-21 12:26:04Z jaume $ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.8 2007-09-21 12:25:32 jaume |
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level |
|
48 |
* |
|
49 |
* Revision 1.7 2007/09/18 14:50:31 caballero |
|
50 |
* Leyendas sobre el Layout |
|
51 |
* |
|
52 |
* Revision 1.6 2007/03/26 14:24:24 jaume |
|
53 |
* IPrintable refactored |
|
54 |
* |
|
55 |
* Revision 1.5 2007/03/09 11:20:56 jaume |
|
56 |
* Advanced symbology (start committing) |
|
57 |
* |
|
58 |
* Revision 1.3.2.4 2007/02/21 16:09:02 jaume |
|
59 |
* *** empty log message *** |
|
60 |
* |
|
61 |
* Revision 1.3.2.3 2007/02/16 10:54:12 jaume |
|
62 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill |
|
63 |
* |
|
64 |
* Revision 1.3.2.2 2007/02/15 16:23:44 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.3.2.1 2007/02/09 07:47:04 jaume |
|
68 |
* Isymbol moved |
|
69 |
* |
|
70 |
* Revision 1.3 2007/01/12 10:08:26 jaume |
|
71 |
* *** empty log message *** |
|
72 |
* |
|
73 |
* Revision 1.2 2007/01/10 16:39:41 jaume |
|
74 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package |
|
75 |
* |
|
76 |
* Revision 1.1 2007/01/10 16:31:36 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* Revision 1.4 2006/11/14 11:10:27 jaume |
|
80 |
* *** empty log message *** |
|
81 |
* |
|
82 |
* Revision 1.3 2006/11/13 09:15:23 jaume |
|
83 |
* javadoc and some clean-up |
|
84 |
* |
|
85 |
* Revision 1.2 2006/11/09 18:39:05 jaume |
|
86 |
* *** empty log message *** |
|
87 |
* |
|
88 |
* Revision 1.1 2006/11/09 10:22:50 jaume |
|
89 |
* *** empty log message *** |
|
90 |
* |
|
91 |
* |
|
92 |
*/ |
|
93 |
package org.gvsig.symbology.fmap.symbols; |
|
94 |
|
|
95 |
import java.awt.Color; |
|
96 |
import java.awt.Graphics2D; |
|
97 |
import java.awt.Rectangle; |
|
98 |
import java.awt.geom.AffineTransform; |
|
99 |
import java.util.Random; |
|
100 |
|
|
101 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
102 |
|
|
103 |
import org.gvsig.compat.print.PrintAttributes; |
|
104 |
import org.gvsig.fmap.dal.feature.Feature; |
|
105 |
import org.gvsig.fmap.geom.Geometry; |
|
106 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
107 |
import org.gvsig.fmap.geom.GeometryManager; |
|
108 |
import org.gvsig.fmap.geom.primitive.Point; |
|
109 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
110 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
111 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
|
112 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol; |
|
113 |
import org.gvsig.tools.ToolsLocator; |
|
114 |
import org.gvsig.tools.dynobject.DynStruct; |
|
115 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
116 |
import org.gvsig.tools.persistence.PersistentState; |
|
117 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
118 |
import org.gvsig.tools.task.Cancellable; |
|
119 |
import org.gvsig.tools.util.Callable; |
|
120 |
import org.slf4j.Logger; |
|
121 |
import org.slf4j.LoggerFactory; |
|
122 |
|
|
123 |
/** |
|
124 |
* <p> |
|
125 |
* Symbol that draws a set of points within a polygon. The amount of points is |
|
126 |
* defined by the field dotCount.<br> |
|
127 |
* </p> |
|
128 |
* <p> |
|
129 |
* This symbol only draws the points. The outline and the fill of the polygon is |
|
130 |
* handled by a SimpleFillSymboll where a DotDensityFillSymbol should be |
|
131 |
* embedded.<br> |
|
132 |
* </p> |
|
133 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
134 |
* |
|
135 |
*/ |
|
136 |
public class DotDensityFillSymbol extends AbstractFillSymbol { |
|
137 |
private static final Logger logger = LoggerFactory.getLogger(DotDensityFillSymbol.class); |
|
138 |
public static final String |
|
139 |
DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME = |
|
140 |
"DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME"; |
|
141 |
|
|
142 |
private int dotCount; |
|
143 |
private double dotSize; |
|
144 |
private double dotSpacing; |
|
145 |
private Color dotColor = Color.BLACK; |
|
146 |
|
|
147 |
private boolean fixedPlacement; |
|
148 |
private PrintRequestAttributeSet properties; |
|
149 |
private GeometryManager geoManager=GeometryLocator.getGeometryManager(); |
|
150 |
|
|
151 |
public DotDensityFillSymbol() { |
|
152 |
super(); |
|
153 |
} |
|
154 |
|
|
155 |
public ISymbol getSymbolForSelection() { |
|
156 |
return this; // the selection color is applied in the SimpleFillSymbol |
|
157 |
} |
|
158 |
|
|
159 |
public void draw(Graphics2D g, AffineTransform atr, |
|
160 |
Geometry theGeom, Feature f, Cancellable cancel) { |
|
161 |
|
|
162 |
try { |
|
163 |
Geometry clo_geo = theGeom.cloneGeometry(); |
|
164 |
clo_geo.transform(atr); |
|
165 |
|
|
166 |
Point interiorPoint=geoManager.createPoint(0, 0, Geometry.SUBTYPES.GEOM2D); |
|
167 |
int maxIntentos = 35; |
|
168 |
int width = clo_geo.getBounds().width; |
|
169 |
int height = clo_geo.getBounds().height; |
|
170 |
int minx = clo_geo.getBounds().x; |
|
171 |
int miny = clo_geo.getBounds().y; |
|
172 |
Random random = new Random(); |
|
173 |
g.setClip(clo_geo.getShape()); |
|
174 |
g.setColor(getDotColor()); |
|
175 |
g.setBackground(null); |
|
176 |
|
|
177 |
int size = (int) dotSize; |
|
178 |
for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < dotCount; i++) { |
|
179 |
int x,y; |
|
180 |
int intentos = 0; |
|
181 |
/* Introducimos este bucle para procurar que los puntos |
|
182 |
* queden dentro del shape. Le ponemos adem?s un |
|
183 |
* numero m?ximo de intentos para evitar las posibilidad de |
|
184 |
* un bucle infinito o excesivamente reiterativo. |
|
185 |
*/ |
|
186 |
do{ |
|
187 |
x = (int) Math.abs(random.nextDouble() * width); |
|
188 |
y = (int) Math.abs(random.nextDouble() * height); |
|
189 |
x = x + minx; |
|
190 |
y = y + miny; |
|
191 |
intentos++; |
|
192 |
interiorPoint.setX(x); |
|
193 |
interiorPoint.setY(y); |
|
194 |
} while (intentos<maxIntentos && !clo_geo.contains(interiorPoint)); |
|
195 |
g.fillRect(x, y, size, size); |
|
196 |
} |
|
197 |
g.setClip(null); |
|
198 |
|
|
199 |
} catch (Exception e) { |
|
200 |
logger.warn("An error has been produced drawing density points for : "+theGeom.toString()); |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
205 |
|
|
206 |
super.saveToState(state); |
|
207 |
|
|
208 |
// color |
|
209 |
Color c = getDotColor(); |
|
210 |
if (c == null) { |
|
211 |
c = Color.BLACK; |
|
212 |
} |
|
213 |
|
|
214 |
state.set("dotColor", c); |
|
215 |
state.set("dotCount", dotCount); |
|
216 |
state.set("dotSize", dotSize); |
|
217 |
state.set("dotSpacing", dotSpacing); |
|
218 |
} |
|
219 |
|
|
220 |
|
|
221 |
public int getSymbolType() { |
|
222 |
return Geometry.TYPES.SURFACE; |
|
223 |
} |
|
224 |
|
|
225 |
public void drawInsideRectangle(Graphics2D g, |
|
226 |
AffineTransform scaleInstance, |
|
227 |
Rectangle r, |
|
228 |
PrintAttributes properties) throws SymbolDrawingException { |
|
229 |
|
|
230 |
int x = r.x; |
|
231 |
int y = r.y; |
|
232 |
int width = r.width; |
|
233 |
int height= r.height; |
|
234 |
int size = height / 5; |
|
235 |
g.setColor(getDotColor()); |
|
236 |
g.setBackground(null); |
|
237 |
g.fillRect((int) (x+width*0.2), (int) (y+height*0.2), size, size); |
|
238 |
g.fillRect((int) (x+width*0.25), (int) (y+height*0.7), size, size); |
|
239 |
g.fillRect((int) (x+width*0.35), (int) (y+height*0.5), size, size); |
|
240 |
g.fillRect((int) (x+width*0.6), (int) (y+height*0.1), size, size); |
|
241 |
g.fillRect((int) (x+width*0.7), (int) (y+height*0.8), size, size); |
|
242 |
g.fillRect((int) (x+width*0.8), (int) (y+height*0.3), size, size); |
|
243 |
g.fillRect((int) (x+width*0.9), (int) (y+height*0.6), size, size); |
|
244 |
} |
|
245 |
|
|
246 |
public void loadFromState(PersistentState state) |
|
247 |
throws PersistenceException { |
|
248 |
|
|
249 |
super.loadFromState(state); |
|
250 |
|
|
251 |
Object obj_col = state.get("dotColor"); |
|
252 |
this.setDotColor((Color) obj_col); |
|
253 |
|
|
254 |
this.setDotCount(state.getInt("dotCount")); |
|
255 |
this.setDotSize(state.getDouble("dotSize")); |
|
256 |
this.setDotSpacing(state.getDouble("dotSpacing")); |
|
257 |
} |
|
258 |
|
|
259 |
|
|
260 |
/** |
|
261 |
* @return |
|
262 |
* @uml.property name="dotCount" |
|
263 |
*/ |
|
264 |
public int getDotCount() { |
|
265 |
return dotCount; |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* @param dotCount |
|
270 |
* @uml.property name="dotCount" |
|
271 |
*/ |
|
272 |
public void setDotCount(int dotCount) { |
|
273 |
this.dotCount = dotCount; |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* @return |
|
278 |
* @uml.property name="dotSize" |
|
279 |
*/ |
|
280 |
public double getDotSize() { |
|
281 |
return dotSize; |
|
282 |
} |
|
283 |
|
|
284 |
public void setDotSize(double dotSize) { |
|
285 |
this.dotSize = dotSize; |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* @return |
|
290 |
* @uml.property name="dotSpacing" |
|
291 |
*/ |
|
292 |
public double getDotSpacing() { |
|
293 |
return dotSpacing; |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* @param dotSpacing |
|
298 |
* @uml.property name="dotSpacing" |
|
299 |
*/ |
|
300 |
public void setDotSpacing(double dotSpacing) { |
|
301 |
this.dotSpacing = dotSpacing; |
|
302 |
} |
|
303 |
|
|
304 |
public Color getDotColor() { |
|
305 |
return dotColor; |
|
306 |
} |
|
307 |
|
|
308 |
public void setDotColor(Color dotColor) { |
|
309 |
this.dotColor = dotColor; |
|
310 |
} |
|
311 |
|
|
312 |
/* (non-Javadoc) |
|
313 |
* @see org.gvsig.fmap.mapcontext.rendering.symbols.IPrintable#print(java.awt.Graphics2D, java.awt.geom.AffineTransform, org.gvsig.fmap.geom.Geometry, org.gvsig.compat.print.PrintAttributes) |
|
314 |
*/ |
|
315 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
|
316 |
PrintAttributes prop) { |
|
317 |
|
|
318 |
// this.properties.=prop; |
|
319 |
draw(g, at, shape, null, null); |
|
320 |
// this.properties=null; |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
public static class RegisterPersistence implements Callable { |
|
325 |
|
|
326 |
public Object call() throws Exception { |
|
327 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
328 |
if( manager.getDefinition( |
|
329 |
DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) { |
|
330 |
DynStruct definition = manager.addDefinition( |
|
331 |
DotDensityFillSymbol.class, |
|
332 |
DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
|
333 |
DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME + |
|
334 |
" Persistence definition", |
|
335 |
null, |
|
336 |
null |
|
337 |
); |
|
338 |
|
|
339 |
// Extend the Symbol base definition |
|
340 |
definition.extend(manager.getDefinition( |
|
341 |
AbstractFillSymbol.FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
|
342 |
|
|
343 |
definition.addDynFieldObject("dotColor").setMandatory(true) |
|
344 |
.setClassOfValue(Color.class); |
|
345 |
definition.addDynFieldInt("dotCount").setMandatory(true); |
|
346 |
definition.addDynFieldDouble("dotSize").setMandatory(true); |
|
347 |
definition.addDynFieldDouble("dotSpacing").setMandatory(true); |
|
348 |
} |
|
349 |
return Boolean.TRUE; |
|
350 |
} |
|
351 |
|
|
352 |
} |
|
353 |
|
|
354 |
|
|
355 |
} |
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.204/src/main/java/org/gvsig/symbology/fmap/rendering/DotDensityLegend.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id: DotDensityLegend.java 14420 2007-10-04 11:23:36Z jvidal $ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.6 2007-09-19 16:25:39 jaume |
|
47 |
* ReadExpansionFileException removed from this context and removed unnecessary imports |
|
48 |
* |
|
49 |
* Revision 1.5 2007/07/25 07:13:34 jaume |
|
50 |
* code style |
|
51 |
* |
|
52 |
* Revision 1.4 2007/05/17 09:32:06 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.3 2007/03/09 11:20:56 jaume |
|
56 |
* Advanced symbology (start committing) |
|
57 |
* |
|
58 |
* Revision 1.2.2.5 2007/02/21 07:34:09 jaume |
|
59 |
* labeling starts working |
|
60 |
* |
|
61 |
* Revision 1.2.2.4 2007/02/15 16:23:44 jaume |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* Revision 1.2.2.3 2007/02/12 15:15:20 jaume |
|
65 |
* refactored interval legend and added graduated symbol legend |
|
66 |
* |
|
67 |
* Revision 1.2.2.2 2007/02/09 07:47:04 jaume |
|
68 |
* Isymbol moved |
|
69 |
* |
|
70 |
* Revision 1.2.2.1 2007/01/26 13:48:17 jaume |
|
71 |
* *** empty log message *** |
|
72 |
* |
|
73 |
* Revision 1.2 2007/01/16 11:50:50 jaume |
|
74 |
* *** empty log message *** |
|
75 |
* |
|
76 |
* Revision 1.1 2007/01/10 16:39:41 jaume |
|
77 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package |
|
78 |
* |
|
79 |
* Revision 1.2 2006/11/17 12:49:58 jaume |
|
80 |
* *** empty log message *** |
|
81 |
* |
|
82 |
* Revision 1.1 2006/11/14 12:30:26 jaume |
|
83 |
* *** empty log message *** |
|
84 |
* |
|
85 |
* |
|
86 |
*/ |
|
87 |
package org.gvsig.symbology.fmap.rendering; |
|
88 |
|
|
89 |
import java.awt.Color; |
|
90 |
|
|
91 |
import org.slf4j.Logger; |
|
92 |
import org.slf4j.LoggerFactory; |
|
93 |
|
|
94 |
import org.gvsig.fmap.dal.feature.Feature; |
|
95 |
import org.gvsig.fmap.geom.Geometry; |
|
96 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
97 |
import org.gvsig.fmap.geom.GeometryManager; |
|
98 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
99 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
100 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
101 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
|
102 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
103 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
|
104 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
105 |
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol; |
|
106 |
import org.gvsig.tools.ToolsLocator; |
|
107 |
import org.gvsig.tools.dynobject.DynStruct; |
|
108 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
109 |
import org.gvsig.tools.persistence.PersistentState; |
|
110 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
111 |
import org.gvsig.tools.util.Callable; |
|
112 |
|
|
113 |
|
|
114 |
/** |
|
115 |
* |
|
116 |
* Implements a legend where the magnitudes of a specific area of the |
|
117 |
* map are represented by the density of the points that are distributed |
|
118 |
* in the surface. |
|
119 |
* |
|
120 |
* |
|
121 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
122 |
*/ |
|
123 |
public class DotDensityLegend extends VectorialUniqueValueLegend { |
|
124 |
|
|
125 |
private static Logger logger = LoggerFactory.getLogger( |
|
126 |
DotDensityLegend.class); |
|
127 |
|
|
128 |
public static final String |
|
129 |
DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME = |
|
130 |
"DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME"; |
|
131 |
public static final String |
|
132 |
DOT_DENSITY_LEGEND_NAME = "DOT_DENSITY_LEGEND_NAME"; |
|
133 |
|
|
134 |
private double dotValue; |
|
135 |
private Color dotColor = Color.BLACK; |
|
136 |
private Color backgroundColor = Color.WHITE; |
|
137 |
private static final int SIMPLE_FILL_LAYER_INDEX = 0; |
|
138 |
private static final int DOT_DENSITY_LAYER_INDEX = 1; |
|
139 |
|
|
140 |
|
|
141 |
public ISymbol getSymbolByValue(Object val) { |
|
142 |
MultiLayerFillSymbol sym = (MultiLayerFillSymbol) getDefaultSymbol(); |
|
143 |
DotDensityFillSymbol densitySym = (DotDensityFillSymbol) sym.getLayer(DOT_DENSITY_LAYER_INDEX); |
|
144 |
|
|
145 |
if (val instanceof Number) { |
|
146 |
Number dou = (Number) val; |
|
147 |
densitySym.setDotCount( |
|
148 |
(int) (dou.doubleValue()/dotValue)); |
|
149 |
return sym; |
|
150 |
} else { |
|
151 |
logger.info("Error: Unexpected value in dot density legend: " + val); |
|
152 |
return null; |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
public ISymbol getSymbolByFeature(Feature feat) { |
|
157 |
|
|
158 |
String[] ff = this.getClassifyingFieldNames(); |
|
159 |
Object val = feat.get(ff[0]); |
|
160 |
return this.getSymbolByValue(val); |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* Establishes the value for the dot used in the dot density legend |
|
165 |
* |
|
166 |
* @param dotValue |
|
167 |
*/ |
|
168 |
public void setDotValue(double dotValue) { |
|
169 |
this.dotValue = dotValue; |
|
170 |
} |
|
171 |
|
|
172 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
173 |
|
|
174 |
super.saveToState(state); |
|
175 |
state.set("dotValue", dotValue); |
|
176 |
state.set("dotColor", getDotColor()); |
|
177 |
state.set("bgColor", getBGColor()); |
|
178 |
} |
|
179 |
|
|
180 |
public void loadFromState(PersistentState state) |
|
181 |
throws PersistenceException { |
|
182 |
|
|
183 |
super.loadFromState(state); |
|
184 |
|
|
185 |
dotValue = state.getDouble("dotValue"); |
|
186 |
Object obj_col = state.get("dotColor"); |
|
187 |
this.setDotColor((Color) obj_col); |
|
188 |
obj_col = state.get("bgColor"); |
|
189 |
this.setBGColor((Color) obj_col); |
|
190 |
} |
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
/** |
|
196 |
* Returns the outline |
|
197 |
* |
|
198 |
* @return |
|
199 |
*/ |
|
200 |
public ILineSymbol getOutline() { |
|
201 |
// defined by the SimpleFillSymbol layer |
|
202 |
ISymbol symbol = getDefaultSymbol(); |
|
203 |
if (!(symbol instanceof IFillSymbol)){ |
|
204 |
return null; |
|
205 |
} |
|
206 |
IFillSymbol fillsym = (IFillSymbol) symbol; |
|
207 |
if (fillsym instanceof MultiLayerFillSymbol){ |
|
208 |
fillsym = (IFillSymbol) ((MultiLayerFillSymbol) fillsym). |
|
209 |
getLayer(SIMPLE_FILL_LAYER_INDEX); |
|
210 |
} |
|
211 |
if (fillsym == null){ |
|
212 |
return null; |
|
213 |
} |
|
214 |
|
|
215 |
return fillsym.getOutline(); |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Returns the color for the dot used in the dot density legend. |
|
220 |
* @return |
|
221 |
*/ |
|
222 |
public Color getDotColor() { |
|
223 |
// try { |
|
224 |
// // defined by the DotDensitySymbol layer |
|
225 |
// DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()). |
|
226 |
// getLayer(DOT_DENSITY_LAYER_INDEX); |
|
227 |
// return sym.getDotColor(); |
|
228 |
// } catch (NullPointerException npE) { |
|
229 |
// return null; |
|
230 |
// } |
|
231 |
return dotColor; |
|
232 |
} |
|
233 |
|
|
234 |
|
|
235 |
/** |
|
236 |
* Sets the color for the dot used in the dot density legend. |
|
237 |
* @return |
|
238 |
*/ |
|
239 |
public void setDotColor(Color color){ |
|
240 |
|
|
241 |
// DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()). |
|
242 |
// getLayer(DOT_DENSITY_LAYER_INDEX); |
|
243 |
// sym.setDotColor(color); |
|
244 |
|
|
245 |
this.dotColor = color; |
|
246 |
|
|
247 |
} |
|
248 |
|
|
249 |
/** |
|
250 |
* Obtains the background color for the dot density legend |
|
251 |
* @return |
|
252 |
*/ |
|
253 |
public Color getBGColor() { |
|
254 |
// try { |
|
255 |
// // defined by the SimpleFillSymbol layer |
|
256 |
// IFillSymbol symbol = (IFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()). |
|
257 |
// getLayer(SIMPLE_FILL_LAYER_INDEX); |
|
258 |
// return symbol.getFillColor(); |
|
259 |
// } catch (NullPointerException npE) { |
|
260 |
// return null; |
|
261 |
// } |
|
262 |
return backgroundColor; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Sets the background color for the dot density legend |
|
267 |
* @return |
|
268 |
*/ |
|
269 |
public void setBGColor(Color color) { |
|
270 |
this.backgroundColor = color; |
|
271 |
} |
|
272 |
/** |
|
273 |
* Returns the value for the dot that is used in the dot density legend |
|
274 |
* @return |
|
275 |
*/ |
|
276 |
public double getDotValue() { |
|
277 |
return this.dotValue; |
|
278 |
} |
|
279 |
/** |
|
280 |
* Obtains the size of the dot that is used in the dot density legend |
|
281 |
* @return |
|
282 |
*/ |
|
283 |
public double getDotSize() { |
|
284 |
|
|
285 |
// defined by the SimpleFillSymbol layer |
|
286 |
ISymbol symbol = getDefaultSymbol(); |
|
287 |
if (symbol == null){ |
|
288 |
return -1; |
|
289 |
} |
|
290 |
if (symbol instanceof DotDensityFillSymbol){ |
|
291 |
return ((DotDensityFillSymbol)symbol).getDotSize(); |
|
292 |
} |
|
293 |
if (!(symbol instanceof IFillSymbol)){ |
|
294 |
return -1; |
|
295 |
} |
|
296 |
IFillSymbol fillsym = (IFillSymbol) symbol; |
|
297 |
if (fillsym instanceof MultiLayerFillSymbol){ |
|
298 |
fillsym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) fillsym). |
|
299 |
getLayer(DOT_DENSITY_LAYER_INDEX); |
|
300 |
} |
|
301 |
if (fillsym instanceof DotDensityFillSymbol){ |
|
302 |
return ((DotDensityFillSymbol)fillsym).getDotSize(); |
|
303 |
} |
|
304 |
return -1; |
|
305 |
|
|
306 |
} |
|
307 |
|
|
308 |
/** |
|
309 |
* Sets the size of the dot that is used in the dot density legend |
|
310 |
*/ |
|
311 |
public void setDotSize(double value) { |
|
312 |
DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()). |
|
313 |
getLayer(DOT_DENSITY_LAYER_INDEX); |
|
314 |
sym.setDotSize(value); |
|
315 |
} |
|
316 |
|
|
317 |
|
|
318 |
public static boolean isPolygonal(int ty) { |
|
319 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
320 |
return geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, ty) || |
|
321 |
geomManager.isSubtype(Geometry.TYPES.SURFACE, ty); |
|
322 |
} |
|
323 |
|
|
324 |
// ============================= |
|
325 |
|
|
326 |
public static class RegisterPersistence implements Callable { |
|
327 |
|
|
328 |
public Object call() throws Exception { |
|
329 |
|
|
330 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
331 |
if (manager.getDefinition( |
|
332 |
DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) { |
|
333 |
DynStruct definition = manager |
|
334 |
.addDefinition(DotDensityLegend.class, |
|
335 |
DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME, |
|
336 |
DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME |
|
337 |
+ " Persistence definition", null, null); |
|
338 |
|
|
339 |
definition.extend(manager.getDefinition( |
|
340 |
VectorialUniqueValueLegend |
|
341 |
.VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
|
342 |
|
|
343 |
definition.addDynFieldDouble("dotValue").setMandatory(true); |
|
344 |
definition.addDynFieldObject("dotColor") |
|
345 |
.setClassOfValue(Color.class).setMandatory(true); |
|
346 |
definition.addDynFieldObject("bgColor") |
|
347 |
.setClassOfValue(Color.class).setMandatory(true); |
|
348 |
} |
|
349 |
return Boolean.TRUE; |
|
350 |
} |
|
351 |
|
|
352 |
} |
|
353 |
|
|
354 |
public static class RegisterLegend implements Callable { |
|
355 |
|
|
356 |
public Object call() throws Exception { |
|
357 |
MapContextManager manager = |
|
358 |
MapContextLocator.getMapContextManager(); |
|
359 |
|
|
360 |
manager.registerLegend( |
|
361 |
DOT_DENSITY_LEGEND_NAME, |
|
362 |
DotDensityLegend.class); |
|
363 |
|
|
364 |
return Boolean.TRUE; |
|
365 |
} |
|
366 |
|
|
367 |
} |
|
368 |
|
|
369 |
public Object clone() throws CloneNotSupportedException { |
|
370 |
|
|
371 |
DotDensityLegend resp = (DotDensityLegend) super.clone(); |
|
372 |
resp.setDotColor(this.getDotColor()); |
|
373 |
resp.setDotSize(this.getDotSize()); |
|
374 |
resp.setDotValue(this.getDotValue()); |
|
375 |
return resp; |
|
376 |
} |
|
377 |
|
|
378 |
|
|
379 |
} |
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.204/src/main/java/org/gvsig/symbology/gui/layerproperties/DotDensityPanel.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id: DotDensity.java 15647 2007-10-30 12:03:52Z jmvivo $ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.11 2007-09-19 15:47:10 jaume |
|
47 |
* refactor name IVectorialLegend -> IVectorLegend and a method name as well |
|
48 |
* |
|
49 |
* Revision 1.10 2007/09/04 14:13:01 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.9 2007/05/21 10:38:27 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.8 2007/05/17 09:32:37 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* Revision 1.7 2007/05/10 09:46:45 jaume |
|
59 |
* Refactored legend interface names |
|
60 |
* |
|
61 |
* Revision 1.6 2007/05/08 15:45:31 jaume |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* Revision 1.5 2007/04/20 07:54:39 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.4 2007/04/20 07:24:56 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* Revision 1.3 2007/04/17 06:53:46 bsanchez |
|
71 |
* - Corregido fallo de Double.MIN_VALUE por Double.NEGATIVE_INFINITY comentado por Victor Olaya. |
|
72 |
* |
|
73 |
* Revision 1.2 2007/03/09 11:25:00 jaume |
|
74 |
* Advanced symbology (start committing) |
|
75 |
* |
|
76 |
* Revision 1.1.2.4 2007/02/21 07:35:14 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* Revision 1.1.2.3 2007/02/12 15:14:41 jaume |
|
80 |
* refactored interval legend and added graduated symbol legend |
|
81 |
* |
|
82 |
* Revision 1.1.2.2 2007/02/09 11:00:03 jaume |
|
83 |
* *** empty log message *** |
|
84 |
* |
|
85 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume |
|
86 |
* *** empty log message *** |
|
87 |
* |
|
88 |
* Revision 1.4 2006/11/17 13:53:45 cesar |
|
89 |
* *** empty log message *** |
|
90 |
* |
|
91 |
* Revision 1.3 2006/11/17 12:50:36 jaume |
|
92 |
* tama๏ฟฝo de punto defecto 2 |
|
93 |
* |
|
94 |
* Revision 1.2 2006/11/15 12:57:31 jaume |
|
95 |
* *** empty log message *** |
|
96 |
* |
|
97 |
* Revision 1.1 2006/11/14 11:10:27 jaume |
|
98 |
* *** empty log message *** |
|
99 |
* |
|
100 |
* |
|
101 |
*/ |
|
102 |
package org.gvsig.symbology.gui.layerproperties; |
|
103 |
|
|
104 |
import java.awt.BorderLayout; |
|
105 |
import java.awt.Color; |
|
106 |
import java.awt.ComponentOrientation; |
|
107 |
import java.awt.Dimension; |
|
108 |
import java.awt.FlowLayout; |
|
109 |
import java.awt.GridLayout; |
|
110 |
import java.awt.LayoutManager; |
|
111 |
import java.awt.event.ActionEvent; |
|
112 |
import java.awt.event.ActionListener; |
|
113 |
import java.awt.event.ItemEvent; |
|
114 |
import java.awt.event.ItemListener; |
|
115 |
import java.text.NumberFormat; |
|
116 |
|
|
117 |
import javax.swing.BorderFactory; |
|
118 |
import javax.swing.BoxLayout; |
|
119 |
import javax.swing.ButtonGroup; |
|
120 |
import javax.swing.Icon; |
|
121 |
import javax.swing.ImageIcon; |
|
122 |
import javax.swing.JComboBox; |
|
123 |
import javax.swing.JLabel; |
|
124 |
import javax.swing.JOptionPane; |
|
125 |
import javax.swing.JPanel; |
|
126 |
import javax.swing.JRadioButton; |
|
127 |
import javax.swing.JSlider; |
|
128 |
import javax.swing.event.ChangeEvent; |
|
129 |
import javax.swing.event.ChangeListener; |
|
130 |
|
|
131 |
import org.slf4j.Logger; |
|
132 |
import org.slf4j.LoggerFactory; |
|
133 |
|
|
134 |
import org.gvsig.andami.IconThemeHelper; |
|
135 |
import org.gvsig.app.ApplicationLocator; |
|
136 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
|
137 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
|
138 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
|
139 |
import org.gvsig.app.project.documents.view.legend.gui.Quantities; |
|
140 |
import org.gvsig.fmap.dal.feature.Feature; |
|
141 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
142 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
143 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
144 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
145 |
import org.gvsig.fmap.geom.Geometry; |
|
146 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
147 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
148 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
149 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
150 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
|
151 |
import org.gvsig.i18n.Messages; |
|
152 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
|
153 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
|
154 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
155 |
import org.gvsig.symbology.fmap.rendering.DotDensityLegend; |
|
156 |
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol; |
|
157 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
158 |
|
|
159 |
/** |
|
160 |
* This panel lets the user choose the dot density legend settings (numeric |
|
161 |
* field, density of points, etc) |
|
162 |
* |
|
163 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
164 |
* @param <JNumberSpinner> |
|
165 |
* |
|
166 |
*/ |
|
167 |
public class DotDensityPanel extends JPanel implements ILegendPanel { |
|
168 |
|
|
169 |
private static Logger logger = LoggerFactory.getLogger(DotDensityPanel.class); |
|
170 |
|
|
171 |
private static final int MAX_VALUE_COUNT = 300; |
|
172 |
private FLyrVect layer; |
|
173 |
private JPanel northPanel = null; |
|
174 |
private GridBagLayoutPanel densityButtonsPanel = null; |
|
175 |
private JPanel pnlDensities = null; |
|
176 |
private JComboBox cmbLegendField = null; |
|
177 |
private JRadioButton rdBtnHigh = null; |
|
178 |
private JRadioButton rdBtnMedium = null; |
|
179 |
private JRadioButton rdBtnLow = null; |
|
180 |
private JNumberSpinner numDotSize = null; |
|
181 |
|
|
182 |
private JNumberSpinner nmbrDotValue = null; |
|
183 |
private JLabel lblLabellingField = null; |
|
184 |
private DotDensityLegend legend; |
|
185 |
|
|
186 |
private String theFieldName; |
|
187 |
private int theFieldType; |
|
188 |
|
|
189 |
private boolean initializing; |
|
190 |
private double max; |
|
191 |
private double maxDotSize = 0; |
|
192 |
private double b, a; // line function params where: y = bx + a |
|
193 |
private int theValueCount; |
|
194 |
|
|
195 |
private NumberFormat nf = NumberFormat.getInstance(); |
|
196 |
|
|
197 |
{ |
|
198 |
nf.setMaximumFractionDigits(3); |
|
199 |
} |
|
200 |
private MyListener cmbAction = new MyListener(); |
|
201 |
|
|
202 |
private class MyListener implements ItemListener, ActionListener { |
|
203 |
|
|
204 |
public void itemStateChanged(ItemEvent e) { |
|
205 |
if (!initializing) { |
|
206 |
doIt(); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
public void actionPerformed(ActionEvent e) { |
|
211 |
if (!initializing) { |
|
212 |
doIt(); |
|
213 |
} |
|
214 |
} |
|
215 |
|
|
216 |
private void doIt() { |
|
217 |
int index = cmbLegendField.getSelectedIndex(); |
|
218 |
try { |
|
219 |
FeatureStore fsto = (FeatureStore) layer.getDataStore(); |
|
220 |
FeatureSet fset = fsto.getFeatureSet(); |
|
221 |
FeatureType fty = fsto.getDefaultFeatureType(); |
|
222 |
|
|
223 |
if (index != -1) { |
|
224 |
theFieldName = (String) cmbLegendField.getSelectedItem(); |
|
225 |
} else { |
|
226 |
theFieldName = (String) cmbLegendField.getItemAt(0); |
|
227 |
} |
|
228 |
|
|
229 |
FeatureAttributeDescriptor att |
|
230 |
= fty.getAttributeDescriptor(theFieldName); |
|
231 |
theFieldType = att.getDataType().getType(); |
|
232 |
|
|
233 |
long vc = 0; |
|
234 |
|
|
235 |
double maxValue = -Double.MAX_VALUE; |
|
236 |
double minValue = Double.MAX_VALUE; |
|
237 |
|
|
238 |
DisposableIterator disp = fset.fastIterator(); |
|
239 |
Feature fitem = null; |
|
240 |
double value = 0; |
|
241 |
|
|
242 |
int i = 0; |
|
243 |
while (i < MAX_VALUE_COUNT && disp.hasNext()) { |
|
244 |
|
|
245 |
fitem = (Feature) disp.next(); |
|
246 |
value = fitem.getDouble(theFieldName); |
|
247 |
if (value < minValue) { |
|
248 |
minValue = value; |
|
249 |
} |
|
250 |
if (value > maxValue) { |
|
251 |
maxValue = value; |
|
252 |
} |
|
253 |
// ========== |
|
254 |
i++; |
|
255 |
} |
|
256 |
disp.dispose(); |
|
257 |
theValueCount = i; |
|
258 |
if (theValueCount == 0) { |
|
259 |
b = 0; |
|
260 |
a = minValue; |
|
261 |
} else { |
|
262 |
b = (maxValue - minValue) / (theValueCount); |
|
263 |
a = minValue; |
|
264 |
} |
|
265 |
buttonsListener.actionPerformed(null); |
|
266 |
|
|
267 |
} catch (Exception ex) { |
|
268 |
logger.info("Error while computing a,b.", ex); |
|
269 |
|
|
270 |
ApplicationLocator.getManager().message( |
|
271 |
Messages.getText("error") |
|
272 |
+ " (" + Messages.getText("dot_density") + ")\n\n" |
|
273 |
+ ex.getMessage(), |
|
274 |
JOptionPane.ERROR_MESSAGE); |
|
275 |
} |
|
276 |
} |
|
277 |
} |
|
278 |
|
|
279 |
private ActionListener buttonsListener = new ActionListener() { |
|
280 |
public void actionPerformed(ActionEvent e) { |
|
281 |
int oldValue = getSldDensity().getValue(); |
|
282 |
int newValue = 0; |
|
283 |
if (getRdBtnHigh().isSelected()) { |
|
284 |
newValue = 33; |
|
285 |
} else if (getRdBtnLow().isSelected()) { |
|
286 |
newValue = 66; |
|
287 |
} else if (getRdBtnMedium().isSelected()) { |
|
288 |
newValue = 50; |
|
289 |
} |
|
290 |
if (oldValue == newValue) { |
|
291 |
sldListener.stateChanged(null); |
|
292 |
} else { |
|
293 |
getSldDensity().setValue(newValue); |
|
294 |
} |
|
295 |
} |
|
296 |
}; |
|
297 |
private JPanel centerPanel = null; |
|
298 |
private JSlider sldDensity = null; |
|
299 |
|
|
300 |
private boolean dotValueChanging = false; |
|
301 |
|
|
302 |
private ChangeListener sldListener = new ChangeListener() { |
|
303 |
public void stateChanged(ChangeEvent e) { |
|
304 |
if (dotValueChanging) { |
|
305 |
return; |
|
306 |
} |
|
307 |
|
|
308 |
dotValueChanging = true; |
|
309 |
double d = sldValueToDotValue(getSldDensity().getValue()); |
|
310 |
nmbrDotValue.setDouble(d); |
|
311 |
dotValueChanging = false; |
|
312 |
} |
|
313 |
|
|
314 |
}; |
|
315 |
|
|
316 |
private ActionListener nmbrDotValueListener = new ActionListener() { |
|
317 |
public void actionPerformed(ActionEvent e) { |
|
318 |
if (dotValueChanging) { |
|
319 |
return; |
|
320 |
} |
|
321 |
|
|
322 |
dotValueChanging = true; |
|
323 |
double dotValue = getNmbrDotValue().getDouble(); |
|
324 |
if (dotValue < 0) { |
|
325 |
dotValue = 0; |
|
326 |
} |
|
327 |
int result = dotValueToSldValue(dotValue); |
|
328 |
getSldDensity().setValue(result); |
|
329 |
dotValueChanging = false; |
|
330 |
} |
|
331 |
}; |
|
332 |
|
|
333 |
private ColorChooserPanel jcc; |
|
334 |
private ILegend oldLegend; |
|
335 |
private JSymbolPreviewButton btnOutline; |
|
336 |
private ColorChooserPanel jccBackground; |
|
337 |
|
|
338 |
public DotDensityPanel() { |
|
339 |
super(); |
|
340 |
initialize(); |
|
341 |
} |
|
342 |
|
|
343 |
/** |
|
344 |
* This method initializes this |
|
345 |
* |
|
346 |
*/ |
|
347 |
private void initialize() { |
|
348 |
this.setLayout(new BorderLayout()); |
|
349 |
this.setSize(new java.awt.Dimension(492, 278)); |
|
350 |
this.add(getNorthPanel(), java.awt.BorderLayout.NORTH); |
|
351 |
this.add(getCenterPanel(), java.awt.BorderLayout.CENTER); |
|
352 |
} |
|
353 |
|
|
354 |
private double sldValueToDotValue(int value) { |
|
355 |
int quantileIndex = (theValueCount * value) / 100; |
|
356 |
double d = (b * quantileIndex + a); // /50; // ?por qu? el 50? |
|
357 |
return d; |
|
358 |
} |
|
359 |
|
|
360 |
private int dotValueToSldValue(double value) { |
|
361 |
int quantileIndex = (int) Math.round((value - a) / b); |
|
362 |
int result = 100 * quantileIndex / theValueCount; |
|
363 |
return result; |
|
364 |
} |
|
365 |
|
|
366 |
public void setData(FLayer lyr, ILegend legend) { |
|
367 |
this.layer = (FLyrVect) lyr; |
|
368 |
this.oldLegend = legend.cloneLegend(); |
|
369 |
|
|
370 |
try { |
|
371 |
// Para evitar los campos no pertenecientes a la fuente original de la capa. |
|
372 |
// SelectableDataSource sds = layer.getSource().getRecordset(); |
|
373 |
// FJP: Otra vez con soporte del join |
|
374 |
// SelectableDataSource sds = layer.getRecordset(); |
|
375 |
FeatureStore fsto = (FeatureStore) layer.getDataStore(); |
|
376 |
FeatureType fty = fsto.getDefaultFeatureType(); |
|
377 |
FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors(); |
|
378 |
|
|
379 |
initializing = true; // silents events to the combo box |
|
380 |
cmbLegendField.removeAllItems(); |
|
381 |
for (int i = 0; i < atts.length; i++) { |
|
382 |
if (atts[i].getDataType().isNumeric()) { |
|
383 |
cmbLegendField.addItem(atts[i].getName()); |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
if (!(legend instanceof DotDensityLegend)) { |
|
388 |
legend = new DotDensityLegend(); |
|
389 |
((DotDensityLegend) legend).setClassifyingFieldNames( |
|
390 |
new String[]{(String) cmbLegendField.getItemAt(0)}); |
|
391 |
((DotDensityLegend) legend).setShapeType(layer.getShapeType()); |
|
392 |
} |
|
393 |
|
|
394 |
DotDensityLegend theLegend = (DotDensityLegend) legend; |
|
395 |
|
|
396 |
initializing = false; // enables events to the combo box |
|
397 |
|
|
398 |
cmbLegendField.setSelectedItem(theLegend.getClassifyingFieldNames()[0]); |
|
399 |
try { |
|
400 |
getDotColorChooserPanel().setColor(theLegend.getDotColor()); |
|
401 |
} catch (NullPointerException npEx) { |
|
402 |
getDotColorChooserPanel().setColor(Color.RED); |
|
403 |
} |
|
404 |
try { |
|
405 |
getBackgroundColorChooserPanel().setColor(theLegend.getBGColor()); |
|
406 |
} catch (NullPointerException npEx) { |
|
407 |
getDotColorChooserPanel().setColor(Color.WHITE); |
|
408 |
} |
|
409 |
|
|
410 |
getBtnOutline().setSymbol(theLegend.getOutline()); |
|
411 |
try { |
|
412 |
double dotValue = theLegend.getDotValue(); |
|
413 |
if (dotValue <= 0) { |
|
414 |
dotValue = sldValueToDotValue(50);//100; |
|
415 |
} |
|
416 |
getNmbrDotValue().setDouble(dotValue); |
|
417 |
dotValueChanging = true; |
|
418 |
getSldDensity().setValue(dotValueToSldValue(dotValue)); |
|
419 |
dotValueChanging = false; |
|
420 |
|
|
421 |
} catch (NullPointerException npEx) { |
|
422 |
getSldDensity().setValue(50); |
|
423 |
} |
|
424 |
try { |
|
425 |
double dotSize = theLegend.getDotSize(); |
|
426 |
if (dotSize <= 0) { |
|
427 |
dotSize = 2; |
|
428 |
} |
|
429 |
getNumDotSize().setDouble(dotSize); |
|
430 |
} catch (NullPointerException npEx) { |
|
431 |
getNumDotSize().setDouble(3); |
|
432 |
} |
|
433 |
|
|
434 |
} catch (Exception e) { |
|
435 |
e.printStackTrace(); |
|
436 |
} |
|
437 |
} |
|
438 |
|
|
439 |
public ILegend getLegend() { |
|
440 |
try { |
|
441 |
int shapeType = layer.getShapeType(); |
|
442 |
|
|
443 |
// shapeType should be always polygon |
|
444 |
if (!DotDensityLegend.isPolygonal(shapeType)) { |
|
445 |
|
|
446 |
ApplicationLocator.getManager().message( |
|
447 |
Messages.getText("cannot_apply_to_a_non_polygon_layer"), |
|
448 |
JOptionPane.ERROR_MESSAGE); |
|
449 |
return null; |
|
450 |
} |
|
451 |
|
|
452 |
// gather values |
|
453 |
double dotValue; |
|
454 |
double dotSize; |
|
455 |
try { |
|
456 |
dotValue = nmbrDotValue.getDouble(); |
|
457 |
} catch (Exception e) { |
|
458 |
dotValue = nmbrDotValue.getDouble(); |
|
459 |
} |
|
460 |
if (dotValue == 0) { |
|
461 |
dotValue = 1; |
|
462 |
} |
|
463 |
try { |
|
464 |
dotSize = numDotSize.getDouble(); |
|
465 |
} catch (Exception e) { |
|
466 |
dotSize = numDotSize.getDouble(); |
|
467 |
} |
|
468 |
|
|
469 |
if (max / dotValue > 50000) { |
|
470 |
int option = JOptionPane.showConfirmDialog(this, |
|
471 |
Messages.getText("looks_like_too_low_value_for_this_field_may_cause_system_to_run_slow"), |
|
472 |
Messages.getText("warning"), |
|
473 |
JOptionPane.OK_CANCEL_OPTION); |
|
474 |
if (option == JOptionPane.CANCEL_OPTION) { |
|
475 |
return oldLegend; |
|
476 |
} |
|
477 |
} |
|
478 |
|
|
479 |
// create the density symbol with the values set above |
|
480 |
DotDensityFillSymbol densitySymbol = new DotDensityFillSymbol(); |
|
481 |
densitySymbol.setDotSize(dotSize); |
|
482 |
densitySymbol.setDotColor(getDotColorChooserPanel().getColor()); |
|
483 |
|
|
484 |
// create a simple-fill symbol over which the dot density will be drawn |
|
485 |
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(); |
|
486 |
fillSymbol.setFillColor(getBackgroundColorChooserPanel().getColor()); |
|
487 |
fillSymbol.setOutline((ILineSymbol) getBtnOutline().getSymbol()); |
|
488 |
|
|
489 |
// combine both the DotDensitySymbol and the SimpleFillSymbol in |
|
490 |
// MultiLayerSymbol so they will be paint as a unique ISymbol |
|
491 |
MultiLayerFillSymbol symbol = new MultiLayerFillSymbol(); |
|
492 |
symbol.setDescription( |
|
493 |
"DotDensitySymbol" + Messages.getText("in_layer") |
|
494 |
+ ": '" + layer.getName() + "'"); |
|
495 |
symbol.addLayer(fillSymbol); |
|
496 |
symbol.addLayer(densitySymbol); |
|
497 |
|
|
498 |
legend = new DotDensityLegend(); |
|
499 |
legend.setClassifyingFieldNames(new String[]{theFieldName}); |
|
500 |
legend.setClassifyingFieldTypes(new int[]{theFieldType}); |
|
501 |
|
|
502 |
legend.addSymbol(0, symbol); |
|
503 |
legend.setDefaultSymbol(symbol); |
|
504 |
legend.setDotValue(dotValue); |
|
505 |
|
|
506 |
legend.setBGColor(getBackgroundColorChooserPanel().getColor()); |
|
507 |
legend.setDotColor(getDotColorChooserPanel().getColor()); |
|
508 |
|
|
509 |
} catch (Exception e) { |
|
510 |
logger.warn(Messages.getText("could_not_setup_legend"), e); |
|
511 |
} |
|
512 |
return legend; |
|
513 |
|
|
514 |
} |
|
515 |
|
|
516 |
/** |
|
517 |
* This method initializes centerPanel |
|
518 |
* |
|
519 |
* @return javax.swing.JPanel |
|
520 |
*/ |
|
521 |
private JPanel getNorthPanel() { |
|
522 |
if (northPanel == null) { |
|
523 |
lblLabellingField = new JLabel(); |
|
524 |
lblLabellingField.setText(Messages.getText("labeling_field") + "."); |
|
525 |
northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 15, 0)); |
|
526 |
northPanel.add(lblLabellingField, null); |
|
527 |
northPanel.add(getCmbLegendField(), null); |
|
528 |
|
|
529 |
} |
|
530 |
return northPanel; |
|
531 |
} |
|
532 |
|
|
533 |
private ColorChooserPanel getDotColorChooserPanel() { |
|
534 |
if (jcc == null) { |
|
535 |
jcc = new ColorChooserPanel(); |
|
536 |
jcc.setAlpha(255); |
|
537 |
} |
|
538 |
return jcc; |
|
539 |
} |
|
540 |
|
|
541 |
/** |
|
542 |
* This method initializes southPanel |
|
543 |
* |
|
544 |
* @return javax.swing.JPanel |
|
545 |
*/ |
|
546 |
private JPanel getDensityButtonsPanel() { |
|
547 |
if (densityButtonsPanel == null) { |
|
548 |
densityButtonsPanel = new GridBagLayoutPanel(); |
|
549 |
LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0, 0); |
|
550 |
JPanel aux = new JPanel(layout); |
|
551 |
aux.add(getNumDotSize()); |
|
552 |
densityButtonsPanel.addComponent( |
|
553 |
Messages.getText("dot_size"), aux); |
|
554 |
aux = new JPanel(layout); |
|
555 |
aux.add(getNmbrDotValue()); |
|
556 |
densityButtonsPanel.addComponent( |
|
557 |
Messages.getText("dot_value"), aux); |
|
558 |
aux = new JPanel(layout); |
|
559 |
aux.add(getDotColorChooserPanel()); |
|
560 |
densityButtonsPanel.addComponent( |
|
561 |
Messages.getText("color"), aux); |
|
562 |
aux = new JPanel(layout); |
|
563 |
aux.add(getBackgroundColorChooserPanel()); |
|
564 |
densityButtonsPanel.addComponent( |
|
565 |
Messages.getText("background_color"), aux); |
|
566 |
aux = new JPanel(layout); |
|
567 |
aux.add(getBtnOutline()); |
|
568 |
densityButtonsPanel.addComponent( |
|
569 |
Messages.getText("outline"), aux); |
|
570 |
} |
|
571 |
return densityButtonsPanel; |
|
572 |
} |
|
573 |
|
|
574 |
private ColorChooserPanel getBackgroundColorChooserPanel() { |
|
575 |
if (jccBackground == null) { |
|
576 |
jccBackground = new ColorChooserPanel(); |
|
577 |
jccBackground.setColor(Color.WHITE); |
|
578 |
jccBackground.setAlpha(255); |
|
579 |
} |
|
580 |
return jccBackground; |
|
581 |
} |
|
582 |
|
|
583 |
private JSymbolPreviewButton getBtnOutline() { |
|
584 |
if (btnOutline == null) { |
|
585 |
btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE); |
|
586 |
btnOutline.setPreferredSize(new Dimension(100, 35)); |
|
587 |
} |
|
588 |
return btnOutline; |
|
589 |
} |
|
590 |
|
|
591 |
/** |
|
592 |
* This method initializes pnlDensities |
|
593 |
* |
|
594 |
* @return javax.swing.JPanel |
|
595 |
*/ |
|
596 |
private JPanel getPnlDensities() { |
|
597 |
if (pnlDensities == null) { |
|
598 |
pnlDensities = new JPanel(new BorderLayout(5, 0)); |
|
599 |
pnlDensities.setBorder(BorderFactory.createTitledBorder(null, |
|
600 |
Messages.getText("densities"))); |
|
601 |
JPanel aux2 = new JPanel(); |
|
602 |
JPanel aux; |
|
603 |
aux = new JPanel(new GridLayout(1, 3)); |
|
604 |
aux.add(new JLabel(Messages.getText("low"))); |
|
605 |
aux.add(new JLabel(Messages.getText("medium"))); |
|
606 |
aux.add(new JLabel(Messages.getText("high"))); |
|
607 |
|
|
608 |
aux2.add(aux); |
|
609 |
|
|
610 |
aux = new JPanel(new GridLayout(1, 3)); |
|
611 |
aux.add(getRdBtnLow()); |
|
612 |
aux.add(getRdBtnMedium()); |
|
613 |
aux.add(getRdBtnHigh()); |
|
614 |
|
|
615 |
aux2.add(aux); |
|
616 |
aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS)); |
|
617 |
|
|
618 |
pnlDensities.add(aux2, BorderLayout.NORTH); |
|
619 |
pnlDensities.add(getSldDensity(), BorderLayout.CENTER); |
|
620 |
pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH); |
|
621 |
|
|
622 |
ButtonGroup group = new ButtonGroup(); |
|
623 |
group.add(getRdBtnHigh()); |
|
624 |
group.add(getRdBtnLow()); |
|
625 |
group.add(getRdBtnMedium()); |
|
626 |
getRdBtnMedium().setSelected(true); |
|
627 |
} |
|
628 |
return pnlDensities; |
|
629 |
} |
|
630 |
|
|
631 |
/** |
|
632 |
* This method initializes cmbLegendField |
|
633 |
* |
|
634 |
* @return javax.swing.JComboBox |
|
635 |
*/ |
|
636 |
private JComboBox getCmbLegendField() { |
|
637 |
if (cmbLegendField == null) { |
|
638 |
cmbLegendField = new JComboBox(); |
|
639 |
cmbLegendField.addActionListener(cmbAction); |
|
640 |
} |
|
641 |
return cmbLegendField; |
|
642 |
} |
|
643 |
|
|
644 |
/** |
|
645 |
* This method initializes rdBtnHigh |
|
646 |
* |
|
647 |
* @return javax.swing.JRadioButton |
|
648 |
*/ |
|
649 |
private JRadioButton getRdBtnHigh() { |
|
650 |
if (rdBtnHigh == null) { |
|
651 |
Icon ic = IconThemeHelper.getImageIcon( |
|
652 |
"legend-dot-density-high-density-sample"); |
|
653 |
rdBtnHigh = new JRadioButton(ic); |
|
654 |
rdBtnHigh.addActionListener(buttonsListener); |
|
655 |
} |
|
656 |
return rdBtnHigh; |
|
657 |
} |
|
658 |
|
|
659 |
/** |
|
660 |
* This method initializes rdBtnMedium |
|
661 |
* |
|
662 |
* @return javax.swing.JRadioButton |
|
663 |
*/ |
|
664 |
private JRadioButton getRdBtnMedium() { |
|
665 |
if (rdBtnMedium == null) { |
|
666 |
Icon ic = IconThemeHelper.getImageIcon( |
|
667 |
"legend-dot-density-medium-density-sample"); |
|
668 |
rdBtnMedium = new JRadioButton(ic); |
|
669 |
rdBtnMedium.addActionListener(buttonsListener); |
|
670 |
} |
|
671 |
return rdBtnMedium; |
|
672 |
} |
|
673 |
|
|
674 |
/** |
|
675 |
* This method initializes rdBtnMax |
|
676 |
* |
Also available in: Unified diff