// might need to be thought about more.
renderer.removeAllChildren();
renderer.addChildren(newconfig);
newcontexts = null;
for( Iterator<AbstractRenderMetrics> iterator = newconfig.iterator(); iterator.hasNext(); ) {
AbstractRenderMetrics abstractRenderMetrics = (AbstractRenderMetrics) iterator.next();
//setup label painter
((RenderContextImpl)abstractRenderMetrics.getRenderContext()).setLabelPainterLocal(tilelabelpainter);
}
}else{
//we have an existing configuration; lets recycle as many of the contexts as possible
//lets get the new configuration
Collection <AbstractRenderMetrics> newconfig = ((TiledRendererCreatorImpl) getRendererCreator()).getConfiguration(t.getReferencedEnvelope());
//items to add/remove from the existing configuration
List<AbstractRenderMetrics> removeList = new ArrayList<AbstractRenderMetrics>();
List<AbstractRenderMetrics> addList = new ArrayList<AbstractRenderMetrics>();
for(AbstractRenderMetrics metric: currentconfiguration){
if (!newconfig.contains(metric)){
//this is an existing context the doesn't exist in the new set
removeList.add(metric);
}
}
for (AbstractRenderMetrics metric: newconfig){
if (!currentconfiguration.contains(metric)){
//this is in the new configuration but not the only one therefore we need to add it
addList.add(metric);
//setup label painter
((RenderContextImpl)metric.getRenderContext()).setLabelPainterLocal(tilelabelpainter);
}
}
newcontexts.addAll(addList);
renderer.removeChildren(removeList);
if (!addList.isEmpty()){
renderer.removeChildren(addList);
}
renderer.addChildren(addList);
//let's properly dispose of anything in the remove List
for( Iterator<AbstractRenderMetrics> iterator = removeList.iterator(); iterator.hasNext(); ) {
AbstractRenderMetrics metric = (AbstractRenderMetrics) iterator.next();
((RenderContextImpl)metric.getRenderContext()).dispose();
}
}
return newcontexts;
}