svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / symbol / CharacterMarkerSymbol.java @ 45526
History | View | Annotate | Download (22.9 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: CharacterMarkerSymbol.java 14501 2007-10-08 15:47:31Z jdominguez $
|
45 |
* $Log$
|
46 |
* Revision 1.27 2007-09-21 12:25:32 jaume
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level
|
48 |
*
|
49 |
* Revision 1.26 2007/08/09 07:20:03 jvidal
|
50 |
* javadoc
|
51 |
*
|
52 |
* Revision 1.25 2007/07/23 06:52:25 jaume
|
53 |
* default selection color refactored, moved to MapContext
|
54 |
*
|
55 |
* Revision 1.24 2007/07/18 06:54:34 jaume
|
56 |
* continuing with cartographic support
|
57 |
*
|
58 |
* Revision 1.23 2007/07/03 10:58:29 jaume
|
59 |
* first refactor on CartographicSupport
|
60 |
*
|
61 |
* Revision 1.22 2007/06/29 13:07:01 jaume
|
62 |
* +PictureLineSymbol
|
63 |
*
|
64 |
* Revision 1.21 2007/06/07 06:50:40 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.20 2007/05/29 15:46:37 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.19 2007/05/28 15:36:42 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.18 2007/05/17 09:32:06 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.17 2007/05/09 16:07:26 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.16 2007/05/09 11:05:28 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.15 2007/05/08 08:47:40 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.14 2007/04/26 11:41:00 jaume
|
86 |
* attempting to let defining size in world units
|
87 |
*
|
88 |
* Revision 1.13 2007/04/20 07:11:11 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.12 2007/04/19 16:01:27 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.11 2007/04/19 14:21:30 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.10 2007/03/26 14:24:13 jaume
|
98 |
* implemented Print
|
99 |
*
|
100 |
* Revision 1.9 2007/03/21 11:37:00 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.8 2007/03/21 11:02:17 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.7 2007/03/09 11:20:56 jaume
|
107 |
* Advanced symbology (start committing)
|
108 |
*
|
109 |
* Revision 1.5.2.8 2007/02/21 07:34:09 jaume
|
110 |
* labeling starts working
|
111 |
*
|
112 |
* Revision 1.5.2.7 2007/02/16 10:54:12 jaume
|
113 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
114 |
*
|
115 |
* Revision 1.5.2.6 2007/02/15 16:23:44 jaume
|
116 |
* *** empty log message ***
|
117 |
*
|
118 |
* Revision 1.5.2.5 2007/02/14 09:58:37 jaume
|
119 |
* *** empty log message ***
|
120 |
*
|
121 |
* Revision 1.5.2.4 2007/02/12 15:15:20 jaume
|
122 |
* refactored interval legend and added graduated symbol legend
|
123 |
*
|
124 |
* Revision 1.5.2.3 2007/02/09 07:47:04 jaume
|
125 |
* Isymbol moved
|
126 |
*
|
127 |
* Revision 1.5.2.2 2007/02/05 14:59:04 jaume
|
128 |
* *** empty log message ***
|
129 |
*
|
130 |
* Revision 1.5.2.1 2007/01/30 18:10:45 jaume
|
131 |
* start commiting labeling stuff
|
132 |
*
|
133 |
* Revision 1.5 2007/01/25 16:25:23 jaume
|
134 |
* *** empty log message ***
|
135 |
*
|
136 |
* Revision 1.4 2007/01/24 17:58:22 jaume
|
137 |
* new features and architecture error fixes
|
138 |
*
|
139 |
* Revision 1.3 2007/01/16 11:50:44 jaume
|
140 |
* *** empty log message ***
|
141 |
*
|
142 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
143 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
144 |
*
|
145 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
146 |
* *** empty log message ***
|
147 |
*
|
148 |
* Revision 1.6 2006/12/04 17:13:39 fjp
|
149 |
* *** empty log message ***
|
150 |
*
|
151 |
* Revision 1.5 2006/11/14 11:10:27 jaume
|
152 |
* *** empty log message ***
|
153 |
*
|
154 |
* Revision 1.4 2006/11/09 18:39:05 jaume
|
155 |
* *** empty log message ***
|
156 |
*
|
157 |
* Revision 1.3 2006/11/08 10:56:47 jaume
|
158 |
* *** empty log message ***
|
159 |
*
|
160 |
* Revision 1.2 2006/11/06 17:08:45 jaume
|
161 |
* *** empty log message ***
|
162 |
*
|
163 |
* Revision 1.1 2006/10/31 16:16:34 jaume
|
164 |
* *** empty log message ***
|
165 |
*
|
166 |
* Revision 1.4 2006/10/30 19:30:35 jaume
|
167 |
* *** empty log message ***
|
168 |
*
|
169 |
* Revision 1.3 2006/10/29 23:53:49 jaume
|
170 |
* *** empty log message ***
|
171 |
*
|
172 |
* Revision 1.2 2006/10/26 16:27:33 jaume
|
173 |
* support for composite marker symbols (not tested)
|
174 |
*
|
175 |
* Revision 1.1 2006/10/25 10:50:41 jaume
|
176 |
* movement of classes and gui stuff
|
177 |
*
|
178 |
* Revision 1.3 2006/10/24 19:54:16 jaume
|
179 |
* added IPersistence
|
180 |
*
|
181 |
* Revision 1.2 2006/10/24 08:02:51 jaume
|
182 |
* *** empty log message ***
|
183 |
*
|
184 |
* Revision 1.1 2006/10/18 07:54:06 jaume
|
185 |
* *** empty log message ***
|
186 |
*
|
187 |
*
|
188 |
*/
|
189 |
package org.gvsig.labeling.symbol; |
190 |
|
191 |
import java.awt.Color; |
192 |
import java.awt.Font; |
193 |
import java.awt.Graphics2D; |
194 |
import java.awt.Rectangle; |
195 |
import java.awt.Shape; |
196 |
import java.awt.font.FontRenderContext; |
197 |
import java.awt.font.GlyphVector; |
198 |
import java.awt.geom.AffineTransform; |
199 |
import java.awt.geom.Point2D; |
200 |
import java.awt.image.BufferedImage; |
201 |
|
202 |
import org.gvsig.compat.print.PrintAttributes; |
203 |
import org.gvsig.fmap.dal.feature.Feature; |
204 |
import org.gvsig.fmap.geom.Geometry; |
205 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
206 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
207 |
import org.gvsig.fmap.geom.GeometryLocator; |
208 |
import org.gvsig.fmap.geom.GeometryManager; |
209 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
210 |
import org.gvsig.fmap.geom.primitive.Envelope; |
211 |
import org.gvsig.fmap.mapcontext.MapContext; |
212 |
import org.gvsig.fmap.mapcontext.ViewPort; |
213 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
214 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
215 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
216 |
import org.gvsig.labeling.lang.LabelClassUtils; |
217 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
218 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask; |
219 |
import org.gvsig.tools.ToolsLocator; |
220 |
import org.gvsig.tools.dynobject.DynStruct; |
221 |
import org.gvsig.tools.persistence.PersistenceManager; |
222 |
import org.gvsig.tools.persistence.PersistentState; |
223 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
224 |
import org.gvsig.tools.task.Cancellable; |
225 |
import org.slf4j.Logger; |
226 |
import org.slf4j.LoggerFactory; |
227 |
|
228 |
/**
|
229 |
* Allows to use a source of TrueType characters to define the marker that will
|
230 |
* substitute the symbol.If the picture is defined in a source, the performance is
|
231 |
* more agile.
|
232 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
233 |
*/
|
234 |
public class CharacterMarkerSymbol implements IMarkerSymbol { |
235 |
|
236 |
private static Logger logger = |
237 |
LoggerFactory.getLogger(CharacterMarkerSymbol.class); |
238 |
|
239 |
public static final String CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME = |
240 |
"CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME";
|
241 |
|
242 |
private Font font = new Font("Arial", Font.PLAIN, 20); |
243 |
private int unicode; |
244 |
private ISymbol selectionSymbol;
|
245 |
private VisualCorrection visualCorrection;
|
246 |
private double size; |
247 |
|
248 |
private boolean isShapeVisible = true; |
249 |
private String desc = ""; |
250 |
|
251 |
private IMask mask;
|
252 |
private int unit = -1; |
253 |
private int referenceSystem = CartographicSupport.WORLD; |
254 |
|
255 |
private int alpha = 255; |
256 |
private Point2D offset = new Point2D.Double(); |
257 |
|
258 |
/*
|
259 |
*
|
260 |
*/
|
261 |
private double rotation_radians = 0; |
262 |
private Color color = Color.BLACK; |
263 |
|
264 |
private static GeometryManager geoman = GeometryLocator.getGeometryManager(); |
265 |
|
266 |
/**
|
267 |
* Creates a new instance of CharacterMarker with default values
|
268 |
*
|
269 |
*/
|
270 |
public CharacterMarkerSymbol() {
|
271 |
super();
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* Creates a new instance of CharacterMarker specifying the marker source
|
276 |
* font, the character code corresponding to the symbol, and the color that
|
277 |
* will be used in rendering time.
|
278 |
*
|
279 |
* @param font -
|
280 |
* src Font
|
281 |
* @param charCode -
|
282 |
* character code of the symbol for this font
|
283 |
* @param color -
|
284 |
* color to be used in when rendering.
|
285 |
*/
|
286 |
public CharacterMarkerSymbol(Font font, int charCode, Color color) { |
287 |
super();
|
288 |
this.font = font;
|
289 |
unicode = charCode; |
290 |
setColor(color); |
291 |
} |
292 |
/**
|
293 |
* Returns the font that will be used to define the symbol
|
294 |
* @return font
|
295 |
*/
|
296 |
public Font getFont() { |
297 |
return font;
|
298 |
} |
299 |
/**
|
300 |
* Sets the font that will be used to define the symbol
|
301 |
* @return font
|
302 |
*/
|
303 |
public void setFont(Font font) { |
304 |
this.font = font;
|
305 |
} |
306 |
|
307 |
public ISymbol getSymbolForSelection() {
|
308 |
if (selectionSymbol == null) { |
309 |
selectionSymbol = (ISymbol) LabelClassUtils.clone(this);
|
310 |
selectionSymbol.setColor(MapContext.getSelectionColor()); |
311 |
}else{
|
312 |
selectionSymbol.setColor(MapContext.getSelectionColor()); |
313 |
} |
314 |
return selectionSymbol;
|
315 |
} |
316 |
|
317 |
|
318 |
public void draw(Graphics2D g, |
319 |
AffineTransform affineTransform, Geometry geom,
|
320 |
Feature feat, Cancellable cancel) { |
321 |
|
322 |
g.setColor(getColor()); |
323 |
double theta = getRotation();
|
324 |
|
325 |
int xOffset = (int) getOffset().getX(); // * multiplicador d'unitats; |
326 |
int yOffset = (int) getOffset().getY(); // * multiplicador d'unitats |
327 |
|
328 |
double size = getSize();
|
329 |
if (size < 0.0001) { |
330 |
return;
|
331 |
} |
332 |
|
333 |
org.gvsig.fmap.geom.primitive.Point cen = null;
|
334 |
try {
|
335 |
cen = geom.centroid(); |
336 |
} catch (Exception e) { |
337 |
logger.error("While getting centroid", e);
|
338 |
} |
339 |
|
340 |
Point2D p = new Point2D.Double(cen.getX(), cen.getY()); |
341 |
|
342 |
if (isVisuallyCorrected()) {
|
343 |
size *= visualCorrection.sizeScale; |
344 |
p.setLocation(p.getX() - xOffset*size*visualCorrection.xOffsetScale, p.getY() - yOffset*size*visualCorrection.yOffsetScale); |
345 |
|
346 |
} |
347 |
g.setFont(getFont().deriveFont((float)size));
|
348 |
|
349 |
g.translate((int) (p.getX() + xOffset), (int) (p.getY() + yOffset)); |
350 |
if (theta != 0) g.rotate(theta); |
351 |
|
352 |
char[] text = new char[] { (char) unicode }; |
353 |
|
354 |
IMask mask = getMask(); |
355 |
if (mask != null) { |
356 |
FontRenderContext frc = g.getFontRenderContext();
|
357 |
|
358 |
GlyphVector gv = font.createGlyphVector(frc, text );
|
359 |
|
360 |
Shape markerShape = gv.getOutline(0, 0); |
361 |
mask.getFillSymbol(). |
362 |
draw(g, null, mask.getHaloShape(markerShape), feat, cancel);
|
363 |
|
364 |
} |
365 |
g.drawChars(text, 0, text.length, - (int) (size*0.4), (int) (size*0.4)); |
366 |
|
367 |
|
368 |
if (theta!=0) g.rotate(-theta); |
369 |
g.translate(-(int) (p.getX() + xOffset), - (int) (p.getY() + yOffset)); |
370 |
} |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
/**
|
377 |
* Sets the unicode for a symbol represented by a character
|
378 |
* @param symbol, int
|
379 |
*/
|
380 |
public void setUnicode(int symbol) { |
381 |
this.unicode = symbol;
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* Obtains the unicode for a symbol
|
386 |
* @return unicode, int
|
387 |
*/
|
388 |
public int getUnicode() { |
389 |
return unicode;
|
390 |
} |
391 |
|
392 |
|
393 |
|
394 |
/*
|
395 |
public void setXMLEntity(XMLEntity xml) {
|
396 |
setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
397 |
Point p = new Point();
|
398 |
p.setLocation(xml.getDoubleProperty("xOffset"), xml.getDoubleProperty("yOffset"));
|
399 |
|
400 |
setDescription(xml.getStringProperty("desc"));
|
401 |
size = xml.getDoubleProperty("size");
|
402 |
font = new Font(xml.getStringProperty("font"),
|
403 |
xml.getIntProperty("fontStyle"),
|
404 |
(int) size);
|
405 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
406 |
unicode = xml.getIntProperty("symbolCode");
|
407 |
setOffset(p);
|
408 |
setRotation(xml.getDoubleProperty("rotation"));
|
409 |
setReferenceSystem(xml.getIntProperty("referenceSystem"));
|
410 |
setUnit(xml.getIntProperty("unit"));
|
411 |
}
|
412 |
*/
|
413 |
|
414 |
|
415 |
public double getSize() { |
416 |
return size;
|
417 |
} |
418 |
|
419 |
public void setSize(double size) { |
420 |
this.size = size;
|
421 |
font = new Font(font.getName(), font.getStyle(), (int) Math.round(size)); |
422 |
} |
423 |
/**
|
424 |
* Returns true of false depending if the character marker symbol selected is visually
|
425 |
* corrected.That is, if the character has been properly scaled to use a specific number
|
426 |
* of pixels to be represented.
|
427 |
*
|
428 |
* @return boolean
|
429 |
*/
|
430 |
public boolean isVisuallyCorrected() { |
431 |
return visualCorrection != null; |
432 |
} |
433 |
/**
|
434 |
* Sets the visual correction for a character in order to scale it if it is necessary.
|
435 |
*
|
436 |
* @return boolean
|
437 |
*/
|
438 |
public void setVisuallyCorrected(boolean visuallyCorrected) { |
439 |
if (visuallyCorrected && visualCorrection == null) { |
440 |
CharacterMarkerSymbol clone = |
441 |
(CharacterMarkerSymbol) LabelClassUtils.clone(this);
|
442 |
int frameSize = 200; |
443 |
double symbolSize = 100; |
444 |
BufferedImage bi = new BufferedImage(frameSize, frameSize, BufferedImage.TYPE_INT_ARGB); |
445 |
Graphics2D aGraphics = bi.createGraphics();
|
446 |
clone.setOffset(new Point2D.Double(0,0)); |
447 |
clone.setSize(symbolSize); |
448 |
clone.setColor(Color.PINK);
|
449 |
|
450 |
|
451 |
// draw it at center of the image
|
452 |
org.gvsig.fmap.geom.primitive.Point pCenter = null;
|
453 |
try {
|
454 |
pCenter = geoman.createPoint( |
455 |
frameSize/2,frameSize/2, SUBTYPES.GEOM2D); |
456 |
} catch (Exception e) { |
457 |
logger.error("While creating point", e);
|
458 |
} |
459 |
clone.draw(aGraphics, new AffineTransform(), pCenter, null, null); |
460 |
|
461 |
int realTop = -1; |
462 |
int realBottom = -1; |
463 |
int realLeft = -1; |
464 |
int realRight = -1; |
465 |
|
466 |
// let's see where the highest pixel is in Y-axis
|
467 |
boolean done = false; |
468 |
for (int j = 0; !done && j < bi.getHeight(); j++) { |
469 |
for (int i = 0; !done && i < bi.getWidth(); i++) { |
470 |
if (bi.getRGB(i, j) != 0) { |
471 |
realTop = j; |
472 |
done = true;
|
473 |
} |
474 |
} |
475 |
} |
476 |
|
477 |
// let's see where the lowest pixel is in Y-axis
|
478 |
done = false;
|
479 |
for (int j = bi.getHeight()-1; !done && j >= 0; j--) { |
480 |
for (int i = 0; !done && i < bi.getWidth(); i++) { |
481 |
if (bi.getRGB(i, j) != 0) { |
482 |
realBottom = i; |
483 |
done = true;
|
484 |
} |
485 |
} |
486 |
} |
487 |
|
488 |
// let's see where the first pixel at left is in X-axis
|
489 |
done = false;
|
490 |
for (int i = 0; !done && i < bi.getWidth(); i++) { |
491 |
for (int j = 0; !done && j < bi.getHeight(); j++) { |
492 |
if (bi.getRGB(i, j) != 0) { |
493 |
realLeft = i; |
494 |
done = true;
|
495 |
} |
496 |
} |
497 |
} |
498 |
|
499 |
// let's see where the first pixel at right is in X-axis
|
500 |
done = false;
|
501 |
for (int i = bi.getWidth()-1; !done && i >=0 ; i--) { |
502 |
for (int j = 0; !done && j < bi.getHeight(); j++) { |
503 |
if (bi.getRGB(i, j) != 0) { |
504 |
realRight = i; |
505 |
done = true;
|
506 |
} |
507 |
} |
508 |
} |
509 |
|
510 |
int realWidth = bi.getWidth() - realRight-realLeft;
|
511 |
int realHeight = bi.getHeight() - realBottom - realTop;
|
512 |
|
513 |
visualCorrection = new VisualCorrection();
|
514 |
|
515 |
if (realBottom!=-1 && realTop!=-1 && realLeft!=-1 && realRight != -1) { |
516 |
double correctingSize = Math.max(realHeight, realWidth); |
517 |
visualCorrection.sizeScale = clone.getSize() / correctingSize; |
518 |
} |
519 |
|
520 |
if (realLeft!=-1 && realRight!=-1) { |
521 |
double correctingCenterX = (((realWidth)*0.5)+realLeft); |
522 |
double correctingCenterY = (((realHeight)*0.5)+realBottom); |
523 |
visualCorrection.xOffsetScale = (pCenter.getX() - correctingCenterX) / frameSize; |
524 |
visualCorrection.yOffsetScale = (pCenter.getY() - correctingCenterY) / frameSize; |
525 |
} |
526 |
} else {
|
527 |
visualCorrection = null;
|
528 |
} |
529 |
} |
530 |
|
531 |
|
532 |
public Object clone() throws CloneNotSupportedException { |
533 |
return LabelClassUtils.clone(this); |
534 |
} |
535 |
|
536 |
|
537 |
public void getPixExtentPlus( |
538 |
Geometry geom, float[] distances, |
539 |
ViewPort viewPort, int dpi) {
|
540 |
|
541 |
float cs = (float) getCartographicSize(viewPort, dpi, geom); |
542 |
distances[0] = cs;
|
543 |
distances[1] = cs;
|
544 |
} |
545 |
|
546 |
public boolean isOneDotOrPixel(Geometry geom, |
547 |
double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) { |
548 |
|
549 |
int type = geom.getType();
|
550 |
switch (type) {
|
551 |
case Geometry.TYPES.NULL:
|
552 |
case Geometry.TYPES.POINT:
|
553 |
case Geometry.TYPES.MULTIPOINT:
|
554 |
return false; |
555 |
default:
|
556 |
org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom |
557 |
.getEnvelope(); |
558 |
|
559 |
double dist1Pixel = viewPort.getDist1pixel();
|
560 |
|
561 |
float[] distances = new float[2]; |
562 |
this.getPixExtentPlus(geom, distances, viewPort, dpi);
|
563 |
|
564 |
boolean onePoint =
|
565 |
(geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds |
566 |
.getLength(1)
|
567 |
+ distances[1] <= dist1Pixel);
|
568 |
|
569 |
if (onePoint) {
|
570 |
Envelope bounds = geom.getEnvelope(); |
571 |
positionOfDotOrPixel[0] = bounds.getMinimum(0); |
572 |
positionOfDotOrPixel[1] = bounds.getMinimum(1); |
573 |
} |
574 |
return onePoint;
|
575 |
} |
576 |
} |
577 |
|
578 |
public int getOnePointRgb() { |
579 |
return this.getColor().getRGB(); |
580 |
} |
581 |
|
582 |
public String getDescription() { |
583 |
return desc;
|
584 |
} |
585 |
|
586 |
public boolean isShapeVisible() { |
587 |
return isShapeVisible;
|
588 |
} |
589 |
|
590 |
public void setDescription(String d) { |
591 |
desc = d; |
592 |
} |
593 |
|
594 |
public int getSymbolType() { |
595 |
return Geometry.TYPES.POINT;
|
596 |
} |
597 |
|
598 |
public boolean isSuitableFor(Geometry geom) { |
599 |
return geom.getType() == Geometry.TYPES.POINT
|
600 |
|| geom.getType() == Geometry.TYPES.MULTIPOINT; |
601 |
} |
602 |
|
603 |
public void drawInsideRectangle(Graphics2D g, |
604 |
AffineTransform scaleInstance, Rectangle r, |
605 |
PrintAttributes properties) throws SymbolDrawingException {
|
606 |
|
607 |
|
608 |
org.gvsig.fmap.geom.primitive.Point center = null;
|
609 |
try {
|
610 |
center = geoman.createPoint( |
611 |
r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D); |
612 |
} catch (CreateGeometryException e) {
|
613 |
throw new SymbolDrawingException(TYPES.POINT); |
614 |
} |
615 |
|
616 |
if (properties==null) { |
617 |
draw(g, scaleInstance, center, null, null); |
618 |
} else {
|
619 |
double originalSize = getSize();
|
620 |
double size=originalSize;
|
621 |
int pq = properties.getPrintQuality();
|
622 |
if (pq == PrintAttributes.PRINT_QUALITY_HIGH) {
|
623 |
size *= (double) 600/72; |
624 |
} else {
|
625 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
626 |
size *= (double) 300/72; |
627 |
} else {
|
628 |
// unitFactor *= 72; (which is the same than doing nothing)
|
629 |
} |
630 |
} |
631 |
setSize(size); |
632 |
print(g, scaleInstance, center, properties); |
633 |
setSize(originalSize); |
634 |
} |
635 |
|
636 |
} |
637 |
|
638 |
|
639 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
640 |
PrintAttributes properties) { |
641 |
|
642 |
/* TODO Use this?
|
643 |
double dpi = 100;
|
644 |
int pq = properties.getPrintQuality();
|
645 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
|
646 |
dpi = 300;
|
647 |
} else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){
|
648 |
dpi = 600;
|
649 |
} else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){
|
650 |
dpi = 72;
|
651 |
}
|
652 |
*/
|
653 |
|
654 |
draw(g,at,geom,null,null); |
655 |
} |
656 |
|
657 |
public void setUnit(int unitIndex) { |
658 |
unit = unitIndex; |
659 |
} |
660 |
|
661 |
public int getUnit() { |
662 |
return unit;
|
663 |
} |
664 |
|
665 |
public int getReferenceSystem() { |
666 |
return this.referenceSystem; |
667 |
} |
668 |
|
669 |
public void setReferenceSystem(int rs) { |
670 |
this.referenceSystem = rs;
|
671 |
} |
672 |
|
673 |
public double toCartographicSize(ViewPort viewPort, double dpi, |
674 |
Geometry geom) { |
675 |
|
676 |
double oldSize = getSize();
|
677 |
setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom); |
678 |
return oldSize; }
|
679 |
|
680 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
681 |
setSize(cartographicSize); |
682 |
} |
683 |
|
684 |
public double getCartographicSize(ViewPort viewPort, double dpi, |
685 |
Geometry geom) { |
686 |
|
687 |
return SymbolUtils.getCartographicLength(this, |
688 |
getSize(), |
689 |
viewPort, |
690 |
dpi); |
691 |
} |
692 |
|
693 |
public double getRotation() { |
694 |
return rotation_radians;
|
695 |
} |
696 |
|
697 |
public void setRotation(double rot) { |
698 |
rotation_radians = rot; |
699 |
} |
700 |
|
701 |
public Point2D getOffset() { |
702 |
return offset;
|
703 |
} |
704 |
|
705 |
public void setOffset(Point2D off) { |
706 |
offset = off; |
707 |
} |
708 |
|
709 |
public Color getColor() { |
710 |
return color;
|
711 |
} |
712 |
|
713 |
public void setColor(Color co) { |
714 |
color = co; |
715 |
} |
716 |
|
717 |
public void setAlpha(int a) { |
718 |
alpha = a; |
719 |
} |
720 |
|
721 |
public IMask getMask() {
|
722 |
return mask;
|
723 |
} |
724 |
|
725 |
public void setMask(IMask m) { |
726 |
mask = m; |
727 |
} |
728 |
|
729 |
// =========================================
|
730 |
|
731 |
public void loadFromState(PersistentState state) throws PersistenceException { |
732 |
|
733 |
if (state.hasValue("vc_xOffsetScale")) { |
734 |
this.visualCorrection = new VisualCorrection(); |
735 |
this.visualCorrection.xOffsetScale = state.getDouble("vc_xOffsetScale"); |
736 |
this.visualCorrection.yOffsetScale = state.getDouble("vc_yOffsetScale"); |
737 |
this.visualCorrection.sizeScale = state.getDouble("vc_sizeScale"); |
738 |
} else {
|
739 |
this.visualCorrection = null; |
740 |
} |
741 |
if (state.hasValue("mask")) { |
742 |
this.mask = (IMask) state.get("mask"); |
743 |
} else {
|
744 |
this.mask = null; |
745 |
} |
746 |
// ==============================================
|
747 |
this.color = (Color) state.get("color"); |
748 |
this.font = (Font) state.get("font"); |
749 |
|
750 |
double aux = state.getDouble("size"); |
751 |
this.setSize(aux);
|
752 |
|
753 |
this.unicode = state.getInt("unicode"); |
754 |
this.desc = state.getString("desc"); |
755 |
this.isShapeVisible = state.getBoolean("isShapeVisible"); |
756 |
|
757 |
double x = state.getDouble("xOffset"); |
758 |
double y = state.getDouble("yOffset"); |
759 |
this.offset = new Point2D.Double(x, y); |
760 |
|
761 |
this.rotation_radians = state.getDouble("rotation"); |
762 |
this.unit = state.getInt("unit"); |
763 |
this.referenceSystem = state.getInt("referenceSystem"); |
764 |
} |
765 |
|
766 |
public void saveToState(PersistentState state) throws PersistenceException { |
767 |
|
768 |
if (this.visualCorrection != null) { |
769 |
state.set("vc_xOffsetScale", this.visualCorrection.xOffsetScale); |
770 |
state.set("vc_yOffsetScale", this.visualCorrection.yOffsetScale); |
771 |
state.set("vc_sizeScale", this.visualCorrection.sizeScale); |
772 |
} |
773 |
if (this.mask != null) { |
774 |
state.set("mask", this.mask); |
775 |
} |
776 |
// ==================================================
|
777 |
state.set("color", this.color); |
778 |
state.set("font", this.font); |
779 |
state.set("size", this.size); |
780 |
state.set("unicode", this.unicode); |
781 |
state.set("desc", this.desc); |
782 |
state.set("isShapeVisible", this.isShapeVisible); |
783 |
state.set("xOffset", this.offset.getX()); |
784 |
state.set("yOffset", this.offset.getY()); |
785 |
state.set("rotation", this.rotation_radians); |
786 |
state.set("unit", this.unit); |
787 |
state.set("referenceSystem", this.referenceSystem); |
788 |
} |
789 |
|
790 |
public static void registerPersistent() { |
791 |
|
792 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
793 |
if( manager.getDefinition(CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME)==null ) { |
794 |
DynStruct definition = manager.addDefinition( |
795 |
CharacterMarkerSymbol.class, |
796 |
CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME, |
797 |
CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME+" Persistence definition",
|
798 |
null,
|
799 |
null
|
800 |
); |
801 |
|
802 |
definition.addDynFieldObject("color").setClassOfValue(Color.class).setMandatory(true); |
803 |
definition.addDynFieldObject("font").setClassOfValue(Font.class).setMandatory(true); |
804 |
definition.addDynFieldDouble("size").setMandatory(true); |
805 |
definition.addDynFieldInt("unicode").setMandatory(true); |
806 |
definition.addDynFieldString("desc").setMandatory(true); |
807 |
definition.addDynFieldBoolean("isShapeVisible").setMandatory(true); |
808 |
definition.addDynFieldDouble("xOffset").setMandatory(true); |
809 |
definition.addDynFieldDouble("yOffset").setMandatory(true); |
810 |
definition.addDynFieldDouble("rotation").setMandatory(true); |
811 |
definition.addDynFieldInt("unit").setMandatory(true); |
812 |
definition.addDynFieldInt("referenceSystem").setMandatory(true); |
813 |
definition.addDynFieldObject("mask").setClassOfValue(IMask.class).setMandatory(false); |
814 |
// =====================
|
815 |
definition.addDynFieldDouble("vc_xOffsetScale").setMandatory(false); |
816 |
definition.addDynFieldDouble("vc_yOffsetScale").setMandatory(false); |
817 |
definition.addDynFieldDouble("vc_sizeScale").setMandatory(false); |
818 |
} |
819 |
} |
820 |
|
821 |
/**
|
822 |
* Class to be used for the methods that control the visual correction of a character.
|
823 |
* This visual correction has the responsibility of modify the dimensions of the
|
824 |
* character to be used as a symbol(in case that the user wants to use more or less
|
825 |
* pixels to represent it )
|
826 |
*
|
827 |
*/
|
828 |
private class VisualCorrection { |
829 |
double xOffsetScale = 1; |
830 |
double yOffsetScale = 1; |
831 |
double sizeScale = 1; |
832 |
} |
833 |
|
834 |
} |