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 @ 47790
History | View | Annotate | Download (20.8 KB)
1 | 40911 | jldominguez | /* 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 | package org.gvsig.labeling.symbol; |
||
43 | |||
44 | import java.awt.Color; |
||
45 | import java.awt.Font; |
||
46 | import java.awt.Graphics2D; |
||
47 | import java.awt.Rectangle; |
||
48 | import java.awt.Shape; |
||
49 | import java.awt.font.FontRenderContext; |
||
50 | import java.awt.font.GlyphVector; |
||
51 | import java.awt.geom.AffineTransform; |
||
52 | import java.awt.geom.Point2D; |
||
53 | import java.awt.image.BufferedImage; |
||
54 | import org.gvsig.compat.print.PrintAttributes; |
||
55 | import org.gvsig.fmap.dal.feature.Feature; |
||
56 | import org.gvsig.fmap.geom.Geometry; |
||
57 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
58 | import org.gvsig.fmap.geom.GeometryLocator; |
||
59 | import org.gvsig.fmap.geom.GeometryManager; |
||
60 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
61 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
62 | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
||
63 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
64 | import org.gvsig.labeling.lang.LabelClassUtils; |
||
65 | 47476 | fdiaz | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol_v2; |
66 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol; |
||
67 | 40911 | jldominguez | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask; |
68 | import org.gvsig.tools.ToolsLocator; |
||
69 | import org.gvsig.tools.dynobject.DynStruct; |
||
70 | import org.gvsig.tools.persistence.PersistenceManager; |
||
71 | import org.gvsig.tools.persistence.PersistentState; |
||
72 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
73 | import org.gvsig.tools.task.Cancellable; |
||
74 | import org.slf4j.Logger; |
||
75 | import org.slf4j.LoggerFactory; |
||
76 | |||
77 | /**
|
||
78 | * Allows to use a source of TrueType characters to define the marker that will
|
||
79 | * substitute the symbol.If the picture is defined in a source, the performance is
|
||
80 | * more agile.
|
||
81 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
82 | */
|
||
83 | 47476 | fdiaz | public class CharacterMarkerSymbol extends AbstractMarkerSymbol implements IMarkerSymbol_v2 { |
84 | 42439 | dmartinezizquierdo | |
85 | 40911 | jldominguez | private static Logger logger = |
86 | LoggerFactory.getLogger(CharacterMarkerSymbol.class); |
||
87 | 42439 | dmartinezizquierdo | |
88 | 40911 | jldominguez | public static final String CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME = |
89 | "CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME";
|
||
90 | 42439 | dmartinezizquierdo | |
91 | 40911 | jldominguez | private Font font = new Font("Arial", Font.PLAIN, 20); |
92 | private int unicode; |
||
93 | private ISymbol selectionSymbol;
|
||
94 | private VisualCorrection visualCorrection;
|
||
95 | 42439 | dmartinezizquierdo | |
96 | 47476 | fdiaz | // private boolean isShapeVisible = true;
|
97 | // private String desc = "";
|
||
98 | 42439 | dmartinezizquierdo | |
99 | 47476 | fdiaz | // private double size;
|
100 | // private Color color = Color.BLACK;
|
||
101 | // private Point2D offset = new Point2D.Double();
|
||
102 | // private IMask mask;
|
||
103 | // private double rotation_radians = 0;
|
||
104 | 42439 | dmartinezizquierdo | |
105 | 47476 | fdiaz | // private int unit = -1;
|
106 | // private int referenceSystem = CartographicSupport.WORLD;
|
||
107 | |||
108 | 40911 | jldominguez | private int alpha = 255; |
109 | 42439 | dmartinezizquierdo | |
110 | 40911 | jldominguez | /*
|
111 | 42439 | dmartinezizquierdo | *
|
112 | 40911 | jldominguez | */
|
113 | 42439 | dmartinezizquierdo | |
114 | 40911 | jldominguez | private static GeometryManager geoman = GeometryLocator.getGeometryManager(); |
115 | |||
116 | /**
|
||
117 | * Creates a new instance of CharacterMarker with default values
|
||
118 | *
|
||
119 | */
|
||
120 | public CharacterMarkerSymbol() {
|
||
121 | super();
|
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * Creates a new instance of CharacterMarker specifying the marker source
|
||
126 | * font, the character code corresponding to the symbol, and the color that
|
||
127 | * will be used in rendering time.
|
||
128 | *
|
||
129 | * @param font -
|
||
130 | * src Font
|
||
131 | * @param charCode -
|
||
132 | * character code of the symbol for this font
|
||
133 | * @param color -
|
||
134 | * color to be used in when rendering.
|
||
135 | */
|
||
136 | public CharacterMarkerSymbol(Font font, int charCode, Color color) { |
||
137 | super();
|
||
138 | this.font = font;
|
||
139 | unicode = charCode; |
||
140 | setColor(color); |
||
141 | } |
||
142 | /**
|
||
143 | * Returns the font that will be used to define the symbol
|
||
144 | * @return font
|
||
145 | */
|
||
146 | public Font getFont() { |
||
147 | 47476 | fdiaz | if(font == null){ |
148 | font = new Font("Arial", Font.PLAIN, (int) Math.round(getSize())); |
||
149 | } |
||
150 | return font;
|
||
151 | 40911 | jldominguez | } |
152 | /**
|
||
153 | * Sets the font that will be used to define the symbol
|
||
154 | * @return font
|
||
155 | */
|
||
156 | public void setFont(Font font) { |
||
157 | this.font = font;
|
||
158 | 47476 | fdiaz | this.setSize(this.font.getSize()); |
159 | 40911 | jldominguez | } |
160 | 47476 | fdiaz | |
161 | @Override
|
||
162 | 47790 | fdiaz | public ISymbol getSymbolForSelection(Color selectionColor) { |
163 | 47476 | fdiaz | if (selectionSymbol == null) { |
164 | selectionSymbol = (ISymbol) LabelClassUtils.clone(this);
|
||
165 | 47790 | fdiaz | selectionSymbol.setColor(selectionColor); |
166 | 47476 | fdiaz | } else {
|
167 | 47790 | fdiaz | selectionSymbol.setColor(selectionColor); |
168 | 47476 | fdiaz | } |
169 | if (selectionSymbol instanceof CartographicSupport) { |
||
170 | ((CartographicSupport) selectionSymbol).setUnit(this.getUnit());
|
||
171 | } |
||
172 | 40911 | jldominguez | |
173 | 47476 | fdiaz | return selectionSymbol;
|
174 | } |
||
175 | 42439 | dmartinezizquierdo | |
176 | |||
177 | 47790 | fdiaz | @Override
|
178 | 40911 | jldominguez | public void draw(Graphics2D g, |
179 | AffineTransform affineTransform, Geometry geom,
|
||
180 | 47476 | fdiaz | Feature feat, Cancellable cancel, Rectangle r) {
|
181 | 42439 | dmartinezizquierdo | |
182 | 47476 | fdiaz | double size_d = getCartographicSize();
|
183 | // size_d = this.getPrintSize(properties, size_d);
|
||
184 | size_d = this.getAdjustedSize(r, size_d);
|
||
185 | 40911 | jldominguez | |
186 | 47476 | fdiaz | double theta = getEfectiveRotationInRadians(feat);
|
187 | 40911 | jldominguez | |
188 | 47476 | fdiaz | int xOffset = (int) getEfectiveOffset(feat).getX(); |
189 | int yOffset = (int) getEfectiveOffset(feat).getY(); |
||
190 | |||
191 | if (size_d < 0.0001) { |
||
192 | 40911 | jldominguez | return;
|
193 | } |
||
194 | 42439 | dmartinezizquierdo | |
195 | 40911 | jldominguez | org.gvsig.fmap.geom.primitive.Point cen = null;
|
196 | try {
|
||
197 | cen = geom.centroid(); |
||
198 | } catch (Exception e) { |
||
199 | 47476 | fdiaz | logger.warn("While getting centroid", e);
|
200 | return;
|
||
201 | 40911 | jldominguez | } |
202 | 47476 | fdiaz | g.setColor(getColor()); |
203 | 42439 | dmartinezizquierdo | |
204 | 40911 | jldominguez | Point2D p = new Point2D.Double(cen.getX(), cen.getY()); |
205 | |||
206 | if (isVisuallyCorrected()) {
|
||
207 | 47476 | fdiaz | size_d *= visualCorrection.sizeScale; |
208 | p.setLocation(p.getX() - xOffset*size_d*visualCorrection.xOffsetScale, p.getY() - yOffset*size_d*visualCorrection.yOffsetScale); |
||
209 | 40911 | jldominguez | |
210 | } |
||
211 | 47476 | fdiaz | g.setFont(getFont().deriveFont((float)size_d));
|
212 | 40911 | jldominguez | |
213 | g.translate((int) (p.getX() + xOffset), (int) (p.getY() + yOffset)); |
||
214 | 47476 | fdiaz | if (theta != 0) { |
215 | g.rotate(theta); |
||
216 | } |
||
217 | 40911 | jldominguez | |
218 | char[] text = new char[] { (char) unicode }; |
||
219 | |||
220 | IMask mask = getMask(); |
||
221 | if (mask != null) { |
||
222 | FontRenderContext frc = g.getFontRenderContext();
|
||
223 | |||
224 | GlyphVector gv = font.createGlyphVector(frc, text );
|
||
225 | |||
226 | Shape markerShape = gv.getOutline(0, 0); |
||
227 | mask.getFillSymbol(). |
||
228 | draw(g, null, mask.getHaloShape(markerShape), feat, cancel);
|
||
229 | |||
230 | } |
||
231 | 47476 | fdiaz | g.drawChars(text, 0, text.length, - (int) (size_d*0.4), (int) (size_d*0.4)); |
232 | 40911 | jldominguez | |
233 | |||
234 | 47476 | fdiaz | if (theta!=0) { |
235 | g.rotate(-theta); |
||
236 | } |
||
237 | 40911 | jldominguez | g.translate(-(int) (p.getX() + xOffset), - (int) (p.getY() + yOffset)); |
238 | } |
||
239 | |||
240 | |||
241 | |||
242 | |||
243 | 42439 | dmartinezizquierdo | |
244 | 40911 | jldominguez | /**
|
245 | * Sets the unicode for a symbol represented by a character
|
||
246 | * @param symbol, int
|
||
247 | */
|
||
248 | public void setUnicode(int symbol) { |
||
249 | this.unicode = symbol;
|
||
250 | } |
||
251 | |||
252 | /**
|
||
253 | * Obtains the unicode for a symbol
|
||
254 | * @return unicode, int
|
||
255 | */
|
||
256 | public int getUnicode() { |
||
257 | return unicode;
|
||
258 | } |
||
259 | |||
260 | |||
261 | |||
262 | /*
|
||
263 | public void setXMLEntity(XMLEntity xml) {
|
||
264 | setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
||
265 | Point p = new Point();
|
||
266 | p.setLocation(xml.getDoubleProperty("xOffset"), xml.getDoubleProperty("yOffset"));
|
||
267 | |||
268 | setDescription(xml.getStringProperty("desc"));
|
||
269 | size = xml.getDoubleProperty("size");
|
||
270 | font = new Font(xml.getStringProperty("font"),
|
||
271 | xml.getIntProperty("fontStyle"),
|
||
272 | (int) size);
|
||
273 | setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
||
274 | unicode = xml.getIntProperty("symbolCode");
|
||
275 | setOffset(p);
|
||
276 | setRotation(xml.getDoubleProperty("rotation"));
|
||
277 | setReferenceSystem(xml.getIntProperty("referenceSystem"));
|
||
278 | setUnit(xml.getIntProperty("unit"));
|
||
279 | }
|
||
280 | */
|
||
281 | |||
282 | |||
283 | 47476 | fdiaz | // public double getSize() {
|
284 | // return size;
|
||
285 | // }
|
||
286 | 40911 | jldominguez | |
287 | 47790 | fdiaz | @Override
|
288 | 40911 | jldominguez | public void setSize(double size) { |
289 | 47476 | fdiaz | super.setSize(size);
|
290 | //NOTE: No hay que llamar al setFont
|
||
291 | 40911 | jldominguez | font = new Font(font.getName(), font.getStyle(), (int) Math.round(size)); |
292 | } |
||
293 | /**
|
||
294 | * Returns true of false depending if the character marker symbol selected is visually
|
||
295 | * corrected.That is, if the character has been properly scaled to use a specific number
|
||
296 | * of pixels to be represented.
|
||
297 | *
|
||
298 | * @return boolean
|
||
299 | */
|
||
300 | public boolean isVisuallyCorrected() { |
||
301 | return visualCorrection != null; |
||
302 | } |
||
303 | /**
|
||
304 | * Sets the visual correction for a character in order to scale it if it is necessary.
|
||
305 | *
|
||
306 | * @return boolean
|
||
307 | */
|
||
308 | public void setVisuallyCorrected(boolean visuallyCorrected) { |
||
309 | if (visuallyCorrected && visualCorrection == null) { |
||
310 | CharacterMarkerSymbol clone = |
||
311 | (CharacterMarkerSymbol) LabelClassUtils.clone(this);
|
||
312 | int frameSize = 200; |
||
313 | double symbolSize = 100; |
||
314 | BufferedImage bi = new BufferedImage(frameSize, frameSize, BufferedImage.TYPE_INT_ARGB); |
||
315 | Graphics2D aGraphics = bi.createGraphics();
|
||
316 | clone.setOffset(new Point2D.Double(0,0)); |
||
317 | clone.setSize(symbolSize); |
||
318 | clone.setColor(Color.PINK);
|
||
319 | |||
320 | |||
321 | // draw it at center of the image
|
||
322 | org.gvsig.fmap.geom.primitive.Point pCenter = null;
|
||
323 | try {
|
||
324 | pCenter = geoman.createPoint( |
||
325 | frameSize/2,frameSize/2, SUBTYPES.GEOM2D); |
||
326 | } catch (Exception e) { |
||
327 | logger.error("While creating point", e);
|
||
328 | } |
||
329 | 47476 | fdiaz | clone.draw(aGraphics, new AffineTransform(), pCenter, null, null, null); |
330 | 40911 | jldominguez | |
331 | int realTop = -1; |
||
332 | int realBottom = -1; |
||
333 | int realLeft = -1; |
||
334 | int realRight = -1; |
||
335 | |||
336 | // let's see where the highest pixel is in Y-axis
|
||
337 | boolean done = false; |
||
338 | for (int j = 0; !done && j < bi.getHeight(); j++) { |
||
339 | for (int i = 0; !done && i < bi.getWidth(); i++) { |
||
340 | if (bi.getRGB(i, j) != 0) { |
||
341 | realTop = j; |
||
342 | done = true;
|
||
343 | } |
||
344 | } |
||
345 | } |
||
346 | |||
347 | // let's see where the lowest pixel is in Y-axis
|
||
348 | done = false;
|
||
349 | for (int j = bi.getHeight()-1; !done && j >= 0; j--) { |
||
350 | for (int i = 0; !done && i < bi.getWidth(); i++) { |
||
351 | if (bi.getRGB(i, j) != 0) { |
||
352 | realBottom = i; |
||
353 | done = true;
|
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | |||
358 | // let's see where the first pixel at left is in X-axis
|
||
359 | done = false;
|
||
360 | for (int i = 0; !done && i < bi.getWidth(); i++) { |
||
361 | for (int j = 0; !done && j < bi.getHeight(); j++) { |
||
362 | if (bi.getRGB(i, j) != 0) { |
||
363 | realLeft = i; |
||
364 | done = true;
|
||
365 | } |
||
366 | } |
||
367 | } |
||
368 | |||
369 | // let's see where the first pixel at right is in X-axis
|
||
370 | done = false;
|
||
371 | for (int i = bi.getWidth()-1; !done && i >=0 ; i--) { |
||
372 | for (int j = 0; !done && j < bi.getHeight(); j++) { |
||
373 | if (bi.getRGB(i, j) != 0) { |
||
374 | realRight = i; |
||
375 | done = true;
|
||
376 | } |
||
377 | } |
||
378 | } |
||
379 | 42439 | dmartinezizquierdo | |
380 | 47476 | fdiaz | int realWidth = bi.getWidth() - realRight - realLeft;
|
381 | 40911 | jldominguez | int realHeight = bi.getHeight() - realBottom - realTop;
|
382 | |||
383 | visualCorrection = new VisualCorrection();
|
||
384 | 42439 | dmartinezizquierdo | |
385 | 40911 | jldominguez | if (realBottom!=-1 && realTop!=-1 && realLeft!=-1 && realRight != -1) { |
386 | double correctingSize = Math.max(realHeight, realWidth); |
||
387 | visualCorrection.sizeScale = clone.getSize() / correctingSize; |
||
388 | } |
||
389 | |||
390 | if (realLeft!=-1 && realRight!=-1) { |
||
391 | double correctingCenterX = (((realWidth)*0.5)+realLeft); |
||
392 | double correctingCenterY = (((realHeight)*0.5)+realBottom); |
||
393 | visualCorrection.xOffsetScale = (pCenter.getX() - correctingCenterX) / frameSize; |
||
394 | visualCorrection.yOffsetScale = (pCenter.getY() - correctingCenterY) / frameSize; |
||
395 | } |
||
396 | } else {
|
||
397 | visualCorrection = null;
|
||
398 | } |
||
399 | } |
||
400 | 42439 | dmartinezizquierdo | |
401 | |||
402 | 47790 | fdiaz | @Override
|
403 | 40911 | jldominguez | public Object clone() throws CloneNotSupportedException { |
404 | return LabelClassUtils.clone(this); |
||
405 | } |
||
406 | 42439 | dmartinezizquierdo | |
407 | |||
408 | 40911 | jldominguez | public void getPixExtentPlus( |
409 | Geometry geom, float[] distances, |
||
410 | ViewPort viewPort, int dpi) {
|
||
411 | 42439 | dmartinezizquierdo | |
412 | 47476 | fdiaz | // float cs = (float) getCartographicSize(viewPort, dpi, geom);
|
413 | float cs = (float) this.getEfectiveSize(null); |
||
414 | 40911 | jldominguez | distances[0] = cs;
|
415 | distances[1] = cs;
|
||
416 | } |
||
417 | |||
418 | public boolean isOneDotOrPixel(Geometry geom, |
||
419 | double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) { |
||
420 | |||
421 | int type = geom.getType();
|
||
422 | switch (type) {
|
||
423 | case Geometry.TYPES.NULL:
|
||
424 | case Geometry.TYPES.POINT:
|
||
425 | case Geometry.TYPES.MULTIPOINT:
|
||
426 | return false; |
||
427 | default:
|
||
428 | org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom |
||
429 | .getEnvelope(); |
||
430 | |||
431 | double dist1Pixel = viewPort.getDist1pixel();
|
||
432 | |||
433 | float[] distances = new float[2]; |
||
434 | this.getPixExtentPlus(geom, distances, viewPort, dpi);
|
||
435 | |||
436 | boolean onePoint =
|
||
437 | (geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds |
||
438 | .getLength(1)
|
||
439 | + distances[1] <= dist1Pixel);
|
||
440 | |||
441 | if (onePoint) {
|
||
442 | Envelope bounds = geom.getEnvelope(); |
||
443 | positionOfDotOrPixel[0] = bounds.getMinimum(0); |
||
444 | positionOfDotOrPixel[1] = bounds.getMinimum(1); |
||
445 | } |
||
446 | return onePoint;
|
||
447 | } |
||
448 | } |
||
449 | 42439 | dmartinezizquierdo | |
450 | 40911 | jldominguez | public int getOnePointRgb() { |
451 | return this.getColor().getRGB(); |
||
452 | } |
||
453 | |||
454 | 47476 | fdiaz | // @Override
|
455 | // public String getDescription() {
|
||
456 | // return desc;
|
||
457 | // }
|
||
458 | //
|
||
459 | // public boolean isShapeVisible() {
|
||
460 | // return isShapeVisible;
|
||
461 | // }
|
||
462 | //
|
||
463 | // public void setDescription(String d) {
|
||
464 | // desc = d;
|
||
465 | // }
|
||
466 | 40911 | jldominguez | |
467 | 47476 | fdiaz | // public int getSymbolType() {
|
468 | // return Geometry.TYPES.POINT;
|
||
469 | // }
|
||
470 | 40911 | jldominguez | |
471 | 47476 | fdiaz | @Override
|
472 | 40911 | jldominguez | public boolean isSuitableFor(Geometry geom) { |
473 | return geom.getType() == Geometry.TYPES.POINT
|
||
474 | || geom.getType() == Geometry.TYPES.MULTIPOINT; |
||
475 | } |
||
476 | |||
477 | 47476 | fdiaz | // public void drawInsideRectangle(Graphics2D g,
|
478 | // AffineTransform scaleInstance, Rectangle r,
|
||
479 | // PrintAttributes properties) throws SymbolDrawingException {
|
||
480 | //
|
||
481 | //
|
||
482 | // org.gvsig.fmap.geom.primitive.Point center = null;
|
||
483 | // try {
|
||
484 | // center = geoman.createPoint(
|
||
485 | // r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D);
|
||
486 | // } catch (CreateGeometryException e) {
|
||
487 | // throw new SymbolDrawingException(TYPES.POINT);
|
||
488 | // }
|
||
489 | //
|
||
490 | // if (properties==null) {
|
||
491 | // draw(g, scaleInstance, center, null, null);
|
||
492 | // } else {
|
||
493 | // double originalSize = getSize();
|
||
494 | // double size=originalSize;
|
||
495 | // int pq = properties.getPrintQuality();
|
||
496 | // if (pq == PrintAttributes.PRINT_QUALITY_HIGH) {
|
||
497 | // size *= (double) 600/72;
|
||
498 | // } else {
|
||
499 | // if (pq == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
||
500 | // size *= (double) 300/72;
|
||
501 | // } else {
|
||
502 | //// unitFactor *= 72; (which is the same than doing nothing)
|
||
503 | // }
|
||
504 | // }
|
||
505 | // setSize(size);
|
||
506 | // print(g, scaleInstance, center, properties);
|
||
507 | // setSize(originalSize);
|
||
508 | // }
|
||
509 | //
|
||
510 | // }
|
||
511 | 42439 | dmartinezizquierdo | |
512 | |||
513 | 47790 | fdiaz | @Override
|
514 | 40911 | jldominguez | public void print(Graphics2D g, AffineTransform at, Geometry geom, |
515 | PrintAttributes properties) { |
||
516 | |||
517 | /* TODO Use this?
|
||
518 | double dpi = 100;
|
||
519 | int pq = properties.getPrintQuality();
|
||
520 | if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
|
||
521 | dpi = 300;
|
||
522 | } else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){
|
||
523 | dpi = 600;
|
||
524 | } else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){
|
||
525 | dpi = 72;
|
||
526 | }
|
||
527 | */
|
||
528 | |||
529 | 42439 | dmartinezizquierdo | draw(g,at,geom,null,null); |
530 | 40911 | jldominguez | } |
531 | |||
532 | 47476 | fdiaz | // public void setUnit(int unitIndex) {
|
533 | // unit = unitIndex;
|
||
534 | // }
|
||
535 | //
|
||
536 | // public int getUnit() {
|
||
537 | // return unit;
|
||
538 | // }
|
||
539 | //
|
||
540 | // public int getReferenceSystem() {
|
||
541 | // return this.referenceSystem;
|
||
542 | // }
|
||
543 | //
|
||
544 | // public void setReferenceSystem(int rs) {
|
||
545 | // this.referenceSystem = rs;
|
||
546 | // }
|
||
547 | //
|
||
548 | // public double toCartographicSize(ViewPort viewPort, double dpi,
|
||
549 | // Geometry geom) {
|
||
550 | //
|
||
551 | // double oldSize = getSize();
|
||
552 | // setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom);
|
||
553 | // return oldSize; }
|
||
554 | //
|
||
555 | // public void setCartographicSize(double cartographicSize, Geometry geom) {
|
||
556 | // setSize(cartographicSize);
|
||
557 | // }
|
||
558 | //
|
||
559 | // public double getCartographicSize(ViewPort viewPort, double dpi,
|
||
560 | // Geometry geom) {
|
||
561 | //
|
||
562 | // return SymbolUtils.getCartographicLength(this,
|
||
563 | // getSize(),
|
||
564 | // viewPort,
|
||
565 | // dpi);
|
||
566 | // }
|
||
567 | 40911 | jldominguez | |
568 | 47476 | fdiaz | // public double getRotation() {
|
569 | // return rotation_radians;
|
||
570 | // }
|
||
571 | //
|
||
572 | // public void setRotation(double rot) {
|
||
573 | // rotation_radians = rot;
|
||
574 | // }
|
||
575 | //
|
||
576 | // public Point2D getOffset() {
|
||
577 | // return offset;
|
||
578 | // }
|
||
579 | //
|
||
580 | // public void setOffset(Point2D off) {
|
||
581 | // offset = off;
|
||
582 | // }
|
||
583 | //
|
||
584 | // public Color getColor() {
|
||
585 | // return color;
|
||
586 | // }
|
||
587 | //
|
||
588 | // public void setColor(Color co) {
|
||
589 | // color = co;
|
||
590 | // }
|
||
591 | 40911 | jldominguez | |
592 | 47790 | fdiaz | @Override
|
593 | 40911 | jldominguez | public void setAlpha(int a) { |
594 | alpha = a; |
||
595 | } |
||
596 | |||
597 | 47476 | fdiaz | // public IMask getMask() {
|
598 | // return mask;
|
||
599 | // }
|
||
600 | //
|
||
601 | // public void setMask(IMask m) {
|
||
602 | // mask = m;
|
||
603 | // }
|
||
604 | 40911 | jldominguez | |
605 | // =========================================
|
||
606 | 42439 | dmartinezizquierdo | |
607 | 47790 | fdiaz | @Override
|
608 | 40911 | jldominguez | public void loadFromState(PersistentState state) throws PersistenceException { |
609 | 47476 | fdiaz | |
610 | super.loadFromState(state);
|
||
611 | 42439 | dmartinezizquierdo | |
612 | 47476 | fdiaz | // if (state.hasValue("mask")) {
|
613 | // this.mask = (IMask) state.get("mask");
|
||
614 | // } else {
|
||
615 | // this.mask = null;
|
||
616 | // }
|
||
617 | // // ==============================================
|
||
618 | // this.color = (Color) state.get("color");
|
||
619 | // double aux = state.getDouble("size");
|
||
620 | // this.setSize(aux);
|
||
621 | // this.rotation_radians = state.getDouble("rotation");
|
||
622 | // this.desc = state.getString("desc");
|
||
623 | // this.isShapeVisible = state.getBoolean("isShapeVisible");
|
||
624 | |||
625 | // state.set("unit", getUnit());
|
||
626 | // state.set("referenceSystem", getReferenceSystem());
|
||
627 | |||
628 | if(state.isNull("offset")) { |
||
629 | double x = state.getDouble("xOffset"); |
||
630 | double y = state.getDouble("yOffset"); |
||
631 | this.setOffset(new Point2D.Double(x, y)); |
||
632 | } |
||
633 | |||
634 | if (state.hasValue("vc_xOffsetScale")) { |
||
635 | 40911 | jldominguez | this.visualCorrection = new VisualCorrection(); |
636 | this.visualCorrection.xOffsetScale = state.getDouble("vc_xOffsetScale"); |
||
637 | this.visualCorrection.yOffsetScale = state.getDouble("vc_yOffsetScale"); |
||
638 | this.visualCorrection.sizeScale = state.getDouble("vc_sizeScale"); |
||
639 | } else {
|
||
640 | this.visualCorrection = null; |
||
641 | } |
||
642 | 42439 | dmartinezizquierdo | |
643 | 47476 | fdiaz | this.font = (Font) state.get("font"); |
644 | 42439 | dmartinezizquierdo | |
645 | 40911 | jldominguez | this.unicode = state.getInt("unicode"); |
646 | } |
||
647 | |||
648 | 47790 | fdiaz | @Override
|
649 | 40911 | jldominguez | public void saveToState(PersistentState state) throws PersistenceException { |
650 | 47476 | fdiaz | |
651 | super.saveToState(state);
|
||
652 | 42439 | dmartinezizquierdo | |
653 | 47476 | fdiaz | // if (this.mask != null) {
|
654 | // state.set("mask", this.mask);
|
||
655 | // }
|
||
656 | // state.set("color", this.color);
|
||
657 | // state.set("size", this.size);
|
||
658 | // state.set("rotation", this.rotation_radians);
|
||
659 | // state.set("desc", this.desc);
|
||
660 | // state.set("isShapeVisible", this.isShapeVisible);
|
||
661 | // setUnit(state.getInt("unit"));
|
||
662 | // setReferenceSystem(state.getInt("referenceSystem"));
|
||
663 | |||
664 | //Mantenemos estas dos l?neas por compatibilidad pero deber?an eliminarse
|
||
665 | state.set("xOffset", this.getOffset().getX()); |
||
666 | state.set("yOffset", this.getOffset().getY()); |
||
667 | if (this.visualCorrection != null) { |
||
668 | 40911 | jldominguez | state.set("vc_xOffsetScale", this.visualCorrection.xOffsetScale); |
669 | state.set("vc_yOffsetScale", this.visualCorrection.yOffsetScale); |
||
670 | state.set("vc_sizeScale", this.visualCorrection.sizeScale); |
||
671 | } |
||
672 | // ==================================================
|
||
673 | state.set("font", this.font); |
||
674 | state.set("unicode", this.unicode); |
||
675 | 47476 | fdiaz | } |
676 | 42439 | dmartinezizquierdo | |
677 | 47476 | fdiaz | |
678 | 40911 | jldominguez | public static void registerPersistent() { |
679 | 42439 | dmartinezizquierdo | |
680 | 40911 | jldominguez | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
681 | if( manager.getDefinition(CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME)==null ) { |
||
682 | DynStruct definition = manager.addDefinition( |
||
683 | CharacterMarkerSymbol.class, |
||
684 | CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME, |
||
685 | CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME+" Persistence definition",
|
||
686 | 42439 | dmartinezizquierdo | null,
|
687 | 40911 | jldominguez | null
|
688 | ); |
||
689 | 42439 | dmartinezizquierdo | |
690 | 47476 | fdiaz | definition.extend(manager.getDefinition(MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
691 | // definition.addDynFieldObject("color").setClassOfValue(Color.class).setMandatory(true);
|
||
692 | // definition.addDynFieldDouble("size").setMandatory(true);
|
||
693 | // definition.addDynFieldDouble("rotation").setMandatory(true);
|
||
694 | // definition.addDynFieldInt("unit").setMandatory(true);
|
||
695 | // definition.addDynFieldInt("referenceSystem").setMandatory(true);
|
||
696 | // definition.addDynFieldObject("mask").setClassOfValue(IMask.class).setMandatory(false);
|
||
697 | // definition.addDynFieldString("desc").setMandatory(true);
|
||
698 | // definition.addDynFieldBoolean("isShapeVisible").setMandatory(true);
|
||
699 | |||
700 | //Por compatibilidad mantenemos estas dos l?neas aunque deber?an eliminarse
|
||
701 | 40911 | jldominguez | definition.addDynFieldDouble("xOffset").setMandatory(true); |
702 | definition.addDynFieldDouble("yOffset").setMandatory(true); |
||
703 | 47476 | fdiaz | |
704 | definition.addDynFieldObject("font").setClassOfValue(Font.class).setMandatory(true); |
||
705 | definition.addDynFieldInt("unicode").setMandatory(true); |
||
706 | 40911 | jldominguez | // =====================
|
707 | definition.addDynFieldDouble("vc_xOffsetScale").setMandatory(false); |
||
708 | definition.addDynFieldDouble("vc_yOffsetScale").setMandatory(false); |
||
709 | definition.addDynFieldDouble("vc_sizeScale").setMandatory(false); |
||
710 | 42439 | dmartinezizquierdo | } |
711 | 40911 | jldominguez | } |
712 | |||
713 | /**
|
||
714 | * Class to be used for the methods that control the visual correction of a character.
|
||
715 | * This visual correction has the responsibility of modify the dimensions of the
|
||
716 | * character to be used as a symbol(in case that the user wants to use more or less
|
||
717 | * pixels to represent it )
|
||
718 | *
|
||
719 | */
|
||
720 | private class VisualCorrection { |
||
721 | double xOffsetScale = 1; |
||
722 | double yOffsetScale = 1; |
||
723 | double sizeScale = 1; |
||
724 | } |
||
725 | 42439 | dmartinezizquierdo | |
726 | 40911 | jldominguez | } |