root / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / labeling / placements / MultiShapePlacement.java @ 29131
History | View | Annotate | Download (3.94 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.symbology.fmap.labeling.placements; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
|
45 |
import com.iver.cit.gvsig.fmap.ViewPort; |
46 |
import com.iver.cit.gvsig.fmap.core.FShape; |
47 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
48 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints; |
49 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
50 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelLocationMetrics; |
51 |
import com.iver.utiles.swing.threads.Cancellable; |
52 |
|
53 |
/**
|
54 |
*
|
55 |
* MultiShapePlacementConstraints.java
|
56 |
*
|
57 |
*
|
58 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Apr 1, 2008
|
59 |
*
|
60 |
*/
|
61 |
public class MultiShapePlacement implements ILabelPlacement { |
62 |
private ILabelPlacement pointPlacement;
|
63 |
private ILabelPlacement linePlacement;
|
64 |
private ILabelPlacement polygonPlacement;
|
65 |
|
66 |
|
67 |
/**
|
68 |
* Creates a new instance of MultiShapePlacement initializing the respective
|
69 |
* placements to those passed as parameters. Null values are allowed for
|
70 |
* the parameters and will cause that no label will be placed when the
|
71 |
* geometry belongs to such null values.
|
72 |
*
|
73 |
* @param pointPlacement, the placement for points
|
74 |
* @param linePlacement, the placement for lines
|
75 |
* @param polygonPlacement, the placement for polygons
|
76 |
*/
|
77 |
public MultiShapePlacement(
|
78 |
ILabelPlacement pointPlacement, |
79 |
ILabelPlacement linePlacement, |
80 |
ILabelPlacement polygonPlacement) { |
81 |
this.pointPlacement = pointPlacement;
|
82 |
this.linePlacement = linePlacement;
|
83 |
this.polygonPlacement = polygonPlacement;
|
84 |
} |
85 |
|
86 |
|
87 |
public ArrayList<LabelLocationMetrics> guess(LabelClass lc, IGeometry geom, IPlacementConstraints placementConstraints, double cartographicSymbolSize, Cancellable cancel, ViewPort vp) { |
88 |
MultiShapePlacementConstraints pc = (MultiShapePlacementConstraints) placementConstraints; |
89 |
|
90 |
FShape shp = (FShape)geom.getInternalShape(); |
91 |
switch (shp.getShapeType() % FShape.Z) {
|
92 |
case FShape.POINT:
|
93 |
if (pointPlacement != null) { |
94 |
return pointPlacement.guess(lc, geom, pc.getPointConstraints(), cartographicSymbolSize, cancel,vp);
|
95 |
} |
96 |
break;
|
97 |
case FShape.LINE:
|
98 |
if (linePlacement != null) { |
99 |
return linePlacement.guess(lc, geom, pc.getLineConstraints(), cartographicSymbolSize, cancel,vp);
|
100 |
} |
101 |
break;
|
102 |
case FShape.POLYGON:
|
103 |
if (polygonPlacement != null) { |
104 |
return polygonPlacement.guess(lc, geom, pc.getPolygonConstraints(), cartographicSymbolSize, cancel,vp);
|
105 |
} |
106 |
break;
|
107 |
} |
108 |
return CannotPlaceLabel.NO_PLACES;
|
109 |
} |
110 |
|
111 |
public boolean isSuitableFor(IPlacementConstraints placementConstraints, |
112 |
int shapeType) {
|
113 |
// TODO shoud I also ask to each placement if it is suitable for these constraints????
|
114 |
return (shapeType % FShape.Z) == FShape.MULTI;
|
115 |
} |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
} |