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