Revision 23369 trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/labeling/placements/LinePlacementAtExtremities.java
LinePlacementAtExtremities.java | ||
---|---|---|
43 | 43 |
import java.awt.geom.Point2D; |
44 | 44 |
|
45 | 45 |
import org.apache.batik.ext.awt.geom.PathLength; |
46 |
import org.gvsig.symbology.fmap.labeling.SmartTextSymbolLabelClass; |
|
47 |
import org.gvsig.symbology.fmap.symbols.SmartTextSymbol; |
|
46 | 48 |
|
47 | 49 |
import com.iver.cit.gvsig.fmap.core.FShape; |
48 | 50 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints; |
... | ... | |
51 | 53 |
import com.iver.utiles.swing.threads.Cancellable; |
52 | 54 |
|
53 | 55 |
/** |
54 |
*
|
|
56 |
* |
|
55 | 57 |
* LinePlacementAtExtremities.java |
56 | 58 |
* |
57 |
*
|
|
59 |
* |
|
58 | 60 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Dec 17, 2007 |
59 | 61 |
* |
60 | 62 |
*/ |
61 | 63 |
public class LinePlacementAtExtremities extends AbstractLinePlacement { |
62 |
|
|
64 |
|
|
63 | 65 |
public LabelLocationMetrics initialLocation(LabelClass lc, IPlacementConstraints pc, PathLength pathLen, Cancellable cancel) { |
64 | 66 |
if (cancel.isCanceled()) return null; |
65 |
|
|
67 |
|
|
66 | 68 |
float distance = 0; |
67 | 69 |
if (pc.isAtTheEndOfLine()) { |
68 | 70 |
distance = (float) (pathLen.lengthOfPath()) ; |
69 | 71 |
} |
70 | 72 |
|
71 | 73 |
Point2D p = pathLen.pointAtLength(distance); |
72 |
|
|
74 |
|
|
73 | 75 |
double theta = 0; |
74 | 76 |
if (pc.isParallel()) { |
75 | 77 |
// get the line theta and apply it |
76 | 78 |
theta = pathLen.angleAtLength(distance); |
77 |
|
|
79 |
|
|
78 | 80 |
} else if (pc.isPerpendicular()) { |
79 | 81 |
// get the line theta with 90 degrees |
80 | 82 |
theta = pathLen.angleAtLength(distance) + AbstractLinePlacement.HALF_PI; |
81 | 83 |
} |
82 |
|
|
83 |
/*
|
|
84 |
|
|
85 |
/* |
|
84 | 86 |
* Offset the point to a distance of the height of the |
85 | 87 |
* label class's height to make the label appear to |
86 | 88 |
* be on the line. |
87 |
*
|
|
88 |
*/
|
|
89 |
* |
|
90 |
*/ |
|
89 | 91 |
double x = p.getX(); |
90 | 92 |
double y = p.getY(); |
91 | 93 |
double halfHeight = lc.getBounds().getHeight()*.5; |
92 |
|
|
94 |
|
|
93 | 95 |
double sinTheta = Math.sin(theta); |
94 | 96 |
double cosTheta = Math.cos(theta); |
95 | 97 |
double xOffset = halfHeight * sinTheta; |
96 | 98 |
double yOffset = halfHeight * cosTheta; |
97 |
|
|
99 |
|
|
98 | 100 |
if (pc.isAtTheEndOfLine()) { |
99 | 101 |
double width = lc.getBounds().getWidth(); |
100 | 102 |
xOffset -= width * cosTheta; |
101 | 103 |
yOffset += width * sinTheta; |
102 | 104 |
} |
103 |
|
|
105 |
|
|
104 | 106 |
p.setLocation(x + xOffset, y - yOffset); |
105 |
|
|
107 |
|
|
106 | 108 |
return new LabelLocationMetrics( |
107 | 109 |
p, |
108 | 110 |
theta, |
... | ... | |
112 | 114 |
public boolean isSuitableFor(IPlacementConstraints placementConstraints, |
113 | 115 |
int shapeType) { |
114 | 116 |
if (shapeType == FShape.LINE) { |
115 |
return placementConstraints != null && !placementConstraints.isFollowingLine()
|
|
117 |
return placementConstraints != null/* && !placementConstraints.isFollowingLine()*/
|
|
116 | 118 |
&& (placementConstraints.isAtTheBeginingOfLine() || placementConstraints |
117 | 119 |
.isAtTheEndOfLine()); |
118 | 120 |
} |
Also available in: Unified diff