root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleTextSymbol.java @ 10679
History | View | Annotate | Download (3.87 KB)
1 |
package com.iver.cit.gvsig.fmap.core.symbols; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Font; |
5 |
import java.awt.Graphics2D; |
6 |
import java.awt.Rectangle; |
7 |
import java.awt.Shape; |
8 |
import java.awt.geom.AffineTransform; |
9 |
import java.awt.geom.Point2D; |
10 |
|
11 |
import org.apache.batik.ext.awt.geom.PathLength; |
12 |
|
13 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
14 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
15 |
import com.iver.cit.gvsig.fmap.core.FShape; |
16 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
17 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
18 |
import com.iver.utiles.StringUtilities; |
19 |
import com.iver.utiles.XMLEntity; |
20 |
import com.vividsolutions.jts.geom.Geometry; |
21 |
import com.vividsolutions.jts.geom.Point; |
22 |
|
23 |
public class SimpleTextSymbol extends AbstractSymbol implements ITextSymbol { |
24 |
private double size = 10; |
25 |
private String text = ""; |
26 |
private Font font = new Font("Arial", Font.PLAIN, 10); |
27 |
private Color textColor = Color.BLACK; |
28 |
|
29 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
30 |
Point2D p = null; |
31 |
shp.transform(affineTransform); |
32 |
double rot=0; |
33 |
switch (shp.getShapeType()) {
|
34 |
case FShape.POINT:
|
35 |
FPoint2D fp=(FPoint2D) shp; |
36 |
p = new Point2D.Double(fp.getX(),fp.getY()); |
37 |
break;
|
38 |
case FShape.LINE:
|
39 |
PathLength pathLen = new PathLength(shp);
|
40 |
|
41 |
// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
|
42 |
float midDistance = pathLen.lengthOfPath() / 2; |
43 |
p = pathLen.pointAtLength(midDistance); |
44 |
rot = pathLen.angleAtLength(midDistance); |
45 |
break;
|
46 |
case FShape.POLYGON:
|
47 |
Geometry geo = FConverter.java2d_to_jts(shp); |
48 |
|
49 |
if (geo == null) { |
50 |
return;
|
51 |
} |
52 |
|
53 |
Point pJTS = geo.getCentroid();
|
54 |
|
55 |
if (pJTS != null) { |
56 |
FShape pLabel = FConverter.jts_to_java2d(pJTS); |
57 |
p= new Point2D.Double(((FPoint2D) pLabel).getX(), |
58 |
((FPoint2D) pLabel).getY()); |
59 |
} |
60 |
break;
|
61 |
} |
62 |
g.setColor(Color.BLACK);
|
63 |
g.setFont(new Font("Arial",Font.PLAIN, 10)); |
64 |
g.translate(p.getX(), p.getY()); |
65 |
g.rotate(rot); |
66 |
g.drawString(getText(), 0, 0); |
67 |
g.rotate(-rot); |
68 |
g.translate(-p.getX(), -p.getY()); |
69 |
} |
70 |
|
71 |
public void drawInsideRectangle(Graphics2D g, |
72 |
AffineTransform scaleInstance, Rectangle r) { |
73 |
g.drawString("Not yet implemented", 0, r.height); |
74 |
|
75 |
} |
76 |
|
77 |
public int getOnePointRgb() { |
78 |
// TODO Implement it
|
79 |
throw new Error("Not yet implemented!"); |
80 |
|
81 |
} |
82 |
|
83 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
84 |
Shape shp) {
|
85 |
// TODO Implement it
|
86 |
throw new Error("Not yet implemented!"); |
87 |
|
88 |
} |
89 |
|
90 |
public ISymbol getSymbolForSelection() {
|
91 |
return this; // a text is not selectable |
92 |
} |
93 |
|
94 |
public int getSymbolType() { |
95 |
return FShape.TEXT;
|
96 |
} |
97 |
|
98 |
public XMLEntity getXMLEntity() {
|
99 |
XMLEntity xml = new XMLEntity();
|
100 |
xml.putProperty("className", getClassName());
|
101 |
xml.putProperty("desc", getDescription());
|
102 |
|
103 |
xml.putProperty("font", font.getName());
|
104 |
xml.putProperty("fontStyle", font.getStyle());
|
105 |
xml.putProperty("size", (int) size); |
106 |
xml.putProperty("text", text);
|
107 |
xml.putProperty("textColor", StringUtilities.color2String(textColor));
|
108 |
return xml;
|
109 |
} |
110 |
|
111 |
public boolean isSuitableFor(IGeometry geom) { |
112 |
return true; |
113 |
} |
114 |
|
115 |
public void setXMLEntity(XMLEntity xml) { |
116 |
font = new Font(xml.getStringProperty("font"), |
117 |
xml.getIntProperty("fontStyle"),
|
118 |
xml.getIntProperty("size"));
|
119 |
text = xml.getStringProperty("text");
|
120 |
textColor = StringUtilities.string2Color(xml.getStringProperty("textColor"));
|
121 |
} |
122 |
|
123 |
public String getClassName() { |
124 |
return getClass().getName();
|
125 |
} |
126 |
|
127 |
public void print(Graphics2D g, AffineTransform at, FShape shape) |
128 |
throws ReadDriverException {
|
129 |
// TODO Implement it
|
130 |
throw new Error("Not yet implemented!"); |
131 |
|
132 |
} |
133 |
|
134 |
public String getText() { |
135 |
return text;
|
136 |
} |
137 |
|
138 |
public Font getFont() { |
139 |
return font;
|
140 |
} |
141 |
|
142 |
public Color getTextColor() { |
143 |
return textColor;
|
144 |
} |
145 |
|
146 |
public void setText(String text) { |
147 |
this.text = text;
|
148 |
} |
149 |
|
150 |
public void setFont(Font font) { |
151 |
this.font = font;
|
152 |
} |
153 |
|
154 |
public void setTextColor(Color color) { |
155 |
this.textColor = color;
|
156 |
} |
157 |
|
158 |
} |