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/PolygonPlacementOnCentroid.java

View differences:

PolygonPlacementOnCentroid.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

  
......
45 28
import java.util.ArrayList;
46 29

  
47 30
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
49 31
import org.gvsig.fmap.geom.Geometry.TYPES;
50 32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
51 34
import org.gvsig.fmap.geom.primitive.Point;
52
import org.gvsig.fmap.geom.type.GeometryType;
53 35
import org.gvsig.fmap.mapcontext.ViewPort;
54 36
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass;
55 37
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints;
......
58 40
import org.slf4j.Logger;
59 41
import org.slf4j.LoggerFactory;
60 42

  
61
/**
62
 *
63
 * PolygonPlacementOnCentroid.java
64
 *
65
 *
66
 * @author jaume dominguez faus - jaume.dominguez@iver.es Apr 1, 2008
67
 *
68
 */
69
//public class PolygonPlacementOnCentroid extends MarkerCenteredAtPoint implements ILabelPlacement {
70 43
public class PolygonPlacementOnCentroid extends MarkerPlacementOnPoint
71 44
implements ILabelPlacement {
72 45
	
73 46
	private static final Logger logger = LoggerFactory.getLogger(
74 47
			PolygonPlacementOnCentroid.class);
75 48

  
49
    @Override
76 50
	public ArrayList<LabelLocationMetrics> guess(
77 51
			ILabelClass lc, Geometry geom,
78 52
			IPlacementConstraints placementConstraints,
79 53
			double cartographicSymbolSize, Cancellable cancel, ViewPort vp) {
80 54

  
81
		if (cancel.isCanceled()) return CannotPlaceLabel.NO_PLACES;
55
		if (cancel.isCanceled()) {
56
            return CannotPlaceLabel.NO_PLACES;
57
        }
82 58

  
83 59
		Point cen = null;
84 60
		try {
85 61
			cen = geom.centroid();
86 62
		} catch (Exception e) {
87
			logger.error("While getting centroid.", e);
63
			logger.warn("Can't get centroid of geometry.", e);
88 64
		}
89 65
		return super.guess(
90 66
				lc,
......
93 69
				cartographicSymbolSize, cancel,vp);
94 70
	}
95 71

  
72
    @Override
96 73
	public ArrayList<LabelLocationMetrics> guess(
97 74
			ILabelClass lc, Geometry geom,
98 75
			IPlacementConstraints placementConstraints,
99 76
			double cartographicSymbolSize, Cancellable cancel) {
100 77

  
101
		if (cancel.isCanceled()) return CannotPlaceLabel.NO_PLACES;
78
		if (cancel.isCanceled()) {
79
            return CannotPlaceLabel.NO_PLACES;
80
        }
102 81

  
103 82
		ArrayList<LabelLocationMetrics> guessed =
104 83
				new ArrayList<LabelLocationMetrics>();
......
107 86
		try {
108 87
			cen = geom.centroid();
109 88
		} catch (Exception e) {
110
			logger.error("While getting centroid.", e);
89
			logger.warn("While getting centroid.", e);
111 90
		}
112 91
		Point2D p = new Point2D.Double(cen.getX(), cen.getY());
113 92
		Rectangle2D bounds = lc.getBounds();
......
118 97
		return guessed;
119 98
	}
120 99

  
100
    @Override
121 101
	public boolean isSuitableFor(
122 102
			IPlacementConstraints placementConstraints,
123 103
			int shapeType) {
124 104
		
125
		GeometryType gt = null;
126
		try {
127
			gt = GeometryLocator.getGeometryManager().getGeometryType(
128
					shapeType, SUBTYPES.GEOM2D);
129
		} catch (Exception e) {
130
			logger.error("While getting geo type.", e);
131
		}
132
		
133
		if (gt.isTypeOf(TYPES.SURFACE) || shapeType == TYPES.MULTISURFACE) {
134
			return (placementConstraints.isHorizontal()
135
					&&
105
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
106
        if( geomManager.isSubtype(TYPES.SURFACE, shapeType) ||
107
            geomManager.isSubtype(TYPES.MULTISURFACE, shapeType) ) {
108
			return placementConstraints != null && 
109
                    (placementConstraints.isHorizontal() &&
136 110
					!placementConstraints.isFitInsidePolygon());
137 111
		}
138 112
		return false;

Also available in: Unified diff