svn-gvsig-desktop / trunk / extSymbology / src / org / gvsig / symbology / fmap / labeling / placements / LinePlacementAtBest.java @ 18755
History | View | Annotate | Download (3.18 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 org.apache.log4j.Logger; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.core.FShape; |
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 |
* LinePlacementAtBest.java
|
55 |
*
|
56 |
*
|
57 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Dec 17, 2007
|
58 |
*
|
59 |
*/
|
60 |
public class LinePlacementAtBest extends CompoundLabelPlacement { |
61 |
static private ILabelPlacement[] pl = new ILabelPlacement[] { |
62 |
new LinePlacementInTheMiddle(),
|
63 |
new LinePlacementAtExtremities()
|
64 |
}; |
65 |
|
66 |
public LinePlacementAtBest() {
|
67 |
super(pl);
|
68 |
// a patch just to keep in mind the end of the lines
|
69 |
} |
70 |
|
71 |
@Override
|
72 |
public ArrayList<LabelLocationMetrics> guess(LabelClass lc, FShape shp, |
73 |
IPlacementConstraints constraints, double cartographicSymbolSize, Cancellable cancel) {
|
74 |
|
75 |
if (cancel.isCanceled()) return CannotPlaceLabel.NO_PLACES; |
76 |
|
77 |
ArrayList<LabelLocationMetrics> llc = super.guess(lc, shp, constraints, cartographicSymbolSize, cancel); |
78 |
if (constraints instanceof AbstractPlacementConstraints) { |
79 |
AbstractPlacementConstraints clone; |
80 |
try {
|
81 |
clone = (AbstractPlacementConstraints) ((AbstractPlacementConstraints) constraints).clone(); |
82 |
clone.setLocationAlongTheLine(IPlacementConstraints.AT_THE_END_OF_THE_LINE); |
83 |
llc.addAll(pl[1].guess(lc, shp, clone, cartographicSymbolSize, cancel));
|
84 |
} catch (CloneNotSupportedException e) { |
85 |
// this should never happen but
|
86 |
// anyway a warning does not hurt anyone
|
87 |
Logger.getLogger(getClass()).info("Couldn't clone "+constraints.getClassName(), e); |
88 |
} |
89 |
|
90 |
} |
91 |
return llc;
|
92 |
} |
93 |
public boolean isSuitableFor(IPlacementConstraints placementConstraints, |
94 |
int shapeType) {
|
95 |
if (shapeType == FShape.LINE) {
|
96 |
return placementConstraints.isAtBestOfLine();
|
97 |
} |
98 |
return false; |
99 |
} |
100 |
|
101 |
|
102 |
} |