root / trunk / libraries / libArcIMS / src / org / gvsig / remoteClient / arcims / styling / renderers / ArcImsFLegendFactory.java @ 8109
History | View | Annotate | Download (22.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop 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 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
|
44 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
45 |
*
|
46 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
47 |
*
|
48 |
* This program is free software; you can redistribute it and/or
|
49 |
* modify it under the terms of the GNU General Public License
|
50 |
* as published by the Free Software Foundation; either version 2
|
51 |
* of the License, or (at your option) any later version.
|
52 |
*
|
53 |
* This program is distributed in the hope that it will be useful,
|
54 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
55 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
56 |
* GNU General Public License for more details.
|
57 |
*
|
58 |
* You should have received a copy of the GNU General Public License
|
59 |
* along with this program; if not, write to the Free Software
|
60 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
61 |
*
|
62 |
* For more information, contact:
|
63 |
*
|
64 |
* Generalitat Valenciana
|
65 |
* Conselleria d'Infraestructures i Transport
|
66 |
* Av. Blasco Ib??ez, 50
|
67 |
* 46010 VALENCIA
|
68 |
* SPAIN
|
69 |
*
|
70 |
* +34 963862235
|
71 |
* gvsig@gva.es
|
72 |
* www.gvsig.gva.es
|
73 |
*
|
74 |
* or
|
75 |
*
|
76 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
77 |
* Conde Salvatierra de ?lava , 34-10
|
78 |
* 46004 Valencia
|
79 |
* Spain
|
80 |
*
|
81 |
* +34 963 510 612
|
82 |
* +34 963 510 968
|
83 |
* gis@prodevelop.es
|
84 |
* http://www.prodevelop.es
|
85 |
*/
|
86 |
package org.gvsig.remoteClient.arcims.styling.renderers; |
87 |
|
88 |
import com.hardcode.gdbms.engine.values.Value; |
89 |
|
90 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
91 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
92 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend; |
93 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
94 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
95 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
96 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
97 |
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue; |
98 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
99 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
100 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
101 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
102 |
|
103 |
import org.apache.log4j.Logger; |
104 |
|
105 |
import org.gvsig.remoteClient.arcims.ArcXML; |
106 |
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException; |
107 |
import org.gvsig.remoteClient.arcims.styling.symbols.ArcImsFSymbolFactory; |
108 |
import org.gvsig.remoteClient.arcims.styling.symbols.IArcIMSSymbol; |
109 |
import org.gvsig.remoteClient.arcims.utils.ArcImsValueFactory; |
110 |
import org.gvsig.remoteClient.arcims.utils.FieldInformation; |
111 |
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags; |
112 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformation; |
113 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures; |
114 |
|
115 |
import java.text.DecimalFormatSymbols; |
116 |
import java.text.ParseException; |
117 |
|
118 |
import java.util.ArrayList; |
119 |
import java.util.Iterator; |
120 |
|
121 |
|
122 |
/**
|
123 |
* Factory class to produce FLegend's from ArcIMS Renderers defintions
|
124 |
* @author jsanz
|
125 |
*
|
126 |
*/
|
127 |
public class ArcImsFLegendFactory { |
128 |
private static Logger logger = Logger.getLogger(ArcImsFLegendFactory.class.getName()); |
129 |
private char ds; |
130 |
private ServiceInformationLayerFeatures silf;
|
131 |
private ServiceInformation si;
|
132 |
|
133 |
//We use a class variable to overwrite every label definition
|
134 |
private VectorialLegend auxLabelsOuter = null; |
135 |
|
136 |
// private String PATRON = ArcXML.PATRON;
|
137 |
// DecimalFormat formatter;
|
138 |
private int featType; |
139 |
|
140 |
/**
|
141 |
* @param ds Decimal separator char
|
142 |
* @param msilf An object with all the information to build
|
143 |
* the legend of a vectorial layer
|
144 |
* @see org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures
|
145 |
*/
|
146 |
public ArcImsFLegendFactory(ServiceInformation msi, String layerId) { |
147 |
si = msi; |
148 |
ds = msi.getSeparators().getDs(); |
149 |
ArcImsFSymbolFactory.ds = ds; |
150 |
|
151 |
silf = (ServiceInformationLayerFeatures) this.si.getLayerById(layerId);
|
152 |
this.featType = getSymbType(silf.getFclasstype());
|
153 |
|
154 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
155 |
dfs.setDecimalSeparator(ds); |
156 |
|
157 |
// formatter = new DecimalFormat(PATRON,dfs);
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* Main method on this class. It calls proper getLegend method
|
162 |
* based on type of render.
|
163 |
* @param render
|
164 |
* @return
|
165 |
* @throws ArcImsException
|
166 |
*/
|
167 |
public Legend getMainLegend() throws ArcImsException { |
168 |
logger.info("======Start creating main layer Legend======");
|
169 |
|
170 |
Renderer render = silf.getLayerMainRenderer();
|
171 |
Legend leg = getLegend(render, true);
|
172 |
logger.info("======Getting main Legend (" +
|
173 |
getClassName(leg.getClass()) + ")======");
|
174 |
|
175 |
return leg;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Main method that calls proper getLengend methods according to the type
|
180 |
* of renderer is passed.
|
181 |
* @param render
|
182 |
* @param isMainRender
|
183 |
* @return
|
184 |
* @throws ArcImsException
|
185 |
*/
|
186 |
private VectorialLegend getLegend(Renderer render, boolean isMainRender) |
187 |
throws ArcImsException {
|
188 |
VectorialLegend leg = null;
|
189 |
|
190 |
/*
|
191 |
if (render instanceof SimpleRenderer) {
|
192 |
SimpleRenderer srender = (SimpleRenderer) render;
|
193 |
leg = getLegend(srender);
|
194 |
}
|
195 |
else if (render instanceof ValueMapRenderer) {
|
196 |
ValueMapRenderer srender = (ValueMapRenderer) render;
|
197 |
leg = getLegend(srender);
|
198 |
}
|
199 |
// In the main legend, a ScaleDependent and a GroupRenderer can be
|
200 |
// treated in the same way
|
201 |
else if (isMainRender && (render instanceof GroupRenderer)) {
|
202 |
GroupRenderer groupRender = (GroupRenderer) render;
|
203 |
leg = getLegend(groupRender);
|
204 |
}
|
205 |
// Otherwise, we will use their proper method
|
206 |
else if (!isMainRender && (render instanceof GroupRenderer)) {
|
207 |
if (render instanceof ScaleDependentRenderer) {
|
208 |
ScaleDependentRenderer sdRender = (ScaleDependentRenderer) render;
|
209 |
leg = getLegend(sdRender);
|
210 |
}
|
211 |
|
212 |
// In the main legend, a ScaleDependent and a GroupRenderer can be
|
213 |
// treated in the same way
|
214 |
else if (render instanceof GroupRenderer) {
|
215 |
GroupRenderer groupRender = (GroupRenderer) render;
|
216 |
leg = getLegend(groupRender);
|
217 |
}
|
218 |
}
|
219 |
else
|
220 |
leg = getDefaultLegend();
|
221 |
*/
|
222 |
if (render instanceof SimpleRenderer) { |
223 |
SimpleRenderer srender = (SimpleRenderer) render; |
224 |
leg = getLegend(srender); |
225 |
} else if (render instanceof ValueMapRenderer) { |
226 |
ValueMapRenderer srender = (ValueMapRenderer) render; |
227 |
leg = getLegend(srender); |
228 |
} |
229 |
// In the main legend, a ScaleDependent and a GroupRenderer can be
|
230 |
// treated in the same way (ScaleDependent inherits from GroupRenderer)
|
231 |
else if (render instanceof GroupRenderer) { |
232 |
GroupRenderer groupRender = (GroupRenderer) render; |
233 |
leg = getLegend(groupRender); |
234 |
} else {
|
235 |
leg = getDefaultLegend(); |
236 |
} |
237 |
|
238 |
if (leg != null) { |
239 |
logger.info("Getting Render of type: " +
|
240 |
getClassName(render.getClass())); |
241 |
|
242 |
return leg;
|
243 |
} else {
|
244 |
throw new ArcImsException("arcims_legend_error"); |
245 |
} |
246 |
} |
247 |
|
248 |
/**
|
249 |
* Method to generate a valid simple legend.
|
250 |
* @return
|
251 |
*/
|
252 |
private VectorialLegend getDefaultLegend() {
|
253 |
SingleSymbolLegend leg = new SingleSymbolLegend();
|
254 |
leg.setDefaultSymbol(ArcImsFSymbolFactory.getDefaultFSymbol(featType)); |
255 |
leg.setShapeType(featType); |
256 |
logger.info("Getting default legend");
|
257 |
|
258 |
return leg;
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* Gets a simple Legend with only one symbol
|
263 |
* @see com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend
|
264 |
* @param renderer
|
265 |
* @return
|
266 |
*/
|
267 |
private VectorialLegend getLegend(SimpleRenderer renderer) {
|
268 |
//Get the ArcIMS Simbol
|
269 |
IArcIMSSymbol imsSimb = renderer.getSymbol(); |
270 |
|
271 |
//Get the FSymbol of the renderer
|
272 |
FSymbol simb = imsSimb.getFSymbol(); |
273 |
|
274 |
//Creates the legend
|
275 |
SingleSymbolLegend leg = new SingleSymbolLegend();
|
276 |
leg.setDefaultSymbol(simb); |
277 |
leg.setShapeType(this.featType);
|
278 |
logger.info("Getting a Simple Renderer");
|
279 |
|
280 |
return (VectorialLegend) leg;
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* Gets a Legend based on intervals
|
285 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend
|
286 |
* @param renderer
|
287 |
* @return
|
288 |
* @throws ArcImsException
|
289 |
*/
|
290 |
private VectorialLegend getLegend(ValueMapRenderer renderer)
|
291 |
throws ArcImsException {
|
292 |
//Get the proper Field Information object
|
293 |
FieldInformation fi = silf.getFieldInformation(renderer.getLookupfield()); |
294 |
|
295 |
//Gets the array of ranges
|
296 |
ArrayList values = renderer.getValues();
|
297 |
Iterator it = values.iterator();
|
298 |
|
299 |
//Creates the two types of legends
|
300 |
VectorialIntervalLegend viLeg = new VectorialIntervalLegend();
|
301 |
VectorialUniqueValueLegend vuLeg = new VectorialUniqueValueLegend();
|
302 |
|
303 |
//Initialize counters
|
304 |
int nIntervals = 0; |
305 |
int nUniques = 0; |
306 |
|
307 |
//Create a default simbol
|
308 |
FSymbol defSimb = ArcImsFSymbolFactory.getDefaultFSymbol(this.featType);
|
309 |
defSimb.setDescription("Default");
|
310 |
|
311 |
boolean hasDefSymbol = false; |
312 |
|
313 |
//Fills with intervals and symbols
|
314 |
while (it.hasNext()) {
|
315 |
//Only RangeValueMaps are allowed
|
316 |
TypeValueMap tvm = (TypeValueMap) it.next(); |
317 |
|
318 |
//Gets the symbol
|
319 |
IArcIMSSymbol simb = tvm.getSymbol(); |
320 |
FSymbol fsimb = simb.getFSymbol(); |
321 |
|
322 |
//Set the description
|
323 |
String descr = tvm.getLabel();
|
324 |
|
325 |
if (descr == null) { |
326 |
descr = "";
|
327 |
} |
328 |
|
329 |
fsimb.setDescription(descr); |
330 |
|
331 |
if (tvm instanceof RangeValueMap) { |
332 |
RangeValueMap rvm = (RangeValueMap) tvm; |
333 |
|
334 |
//Get the bounds of the intverval
|
335 |
String sFrom = rvm.getLower();
|
336 |
String sTo = rvm.getUpper();
|
337 |
double from = Double.parseDouble(sFrom.replace(ds, '.')); |
338 |
double to = Double.parseDouble(sTo.replace(ds, '.')); |
339 |
|
340 |
if (descr == null) { |
341 |
fsimb.setDescription(sFrom + "-" + sTo);
|
342 |
} |
343 |
|
344 |
//Creates the Interval
|
345 |
FInterval interv = new FInterval(from, to);
|
346 |
|
347 |
//Adds the symbol to the legend
|
348 |
viLeg.addSymbol(interv, fsimb); |
349 |
|
350 |
// viLeg.setIntervalSymbol(interv,fsimb);
|
351 |
nIntervals++; |
352 |
} else if (tvm instanceof ExactValueMap) { |
353 |
ExactValueMap evm = (ExactValueMap) tvm; |
354 |
|
355 |
//We have to build a Value object
|
356 |
String strVal = evm.getValue();
|
357 |
|
358 |
try {
|
359 |
Value val = ArcImsValueFactory.createValueByType(strVal, |
360 |
fi.getType(), this.ds);
|
361 |
vuLeg.addSymbol(val, fsimb); |
362 |
} catch (ParseException e) { |
363 |
logger.error(e.getMessage(), e); |
364 |
throw new ArcImsException("arcims_legend_error"); |
365 |
} |
366 |
|
367 |
nUniques++; |
368 |
} else if (tvm instanceof OtherValueMap) { |
369 |
hasDefSymbol = true;
|
370 |
defSimb = fsimb; |
371 |
} |
372 |
} |
373 |
|
374 |
/*
|
375 |
* Determine what type of legend the method will return (Unique or Interval)
|
376 |
* The condition will be the legend with more classes (intervals, values)
|
377 |
*/
|
378 |
VectorialLegend leg = null;
|
379 |
ClassifiedLegend cleg = null;
|
380 |
|
381 |
if (nUniques >= nIntervals) {
|
382 |
leg = vuLeg; |
383 |
cleg = vuLeg; |
384 |
} else {
|
385 |
leg = viLeg; |
386 |
cleg = viLeg; |
387 |
} |
388 |
|
389 |
/*
|
390 |
* Finally we can add the field name and default symbol
|
391 |
*/
|
392 |
|
393 |
//Set the field name
|
394 |
cleg.setFieldName(ArcXML.replaceUnwantedCharacters(fi.getName())); |
395 |
|
396 |
// Set the default symbol, if it is used and asign the symbol to a nullvalue
|
397 |
leg.setDefaultSymbol(defSimb); |
398 |
leg.useDefaultSymbol(hasDefSymbol); |
399 |
|
400 |
if (hasDefSymbol) {
|
401 |
if (leg instanceof VectorialUniqueValueLegend) { |
402 |
vuLeg.addSymbol(new NullUniqueValue(), leg.getDefaultSymbol());
|
403 |
} else {
|
404 |
viLeg.addSymbol(new NullIntervalValue(), leg.getDefaultSymbol());
|
405 |
} |
406 |
} |
407 |
|
408 |
logger.info("Getting a Value Map Renderer");
|
409 |
|
410 |
return leg;
|
411 |
} |
412 |
|
413 |
// /**
|
414 |
// * Gets the most detailed legend from the ScaleDependentRender
|
415 |
// * @param sdrender
|
416 |
// * @return
|
417 |
// */
|
418 |
// private VectorialLegend getLegend(ScaleDependentRenderer sdrender) throws ArcImsException {
|
419 |
// VectorialLegend leg = getLegend((GroupRenderer) sdrender);
|
420 |
// logger.info("Getting a ScaleDependent Renderer");
|
421 |
// return leg;
|
422 |
// }
|
423 |
private VectorialLegend getLegend(GroupRenderer groupRender)
|
424 |
throws ArcImsException {
|
425 |
ArrayList renderers = groupRender.renderers;
|
426 |
ArrayList legends = new ArrayList(); |
427 |
VectorialLegend biggerScale = null;
|
428 |
VectorialLegend leg = null;
|
429 |
double[] limit = { Double.MAX_VALUE, 0 }; |
430 |
Iterator it = renderers.iterator();
|
431 |
|
432 |
//We use a class variable to overwrite every label definition
|
433 |
VectorialLegend auxLabelsInner = null;
|
434 |
|
435 |
while (it.hasNext()) {
|
436 |
leg = null;
|
437 |
|
438 |
Renderer iRender = (Renderer) it.next(); |
439 |
|
440 |
//If we don't have a Label renderer use the generic method
|
441 |
if (!(iRender instanceof ILabelRenderer)) { |
442 |
leg = getLegend(iRender, false);
|
443 |
} |
444 |
//Otherwise, use the specific method for labels
|
445 |
else {
|
446 |
auxLabelsInner = getLegend((ILabelRenderer) iRender); |
447 |
} |
448 |
|
449 |
//If renderer is Scale Dependent, we inspect their scale limits
|
450 |
if (iRender instanceof ScaleDependentRenderer) { |
451 |
ScaleDependentRenderer iSDRender = (ScaleDependentRenderer) iRender; |
452 |
String strLow = iSDRender.getLower();
|
453 |
String strUpp = iSDRender.getUpper();
|
454 |
double low = 0; |
455 |
double upp = Double.MAX_VALUE; |
456 |
|
457 |
if (strLow != null) { |
458 |
low = Double.parseDouble(strLow.replace(ds, '.')); |
459 |
} |
460 |
|
461 |
if (strUpp != null) { |
462 |
upp = Double.parseDouble(strUpp.replace(ds, '.')); |
463 |
} |
464 |
|
465 |
//First loop
|
466 |
if (biggerScale == null) { |
467 |
biggerScale = leg; |
468 |
limit[0] = low;
|
469 |
limit[1] = upp;
|
470 |
} |
471 |
/*
|
472 |
* Next loops we allways get the minimum interval
|
473 |
* If lower bounds are equal, we get the lower upper value
|
474 |
*/
|
475 |
else if ((low <= limit[0]) && (upp <= limit[1])) { |
476 |
limit[0] = low;
|
477 |
limit[1] = upp;
|
478 |
biggerScale = leg; |
479 |
} |
480 |
} |
481 |
|
482 |
if (leg != null) { |
483 |
legends.add(leg); |
484 |
} |
485 |
} |
486 |
|
487 |
/*
|
488 |
* TODO At this time we will return the first (bottom) legend of the ArrayList
|
489 |
* or the most detailed legend if there are any ScaleDependentRenderers
|
490 |
* Probably I will add more "logic" into this code
|
491 |
*/
|
492 |
VectorialLegend finalLegend = null;
|
493 |
boolean onlyLabels = false; |
494 |
|
495 |
/*
|
496 |
* Check if auxLabels is equal to the last element of the array Legends and if
|
497 |
* it's true, merge it with the first one (its label definition)
|
498 |
*/
|
499 |
if (auxLabelsOuter!=null && legends.size()>0){ |
500 |
|
501 |
for (int i=0;i<legends.size();i++){ |
502 |
FSymbol simb1 = auxLabelsOuter.getDefaultSymbol(); |
503 |
FSymbol simb2 = ((VectorialLegend) legends.get(i)).getDefaultSymbol(); |
504 |
|
505 |
if (simb1==simb2){
|
506 |
//Null the biggerScale to force the next if statement
|
507 |
biggerScale = null;
|
508 |
//Merge the auxLabels object into the first legend of the arrayList
|
509 |
VectorialLegend legend = setLabelDefIntoSymbol(auxLabelsOuter,(VectorialLegend) legends.get(0));
|
510 |
legends.set(0,legend);
|
511 |
//Null the auxlabelsinner to avoid the last if
|
512 |
auxLabelsInner = null;
|
513 |
break;
|
514 |
} |
515 |
} |
516 |
|
517 |
|
518 |
} |
519 |
|
520 |
//We don't have any scaledependent
|
521 |
if (((biggerScale == null) && (legends.size() > 0))) { |
522 |
//if (!(groupRender instanceof ScaleDependentRenderer)){
|
523 |
logger.info("Getting the bottom renderer of the Group Renderer");
|
524 |
finalLegend = (VectorialLegend) legends.get(0);
|
525 |
} |
526 |
//We have any scaledpendent
|
527 |
else if (biggerScale != null) { |
528 |
logger.info( |
529 |
"Getting the most detailed ScaleDependent renderer of the Group Renderer");
|
530 |
finalLegend = biggerScale; |
531 |
} |
532 |
//We don't have any legend parsed (maybe the layer only have label definitions
|
533 |
else {
|
534 |
finalLegend = LegendFactory.createSingleSymbolLegend(this.featType);
|
535 |
onlyLabels = true;
|
536 |
} |
537 |
|
538 |
/*
|
539 |
* Finally if some label renderer is found, we have to pass the label
|
540 |
* properties to the final legend
|
541 |
*/
|
542 |
if (auxLabelsInner != null) { |
543 |
finalLegend = setLabelDefIntoSymbol(auxLabelsInner,finalLegend); |
544 |
finalLegend.getDefaultSymbol().setShapeVisible(!onlyLabels); |
545 |
auxLabelsOuter = finalLegend; |
546 |
} |
547 |
return finalLegend;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* Method that returns a SingleSymboLegend with Font definition and
|
552 |
* field to retrieve labels. These properties will be transferred to the
|
553 |
* main layer legend.
|
554 |
* @param renderer
|
555 |
* @return
|
556 |
*/
|
557 |
private VectorialLegend getLegend(ILabelRenderer renderer) {
|
558 |
//Get the proper Field Information object
|
559 |
FieldInformation fi = silf.getFieldInformation(renderer.getField()); |
560 |
|
561 |
//Create a legend
|
562 |
SingleSymbolLegend leg = (SingleSymbolLegend) LegendFactory.createSingleSymbolLegend(this.featType);
|
563 |
IArcIMSSymbol arcSimb = null;
|
564 |
|
565 |
//Get the ArcIMS Symbol with Font definition
|
566 |
if (renderer instanceof SimpleLabelRenderer) { |
567 |
SimpleLabelRenderer slrender = (SimpleLabelRenderer) renderer; |
568 |
arcSimb = slrender.getSymbol(); |
569 |
} else if (renderer instanceof ValueMapLabelRenderer) { |
570 |
ValueMapLabelRenderer vmlrender = (ValueMapLabelRenderer) renderer; |
571 |
arcSimb = vmlrender.getValue(0).getSymbol();
|
572 |
} |
573 |
|
574 |
//Asign it (or a default) to the legend
|
575 |
if (arcSimb != null) { |
576 |
leg.setDefaultSymbol(arcSimb.getFSymbol()); |
577 |
} else {
|
578 |
leg.setDefaultSymbol(ArcImsFSymbolFactory.getDefaultFSymbol( |
579 |
this.featType));
|
580 |
} |
581 |
|
582 |
//Set the label field
|
583 |
leg.setLabelField(ArcXML.replaceUnwantedCharacters(fi.getName())); |
584 |
|
585 |
//Return the legend
|
586 |
return leg;
|
587 |
} |
588 |
|
589 |
/**
|
590 |
* @return Returns the featType.
|
591 |
*/
|
592 |
public int getFeatType() { |
593 |
return featType;
|
594 |
} |
595 |
|
596 |
/**
|
597 |
* @param featType The featType to set.
|
598 |
*/
|
599 |
public void setFeatType(int featType) { |
600 |
this.featType = featType;
|
601 |
} |
602 |
|
603 |
/**
|
604 |
* Gets the simple class name
|
605 |
* @param mclass
|
606 |
* @return
|
607 |
*/
|
608 |
private String getClassName(Class mclass) { |
609 |
String[] classSplitted = mclass.getName().split("\\."); |
610 |
|
611 |
return classSplitted[classSplitted.length - 1]; |
612 |
} |
613 |
|
614 |
/**
|
615 |
* Private method to set into a legend the label definition of another legend
|
616 |
* @param withLabels
|
617 |
* @param finalLegend
|
618 |
* @return
|
619 |
*/
|
620 |
private VectorialLegend setLabelDefIntoSymbol(VectorialLegend withLabels,
|
621 |
VectorialLegend finalLegend) { |
622 |
|
623 |
//Set the label
|
624 |
finalLegend.setLabelField(withLabels.getLabelField()); |
625 |
//Get simbol with font definition
|
626 |
FSymbol simbWithFont = withLabels.getDefaultSymbol(); |
627 |
//Get simbol to insert font definition
|
628 |
FSymbol simb = finalLegend.getDefaultSymbol(); |
629 |
//Insert into simb the font properties
|
630 |
simb.setFont(simbWithFont.getFont()); |
631 |
simb.setFontColor(simbWithFont.getFontColor()); |
632 |
simb.setFontSize(simbWithFont.getFontSize()); |
633 |
simb.setFontSizeInPixels(true);
|
634 |
//Set simbol modified into final legend to return
|
635 |
finalLegend.setDefaultSymbol(simb); |
636 |
|
637 |
return finalLegend;
|
638 |
} |
639 |
|
640 |
/**
|
641 |
* Converts ArcIMS feature type to a FConstant value
|
642 |
* @param fclasstype
|
643 |
* @return
|
644 |
*/
|
645 |
private int getSymbType(String fclasstype) { |
646 |
if (fclasstype.equals(ServiceInfoTags.aPOLYGON)) {
|
647 |
return FConstant.SYMBOL_TYPE_FILL;
|
648 |
} |
649 |
|
650 |
if (fclasstype.equals(ServiceInfoTags.aPOLYLINE)) {
|
651 |
return FConstant.SYMBOL_TYPE_LINE;
|
652 |
} |
653 |
|
654 |
if (fclasstype.equals(ServiceInfoTags.aMULTIPOINT)) {
|
655 |
return FConstant.SYMBOL_TYPE_POINT;
|
656 |
} |
657 |
|
658 |
return FConstant.SHAPE_TYPE_NULL;
|
659 |
} |
660 |
} |