svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleMarkerSymbol.java @ 10436
History | View | Annotate | Download (8.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: SimpleMarkerSymbol.java 10436 2007-02-21 07:34:09Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3.2.7 2007-02-21 07:34:09 jaume
|
47 |
* labeling starts working
|
48 |
*
|
49 |
* Revision 1.3.2.6 2007/02/16 10:54:12 jaume
|
50 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
51 |
*
|
52 |
* Revision 1.3.2.5 2007/02/15 16:23:44 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.3.2.4 2007/02/13 16:19:19 jaume
|
56 |
* graduated symbol legends (start commiting)
|
57 |
*
|
58 |
* Revision 1.3.2.3 2007/02/12 15:15:20 jaume
|
59 |
* refactored interval legend and added graduated symbol legend
|
60 |
*
|
61 |
* Revision 1.3.2.2 2007/02/09 07:47:05 jaume
|
62 |
* Isymbol moved
|
63 |
*
|
64 |
* Revision 1.3.2.1 2007/02/05 14:59:03 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.3 2007/01/25 16:25:23 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
71 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
72 |
*
|
73 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.1 2006/11/14 11:10:27 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
*
|
80 |
*/
|
81 |
package com.iver.cit.gvsig.fmap.core.symbols; |
82 |
|
83 |
import java.awt.Color; |
84 |
import java.awt.Graphics2D; |
85 |
import java.awt.Point; |
86 |
import java.awt.Rectangle; |
87 |
import java.awt.RenderingHints; |
88 |
import java.awt.Shape; |
89 |
import java.awt.geom.AffineTransform; |
90 |
import java.awt.geom.Point2D; |
91 |
|
92 |
import org.apache.batik.ext.awt.geom.PathLength; |
93 |
|
94 |
import com.iver.cit.gvsig.fmap.DriverException; |
95 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
96 |
import com.iver.cit.gvsig.fmap.core.FShape; |
97 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
98 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
99 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
100 |
import com.iver.utiles.StringUtilities; |
101 |
import com.iver.utiles.XMLEntity; |
102 |
import com.vividsolutions.jts.geom.Geometry; |
103 |
|
104 |
/**
|
105 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
106 |
*/
|
107 |
public class SimpleMarkerSymbol extends AbstractMarkerSymbol { |
108 |
/**
|
109 |
* @uml.property name="outline"
|
110 |
*/
|
111 |
private boolean outline; |
112 |
/**
|
113 |
* @uml.property name="outlineColor"
|
114 |
*/
|
115 |
private Color outlineColor; |
116 |
/**
|
117 |
* @uml.property name="outlineSize"
|
118 |
*/
|
119 |
private double outlineSize; |
120 |
|
121 |
|
122 |
private ISymbol selectionSymbol;
|
123 |
|
124 |
public ISymbol getSymbolForSelection() {
|
125 |
if (selectionSymbol == null) { |
126 |
XMLEntity xml = getXMLEntity(); |
127 |
xml.putProperty("color", StringUtilities.color2String(FSymbol.getSelectionColor()));
|
128 |
selectionSymbol = (SimpleMarkerSymbol) SymbologyFactory. |
129 |
createSymbolFromXML(xml, getDescription()+" version for selection");
|
130 |
} |
131 |
return selectionSymbol;
|
132 |
} |
133 |
|
134 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
135 |
int minx, miny;
|
136 |
Point2D p = null; |
137 |
switch (shp.getShapeType()) {
|
138 |
case FShape.POINT:
|
139 |
p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp) |
140 |
.getY()); |
141 |
break;
|
142 |
case FShape.LINE:
|
143 |
PathLength pathLen = new PathLength(shp);
|
144 |
float midDistance = pathLen.lengthOfPath() / 2; |
145 |
p = pathLen.pointAtLength(midDistance); |
146 |
break;
|
147 |
case FShape.POLYGON:
|
148 |
Geometry geom = FConverter.java2d_to_jts(shp); |
149 |
com.vividsolutions.jts.geom.Point centroid = geom.getCentroid(); |
150 |
p = new Point2D.Double(centroid.getX(), centroid.getY()); |
151 |
} |
152 |
int halfSize = (int) getSize()/2; |
153 |
minx = ((int) (p.getX() - getOffset().getX()) - halfSize);
|
154 |
miny = ((int) (p.getY() - getOffset().getY()) - halfSize);
|
155 |
g.setColor(getColor()); |
156 |
g.fillOval(minx, miny, (int) getSize(), (int) getSize()); |
157 |
} |
158 |
|
159 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
160 |
return 0; |
161 |
} |
162 |
|
163 |
public XMLEntity getXMLEntity() {
|
164 |
XMLEntity xml = new XMLEntity();
|
165 |
xml.putProperty("className", getClassName());
|
166 |
xml.putProperty("desc", getDescription());
|
167 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
168 |
xml.putProperty("color", StringUtilities.color2String(getColor()));
|
169 |
xml.putProperty("rotation", getRotation());
|
170 |
xml.putProperty("offsetX", getOffset().getX());
|
171 |
xml.putProperty("offsetY", getOffset().getY());
|
172 |
xml.putProperty("size", getSize());
|
173 |
xml.putProperty("outline", outline);
|
174 |
if (outline) {
|
175 |
xml.putProperty("outlineColor", StringUtilities.color2String(outlineColor));
|
176 |
xml.putProperty("outlineSize", outlineSize);
|
177 |
} |
178 |
return xml;
|
179 |
} |
180 |
|
181 |
public int getSymbolType() { |
182 |
return FShape.POINT;
|
183 |
} |
184 |
|
185 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
186 |
int minx, miny;
|
187 |
RenderingHints old = g.getRenderingHints();
|
188 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
189 |
|
190 |
int rectSize = (int) ((getSize() < r.width && getSize() < r.height) |
191 |
? getSize() |
192 |
: (int) (Math.min(r.width, r.height) * 0.8)); // does not fit, scale it |
193 |
|
194 |
minx = (int) ((r.getWidth() - rectSize) / 2); |
195 |
miny = (int) ((r.getHeight()- rectSize) / 2); |
196 |
g.setColor(getColor()); |
197 |
g.fillOval(minx, miny, rectSize, rectSize); |
198 |
g.setRenderingHints(old); |
199 |
} |
200 |
|
201 |
public String getClassName() { |
202 |
return getClass().getName();
|
203 |
} |
204 |
|
205 |
public void setXMLEntity(XMLEntity xml) { |
206 |
setDescription(xml.getStringProperty("desc"));
|
207 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
208 |
setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
209 |
setRotation(xml.getDoubleProperty("rotation"));
|
210 |
setOffset(new Point.Double(xml.getDoubleProperty("offsetX"), |
211 |
xml.getDoubleProperty("offsetY")));
|
212 |
setSize(xml.getDoubleProperty("size"));
|
213 |
setOutline(xml.getBooleanProperty("outline"));
|
214 |
if (hasOutline()) {
|
215 |
setOutlineColor(StringUtilities.string2Color(xml.getStringProperty("outlineColor")));
|
216 |
setOutlineSize(xml.getDoubleProperty("outlineSize"));
|
217 |
} |
218 |
|
219 |
} |
220 |
|
221 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws DriverException { |
222 |
// TODO Implement it
|
223 |
throw new Error("Not yet implemented!"); |
224 |
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* @return Returns the outline.
|
229 |
*/
|
230 |
public boolean hasOutline() { |
231 |
return outline;
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* @param outline The outline to set.
|
236 |
* @uml.property name="outline"
|
237 |
*/
|
238 |
public void setOutline(boolean outline) { |
239 |
this.outline = outline;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @return Returns the outlineColor.
|
244 |
* @uml.property name="outlineColor"
|
245 |
*/
|
246 |
public Color getOutlineColor() { |
247 |
return outlineColor;
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* @param outlineColor The outlineColor to set.
|
252 |
* @uml.property name="outlineColor"
|
253 |
*/
|
254 |
public void setOutlineColor(Color outlineColor) { |
255 |
this.outlineColor = outlineColor;
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* @return Returns the outlineSize.
|
260 |
* @uml.property name="outlineSize"
|
261 |
*/
|
262 |
public double getOutlineSize() { |
263 |
return outlineSize;
|
264 |
} |
265 |
|
266 |
/**
|
267 |
* @param outlineSize The outlineSize to set.
|
268 |
* @uml.property name="outlineSize"
|
269 |
*/
|
270 |
public void setOutlineSize(double outlineSize) { |
271 |
this.outlineSize = outlineSize;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* @return Returns the selectionSymbol.
|
276 |
* @uml.property name="selectionSymbol"
|
277 |
*/
|
278 |
public ISymbol getSelectionSymbol() {
|
279 |
return selectionSymbol;
|
280 |
} |
281 |
|
282 |
/**
|
283 |
* @param selectionSymbol The selectionSymbol to set.
|
284 |
* @uml.property name="selectionSymbol"
|
285 |
*/
|
286 |
public void setSelectionSymbol(ISymbol selectionSymbol) { |
287 |
this.selectionSymbol = selectionSymbol;
|
288 |
} |
289 |
|
290 |
} |