Revision 11192 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LinePlacementConstraints.java
LinePlacementConstraints.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.6 2007-04-12 16:01:11 jaume
|
|
46 |
* Revision 1.7 2007-04-13 11:59:30 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.6 2007/04/12 16:01:11 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
49 | 52 |
* Revision 1.5 2007/04/12 14:28:43 jaume |
50 | 53 |
* basic labeling support for lines |
51 | 54 |
* |
... | ... | |
66 | 69 |
package com.iver.cit.gvsig.fmap.rendering.styling; |
67 | 70 |
|
68 | 71 |
import java.awt.Graphics2D; |
72 |
import java.awt.Rectangle; |
|
69 | 73 |
import java.awt.geom.AffineTransform; |
70 |
import java.awt.geom.Point2D; |
|
71 |
import java.awt.image.AffineTransformOp; |
|
72 | 74 |
|
73 | 75 |
import org.apache.batik.ext.awt.geom.PathLength; |
74 | 76 |
import org.cresques.px.gml.MultiPolygon; |
75 | 77 |
|
78 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
76 | 79 |
import com.iver.cit.gvsig.fmap.core.FShape; |
77 | 80 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
81 |
import com.iver.utiles.XMLEntity; |
|
78 | 82 |
/** |
79 | 83 |
* |
80 | 84 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
... | ... | |
86 | 90 |
public FShape[] getLocationsFor(IGeometry geom, FShape labelShape, MultiPolygon exclusionZone) { |
87 | 91 |
return new FShape[] { (FShape) geom.getInternalShape() }; |
88 | 92 |
} |
89 |
public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform at, String[] labelTexts) { |
|
90 |
Point2D startingPoint = null; |
|
91 |
double rot = 0; |
|
93 |
|
|
94 |
public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform at) { |
|
95 |
Rectangle labelBounds = lc.getShape(g, at, geom).getBounds(); |
|
96 |
|
|
97 |
|
|
98 |
FPoint2D startingPoint = null; |
|
99 |
double theta = 0; |
|
92 | 100 |
if (isFollowingLine()) { |
93 | 101 |
throw new Error("following line option not yet implemented"); |
94 | 102 |
// 1. create text path |
... | ... | |
107 | 115 |
distance = pathLen.lengthOfPath() * 0.5F; |
108 | 116 |
} |
109 | 117 |
|
110 |
startingPoint = pathLen.pointAtLength(distance);
|
|
118 |
startingPoint = new FPoint2D(pathLen.pointAtLength(distance));
|
|
111 | 119 |
|
112 | 120 |
if (isParallel()) { |
113 | 121 |
// get the line theta and apply it |
114 |
rot = pathLen.angleAtLength(distance);
|
|
122 |
theta = -pathLen.angleAtLength(distance);
|
|
115 | 123 |
|
116 | 124 |
} else if (isPerpendicular()) { |
117 | 125 |
// get the line theta with 90 degrees |
118 |
rot = pathLen.angleAtLength(distance) + HALF_PI;
|
|
126 |
theta = -pathLen.angleAtLength(distance) + HALF_PI;
|
|
119 | 127 |
} |
120 | 128 |
} |
121 | 129 |
|
... | ... | |
131 | 139 |
// Offset to be on bellow of the line. |
132 | 140 |
} else if (isAboveTheLine()) { |
133 | 141 |
// Offset to be above the line (inverse offset to under the line) |
134 |
|
|
135 | 142 |
} else { |
136 | 143 |
// No offset. |
137 | 144 |
} |
138 | 145 |
|
139 |
|
|
140 |
|
|
141 | 146 |
/* |
142 | 147 |
* Now, we'll need to see who is defining the orientation |
143 | 148 |
* either the line or the page. |
... | ... | |
154 | 159 |
// will be better handled by a SmartLinePlacement |
155 | 160 |
throw new Error("overlapping detection option not yet implemented"); |
156 | 161 |
} |
157 |
AffineTransform old = g.getTransform(); |
|
158 |
// g.transform(despla?ament, rotaci?, orientaci?) |
|
159 |
lc.drawInsideRectangle(g, lc.getShape(g, at, geom).getBounds()); |
|
160 |
// g.transform(old) |
|
162 |
startingPoint.transform(at); |
|
163 |
labelBounds.setLocation(0-(int) (labelBounds.width*.5), 0 - (int) (labelBounds.height*.5)); |
|
164 |
g.translate((int) startingPoint.getX(), (int) startingPoint.getY()); |
|
165 |
if (theta != 0) { |
|
166 |
g.rotate(theta); |
|
167 |
} |
|
168 |
lc.drawInsideRectangle(g, labelBounds); |
|
169 |
if (theta != 0) { |
|
170 |
g.rotate(-theta); |
|
171 |
} |
|
172 |
g.translate(-(int) startingPoint.getX(), -(int) startingPoint.getY()); |
|
173 |
|
|
161 | 174 |
} |
162 | 175 |
|
176 |
public String getClassName() { |
|
177 |
return getClass().getName(); |
|
178 |
} |
|
179 |
|
|
180 |
public XMLEntity getXMLEntity() { |
|
181 |
XMLEntity xml = super.getXMLEntity(); |
|
182 |
xml.putProperty("className", getClassName()); |
|
183 |
return xml; |
|
184 |
} |
|
163 | 185 |
} |
Also available in: Unified diff