public void addLayer(Layer layer,int position){
  List<Layer> currentLayers=getLayerList();
  currentLayers.remove(layer);
  if (position > allLayers.size()) {
    currentLayers.add(layer);
  }
 else {
    if (position < 0) {
      position=0;
    }
    currentLayers.add(position,layer);
  }
  if (propertyHandler != null) {
    String pre=layer.getPropertyPrefix();
    if (pre != null && pre.length() > 0) {
      propertyHandler.addUsedPrefix(pre);
    }
  }
  setLayerList(currentLayers);
  BeanContext bc=getBeanContext();
  if (bc != null && layer.getAddToBeanContext() && layer.getBeanContext() == null) {
    bc.add(layer);
  }
}

public void addLayer ( Layer layer , int position ) { List < Layer > currentLayers = getLayerList ( ) ; currentLayers . remove ( layer ) ; if ( position > allLayers . size ( ) ) { currentLayers . add ( layer ) ; } else { if ( position < 0 ) { position = 0 ; } currentLayers . add ( position , layer ) ; } if ( propertyHandler != null ) { String pre = layer . getPropertyPrefix ( ) ; if ( pre != null && pre . length ( ) > 0 ) { propertyHandler . addUsedPrefix ( pre ) ; } } setLayerList ( currentLayers ) ; BeanContext bc = getBeanContext ( ) ; if ( bc != null && layer . getAddToBeanContext ( ) && layer . getBeanContext ( ) == null ) { bc . add ( layer ) ; } }
add a layer to a certain position in the layer array . if the position is 0 or less , the layer is put up front ( on top ) . if the position is greater than the length of the current array , the layer is put at the end , ( on the bottom ) . a layer can only be added once . if you add a layer that is already added to the layerhandler , it will be moved to the requested position .
