svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / DotDensityFillSymbol.java @ 10315
History | View | Annotate | Download (6.21 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: DotDensityFillSymbol.java 10225 2007-02-09 07:47:05Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3.2.1 2007-02-09 07:47:04 jaume
|
47 |
* Isymbol moved
|
48 |
*
|
49 |
* Revision 1.3 2007/01/12 10:08:26 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
53 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
54 |
*
|
55 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.4 2006/11/14 11:10:27 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.3 2006/11/13 09:15:23 jaume
|
62 |
* javadoc and some clean-up
|
63 |
*
|
64 |
* Revision 1.2 2006/11/09 18:39:05 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1 2006/11/09 10:22:50 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
package com.iver.cit.gvsig.fmap.core.symbols; |
73 |
|
74 |
import java.awt.Color; |
75 |
import java.awt.Graphics2D; |
76 |
import java.awt.Point; |
77 |
import java.awt.Rectangle; |
78 |
import java.awt.Shape; |
79 |
import java.awt.geom.AffineTransform; |
80 |
import java.util.Random; |
81 |
|
82 |
import com.iver.cit.gvsig.fmap.DriverException; |
83 |
import com.iver.cit.gvsig.fmap.core.FShape; |
84 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
85 |
import com.iver.utiles.StringUtilities; |
86 |
import com.iver.utiles.XMLEntity; |
87 |
|
88 |
/**
|
89 |
* <p>
|
90 |
* Symbol that draws a set of points within a polygon. The amount of points is
|
91 |
* defined by the field dotCount.<br>
|
92 |
* </p>
|
93 |
* <p>
|
94 |
* This symbol only draws the points. The outline and the fill of the polygon is
|
95 |
* handled by a SimpleFillSymboll where a DotDensityFillSymbol should be
|
96 |
* embedded.<br>
|
97 |
* </p>
|
98 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
99 |
*
|
100 |
*/
|
101 |
public class DotDensityFillSymbol extends AbstractFillSymbol { |
102 |
private int dotCount; |
103 |
private double dotSize; |
104 |
private double dotSpacing; |
105 |
private boolean fixedPlacement; |
106 |
|
107 |
public DotDensityFillSymbol() {
|
108 |
super();
|
109 |
} |
110 |
|
111 |
public ISymbol getSymbolForSelection() {
|
112 |
return this; // the selection color is applied in the SimpleFillSymbol |
113 |
} |
114 |
|
115 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
116 |
int width = shp.getBounds().width;
|
117 |
int height = shp.getBounds().height;
|
118 |
int minx = shp.getBounds().x;
|
119 |
int miny = shp.getBounds().y;
|
120 |
Random random = new Random(); |
121 |
g.setClip(shp); |
122 |
g.setColor(color); |
123 |
g.setBackground(null);
|
124 |
int size = (int) dotSize; |
125 |
for (int i = 0; i < dotCount; i++) { |
126 |
int x = (int) Math.abs(random.nextDouble() * width); |
127 |
int y = (int) Math.abs(random.nextDouble() * height); |
128 |
x = x + minx; |
129 |
y = y + miny; |
130 |
g.fillRect(x, y, size, size); |
131 |
} |
132 |
g.setClip(null);
|
133 |
} |
134 |
|
135 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
136 |
Shape shp) {
|
137 |
// TODO Auto-generated method stub
|
138 |
throw new Error("Not yet implemented!"); |
139 |
} |
140 |
|
141 |
public XMLEntity getXMLEntity() {
|
142 |
XMLEntity xml = new XMLEntity();
|
143 |
xml.putProperty("className", getClassName());
|
144 |
|
145 |
// color
|
146 |
xml.putProperty("color", StringUtilities.color2String(color));
|
147 |
|
148 |
// description
|
149 |
xml.putProperty("desc", getDescription());
|
150 |
|
151 |
// is shape visible
|
152 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
153 |
|
154 |
// dot count
|
155 |
xml.putProperty("dotCount", dotCount);
|
156 |
|
157 |
// dot size
|
158 |
xml.putProperty("dotSize", dotSize);
|
159 |
|
160 |
// dot spacing
|
161 |
xml.putProperty("dotSpacing", dotSpacing);
|
162 |
|
163 |
return xml;
|
164 |
} |
165 |
|
166 |
public int getSymbolType() { |
167 |
return FShape.POLYGON;
|
168 |
} |
169 |
|
170 |
public void drawInsideRectangle(Graphics2D g, |
171 |
AffineTransform scaleInstance, Rectangle r) { |
172 |
int x = r.x;
|
173 |
int y = r.y;
|
174 |
int width = r.width;
|
175 |
int height= r.height;
|
176 |
int size = height / 5; |
177 |
g.setColor(color); |
178 |
g.setBackground(null);
|
179 |
g.fillRect((int) (x+height*0.2), (int) (y+width*0.2), size, size); |
180 |
g.fillRect((int) (x+height*0.25), (int) (y+width*0.7), size, size); |
181 |
g.fillRect((int) (x+height*0.65), (int) (y+width*0.5), size, size); |
182 |
g.fillRect((int) (x+height*0.8), (int) (y+width*0.1), size, size); |
183 |
g.fillRect((int) (x+height*0.8), (int) (y+width*0.8), size, size); |
184 |
g.fillRect((int) (x+height*0.9), (int) (y+width*0.3), size, size); |
185 |
g.fillRect((int) (x+height*1.1), (int) (y+width*0.8), size, size); |
186 |
} |
187 |
|
188 |
public String getClassName() { |
189 |
return getClass().getName();
|
190 |
} |
191 |
|
192 |
public void setXMLEntity(XMLEntity xml) { |
193 |
// color
|
194 |
color = StringUtilities.string2Color(xml.getStringProperty("color"));
|
195 |
|
196 |
// description
|
197 |
setDescription(xml.getStringProperty("desc"));
|
198 |
|
199 |
// is shape visible
|
200 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
201 |
|
202 |
// dot count
|
203 |
dotCount = xml.getIntProperty("dotCount");
|
204 |
|
205 |
// dot size
|
206 |
dotSize = xml.getDoubleProperty("dotSize");
|
207 |
|
208 |
// dot spacing
|
209 |
dotSpacing = xml.getDoubleProperty("dotSpacing");
|
210 |
} |
211 |
|
212 |
public int getDotCount() { |
213 |
return dotCount;
|
214 |
} |
215 |
|
216 |
public void setDotCount(int dotCount) { |
217 |
this.dotCount = dotCount;
|
218 |
} |
219 |
|
220 |
public double getDotSize() { |
221 |
return dotSize;
|
222 |
} |
223 |
|
224 |
public void setDotSize(double dotSize) { |
225 |
this.dotSize = dotSize;
|
226 |
} |
227 |
|
228 |
public double getDotSpacing() { |
229 |
return dotSpacing;
|
230 |
} |
231 |
|
232 |
public void setDotSpacing(double dotSpacing) { |
233 |
this.dotSpacing = dotSpacing;
|
234 |
} |
235 |
|
236 |
public Color getDotColor() { |
237 |
return color;
|
238 |
} |
239 |
|
240 |
public void setDotColor(Color dotColor) { |
241 |
this.color = dotColor;
|
242 |
} |
243 |
|
244 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws DriverException { |
245 |
// TODO Implement it
|
246 |
throw new Error("Not yet implemented!"); |
247 |
|
248 |
} |
249 |
|
250 |
} |