root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MarkerFillSymbol.java @ 11486
History | View | Annotate | Download (10 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: MarkerFillSymbol.java 11486 2007-05-08 08:47:40Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.9 2007-05-08 08:47:40 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.8 2007/03/28 16:48:14 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.7 2007/03/26 14:25:17 jaume
|
53 |
* implements IPrintable
|
54 |
*
|
55 |
* Revision 1.6 2007/03/21 17:36:22 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.5 2007/03/13 16:58:36 jaume
|
59 |
* Added QuantityByCategory (Multivariable legend) and some bugfixes in symbols
|
60 |
*
|
61 |
* Revision 1.4 2007/03/09 11:20:57 jaume
|
62 |
* Advanced symbology (start committing)
|
63 |
*
|
64 |
* Revision 1.2.2.4 2007/02/16 10:54:12 jaume
|
65 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
66 |
*
|
67 |
* Revision 1.2.2.3 2007/02/15 16:23:44 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.2.2.2 2007/02/12 15:15:20 jaume
|
71 |
* refactored interval legend and added graduated symbol legend
|
72 |
*
|
73 |
* Revision 1.2.2.1 2007/02/09 07:47:05 jaume
|
74 |
* Isymbol moved
|
75 |
*
|
76 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
77 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
78 |
*
|
79 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.10 2006/11/09 18:39:05 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.9 2006/11/09 10:22:50 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.8 2006/11/08 13:05:51 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.7 2006/11/08 10:56:47 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.6 2006/11/07 08:52:30 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.5 2006/11/06 17:08:45 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.4 2006/11/06 16:06:52 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.3 2006/11/06 07:33:54 jaume
|
104 |
* javadoc, source style
|
105 |
*
|
106 |
* Revision 1.2 2006/10/31 16:16:34 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.1 2006/10/30 19:30:35 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
*
|
113 |
*/
|
114 |
package com.iver.cit.gvsig.fmap.core.symbols; |
115 |
|
116 |
import java.awt.Graphics2D; |
117 |
import java.awt.Paint; |
118 |
import java.awt.Rectangle; |
119 |
import java.awt.RenderingHints; |
120 |
import java.awt.Shape; |
121 |
import java.awt.TexturePaint; |
122 |
import java.awt.geom.AffineTransform; |
123 |
import java.awt.geom.Point2D; |
124 |
import java.awt.image.BufferedImage; |
125 |
import java.util.ArrayList; |
126 |
import java.util.Random; |
127 |
|
128 |
import javax.print.attribute.PrintRequestAttributeSet; |
129 |
|
130 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
131 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
132 |
import com.iver.cit.gvsig.fmap.core.FShape; |
133 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
134 |
import com.iver.cit.gvsig.fmap.core.styles.IMarkerFillProperties; |
135 |
import com.iver.cit.gvsig.fmap.core.styles.MarkerFillProperties; |
136 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
137 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
138 |
import com.iver.utiles.StringUtilities; |
139 |
import com.iver.utiles.XMLEntity; |
140 |
import com.vividsolutions.jts.geom.Geometry; |
141 |
|
142 |
/**
|
143 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
144 |
*/
|
145 |
public class MarkerFillSymbol extends AbstractFillSymbol { |
146 |
public static final int RANDOM_FILL = 3; |
147 |
public static final int GRID_FILL = 1; |
148 |
public static final int SINGLE_CENTERED_SYMBOL = 2; |
149 |
private MarkerFillSymbol selectionSymbol;
|
150 |
private IMarkerFillProperties markerFillStyle = new MarkerFillProperties(); |
151 |
private IMarkerSymbol markerSymbol = new SimpleMarkerSymbol(); |
152 |
private int fillStyle; |
153 |
|
154 |
|
155 |
|
156 |
public ISymbol getSymbolForSelection() {
|
157 |
if (selectionSymbol == null) { |
158 |
selectionSymbol = (MarkerFillSymbol) SymbologyFactory.createSymbolFromXML(getXMLEntity(), null);
|
159 |
selectionSymbol.setFillColor(FSymbol.getSelectionColor()); |
160 |
} |
161 |
|
162 |
return selectionSymbol;
|
163 |
} |
164 |
|
165 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
166 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
167 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
168 |
|
169 |
switch (getFillStyle()) {
|
170 |
case SINGLE_CENTERED_SYMBOL:
|
171 |
// case a single marker is used into a polygon shapetype
|
172 |
Geometry geom = FConverter.java2d_to_jts(shp); |
173 |
com.vividsolutions.jts.geom.Point centroid = geom.getCentroid(); |
174 |
FPoint2D p = new FPoint2D(new Point2D.Double( |
175 |
centroid.getX()+markerFillStyle.getXOffset(), |
176 |
centroid.getY()+markerFillStyle.getYOffset())); |
177 |
markerSymbol.draw(g, affineTransform, p); |
178 |
break;
|
179 |
case GRID_FILL:
|
180 |
// case a grid fill is used
|
181 |
{ |
182 |
|
183 |
int s = (int) markerSymbol.getSize(); |
184 |
Rectangle rProv = new Rectangle(); |
185 |
rProv.setFrame(0, 0, s, s); |
186 |
Paint resulPatternFill = null; |
187 |
BufferedImage bi = null; |
188 |
bi= new BufferedImage(s, s, BufferedImage.TYPE_INT_ARGB); |
189 |
Graphics2D gAux = bi.createGraphics();
|
190 |
markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv); |
191 |
resulPatternFill = new TexturePaint(bi,rProv); |
192 |
g.setColor(null);
|
193 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
194 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
195 |
g.setPaint(resulPatternFill); |
196 |
g.fill(shp); |
197 |
|
198 |
} |
199 |
break;
|
200 |
case RANDOM_FILL:
|
201 |
{ |
202 |
double s = markerSymbol.getSize();
|
203 |
Rectangle r = shp.getBounds();
|
204 |
int drawCount = (int) (Math.min(r.getWidth(), r.getHeight())/s); |
205 |
Random random = new Random(); |
206 |
|
207 |
int minx = r.x;
|
208 |
int miny = r.y;
|
209 |
int width = r.width;
|
210 |
int height = r.height;
|
211 |
|
212 |
r = new Rectangle(); |
213 |
g.setClip(shp); |
214 |
|
215 |
for (int i = 0; i < drawCount; i++) { |
216 |
int x = (int) Math.abs(random.nextDouble() * width); |
217 |
int y = (int) Math.abs(random.nextDouble() * height); |
218 |
x = x + minx; |
219 |
y = y + miny; |
220 |
markerSymbol.draw(g, new AffineTransform(), new FPoint2D(x, y)); |
221 |
|
222 |
} |
223 |
g.setClip(null);
|
224 |
} |
225 |
break;
|
226 |
} |
227 |
} |
228 |
|
229 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
230 |
// TODO Auto-generated method stub
|
231 |
throw new Error("Not yet implemented!"); |
232 |
} |
233 |
|
234 |
public XMLEntity getXMLEntity() {
|
235 |
XMLEntity xml = new XMLEntity();
|
236 |
xml.putProperty("className", getClassName());
|
237 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
238 |
// color (necessite)
|
239 |
if (getFillColor() !=null) |
240 |
xml.putProperty("color", StringUtilities.color2String(getFillColor()));
|
241 |
xml.putProperty("desc", getDescription());
|
242 |
xml.putProperty("fillStyle", fillStyle);
|
243 |
|
244 |
xml.addChild(markerSymbol.getXMLEntity()); |
245 |
xml.addChild(markerFillStyle.getXMLEntity()); |
246 |
return xml;
|
247 |
} |
248 |
|
249 |
public int getSymbolType() { |
250 |
return FShape.POLYGON;
|
251 |
} |
252 |
|
253 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
254 |
markerFillStyle.setSampleSymbol(markerSymbol); |
255 |
switch (fillStyle) {
|
256 |
case SINGLE_CENTERED_SYMBOL:
|
257 |
FPoint2D p = new FPoint2D(r.getCenterX(), r.getCenterY());
|
258 |
markerSymbol.draw(g, null, p);
|
259 |
break;
|
260 |
case GRID_FILL:
|
261 |
{ |
262 |
int size = (int) markerSymbol.getSize(); |
263 |
|
264 |
Rectangle rProv = new Rectangle(); |
265 |
|
266 |
rProv.setFrame(0, 0,size,size); |
267 |
Paint resulPatternFill = null; |
268 |
BufferedImage bi = null; |
269 |
bi= new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); |
270 |
Graphics2D gAux = bi.createGraphics();
|
271 |
markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv); |
272 |
resulPatternFill = new TexturePaint(bi,rProv); |
273 |
g.setColor(null);
|
274 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
275 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
276 |
g.setPaint(resulPatternFill); |
277 |
g.fill(r); |
278 |
} |
279 |
break;
|
280 |
case RANDOM_FILL:
|
281 |
int x = r.x;
|
282 |
int y = r.y;
|
283 |
int width = r.width;
|
284 |
int height= r.height;
|
285 |
g.setBackground(null);
|
286 |
|
287 |
markerSymbol.draw(g, null, new FPoint2D((x+width*0.2), (y+height*0.8))); |
288 |
markerSymbol.draw(g, null, new FPoint2D((x+width*0.634), (y+height*0.3))); |
289 |
markerSymbol.draw(g, null, new FPoint2D((x+width*0.26), (y+height*0.35))); |
290 |
markerSymbol.draw(g, null, new FPoint2D((x+width*0.45), (y+height*0.98))); |
291 |
markerSymbol.draw(g, null, new FPoint2D((x+width*0.9), (y+height*0.54))); |
292 |
markerSymbol.draw(g, null, new FPoint2D((x+width*1.1), (y+height*0.7))); |
293 |
break;
|
294 |
} |
295 |
} |
296 |
|
297 |
private Point2D[] ramdonizePoints(Rectangle r) { |
298 |
ArrayList points = new ArrayList(); |
299 |
throw new Error("Not yet implemented!"); |
300 |
// return (Point2D[]) points.toArray(new Point2D[0]);
|
301 |
} |
302 |
|
303 |
public int getFillStyle() { |
304 |
return fillStyle;
|
305 |
} |
306 |
|
307 |
public void setFillStyle(int fillStyle) { |
308 |
this.fillStyle = fillStyle;
|
309 |
} |
310 |
public String getClassName() { |
311 |
return getClass().getName();
|
312 |
} |
313 |
|
314 |
public void setXMLEntity(XMLEntity xml) { |
315 |
setDescription(xml.getStringProperty("desc"));
|
316 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
317 |
fillStyle = xml.getIntProperty("fillStyle");
|
318 |
|
319 |
markerSymbol = (AbstractMarkerSymbol) SymbologyFactory. |
320 |
createSymbolFromXML(xml.getChild(0), null); |
321 |
markerFillStyle = (MarkerFillProperties) SymbologyFactory. |
322 |
createStyleFromXML(xml.getChild(1), null); |
323 |
} |
324 |
|
325 |
public void setMarker(IMarkerSymbol marker) { |
326 |
this.markerSymbol = marker;
|
327 |
} |
328 |
|
329 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) throws ReadDriverException { |
330 |
// TODO Implement it
|
331 |
throw new Error("Not yet implemented!"); |
332 |
|
333 |
} |
334 |
|
335 |
public void setMarkerFillStyle(IMarkerFillProperties markerFillStyle) { |
336 |
this.markerFillStyle = markerFillStyle;
|
337 |
} |
338 |
|
339 |
public IMarkerFillProperties getFillProperties() {
|
340 |
return markerFillStyle;
|
341 |
} |
342 |
|
343 |
} |