Revision 43510 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/placements/LinePlacementInTheMiddle.java
LinePlacementInTheMiddle.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
2 | 3 |
* |
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
|
4 | 5 |
* |
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
8 | 9 |
* of the License, or (at your option) any later version. |
9 | 10 |
* |
10 | 11 |
* This program is distributed in the hope that it will be useful, |
... | ... | |
14 | 15 |
* |
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
18 | 20 |
* |
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 |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
40 | 23 |
*/ |
41 | 24 |
package org.gvsig.labeling.placements; |
42 | 25 |
|
43 | 26 |
import java.awt.geom.Point2D; |
44 | 27 |
|
45 | 28 |
import org.apache.batik.ext.awt.geom.PathLength; |
46 |
import org.gvsig.fmap.geom.Geometry; |
|
47 | 29 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
48 | 30 |
import org.gvsig.fmap.geom.GeometryLocator; |
49 |
import org.gvsig.fmap.geom.type.GeometryType;
|
|
31 |
import org.gvsig.fmap.geom.GeometryManager;
|
|
50 | 32 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
51 | 33 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
52 | 34 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelLocationMetrics; |
... | ... | |
54 | 36 |
import org.slf4j.Logger; |
55 | 37 |
import org.slf4j.LoggerFactory; |
56 | 38 |
|
57 |
/** |
|
58 |
* |
|
59 |
* LinePlacementInTheMiddle.java |
|
60 |
* |
|
61 |
* |
|
62 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Dec 17, 2007 |
|
63 |
* |
|
64 |
*/ |
|
65 | 39 |
public class LinePlacementInTheMiddle extends AbstractLinePlacement { |
66 | 40 |
|
67 | 41 |
private static Logger logger = |
68 | 42 |
LoggerFactory.getLogger(LinePlacementInTheMiddle.class); |
69 | 43 |
|
44 |
@Override |
|
70 | 45 |
public boolean isSuitableFor( |
71 | 46 |
IPlacementConstraints placementConstraints, |
72 | 47 |
int shapeType) { |
73 | 48 |
|
74 |
GeometryType gt = null; |
|
75 |
|
|
76 |
try { |
|
77 |
gt = GeometryLocator.getGeometryManager().getGeometryType( |
|
78 |
shapeType, Geometry.SUBTYPES.GEOM2D); |
|
79 |
} catch (Exception e) { |
|
80 |
logger.error("While getting aux geo type.", e); |
|
81 |
} |
|
82 |
|
|
83 |
if (gt.isTypeOf(TYPES.CURVE) |
|
84 |
|| shapeType == TYPES.MULTICURVE) { |
|
85 |
|
|
49 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
50 |
if( geomManager.isSubtype(TYPES.CURVE, shapeType) || |
|
51 |
geomManager.isSubtype(TYPES.MULTICURVE, shapeType) ) { |
|
86 | 52 |
return placementConstraints != null && |
87 | 53 |
placementConstraints.isInTheMiddleOfLine() |
88 | 54 |
/* && !placementConstraints.isFollowingLine()*/; |
... | ... | |
92 | 58 |
|
93 | 59 |
} |
94 | 60 |
|
61 |
@Override |
|
95 | 62 |
public LabelLocationMetrics initialLocation(ILabelClass lc, |
96 | 63 |
IPlacementConstraints pc, PathLength pathLen, Cancellable cancel) { |
97 | 64 |
|
98 |
if (cancel.isCanceled()) return null; |
|
65 |
if (cancel.isCanceled()) { |
|
66 |
return null; |
|
67 |
} |
|
99 | 68 |
|
100 | 69 |
float length = pathLen.lengthOfPath(); |
101 | 70 |
float distance = (float) (length * 0.5); |
Also available in: Unified diff