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