}
boolean oldChange = getDoContainerChange();
setDoContainerChange(false);
BufferedLayer bufLayer;
synchronized (this) {
bufLayer = getBufferedLayer();
}
// use LayerEvent.REPLACE when you want to remove all current
// layers
// add a new set
if (type == LayerEvent.REPLACE) {
if (DEBUG) {
debugmsg("Replacing all layers");
}
removeAll();
bufLayer.clearLayers();
for (int i = 0; i < layers.length; i++) {
// @HACK is this cool?:
if (layers[i] == null) {
System.err.println("MapBean.setLayers(): layer " + i
+ " is null");
continue;
}
if (DEBUG) {
debugmsg("Adding layer[" + i + "]= " + layers[i].getName());
}
if (layers[i].getAddAsBackground()) {
if (DEBUG) {
Debug.output("Adding layer[" + i + "]= "
+ layers[i].getName() + " to background");
}
bufLayer.addLayer(layers[i]);
} else {
add(layers[i]);
}
layers[i].setVisible(true);
}
if (bufLayer.hasLayers()) {
add(bufLayer);
}
}
// use LayerEvent.ADD when adding and/or reshuffling layers
else if (type == LayerEvent.ADD) {
remove(bufLayer);
if (DEBUG) {
debugmsg("Adding new layers");
}
for (int i = 0; i < layers.length; i++) {
if (DEBUG) {
debugmsg("Adding layer[" + i + "]= " + layers[i].getName());
}
// add(layers[i]);
layers[i].setVisible(true);
if (layers[i].getAddAsBackground()) {
if (DEBUG) {
Debug.output("Adding layer[" + i + "]= "
+ layers[i].getName() + " to background");
}
bufLayer.addLayer(layers[i]);
} else {
add(layers[i]);
}
}
if (bufLayer.hasLayers()) {
add(bufLayer);
}
}
// use LayerEvent.REMOVE when you want to delete layers from
// the map
else if (type == LayerEvent.REMOVE) {
if (DEBUG) {
debugmsg("Removing layers");
}
for (int i = 0; i < layers.length; i++) {
if (DEBUG) {
debugmsg("Removing layer[" + i + "]= "
+ layers[i].getName());
}
remove(layers[i]);
bufLayer.removeLayer(layers[i]);
}
}
if (!layerRemovalDelayed) {
purgeAndNotifyRemovedLayers();