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