Revision 19936
trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/labeling/PlacementManager.java | ||
---|---|---|
48 | 48 |
import org.gvsig.symbology.fmap.labeling.placements.CompoundLabelPlacement; |
49 | 49 |
import org.gvsig.symbology.fmap.labeling.placements.ILabelPlacement; |
50 | 50 |
import org.gvsig.symbology.fmap.labeling.placements.LinePlacementConstraints; |
51 |
import org.gvsig.symbology.fmap.labeling.placements.MultiShapePlacement; |
|
52 |
import org.gvsig.symbology.fmap.labeling.placements.MultiShapePlacementConstraints; |
|
51 | 53 |
import org.gvsig.symbology.fmap.labeling.placements.PointPlacementConstraints; |
52 | 54 |
import org.gvsig.symbology.fmap.labeling.placements.PolygonPlacementConstraints; |
53 | 55 |
|
54 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
55 | 56 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
56 | 57 |
import com.iver.cit.gvsig.fmap.core.FShape; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
58 | 58 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints; |
59 | 59 |
import com.iver.utiles.IPersistence; |
60 | 60 |
import com.iver.utiles.NotExistInXMLEntity; |
... | ... | |
76 | 76 |
private PlacementManager() {} |
77 | 77 |
|
78 | 78 |
public static ILabelPlacement getPlacement(IPlacementConstraints placementConstraints, int shapeType) { |
79 |
|
|
79 | 80 |
ArrayList<ILabelPlacement> suitablePlacements = new ArrayList<ILabelPlacement>(); |
80 |
for (Iterator<ILabelPlacement> iterator = getAvailablePlacements().iterator(); iterator.hasNext();) { |
|
81 |
ILabelPlacement placement = iterator.next(); |
|
82 |
if (placement.isSuitableFor(placementConstraints, shapeType)) { |
|
83 |
suitablePlacements.add(placement); |
|
81 |
if (placementConstraints.getClass().equals(MultiShapePlacementConstraints.class)) { |
|
82 |
MultiShapePlacementConstraints msp = (MultiShapePlacementConstraints) placementConstraints; |
|
83 |
|
|
84 |
return new MultiShapePlacement( |
|
85 |
getPlacement(msp.getPointConstraints(), FShape.POINT), |
|
86 |
getPlacement(msp.getLineConstraints(), FShape.LINE), |
|
87 |
getPlacement(msp.getPolygonConstraints(), FShape.POLYGON) |
|
88 |
); |
|
89 |
} else { |
|
90 |
for (Iterator<ILabelPlacement> iterator = getAvailablePlacements().iterator(); iterator.hasNext();) { |
|
91 |
ILabelPlacement placement = iterator.next(); |
|
92 |
if (placement.isSuitableFor(placementConstraints, shapeType)) { |
|
93 |
suitablePlacements.add(placement); |
|
94 |
} |
|
84 | 95 |
} |
96 |
|
|
97 |
if (suitablePlacements.size() == 0) |
|
98 |
return cantPlaceLabel; |
|
99 |
else if (suitablePlacements.size() == 1) |
|
100 |
return suitablePlacements.get(0); |
|
101 |
else |
|
102 |
return new CompoundLabelPlacement( |
|
103 |
(ILabelPlacement[]) suitablePlacements. |
|
104 |
toArray(new ILabelPlacement[suitablePlacements.size()])); |
|
105 |
|
|
85 | 106 |
} |
86 |
|
|
87 |
if (suitablePlacements.size() == 0) |
|
88 |
return cantPlaceLabel; |
|
89 |
else if (suitablePlacements.size() == 1) |
|
90 |
return suitablePlacements.get(0); |
|
91 |
else |
|
92 |
return new CompoundLabelPlacement( |
|
93 |
(ILabelPlacement[]) suitablePlacements. |
|
94 |
toArray(new ILabelPlacement[suitablePlacements.size()])); |
|
107 |
|
|
95 | 108 |
} |
96 | 109 |
|
97 | 110 |
public static void addLabelPlacement(Class<?> labelPlacementClass) { |
... | ... | |
124 | 137 |
} |
125 | 138 |
|
126 | 139 |
|
127 |
// /** |
|
128 |
// * Given a layer, a labeling method, a label placements constraints, and a label |
|
129 |
// * zoom constraints it will figure out the best ILabelingStrategy that meets all |
|
130 |
// * the needs. |
|
131 |
// * @param layer, the target layer |
|
132 |
// * @param method, the desired methods |
|
133 |
// * @param placement, the desired placement constraints |
|
134 |
// * @param zoom, the desired zoom constraints |
|
135 |
// * @return ILabelingStrategy |
|
136 |
// * @throws DriverException |
|
137 |
// */ |
|
138 |
// public static ILabelingStrategy createStrategy(FLayer layer, |
|
139 |
// ILabelingMethod method, IPlacementConstraints placement, |
|
140 |
// IZoomConstraints zoom) |
|
141 |
// throws ReadDriverException { |
|
142 |
// if (method == null && placement == null && zoom == null) |
|
143 |
// return LabelingFactory.createDefaultStrategy(layer); |
|
144 |
// |
|
145 |
// ILabelingStrategy strat = LabelingFactory.createDefaultStrategy(layer); |
|
146 |
// if (method != null) |
|
147 |
// strat.setLabelingMethod(method); |
|
148 |
// if (placement != null) |
|
149 |
// strat.setPlacementConstraints(placement); |
|
150 |
// return strat; |
|
151 |
// /* solament per a proves, ac? falta muntar el sistema expert que |
|
152 |
// * decidisca quina estrat?gia ?s la millor a partir dels par?metres. |
|
153 |
// */ |
|
154 |
// } |
|
155 |
|
|
156 | 140 |
/** |
157 | 141 |
* Creates a new instance of placement constraints from a vector layer. The |
158 | 142 |
* placement constraints are created according the layer shape type. |
... | ... | |
160 | 144 |
* @return |
161 | 145 |
* @throws DriverException |
162 | 146 |
*/ |
163 |
public static IPlacementConstraints createPlacementConstraints(FLyrVect layerDest) |
|
164 |
throws ReadDriverException { |
|
165 |
int shapeType = layerDest.getShapeType(); |
|
147 |
public static IPlacementConstraints createPlacementConstraints(int shapeType) { |
|
166 | 148 |
switch (shapeType) { |
167 | 149 |
case FShape.LINE: |
168 | 150 |
return new LinePlacementConstraints(); |
... | ... | |
171 | 153 |
case FShape.POINT: |
172 | 154 |
case FShape.MULTIPOINT: // TODO (09/01/08) is this correct??? if not fix it also in PlacementProperties (twice), , MarkerPlacementAroundPoint |
173 | 155 |
return new PointPlacementConstraints(); |
156 |
case FShape.MULTI: |
|
157 |
return new MultiShapePlacementConstraints( |
|
158 |
createPlacementConstraints(FShape.POINT), |
|
159 |
createPlacementConstraints(FShape.LINE), |
|
160 |
createPlacementConstraints(FShape.POLYGON)); |
|
174 | 161 |
} |
175 | 162 |
throw new Error("Shape type not yet supported"); |
176 | 163 |
// return null; |
... | ... | |
197 | 184 |
|
198 | 185 |
} catch (InstantiationException e) { |
199 | 186 |
logger.error("Trying to instantiate an interface" + |
200 |
" or abstract class + "+className, e); |
|
187 |
" or abstract class + "+className+"\n"+e.getMessage(), e);
|
|
201 | 188 |
} catch (IllegalAccessException e) { |
202 | 189 |
logger.error(null, e); |
203 | 190 |
} catch (ClassNotFoundException e) { |
Also available in: Unified diff