Index: FLayers.java
===================================================================
--- FLayers.java	(revision 42292)
+++ FLayers.java	(revision 42293)
@@ -26,9 +26,11 @@
 import java.awt.Point;
 import java.awt.image.BufferedImage;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -65,7 +67,6 @@
 import org.gvsig.tools.persistence.exception.PersistenceException;
 import org.gvsig.tools.task.Cancellable;
 import org.gvsig.tools.util.Callable;
-import org.gvsig.tools.visitor.NotSupportedOperationException;
 import org.gvsig.tools.visitor.VisitCanceledException;
 import org.gvsig.tools.visitor.Visitor;
 
@@ -84,7 +85,7 @@
  * @see FLyrDefault
  */
 public class FLayers extends FLyrDefault implements LayerCollection,
-        InfoByPoint {
+        InfoByPoint, List {
 
     /**
      * List with all listeners registered for this kind of node.
@@ -187,7 +188,7 @@
         IProjection layerProj = layer.getProjection();
         if (layerProj != null && fmap != null) {
             IProjection mapContextProj = fmap.getProjection();
-			// TODO REVISAR ESTO !!!!
+            // TODO REVISAR ESTO !!!!
             // Esta condición puede que no fuese exacta para todos los casos
             if (!layerProj.getAbrev().equals(mapContextProj.getAbrev())) {
                 ICoordTrans ct = layerProj.getCT(mapContextProj);
@@ -400,52 +401,38 @@
      * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(java.lang.String)
      */
     public FLayer getLayer(String layerName) {
-        FLayer lyr;
-        FLayer lyr2;
-        ArrayList layerList;
-
         for (int i = 0; i < layers.size(); i++) {
-            lyr = ((FLayer) layers.get(i));
-
+            FLayer lyr = ((FLayer) layers.get(i));
             if (lyr.getName().compareToIgnoreCase(layerName) == 0) {
                 return lyr;
             }
-
-            layerList = new ArrayList();
-            splitLayerGroup(lyr, layerList);
-            for (int j = 0; j < layerList.size(); j++) {
-                lyr2 = ((FLayer) layerList.get(j));
-                if (lyr2.getName().compareToIgnoreCase(layerName) == 0) {
-                    return lyr2;
+            if (lyr instanceof FLayers) {
+                List layerList = toPlainList(lyr);
+                for (int j = 0; j < layerList.size(); j++) {
+                    FLayer lyr2 = ((FLayer) layerList.get(j));
+                    if (lyr2.getName().compareToIgnoreCase(layerName) == 0) {
+                        return lyr2;
+                    }
                 }
             }
         }
-
         return null;
     }
 
-    /**
-     * <p>
-     * Splits up a layer group in order to get a layer by name when there are
-     * layer groups</p>
-     *
-     * <p>
-     * In <code>result</code> always will be at least one layer.</p>
-     *
-     * @param layer the layer we are looking for
-     * @param result an array list that will have the results of the search
-     */
-    private void splitLayerGroup(FLayer layer, ArrayList result) {
-        int i;
-        FLayers layerGroup;
+    private List toPlainList(FLayer layer) {
+        return toPlainList(layer, new ArrayList());
+    }
+
+    private List toPlainList(FLayer layer, List result) {
         if (layer instanceof FLayers) {
-            layerGroup = (FLayers) layer;
-            for (i = 0; i < layerGroup.getLayersCount(); i++) {
-                splitLayerGroup(layerGroup.getLayer(i), result);
+            FLayers layerGroup = (FLayers) layer;
+            for (int i = 0; i < layerGroup.getLayersCount(); i++) {
+                toPlainList(layerGroup.getLayer(i), result);
             }
         } else {
             result.add(layer);
         }
+        return result;
     }
 
     /*
@@ -546,7 +533,7 @@
             dpi = 72;
         }
 
-		// TODO: A la hora de imprimir, isWithinScale falla, porque está
+        // TODO: A la hora de imprimir, isWithinScale falla, porque está
         // calculando la escala en pantalla, no para el layout.
         // Revisar esto.
         // TODO: We have to check when we have to call the drawLabels method when exists a ComposedLayer group.
@@ -558,7 +545,7 @@
 
             try {
 
-				///// CHEMA ComposedLayer
+                ///// CHEMA ComposedLayer
                 // Checks for draw group (ComposedLayer)
                 if (group != null) {
                     if (lyr instanceof FLayers) {
@@ -647,7 +634,7 @@
         }
 		///// CHEMA ComposedLayer
 
-		//		if (getVirtualLayers() != null) {
+        //		if (getVirtualLayers() != null) {
         //			getVirtualLayers().print( g, viewPort, cancel, scale, properties);
         //		}
         ///// CHEMA ComposedLayer
@@ -843,7 +830,7 @@
      * @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
      */
     public FLayer[] getActives() {
-        ArrayList ret = new ArrayList();
+        List ret = new ArrayList();
         LayersIterator it = new LayersIterator(this) {
 
             public boolean evaluate(FLayer layer) {
@@ -968,7 +955,7 @@
      *
      * @throws LoadLayerException if fails loading this layer.
      */
-	//	public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException {
+    //	public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException {
     //		fmap.clearErrors();
     //		this.addLayerFromXML(xml,name);
     //
@@ -1453,4 +1440,132 @@
 
     }
 
+    public FLayer getFirstActiveLayer() {
+        LayersIterator it = new LayersIterator(this) {
+            public boolean evaluate(FLayer layer) {
+                return layer.isActive();
+            }
+        };
+        if( it.hasNext() ) {
+            return (FLayer) it.next();
+        }
+        return null;
+    }
+    
+    public Iterator iterator() {
+        return this.layers.iterator();
+    }
+
+    public Iterator deepiterator() {
+        List layers = toPlainList(this);
+        return layers.iterator();
+    }
+    
+    public int size() {
+        return this.layers.size();
+    }
+    
+    public Object get(int index) {
+        return this.layers.get(index);
+    }
+    
+    public boolean isEmpty() {
+        return this.layers.isEmpty();
+    }
+
+    public boolean contains(Object o) {
+        return this.layers.contains(o);
+    }
+
+    public Object[] toArray() {
+        return this.layers.toArray();
+    }
+
+    public Object[] toArray(Object[] ts) {
+        return this.layers.toArray(ts);
+    }
+
+    public boolean add(Object e) {
+        this.addLayer((FLayer) e);
+        return true;
+    }
+
+    public boolean remove(Object o) {
+        this.removeLayer((FLayer) o);
+        return true;
+    }
+
+    public boolean containsAll(Collection clctn) {
+        return this.layers.containsAll(clctn);
+    }
+
+    public void add(int i, Object e) {
+        this.addLayer(i, (FLayer) e);
+    }
+
+    public Object remove(int i) {
+        FLayer o = this.getLayer(i);
+        this.removeLayer(i);
+        return o;
+    }
+
+    public int indexOf(Object o) {
+        return this.layers.indexOf(o);
+    }
+
+    public int lastIndexOf(Object o) {
+        return this.layers.lastIndexOf(o);
+    }
+
+    public ListIterator listIterator() {
+        return this.layers.listIterator();
+    }
+
+    public ListIterator listIterator(int i) {
+        return this.layers.listIterator(i);
+    }
+
+    public List subList(int i, int i1) {
+        return this.layers.subList(i, i1);
+    }
+    
+    public boolean addAll(Collection clctn) {
+        Iterator it = clctn.iterator();
+        while( it.hasNext() ) {
+            this.add(it.next());
+        }
+        return true;
+    }
+
+    public boolean addAll(int i, Collection clctn) {
+        Iterator it = clctn.iterator();
+        while( it.hasNext() ) {
+            this.add(i,it.next());
+        }
+        return true;
+    }
+
+    public boolean removeAll(Collection clctn) {
+        Iterator it = clctn.iterator();
+        while( it.hasNext() ) {
+            this.remove(it.next());
+        }
+        return true;
+    }
+
+    public boolean retainAll(Collection clctn) {
+        Iterator it = this.layers.iterator();
+        while( it.hasNext() ) {
+            Object o = it.next();
+            if( !clctn.contains(o) ) {
+                this.remove(o);
+            }
+        }
+        return true;
+    }
+
+    public Object set(int i, Object e) {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
 }
