root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / fmap / core / symbols / MarkerFillSymbol.java @ 8658
History | View | Annotate | Download (7.01 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 8658 2006-11-09 18:39:05Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.10 2006-11-09 18:39:05 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.9 2006/11/09 10:22:50 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.8 2006/11/08 13:05:51 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.7 2006/11/08 10:56:47 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.6 2006/11/07 08:52:30 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.5 2006/11/06 17:08:45 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.4 2006/11/06 16:06:52 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.3 2006/11/06 07:33:54 jaume
|
68 |
* javadoc, source style
|
69 |
*
|
70 |
* Revision 1.2 2006/10/31 16:16:34 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1 2006/10/30 19:30:35 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
package com.iver.cit.gvsig.fmap.core.symbols; |
79 |
|
80 |
import java.awt.BasicStroke; |
81 |
import java.awt.Color; |
82 |
import java.awt.Dimension; |
83 |
import java.awt.Graphics2D; |
84 |
import java.awt.Paint; |
85 |
import java.awt.Rectangle; |
86 |
import java.awt.RenderingHints; |
87 |
import java.awt.Shape; |
88 |
import java.awt.TexturePaint; |
89 |
import java.awt.geom.AffineTransform; |
90 |
import java.awt.geom.Point2D; |
91 |
import java.awt.image.BufferedImage; |
92 |
import java.util.ArrayList; |
93 |
|
94 |
import com.iver.cit.gvsig.fmap.core.FShape; |
95 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
96 |
import com.iver.utiles.StringUtilities; |
97 |
import com.iver.utiles.XMLEntity; |
98 |
|
99 |
public class MarkerFillSymbol extends AbstractFillSymbol { |
100 |
private double rotation; |
101 |
private AbstractMarkerSymbol markerSymbol = new CharacterMarkerSymbol(); |
102 |
private boolean grid = true; |
103 |
private double xOffset = 0; |
104 |
private double yOffset = 0; |
105 |
private double xSeparation = 20; |
106 |
private double ySeparation = 20; |
107 |
|
108 |
public boolean isGrid() { |
109 |
return grid;
|
110 |
} |
111 |
|
112 |
public void setGrid(boolean grid) { |
113 |
this.grid = grid;
|
114 |
} |
115 |
|
116 |
public AbstractMarkerSymbol getMarkerSymbol() {
|
117 |
return markerSymbol;
|
118 |
} |
119 |
|
120 |
public void setMarkerSymbol(AbstractMarkerSymbol markerSymbol) { |
121 |
this.markerSymbol = markerSymbol;
|
122 |
} |
123 |
|
124 |
public double getRotation() { |
125 |
return rotation;
|
126 |
} |
127 |
|
128 |
public void setRotation(double rotation) { |
129 |
this.rotation = rotation;
|
130 |
} |
131 |
|
132 |
public double getXOffset() { |
133 |
return xOffset;
|
134 |
} |
135 |
|
136 |
public void setXOffset(double offset) { |
137 |
xOffset = offset; |
138 |
} |
139 |
|
140 |
public double getXSeparation() { |
141 |
return xSeparation;
|
142 |
} |
143 |
|
144 |
public void setXSeparation(double separation) { |
145 |
xSeparation = separation; |
146 |
} |
147 |
|
148 |
public double getYOffset() { |
149 |
return yOffset;
|
150 |
} |
151 |
|
152 |
public void setYOffset(double offset) { |
153 |
yOffset = offset; |
154 |
} |
155 |
|
156 |
public double getYSeparation() { |
157 |
return ySeparation;
|
158 |
} |
159 |
|
160 |
public void setYSeparation(double separation) { |
161 |
ySeparation = separation; |
162 |
} |
163 |
|
164 |
public ISymbol getSymbolForSelection() {
|
165 |
// TODO Auto-generated method stub
|
166 |
throw new Error("Not yet implemented!"); |
167 |
} |
168 |
|
169 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
170 |
g.setColor(null);
|
171 |
g.setStroke(new BasicStroke(0)); |
172 |
int w=7; |
173 |
int h=7; |
174 |
|
175 |
BufferedImage bi = null; |
176 |
|
177 |
|
178 |
Rectangle rProv = new Rectangle(); |
179 |
rProv.setFrame(0, 0,w,h); |
180 |
|
181 |
Paint resulPatternFill = null; |
182 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
183 |
Graphics2D gAux = bi.createGraphics();
|
184 |
markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv); |
185 |
resulPatternFill = new TexturePaint(bi,rProv); |
186 |
g.setColor(null);
|
187 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
188 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
189 |
|
190 |
g.setPaint(resulPatternFill); |
191 |
g.fill(shp); |
192 |
//g.draw(shp);
|
193 |
if (layers!=null) { |
194 |
for (int i = 0; i < layers.length; i++) { |
195 |
layers[i].draw(g, affineTransform, shp); |
196 |
} |
197 |
} |
198 |
} |
199 |
|
200 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
201 |
// TODO Auto-generated method stub
|
202 |
throw new Error("Not yet implemented!"); |
203 |
} |
204 |
|
205 |
public XMLEntity getXMLEntity() {
|
206 |
XMLEntity xml = new XMLEntity();
|
207 |
xml.putProperty("className", getClassName());
|
208 |
// color
|
209 |
xml.putProperty("color", StringUtilities.color2String(color));
|
210 |
|
211 |
xml.putProperty("rotation", rotation);
|
212 |
xml.putProperty("grid", grid);
|
213 |
xml.putProperty("xOffset", xOffset);
|
214 |
xml.putProperty("yOffset", yOffset);
|
215 |
xml.putProperty("xSeparation", xSeparation);
|
216 |
xml.putProperty("ySeparation", ySeparation);
|
217 |
|
218 |
xml.addChild(markerSymbol.getXMLEntity()); |
219 |
return xml;
|
220 |
} |
221 |
|
222 |
public int getSymbolType() { |
223 |
// TODO Auto-generated method stub
|
224 |
throw new Error("Not yet implemented!"); |
225 |
} |
226 |
|
227 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
228 |
if (isGrid()) {
|
229 |
// Use a TexturePaint
|
230 |
int w=7; |
231 |
int h=7; |
232 |
|
233 |
BufferedImage bi = null; |
234 |
|
235 |
Rectangle rProv = new Rectangle(); |
236 |
rProv.setFrame(0, 0,w,h); |
237 |
|
238 |
Paint resulPatternFill = null; |
239 |
bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); |
240 |
Graphics2D gAux = bi.createGraphics();
|
241 |
markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv); |
242 |
resulPatternFill = new TexturePaint(bi,rProv); |
243 |
g.setColor(null);
|
244 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
245 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
246 |
|
247 |
g.setPaint(resulPatternFill); |
248 |
g.fill(r); |
249 |
g.drawRect(0, 0, r.width, r.height); |
250 |
} else {
|
251 |
Point2D[] points = ramdonizePoints(r); |
252 |
for (int i = 0; i < points.length; i++) { |
253 |
|
254 |
} |
255 |
} |
256 |
} |
257 |
|
258 |
private Point2D[] ramdonizePoints(Rectangle r) { |
259 |
ArrayList points = new ArrayList(); |
260 |
throw new Error("Not yet implemented!"); |
261 |
// return (Point2D[]) points.toArray(new Point2D[0]);
|
262 |
} |
263 |
|
264 |
public String getClassName() { |
265 |
return getClass().getName();
|
266 |
} |
267 |
|
268 |
public void setXMLEntity(XMLEntity xml) { |
269 |
rotation = xml.getDoubleProperty("rotation");
|
270 |
grid = xml.getBooleanProperty("grid");
|
271 |
xOffset = xml.getDoubleProperty("xOffset");
|
272 |
yOffset = xml.getDoubleProperty("yOffset");
|
273 |
xSeparation = xml.getDoubleProperty("xSeparation");
|
274 |
ySeparation = xml.getDoubleProperty("ySeparation");
|
275 |
markerSymbol = (AbstractMarkerSymbol) SymbolFactory. |
276 |
createFromXML(xml.getChild(0), null); |
277 |
} |
278 |
|
279 |
public void setMarker(AbstractMarkerSymbol marker) { |
280 |
this.markerSymbol = marker;
|
281 |
} |
282 |
|
283 |
} |