svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / LabelingFactory.java @ 10436
History | View | Annotate | Download (6 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 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: LabelingFactory.java 10436 2007-02-21 07:34:09Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.4 2007-02-21 07:34:08 jaume
|
47 |
* labeling starts working
|
48 |
*
|
49 |
* Revision 1.1.2.3 2007/02/12 15:15:20 jaume
|
50 |
* refactored interval legend and added graduated symbol legend
|
51 |
*
|
52 |
* Revision 1.1.2.2 2007/02/09 07:47:05 jaume
|
53 |
* Isymbol moved
|
54 |
*
|
55 |
* Revision 1.1.2.1 2007/02/02 16:21:24 jaume
|
56 |
* start commiting labeling stuff
|
57 |
*
|
58 |
* Revision 1.1.2.1 2007/01/30 18:10:45 jaume
|
59 |
* start commiting labeling stuff
|
60 |
*
|
61 |
*
|
62 |
*/
|
63 |
package com.iver.cit.gvsig.fmap.rendering.styling; |
64 |
|
65 |
import org.apache.log4j.Logger; |
66 |
|
67 |
import com.iver.cit.gvsig.fmap.DriverException; |
68 |
import com.iver.cit.gvsig.fmap.core.FShape; |
69 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
72 |
import com.iver.utiles.IPersistance; |
73 |
import com.iver.utiles.NotExistInXMLEntity; |
74 |
import com.iver.utiles.XMLEntity; |
75 |
|
76 |
public class LabelingFactory { |
77 |
private static Logger logger = Logger.getLogger(SymbologyFactory.class.getName()); |
78 |
|
79 |
/**
|
80 |
* Instantiates an object from an instance of XMLEntity. The XMLEntity
|
81 |
* must follow the XMLEntity contract in IPersistence. It at least must
|
82 |
* contain a className that allow create objects via instrospection. It
|
83 |
* also should have the set of attributes that the instantiated object's
|
84 |
* setXMLEntity(XMLEntity) method expects.
|
85 |
* @param xml
|
86 |
* @return
|
87 |
*/
|
88 |
private static Object createFromXML(XMLEntity xml) { |
89 |
String className = null; |
90 |
try {
|
91 |
className = xml.getStringProperty("className");
|
92 |
} catch (NotExistInXMLEntity e) {
|
93 |
logger.error("Symbol class name not set.\n" +
|
94 |
" Maybe you forgot to add the" +
|
95 |
" putProperty(\"className\", yourClassName)" +
|
96 |
" call in the getXMLEntity method of your symbol", e);
|
97 |
} |
98 |
|
99 |
|
100 |
Class clazz = null; |
101 |
Object obj = null; |
102 |
try {
|
103 |
clazz = Class.forName(className);
|
104 |
// TODO remove the patch the day we deprecate FSymbol
|
105 |
obj = clazz.newInstance(); |
106 |
((IPersistance) obj).setXMLEntity(xml); |
107 |
|
108 |
} catch (InstantiationException e) { |
109 |
logger.error("Trying to instantiate an interface" +
|
110 |
" or abstract class + "+className, e);
|
111 |
} catch (IllegalAccessException e) { |
112 |
logger.error(null, e);
|
113 |
} catch (ClassNotFoundException e) { |
114 |
logger.error("No class called " + className +
|
115 |
" was found.\nCheck the following.\n<br>" +
|
116 |
"\t- The fullname of the class you're looking " +
|
117 |
"for matches the value in the className " +
|
118 |
"property of the XMLEntity ("+className+").\n<br>" + |
119 |
"\t- The jar file containing your symbol class is in" +
|
120 |
"the application classpath<br>", e);
|
121 |
} |
122 |
return obj;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Creates a new instance of a ILabelingStrategy from an XMLEntity.
|
127 |
* @param xml
|
128 |
* @return ILabelingStrategy
|
129 |
*/
|
130 |
public static ILabelingStrategy createStrategyFromXML(XMLEntity xml) { |
131 |
return (ILabelingStrategy) createFromXML(xml);
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Creates a new instance of ILabelingMethod from an XMLEntity.
|
136 |
* @param xml
|
137 |
* @return ILabelingMethod
|
138 |
*/
|
139 |
public static ILabelingMethod createMethodFromXML(XMLEntity xml) { |
140 |
return (ILabelingMethod) createFromXML(xml);
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Creates a default labeling strategy from an XMLEntity.
|
145 |
* @param layer
|
146 |
* @return an instance of DefaultStrategy
|
147 |
* @throws DriverException
|
148 |
*/
|
149 |
public static ILabelingStrategy createDefaultStrategy(FLayer layer) throws DriverException { |
150 |
return new DefaultLabelingStrategy(layer); |
151 |
} |
152 |
|
153 |
/**
|
154 |
* Given a layer, a labeling method, a label placements constraints, and a label
|
155 |
* zoom constraints it will figure out the best ILabelingStrategy that meets all
|
156 |
* the needs.
|
157 |
* @param layer, the target layer
|
158 |
* @param method, the desired methods
|
159 |
* @param placement, the desired placement constraints
|
160 |
* @param zoom, the desired zoom constraints
|
161 |
* @return ILabelingStrategy
|
162 |
* @throws DriverException
|
163 |
*/
|
164 |
public static ILabelingStrategy createStrategy(FLayer layer, ILabelingMethod method, IPlacementConstraints placement, IZoomConstraints zoom) throws DriverException { |
165 |
if (method == null && placement == null && zoom == null) |
166 |
return createDefaultStrategy(layer);
|
167 |
|
168 |
return createDefaultStrategy(layer);
|
169 |
/* solament per a proves, ac? falta muntar el sistema expert que
|
170 |
* decidisca quina estrat?gia ?s la millor a partir dels par?metres.
|
171 |
*/
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Creates a new instance of placement constraints from a vector layer. The
|
176 |
* placement constraints are created according the layer shape type.
|
177 |
* @param layerDest
|
178 |
* @return
|
179 |
* @throws DriverException
|
180 |
*/
|
181 |
public static IPlacementConstraints createPlacementConstraints(FLyrVect layerDest) throws DriverException { |
182 |
int shapeType = layerDest.getShapeType();
|
183 |
switch (shapeType) {
|
184 |
case FShape.LINE:
|
185 |
return new LinePlacementConstraints(); |
186 |
case FShape.POLYGON:
|
187 |
return new PolygonPlacementConstraints(); |
188 |
case FShape.POINT:
|
189 |
return new PointPlacementConstraints(); |
190 |
} |
191 |
throw new Error("Shape type not yet supported"); |
192 |
} |
193 |
|
194 |
|
195 |
} |