Revision 47476 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/symbol/SmartTextSymbol.java
SmartTextSymbol.java | ||
---|---|---|
12 | 12 |
import java.awt.font.LineMetrics; |
13 | 13 |
import java.awt.geom.AffineTransform; |
14 | 14 |
import org.apache.commons.lang3.StringUtils; |
15 |
|
|
16 | 15 |
import org.gvsig.compat.print.PrintAttributes; |
17 | 16 |
import org.gvsig.fmap.dal.feature.Feature; |
18 | 17 |
import org.gvsig.fmap.geom.Geometry; |
... | ... | |
28 | 27 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
29 | 28 |
import org.gvsig.fmap.mapcontext.ViewPort; |
30 | 29 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
31 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
|
32 | 30 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
33 | 31 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
34 | 32 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
35 | 33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
36 | 34 |
import org.gvsig.labeling.placements.PointPlacementConstraints; |
37 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
35 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.TextPath; |
|
36 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol; |
|
38 | 37 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
39 | 38 |
import org.gvsig.tools.ToolsLocator; |
40 | 39 |
import org.gvsig.tools.dynobject.DynStruct; |
... | ... | |
45 | 44 |
import org.slf4j.Logger; |
46 | 45 |
import org.slf4j.LoggerFactory; |
47 | 46 |
|
48 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.TextPath; |
|
49 |
|
|
50 | 47 |
|
51 | 48 |
/** |
52 | 49 |
* Class used to create symbols composed using a text defined by |
... | ... | |
55 | 52 |
* does not exist, the text is treated as a simpletextsymbol (when is drawn). |
56 | 53 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
57 | 54 |
*/ |
58 |
public class SmartTextSymbol implements ISimpleTextSymbol, CartographicSupport {
|
|
55 |
public class SmartTextSymbol extends AbstractSymbol implements ISimpleTextSymbol {
|
|
59 | 56 |
|
60 | 57 |
private static final Logger logger = LoggerFactory.getLogger( |
61 | 58 |
SmartTextSymbol.class); |
... | ... | |
90 | 87 |
private FontRenderContext frc = new FontRenderContext( |
91 | 88 |
new AffineTransform(), false, true); |
92 | 89 |
|
93 |
// Background: ITextBackground |
|
94 |
// Case |
|
95 | 90 |
private double characterSpacing; |
96 | 91 |
private double characterWidth; |
97 |
// Direction |
|
98 |
private IFillSymbol fillSymbol; |
|
99 |
private double flipAngle; |
|
100 |
// boolean kerning; |
|
101 | 92 |
private double leading; |
102 |
// Position: textPosition |
|
103 |
private Color ShadowColor; |
|
104 |
private double ShadowXOffset; |
|
105 |
private double ShadowYOffset; |
|
106 |
// TypeSetting: Boolean |
|
107 | 93 |
private double wordSpacing; |
108 |
// ISimpleTextSymbol : ITextSymbol |
|
109 |
// BreakCharacter: Long |
|
110 |
// Clip: Boolean |
|
111 |
private TextPath textPath; |
|
112 |
private double xOffset; |
|
113 |
private double yOffset; |
|
114 |
private double angle; |
|
115 |
// Color: IColor |
|
116 |
|
|
117 |
// HorizontalAlignment: |
|
118 |
// esriTextHorizontalAlignment |
|
119 | 94 |
private boolean rightToLeft; |
120 |
// VerticalAlignment |
|
121 |
private double maskSize; |
|
122 |
// MaskStyle |
|
123 |
private IFillSymbol maskSymbol; |
|
124 | 95 |
private double margin; |
125 | 96 |
private int alignment; |
126 | 97 |
private boolean kerning = false; |
127 | 98 |
private TextPath tp; |
128 |
private IPlacementConstraints constraints; |
|
129 |
|
|
130 |
private boolean shapeVisible = true; |
|
131 |
private int unit = -1; |
|
132 |
private int referenceSystem = CartographicSupport.WORLD; |
|
99 |
private final IPlacementConstraints constraints; |
|
133 | 100 |
private double rotation = 0; |
134 |
private String desc = ""; |
|
135 | 101 |
private Color textColor = Color.BLACK; |
136 | 102 |
private Font font; |
137 | 103 |
private boolean autoresize = false; |
... | ... | |
195 | 161 |
} |
196 | 162 |
|
197 | 163 |
|
198 |
public void setIsShapeVisible(boolean v) { |
|
199 |
this.shapeVisible = v; |
|
200 |
} |
|
164 |
// public void setIsShapeVisible(boolean v) { |
|
165 |
// this.shapeVisible = v; |
|
166 |
// } |
|
167 |
// |
|
168 |
// public boolean isShapeVisible() { |
|
169 |
// return shapeVisible; |
|
170 |
// } |
|
201 | 171 |
|
202 |
public boolean isShapeVisible() { |
|
203 |
return shapeVisible; |
|
204 |
} |
|
205 |
|
|
206 | 172 |
|
207 | 173 |
|
208 | 174 |
public SmartTextSymbol() { |
... | ... | |
224 | 190 |
|
225 | 191 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
226 | 192 |
Geometry geom, Feature f, Cancellable cancel) { |
193 |
draw(g, affineTransform, geom, f, cancel, null); |
|
194 |
} |
|
195 |
|
|
196 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
|
197 |
Geometry geom, Feature f, Cancellable cancel, Rectangle r) { |
|
227 | 198 |
|
228 |
if (!isShapeVisible()) return; |
|
199 |
if (!isShapeVisible()){ |
|
200 |
return; |
|
201 |
} |
|
202 |
|
|
203 |
if(r != null) { |
|
204 |
geom = getSampleGeometry(r); |
|
205 |
} |
|
229 | 206 |
|
230 | 207 |
setMargin(0); |
231 | 208 |
if ( StringUtils.isEmpty(text) ) { |
... | ... | |
335 | 312 |
public boolean isSuitableFor(Geometry geom) { |
336 | 313 |
return geom.getGeometryType().isTypeOf(TYPES.CURVE); |
337 | 314 |
} |
315 |
|
|
316 |
public Geometry getSampleGeometry(Rectangle r) { |
|
317 |
Surface surf = null; |
|
318 |
try { |
|
319 |
surf = geoman.createSurface(SUBTYPES.GEOM2D); |
|
320 |
} catch (CreateGeometryException e) { |
|
321 |
logger.warn("Error while creating surface.", e); |
|
322 |
throw new RuntimeException("Can't create sample geometry.", e); |
|
323 |
} |
|
324 |
surf.addVertex(r.getX(), r.getY()); |
|
325 |
surf.addVertex(r.getX() + r.getWidth(), r.getY()); |
|
326 |
return surf; |
|
327 |
|
|
328 |
} |
|
338 | 329 |
|
339 | 330 |
public void drawInsideRectangle( |
340 | 331 |
Graphics2D g, |
341 | 332 |
AffineTransform scaleInstance, |
342 |
Rectangle r,
|
|
343 |
PrintAttributes properties) throws SymbolDrawingException {
|
|
344 |
// let's take the bottom segment of the rectangle as the line
|
|
345 |
|
|
346 |
Surface surf = null;
|
|
347 |
try {
|
|
348 |
surf = geoman.createSurface(SUBTYPES.GEOM2D);
|
|
349 |
} catch (CreateGeometryException e) {
|
|
350 |
logger.info("Error while creating surface.", e);
|
|
351 |
throw new SymbolDrawingException(
|
|
352 |
SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
|
|
353 |
}
|
|
354 |
surf.addVertex(r.getX(), r.getY());
|
|
355 |
surf.addVertex(r.getX() + r.getWidth(), r.getY());
|
|
356 |
|
|
357 |
if (properties == null) {
|
|
358 |
draw(g, scaleInstance, surf, null, null);
|
|
359 |
} else {
|
|
360 |
print(g, scaleInstance, surf, properties);
|
|
361 |
}
|
|
333 |
Rectangle r) throws SymbolDrawingException {
|
|
334 |
// // let's take the bottom segment of the rectangle as the line
|
|
335 |
//
|
|
336 |
// Surface surf = null; |
|
337 |
// try {
|
|
338 |
// surf = geoman.createSurface(SUBTYPES.GEOM2D);
|
|
339 |
// } catch (CreateGeometryException e) {
|
|
340 |
// logger.info("Error while creating surface.", e);
|
|
341 |
// throw new SymbolDrawingException(
|
|
342 |
// SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
|
|
343 |
// }
|
|
344 |
// surf.addVertex(r.getX(), r.getY());
|
|
345 |
// surf.addVertex(r.getX() + r.getWidth(), r.getY());
|
|
346 |
//
|
|
347 |
// if (properties == null) { |
|
348 |
// draw(g, scaleInstance, surf, null, null);
|
|
349 |
// } else {
|
|
350 |
// print(g, scaleInstance, surf, properties);
|
|
351 |
// }
|
|
352 |
draw(g, scaleInstance, null, null, null, r);
|
|
362 | 353 |
} |
363 | 354 |
|
364 | 355 |
|
... | ... | |
443 | 434 |
|
444 | 435 |
|
445 | 436 |
|
446 |
public String getDescription() { |
|
447 |
return desc; |
|
448 |
} |
|
437 |
// public String getDescription() { |
|
438 |
// return desc; |
|
439 |
// } |
|
440 |
// |
|
441 |
// |
|
442 |
// public void setDescription(String d) { |
|
443 |
// desc = d; |
|
444 |
// } |
|
449 | 445 |
|
450 | 446 |
|
451 |
public void setDescription(String d) { |
|
452 |
desc = d; |
|
453 |
} |
|
454 |
|
|
455 |
|
|
456 | 447 |
public Color getColor() { |
457 | 448 |
return this.getTextColor(); |
458 | 449 |
} |
... | ... | |
465 | 456 |
|
466 | 457 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
467 | 458 |
PrintAttributes properties) { |
468 |
|
|
469 |
/* |
|
470 |
* TODO Use properties |
|
471 |
* (perhaps when using things of CartographicSupport) |
|
472 |
*/ |
|
473 |
this.draw(g, at, geom, null, null); |
|
459 |
this.draw(g, at, geom, null, null, null); |
|
474 | 460 |
} |
475 | 461 |
|
476 | 462 |
|
... | ... | |
596 | 582 |
// ============================== |
597 | 583 |
|
598 | 584 |
|
599 |
public void setUnit(int unitIndex) { |
|
600 |
unit = unitIndex; |
|
601 |
} |
|
585 |
// public void setUnit(int unitIndex) { |
|
586 |
// unit = unitIndex; |
|
587 |
// } |
|
588 |
// |
|
589 |
// |
|
590 |
// public int getUnit() { |
|
591 |
// return unit; |
|
592 |
// } |
|
593 |
// |
|
594 |
// |
|
595 |
// public int getReferenceSystem() { |
|
596 |
// return this.referenceSystem; |
|
597 |
// } |
|
598 |
// |
|
599 |
// |
|
600 |
// public void setReferenceSystem(int rs) { |
|
601 |
// this.referenceSystem = rs; |
|
602 |
// } |
|
602 | 603 |
|
603 | 604 |
|
604 |
public int getUnit() { |
|
605 |
return unit; |
|
606 |
} |
|
605 |
// public void setCartographicSize(double cartographicSize, Geometry geom) { |
|
606 |
// setFontSize(cartographicSize); |
|
607 |
// } |
|
608 |
// |
|
609 |
// public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
610 |
// double oldSize = getFont().getSize(); |
|
611 |
// setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom); |
|
612 |
// return oldSize; |
|
613 |
// } |
|
614 |
// |
|
615 |
// public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
616 |
// return SymbolUtils. getCartographicLength( |
|
617 |
// this, getFont().getSize(), viewPort, dpi); |
|
618 |
// } |
|
607 | 619 |
|
608 |
|
|
609 |
public int getReferenceSystem() { |
|
610 |
return this.referenceSystem; |
|
611 |
} |
|
612 |
|
|
613 |
|
|
614 |
public void setReferenceSystem(int rs) { |
|
615 |
this.referenceSystem = rs; |
|
616 |
} |
|
617 |
|
|
618 |
|
|
619 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
|
620 |
setFontSize(cartographicSize); |
|
621 |
} |
|
622 |
|
|
623 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
624 |
double oldSize = getFont().getSize(); |
|
625 |
setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom); |
|
626 |
return oldSize; |
|
627 |
} |
|
628 |
|
|
629 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
630 |
return SymbolUtils. getCartographicLength( |
|
631 |
this, getFont().getSize(), viewPort, dpi); |
|
632 |
} |
|
633 |
|
|
634 | 620 |
// ======================== |
635 | 621 |
|
636 | 622 |
public Object clone() throws CloneNotSupportedException { |
Also available in: Unified diff