root / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / symbols / DotDensityFillSymbol.java @ 20768
History | View | Annotate | Download (7.64 KB)
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 com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
104 |
import com.iver.cit.gvsig.fmap.core.FShape; |
105 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractFillSymbol; |
106 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
107 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
108 |
import com.iver.utiles.StringUtilities; |
109 |
import com.iver.utiles.XMLEntity; |
110 |
import com.iver.utiles.swing.threads.Cancellable; |
111 |
|
112 |
/**
|
113 |
* <p>
|
114 |
* Symbol that draws a set of points within a polygon. The amount of points is
|
115 |
* defined by the field dotCount.<br>
|
116 |
* </p>
|
117 |
* <p>
|
118 |
* This symbol only draws the points. The outline and the fill of the polygon is
|
119 |
* handled by a SimpleFillSymboll where a DotDensityFillSymbol should be
|
120 |
* embedded.<br>
|
121 |
* </p>
|
122 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
123 |
*
|
124 |
*/
|
125 |
public class DotDensityFillSymbol extends AbstractFillSymbol { |
126 |
private int dotCount; |
127 |
private double dotSize; |
128 |
private double dotSpacing; |
129 |
private Color dotColor; |
130 |
private boolean fixedPlacement; |
131 |
|
132 |
public DotDensityFillSymbol() {
|
133 |
super();
|
134 |
} |
135 |
|
136 |
public ISymbol getSymbolForSelection() {
|
137 |
return this; // the selection color is applied in the SimpleFillSymbol |
138 |
} |
139 |
|
140 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) { |
141 |
int width = shp.getBounds().width;
|
142 |
int height = shp.getBounds().height;
|
143 |
int minx = shp.getBounds().x;
|
144 |
int miny = shp.getBounds().y;
|
145 |
Random random = new Random(); |
146 |
g.setClip(shp); |
147 |
g.setColor(getDotColor()); |
148 |
g.setBackground(null);
|
149 |
int size = (int) dotSize; |
150 |
for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < dotCount; i++) { |
151 |
int x = (int) Math.abs(random.nextDouble() * width); |
152 |
int y = (int) Math.abs(random.nextDouble() * height); |
153 |
x = x + minx; |
154 |
y = y + miny; |
155 |
g.fillRect(x, y, size, size); |
156 |
} |
157 |
g.setClip(null);
|
158 |
} |
159 |
|
160 |
|
161 |
public XMLEntity getXMLEntity() {
|
162 |
XMLEntity xml = new XMLEntity();
|
163 |
xml.putProperty("className", getClassName());
|
164 |
|
165 |
// color
|
166 |
Color c = getDotColor();
|
167 |
if (c!= null) |
168 |
xml.putProperty("color", StringUtilities.color2String(getDotColor()));
|
169 |
|
170 |
// description
|
171 |
xml.putProperty("desc", getDescription());
|
172 |
|
173 |
// is shape visible
|
174 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
175 |
|
176 |
// dot count
|
177 |
xml.putProperty("dotCount", dotCount);
|
178 |
|
179 |
// dot size
|
180 |
xml.putProperty("dotSize", dotSize);
|
181 |
|
182 |
// dot spacing
|
183 |
xml.putProperty("dotSpacing", dotSpacing);
|
184 |
|
185 |
xml.putProperty("referenceSystem", getReferenceSystem());
|
186 |
xml.putProperty("unit", getUnit());
|
187 |
|
188 |
return xml;
|
189 |
} |
190 |
|
191 |
public int getSymbolType() { |
192 |
return FShape.POLYGON;
|
193 |
} |
194 |
|
195 |
public void drawInsideRectangle(Graphics2D g, |
196 |
AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException { |
197 |
int x = r.x;
|
198 |
int y = r.y;
|
199 |
int width = r.width;
|
200 |
int height= r.height;
|
201 |
int size = height / 5; |
202 |
g.setColor(getDotColor()); |
203 |
g.setBackground(null);
|
204 |
g.fillRect((int) (x+width*0.2), (int) (y+height*0.2), size, size); |
205 |
g.fillRect((int) (x+width*0.25), (int) (y+height*0.7), size, size); |
206 |
g.fillRect((int) (x+width*0.35), (int) (y+height*0.5), size, size); |
207 |
g.fillRect((int) (x+width*0.6), (int) (y+height*0.1), size, size); |
208 |
g.fillRect((int) (x+width*0.7), (int) (y+height*0.8), size, size); |
209 |
g.fillRect((int) (x+width*0.8), (int) (y+height*0.3), size, size); |
210 |
g.fillRect((int) (x+width*0.9), (int) (y+height*0.6), size, size); |
211 |
} |
212 |
|
213 |
public String getClassName() { |
214 |
return getClass().getName();
|
215 |
} |
216 |
|
217 |
public void setXMLEntity(XMLEntity xml) { |
218 |
// color
|
219 |
if (xml.contains("color")) |
220 |
setDotColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
221 |
|
222 |
// description
|
223 |
setDescription(xml.getStringProperty("desc"));
|
224 |
|
225 |
// is shape visible
|
226 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
227 |
|
228 |
// dot count
|
229 |
dotCount = xml.getIntProperty("dotCount");
|
230 |
|
231 |
// dot size
|
232 |
dotSize = xml.getDoubleProperty("dotSize");
|
233 |
|
234 |
// dot spacing
|
235 |
dotSpacing = xml.getDoubleProperty("dotSpacing");
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* @return
|
240 |
* @uml.property name="dotCount"
|
241 |
*/
|
242 |
public int getDotCount() { |
243 |
return dotCount;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* @param dotCount
|
248 |
* @uml.property name="dotCount"
|
249 |
*/
|
250 |
public void setDotCount(int dotCount) { |
251 |
this.dotCount = dotCount;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* @return
|
256 |
* @uml.property name="dotSize"
|
257 |
*/
|
258 |
public double getDotSize() { |
259 |
return dotSize;
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* @param dotSize
|
264 |
* @uml.property name="dotSize"
|
265 |
*/
|
266 |
public void setDotSize(double dotSize) { |
267 |
this.dotSize = dotSize;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* @return
|
272 |
* @uml.property name="dotSpacing"
|
273 |
*/
|
274 |
public double getDotSpacing() { |
275 |
return dotSpacing;
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* @param dotSpacing
|
280 |
* @uml.property name="dotSpacing"
|
281 |
*/
|
282 |
public void setDotSpacing(double dotSpacing) { |
283 |
this.dotSpacing = dotSpacing;
|
284 |
} |
285 |
|
286 |
public Color getDotColor() { |
287 |
return dotColor;
|
288 |
} |
289 |
|
290 |
public void setDotColor(Color dotColor) { |
291 |
this.dotColor = dotColor;
|
292 |
} |
293 |
|
294 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) throws ReadDriverException { |
295 |
// TODO Implement it
|
296 |
throw new Error("Not yet implemented!"); |
297 |
|
298 |
} |
299 |
|
300 |
} |