svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleMarkerSymbol.java @ 12043
History | View | Annotate | Download (10.3 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 12043 2007-06-07 06:58:18Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.12 2007-06-07 06:50:40 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.11 2007/05/29 15:46:37 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.10 2007/05/28 15:36:42 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.9 2007/05/09 16:07:26 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.8 2007/05/08 08:47:40 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.7 2007/03/27 07:11:32 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.6 2007/03/13 16:58:36 jaume
|
65 |
* Added QuantityByCategory (Multivariable legend) and some bugfixes in symbols
|
66 |
*
|
67 |
* Revision 1.5 2007/03/09 11:20:56 jaume
|
68 |
* Advanced symbology (start committing)
|
69 |
*
|
70 |
* Revision 1.3.2.7 2007/02/21 07:34:09 jaume
|
71 |
* labeling starts working
|
72 |
*
|
73 |
* Revision 1.3.2.6 2007/02/16 10:54:12 jaume
|
74 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
75 |
*
|
76 |
* Revision 1.3.2.5 2007/02/15 16:23:44 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.3.2.4 2007/02/13 16:19:19 jaume
|
80 |
* graduated symbol legends (start commiting)
|
81 |
*
|
82 |
* Revision 1.3.2.3 2007/02/12 15:15:20 jaume
|
83 |
* refactored interval legend and added graduated symbol legend
|
84 |
*
|
85 |
* Revision 1.3.2.2 2007/02/09 07:47:05 jaume
|
86 |
* Isymbol moved
|
87 |
*
|
88 |
* Revision 1.3.2.1 2007/02/05 14:59:03 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.3 2007/01/25 16:25:23 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
95 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
96 |
*
|
97 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.1 2006/11/14 11:10:27 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
*
|
104 |
*/
|
105 |
package com.iver.cit.gvsig.fmap.core.symbols; |
106 |
|
107 |
import java.awt.Color; |
108 |
import java.awt.Graphics2D; |
109 |
import java.awt.Point; |
110 |
import java.awt.Rectangle; |
111 |
import java.awt.RenderingHints; |
112 |
import java.awt.Shape; |
113 |
import java.awt.geom.AffineTransform; |
114 |
import java.awt.geom.Point2D; |
115 |
|
116 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
117 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
118 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
119 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
120 |
import com.iver.cit.gvsig.fmap.core.FShape; |
121 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
122 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
123 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
124 |
import com.iver.cit.gvsig.fmap.core.styles.IMask; |
125 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
126 |
import com.iver.utiles.StringUtilities; |
127 |
import com.iver.utiles.XMLEntity; |
128 |
|
129 |
/**
|
130 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
131 |
*/
|
132 |
public class SimpleMarkerSymbol extends AbstractMarkerSymbol { |
133 |
|
134 |
public static final int CIRCLE_STYLE = 0; |
135 |
public static final int SQUARE_STYLE = 1; |
136 |
public static final int CROSS_STYLE = 2; |
137 |
public static final int DIAMOND_STYLE = 3; |
138 |
public static final int X_STYLE = 4; |
139 |
public static final int TRIANGLE_STYLE = 5; |
140 |
private boolean outlined; |
141 |
private Color outlineColor; |
142 |
private double outlineSize; |
143 |
private ISymbol selectionSymbol;
|
144 |
private int markerStyle; |
145 |
|
146 |
public ISymbol getSymbolForSelection() {
|
147 |
if (selectionSymbol == null) { |
148 |
XMLEntity xml = getXMLEntity(); |
149 |
xml.putProperty("color", StringUtilities.color2String(FSymbol.getSelectionColor()));
|
150 |
selectionSymbol = (SimpleMarkerSymbol) SymbologyFactory. |
151 |
createSymbolFromXML(xml, getDescription()+" version for selection");
|
152 |
} |
153 |
return selectionSymbol;
|
154 |
} |
155 |
|
156 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
157 |
int x, y;
|
158 |
Point2D p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp) |
159 |
.getY()); |
160 |
RenderingHints old = g.getRenderingHints();
|
161 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
162 |
|
163 |
int halfSize = (int) getSize()/2; // TODO CartographicSupport |
164 |
x = ((int) (p.getX() - getOffset().getX()) - halfSize);
|
165 |
y = ((int) (p.getY() - getOffset().getY()) - halfSize);
|
166 |
|
167 |
IMask mask = getMask(); |
168 |
if (mask != null) { |
169 |
IFillSymbol maskShape = mask.getFillSymbol(); |
170 |
// maskShape.draw(g, null, mask.getHaloShape(shp));
|
171 |
} |
172 |
|
173 |
int size = (int) getSize(); // TODO CartographicSupport |
174 |
g.setColor(getColor()); |
175 |
GeneralPathX genPath = null;
|
176 |
|
177 |
switch (markerStyle) {
|
178 |
case CIRCLE_STYLE:
|
179 |
g.fillOval(x, y, size, size); |
180 |
break;
|
181 |
case SQUARE_STYLE:
|
182 |
g.fillRect(x, y, size, size); |
183 |
break;
|
184 |
case CROSS_STYLE:
|
185 |
x = x + halfSize; |
186 |
y = y + halfSize; |
187 |
genPath = new GeneralPathX();
|
188 |
genPath.moveTo(x, y - halfSize); |
189 |
genPath.lineTo(x, y + halfSize); |
190 |
genPath.moveTo(x - halfSize, y); |
191 |
genPath.lineTo(x + halfSize, y); |
192 |
g.draw(genPath); |
193 |
break;
|
194 |
case DIAMOND_STYLE:
|
195 |
x = x + halfSize; |
196 |
y = y + halfSize; |
197 |
genPath = new GeneralPathX();
|
198 |
genPath.moveTo(x-halfSize, y); |
199 |
genPath.lineTo(x, y+halfSize); |
200 |
genPath.lineTo(x+halfSize, y); |
201 |
genPath.lineTo(x, y-halfSize); |
202 |
genPath.lineTo(x-halfSize, y); |
203 |
genPath.closePath(); |
204 |
g.fill(genPath); |
205 |
break;
|
206 |
case X_STYLE:
|
207 |
x = x + halfSize; |
208 |
y = y + halfSize; |
209 |
genPath = new GeneralPathX();
|
210 |
genPath.moveTo(x-halfSize, y - halfSize); |
211 |
genPath.lineTo(x+halfSize, y + halfSize); |
212 |
genPath.moveTo(x - halfSize, y + halfSize); |
213 |
genPath.lineTo(x + halfSize, y - halfSize); |
214 |
g.draw(genPath); |
215 |
break;
|
216 |
case TRIANGLE_STYLE:
|
217 |
x = x + halfSize; |
218 |
y = y + halfSize; |
219 |
int otherSize = (int) (size * 0.55); |
220 |
genPath = new GeneralPathX();
|
221 |
genPath.moveTo(x - halfSize, |
222 |
y + halfSize); |
223 |
genPath.lineTo(x + halfSize, |
224 |
y + halfSize); |
225 |
genPath.lineTo(x, y - otherSize); |
226 |
genPath.closePath(); |
227 |
|
228 |
g.fill(genPath); |
229 |
break;
|
230 |
} |
231 |
|
232 |
if (outlined) {
|
233 |
g.setColor(outlineColor); |
234 |
|
235 |
switch (markerStyle) {
|
236 |
case CIRCLE_STYLE:
|
237 |
g.drawOval(x, y, size, size); |
238 |
break;
|
239 |
case SQUARE_STYLE:
|
240 |
g.drawRect(x, y, size, size); |
241 |
break;
|
242 |
case CROSS_STYLE:
|
243 |
case DIAMOND_STYLE:
|
244 |
case X_STYLE:
|
245 |
case TRIANGLE_STYLE:
|
246 |
g.draw(genPath); |
247 |
break;
|
248 |
} |
249 |
} |
250 |
g.setRenderingHints(old); |
251 |
} |
252 |
|
253 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
254 |
return 0; |
255 |
} |
256 |
|
257 |
public XMLEntity getXMLEntity() {
|
258 |
XMLEntity xml = new XMLEntity();
|
259 |
xml.putProperty("className", getClassName());
|
260 |
xml.putProperty("desc", getDescription());
|
261 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
262 |
xml.putProperty("color", StringUtilities.color2String(getColor()));
|
263 |
xml.putProperty("rotation", getRotation());
|
264 |
xml.putProperty("offsetX", getOffset().getX());
|
265 |
xml.putProperty("offsetY", getOffset().getY());
|
266 |
xml.putProperty("size", getSize());
|
267 |
xml.putProperty("outline", outlined);
|
268 |
xml.putProperty("unit", getUnit());
|
269 |
xml.putProperty("referenceSystem", getReferenceSystem());
|
270 |
xml.putProperty("markerStyle", getStyle());
|
271 |
|
272 |
if (outlined) {
|
273 |
xml.putProperty("outlineColor", StringUtilities.color2String(outlineColor));
|
274 |
xml.putProperty("outlineSize", outlineSize);
|
275 |
} |
276 |
return xml;
|
277 |
} |
278 |
|
279 |
public int getSymbolType() { |
280 |
return FShape.POINT;
|
281 |
} |
282 |
|
283 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
284 |
|
285 |
FPoint2D shp = new FPoint2D(r.getCenterX(), r.getCenterY());
|
286 |
draw(g, scaleInstance, shp); |
287 |
} |
288 |
|
289 |
public String getClassName() { |
290 |
return getClass().getName();
|
291 |
} |
292 |
|
293 |
public void setXMLEntity(XMLEntity xml) { |
294 |
setDescription(xml.getStringProperty("desc"));
|
295 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
296 |
setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
297 |
setRotation(xml.getDoubleProperty("rotation"));
|
298 |
setOffset(new Point.Double(xml.getDoubleProperty("offsetX"), |
299 |
xml.getDoubleProperty("offsetY")));
|
300 |
setSize(xml.getDoubleProperty("size"));
|
301 |
setOutlined(xml.getBooleanProperty("outline"));
|
302 |
setUnit(xml.getIntProperty("unit"));
|
303 |
setReferenceSystem(xml.getIntProperty("referenceSystem"));
|
304 |
setStyle(xml.getIntProperty("markerStyle"));
|
305 |
if (hasOutline()) {
|
306 |
setOutlineColor(StringUtilities.string2Color(xml.getStringProperty("outlineColor")));
|
307 |
setOutlineSize(xml.getDoubleProperty("outlineSize"));
|
308 |
} |
309 |
|
310 |
} |
311 |
|
312 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException { |
313 |
// TODO Implement it
|
314 |
throw new Error("Not yet implemented!"); |
315 |
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* @return Returns the outline.
|
320 |
*/
|
321 |
public boolean hasOutline() { |
322 |
return outlined;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* @param outline The outline to set.
|
327 |
*/
|
328 |
public void setOutlined(boolean outlined) { |
329 |
this.outlined = outlined;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* @return Returns the outlineColor.
|
334 |
*/
|
335 |
public Color getOutlineColor() { |
336 |
return outlineColor;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* @param outlineColor The outlineColor to set.
|
341 |
*/
|
342 |
public void setOutlineColor(Color outlineColor) { |
343 |
this.outlineColor = outlineColor;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* @return Returns the outlineSize.
|
348 |
*/
|
349 |
public double getOutlineSize() { |
350 |
return outlineSize;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* @param outlineSize The outlineSize to set.
|
355 |
*/
|
356 |
public void setOutlineSize(double outlineSize) { |
357 |
this.outlineSize = outlineSize;
|
358 |
} |
359 |
|
360 |
/**
|
361 |
* @return Returns the selectionSymbol.
|
362 |
*/
|
363 |
public ISymbol getSelectionSymbol() {
|
364 |
return selectionSymbol;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* @param selectionSymbol The selectionSymbol to set.
|
369 |
*/
|
370 |
public void setSelectionSymbol(ISymbol selectionSymbol) { |
371 |
this.selectionSymbol = selectionSymbol;
|
372 |
} |
373 |
|
374 |
public void setStyle(int style) { |
375 |
this.markerStyle = style;
|
376 |
} |
377 |
|
378 |
public int getStyle() { |
379 |
return markerStyle;
|
380 |
} |
381 |
} |