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