svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / placements / MarkerPlacementOnPoint.java @ 43510
History | View | Annotate | Download (4.46 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.labeling.placements; |
25 |
|
26 |
import java.awt.geom.Point2D; |
27 |
import java.awt.geom.Rectangle2D; |
28 |
import java.util.ArrayList; |
29 |
|
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
32 |
import org.gvsig.fmap.geom.GeometryLocator; |
33 |
import org.gvsig.fmap.geom.GeometryManager; |
34 |
import org.gvsig.fmap.geom.primitive.Point; |
35 |
import org.gvsig.fmap.mapcontext.ViewPort; |
36 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
37 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
38 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelLocationMetrics; |
39 |
import org.gvsig.tools.task.Cancellable; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
|
44 |
public class MarkerPlacementOnPoint implements ILabelPlacement{ |
45 |
|
46 |
private Logger logger = LoggerFactory.getLogger(MarkerPlacementOnPoint.class); |
47 |
|
48 |
public ArrayList<LabelLocationMetrics> guess( |
49 |
ILabelClass lc, |
50 |
Geometry shp, |
51 |
IPlacementConstraints placementConstraints, |
52 |
double cartographicSymbolSize, Cancellable cancel) {
|
53 |
|
54 |
if (cancel.isCanceled()) {
|
55 |
return CannotPlaceLabel.NO_PLACES;
|
56 |
} |
57 |
|
58 |
ArrayList<LabelLocationMetrics> guessed = new ArrayList<LabelLocationMetrics>(); |
59 |
|
60 |
Point cen = null; |
61 |
try {
|
62 |
cen = shp.centroid(); |
63 |
} catch (Exception ex) { |
64 |
logger.error("While getting centroid", ex);
|
65 |
} |
66 |
Point2D p = new Point2D.Double(cen.getX(), cen.getY()); |
67 |
Rectangle2D bounds = lc.getBounds();
|
68 |
//FIXME: Con este posicionamiento, es identico al MarkerCenteredAtPoint
|
69 |
//pero es as? como lo hacen otros programas
|
70 |
//(tal vez, hubo una confusi?n por el nombre de la constante ON_TOP_OF_THE_POINT).
|
71 |
//Entonces sobrar?a el posicionamiento MarkerCenteredAtPoint debiendose utilizar siempre ?ste.
|
72 |
p.setLocation(p.getX() - (bounds.getWidth()*0.5), p.getY() - (bounds.getHeight()*0.5));// - 2); |
73 |
guessed.add(new LabelLocationMetrics(
|
74 |
p, 0, true)); |
75 |
return guessed;
|
76 |
} |
77 |
|
78 |
|
79 |
@Override
|
80 |
public ArrayList<LabelLocationMetrics> guess( |
81 |
ILabelClass lc, |
82 |
Geometry geom, |
83 |
IPlacementConstraints placementConstraints, |
84 |
double cartographicSymbolSize, Cancellable cancel, ViewPort vp) {
|
85 |
|
86 |
if (cancel.isCanceled()) return CannotPlaceLabel.NO_PLACES; |
87 |
|
88 |
Geometry shp = geom.cloneGeometry(); |
89 |
shp.transform(vp.getAffineTransform()); |
90 |
|
91 |
ArrayList<LabelLocationMetrics> guessed =
|
92 |
new ArrayList<LabelLocationMetrics>(); |
93 |
|
94 |
Point cen = null; |
95 |
try {
|
96 |
cen = shp.centroid(); |
97 |
} catch (Exception ex) { |
98 |
logger.error("While getting centroid", ex);
|
99 |
} |
100 |
Point2D p = new Point2D.Double(cen.getX(), cen.getY()); |
101 |
Rectangle2D bounds = lc.getBounds();
|
102 |
//FIXME: Con este posicionamiento, es identico al MarkerCenteredAtPoint
|
103 |
//pero es as? como lo hacen otros programas
|
104 |
//(tal vez, hubo una confusi?n por el nombre de la constante ON_TOP_OF_THE_POINT).
|
105 |
//Entonces sobrar?a el posicionamiento MarkerCenteredAtPoint debiendose utilizar siempre ?ste.
|
106 |
p.setLocation(p.getX() - (bounds.getWidth()*0.5), p.getY() - bounds.getHeight()*0.5);// - 2); |
107 |
guessed.add(new LabelLocationMetrics(
|
108 |
p, 0, true)); |
109 |
return guessed;
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
public boolean isSuitableFor( |
114 |
IPlacementConstraints placementConstraints, |
115 |
int shapeType) {
|
116 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
117 |
if( geomManager.isSubtype(TYPES.POINT, shapeType) ) {
|
118 |
return placementConstraints != null && placementConstraints.isOnTopOfThePoint(); |
119 |
} else{
|
120 |
return false; |
121 |
} |
122 |
|
123 |
} |
124 |
|
125 |
|
126 |
|
127 |
} |