svn-gvsig-desktop / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / fmap / core / symbols / DotDensityFillSymbol.java @ 8658
History | View | Annotate | Download (4.67 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 8658 2006-11-09 18:39:05Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2006-11-09 18:39:05 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1 2006/11/09 10:22:50 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
*
|
53 |
*/
|
54 |
package com.iver.cit.gvsig.fmap.core.symbols; |
55 |
|
56 |
import java.awt.Color; |
57 |
import java.awt.Graphics2D; |
58 |
import java.awt.Point; |
59 |
import java.awt.Rectangle; |
60 |
import java.awt.Shape; |
61 |
import java.awt.geom.AffineTransform; |
62 |
import java.util.Random; |
63 |
|
64 |
import com.iver.cit.gvsig.fmap.core.FShape; |
65 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
66 |
import com.iver.utiles.StringUtilities; |
67 |
import com.iver.utiles.XMLEntity; |
68 |
|
69 |
public class DotDensityFillSymbol extends AbstractFillSymbol { |
70 |
private int dotCount; |
71 |
private double dotSize; |
72 |
private double dotSpacing; |
73 |
private boolean fixedPlacement; |
74 |
|
75 |
public DotDensityFillSymbol() {
|
76 |
super();
|
77 |
isShapeVisible = true;
|
78 |
} |
79 |
|
80 |
public ISymbol getSymbolForSelection() {
|
81 |
// TODO Auto-generated method stub
|
82 |
throw new Error("Not yet implemented!"); |
83 |
} |
84 |
|
85 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
86 |
int width = shp.getBounds().width;
|
87 |
int height = shp.getBounds().height;
|
88 |
int minx = shp.getBounds().x;
|
89 |
int miny = shp.getBounds().y;
|
90 |
Random random = new Random(); |
91 |
g.setClip(shp); |
92 |
g.setColor(color); |
93 |
int size = (int) dotSize; |
94 |
for (int i = 0; i < dotCount; i++) { |
95 |
int x = (int) Math.abs(random.nextDouble() * width); |
96 |
int y = (int) Math.abs(random.nextDouble() * height); |
97 |
x = x + minx; |
98 |
y = y + miny; |
99 |
g.fillRect(x, y, size, size); |
100 |
} |
101 |
} |
102 |
|
103 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
104 |
Shape shp) {
|
105 |
// TODO Auto-generated method stub
|
106 |
throw new Error("Not yet implemented!"); |
107 |
} |
108 |
|
109 |
public XMLEntity getXMLEntity() {
|
110 |
XMLEntity xml = new XMLEntity();
|
111 |
xml.putProperty("className", getClassName());
|
112 |
|
113 |
// color
|
114 |
xml.putProperty("color", StringUtilities.color2String(color));
|
115 |
|
116 |
// description
|
117 |
xml.putProperty("desc", desc);
|
118 |
|
119 |
// is shape visible
|
120 |
xml.putProperty("isShapeVisible", isShapeVisible);
|
121 |
|
122 |
// dot count
|
123 |
xml.putProperty("dotCount", dotCount);
|
124 |
|
125 |
// dot size
|
126 |
xml.putProperty("dotSize", dotSize);
|
127 |
|
128 |
// dot spacing
|
129 |
xml.putProperty("dotSpacing", dotSpacing);
|
130 |
|
131 |
|
132 |
// layers
|
133 |
if (layers!=null) |
134 |
for (int i = 0; i < layers.length; i++) { |
135 |
xml.addChild(layers[i].getXMLEntity()); |
136 |
} |
137 |
|
138 |
return xml;
|
139 |
} |
140 |
|
141 |
public int getSymbolType() { |
142 |
return FShape.POLYGON;
|
143 |
} |
144 |
|
145 |
public void drawInsideRectangle(Graphics2D g, |
146 |
AffineTransform scaleInstance, Rectangle r) { |
147 |
// TODO Auto-generated method stub
|
148 |
|
149 |
} |
150 |
|
151 |
public String getClassName() { |
152 |
return getClass().getName();
|
153 |
} |
154 |
|
155 |
public void setXMLEntity(XMLEntity xml) { |
156 |
// color
|
157 |
color = StringUtilities.string2Color(xml.getStringProperty("color"));
|
158 |
|
159 |
// description
|
160 |
desc = xml.getStringProperty("desc");
|
161 |
|
162 |
// is shape visible
|
163 |
isShapeVisible = xml.getBooleanProperty("isShapeVisible");
|
164 |
|
165 |
// dot count
|
166 |
dotCount = xml.getIntProperty("dotCount");
|
167 |
|
168 |
// dot size
|
169 |
dotSize = xml.getDoubleProperty("dotSize");
|
170 |
|
171 |
// dot spacing
|
172 |
dotSpacing = xml.getDoubleProperty("dotSpacing");
|
173 |
|
174 |
} |
175 |
|
176 |
public int getDotCount() { |
177 |
return dotCount;
|
178 |
} |
179 |
|
180 |
public void setDotCount(int dotCount) { |
181 |
this.dotCount = dotCount;
|
182 |
} |
183 |
|
184 |
public double getDotSize() { |
185 |
return dotSize;
|
186 |
} |
187 |
|
188 |
public void setDotSize(double dotSize) { |
189 |
this.dotSize = dotSize;
|
190 |
} |
191 |
|
192 |
public double getDotSpacing() { |
193 |
return dotSpacing;
|
194 |
} |
195 |
|
196 |
public void setDotSpacing(double dotSpacing) { |
197 |
this.dotSpacing = dotSpacing;
|
198 |
} |
199 |
|
200 |
public Color getDotColor() { |
201 |
return color;
|
202 |
} |
203 |
|
204 |
public void setDotColor(Color dotColor) { |
205 |
this.color = dotColor;
|
206 |
} |
207 |
|
208 |
} |