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