Revision 824
org.gvsig.legend.dotdensity.app.mainplugin/trunk/org.gvsig.legend.dotdensity.app.mainplugin/src/main/java/org/gvsig/symbology/fmap/symbols/DotDensityFillSymbol.java | ||
---|---|---|
103 | 103 |
import org.gvsig.compat.print.PrintAttributes; |
104 | 104 |
import org.gvsig.fmap.dal.feature.Feature; |
105 | 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; |
|
106 | 110 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
107 | 111 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
108 | 112 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol; |
... | ... | |
142 | 146 |
|
143 | 147 |
private boolean fixedPlacement; |
144 | 148 |
private PrintRequestAttributeSet properties; |
149 |
private GeometryManager geoManager=GeometryLocator.getGeometryManager(); |
|
145 | 150 |
|
146 | 151 |
public DotDensityFillSymbol() { |
147 | 152 |
super(); |
... | ... | |
158 | 163 |
Geometry clo_geo = theGeom.cloneGeometry(); |
159 | 164 |
clo_geo.transform(atr); |
160 | 165 |
|
166 |
Point interiorPoint=geoManager.createPoint(0, 0, Geometry.SUBTYPES.GEOM2D); |
|
161 | 167 |
int maxIntentos = 35; |
162 | 168 |
int width = clo_geo.getBounds().width; |
163 | 169 |
int height = clo_geo.getBounds().height; |
... | ... | |
167 | 173 |
g.setClip(clo_geo.getShape()); |
168 | 174 |
g.setColor(getDotColor()); |
169 | 175 |
g.setBackground(null); |
176 |
|
|
170 | 177 |
int size = (int) dotSize; |
171 | 178 |
for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < dotCount; i++) { |
172 |
int x,y; |
|
173 |
int intentos = 0; |
|
174 |
/* Introducimos este bucle para procurar que los puntos |
|
175 |
* queden dentro del shape. Le ponemos adem?s un |
|
176 |
* numero m?ximo de intentos para evitar las posibilidad de |
|
177 |
* un bucle infinito o excesivamente reiterativo. |
|
178 |
*/ |
|
179 |
do{ |
|
180 |
x = (int) Math.abs(random.nextDouble() * width); |
|
181 |
y = (int) Math.abs(random.nextDouble() * height); |
|
182 |
x = x + minx; |
|
183 |
y = y + miny; |
|
184 |
intentos++; |
|
185 |
} while (intentos<maxIntentos && !clo_geo.contains(x, y)); |
|
186 |
g.fillRect(x, y, size, size); |
|
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); |
|
187 | 196 |
} |
188 | 197 |
g.setClip(null); |
198 |
|
|
189 | 199 |
} catch (Exception e) { |
190 | 200 |
logger.warn("An error has been produced drawing density points for : "+theGeom.toString()); |
191 | 201 |
} |
Also available in: Unified diff