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