Class FLayers

java.lang.Object
org.gvsig.tools.dispose.impl.AbstractDisposable
org.gvsig.fmap.mapcontext.layers.FLyrDefault
org.gvsig.fmap.mapcontext.layers.FLayers
All Implemented Interfaces:
Iterable<FLayer>, Collection<FLayer>, List<FLayer>, SequencedCollection<FLayer>, ExtendedPropertiesSupport, FLayer, FLayerHidesArea, LayerListener, InfoByPoint, LayerCollection, LayersVisitable, Projected, org.gvsig.metadata.Metadata, org.gvsig.tools.dispose.Disposable, org.gvsig.tools.dynobject.DynObject, org.gvsig.tools.persistence.Persistent, org.gvsig.tools.visitor.Visitable

public class FLayers extends FLyrDefault implements LayerCollection, InfoByPoint, List<FLayer>

Represents a generic collection of layers, that can be represented as a node in a tree of nodes of layers.

Adapts the basic functionality implemented for a layer in the abstract class FLyrDefault, to a collection of layers, implementing, as well, specific methods for this kind of object, defined in the interfaces VectorialData, LayerCollection, and InfoByPoint.

See Also:
  • Field Details

  • Constructor Details

    • FLayers

      public FLayers()
  • Method Details

    • addLayerCollectionListener

      public void addLayerCollectionListener(LayerCollectionListener listener)
      Description copied from interface: LayerCollection

      Adds a listener of events produced on a collection of layers.

      Specified by:
      addLayerCollectionListener in interface LayerCollection
      Parameters:
      listener - a LayerCollectionListener
      See Also:
    • setAllVisibles

      public void setAllVisibles(boolean visible)
      Description copied from interface: LayerCollection

      Changes the status of all layers to visible or invisible.

      Specified by:
      setAllVisibles in interface LayerCollection
      Parameters:
      visible - a boolean value
      See Also:
    • removeLayerCollectionListener

      public void removeLayerCollectionListener(LayerCollectionListener listener)
      Description copied from interface: LayerCollection

      Removes a listener of events produced on a collection of layers.

      Specified by:
      removeLayerCollectionListener in interface LayerCollection
      Parameters:
      listener - a LayerCollectionListener
      See Also:
    • addLayer

      public void addLayer(FLayer layer)
      Description copied from interface: LayerCollection

      Adds a new layer to this collection.

      Specified by:
      addLayer in interface LayerCollection
      Parameters:
      layer - the new layer
      See Also:
    • addLayer

      public void addLayer(org.gvsig.fmap.dal.DataStore store)
    • addLayer

      public void addLayer(int pos, FLayer layer)
      Adds a layer in an specified position in this node.
      Parameters:
      pos -
      layer - a layer
    • moveTo

      public void moveTo(int from, int to) throws CancelationException
      Description copied from interface: LayerCollection

      Moves a layer of the collection to another position in internal list. It doesn't consider sub-nodes of layers.

      Specified by:
      moveTo in interface LayerCollection
      Parameters:
      from - origin position
      to - destination position
      Throws:
      CancelationException - any exception produced during the cancellation of the driver.
    • removeLayer

      public void removeLayer(FLayer lyr) throws CancelationException
      Description copied from interface: LayerCollection

      Removes a layer from this collection.

      Specified by:
      removeLayer in interface LayerCollection
      Parameters:
      lyr - a layer
      Throws:
      CancelationException - any exception produced during the cancellation of the driver.
      See Also:
    • removeLayer

      public void removeLayer(int idLayer)
      Description copied from interface: LayerCollection

      Removes a layer using its identifier.

      Specified by:
      removeLayer in interface LayerCollection
      Parameters:
      idLayer - layer identifier
      See Also:
    • removeLayer

      public void removeLayer(String layerName)
      Description copied from interface: LayerCollection

      Removes a layer using its name.

      Specified by:
      removeLayer in interface LayerCollection
      Parameters:
      layerName - the name of the layer
      See Also:
    • replaceLayer

      public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException
      Replace a layer identified by its name, by another.
      Parameters:
      layerName - the name of the layer to be replaced
      layer - the new layer
      Throws:
      LoadLayerException
    • replaceLayer

      public void replaceLayer(FLayer layer, FLayer newLayer) throws LoadLayerException
      Replace a layer by another layer. It search recursively by all the ILayerCollection nodes
      Parameters:
      layer - the layer to be replaced
      newLayer - the new layer
      Throws:
      LoadLayerException
    • getVisibles

      public FLayer[] getVisibles()
      Description copied from interface: LayerCollection

      Returns an array with all visible layers in this collection.

      Specified by:
      getVisibles in interface LayerCollection
      Returns:
      array with first-level visible layer nodes, or null if no there is no layer visible
      See Also:
    • getLayer

      public FLayer getLayer(int index)
      Description copied from interface: LayerCollection

      Returns the ith-output directed son (from bottom up) of this collection.

      Specified by:
      getLayer in interface LayerCollection
      Parameters:
      index - index of the ith-output layer in this collection.
      Returns:
      a layer
      See Also:
    • getLayer

      public FLayer getLayer(String layerName)
      Description copied from interface: LayerCollection
      Returns a first-level layer of this collection, using its name.
      Specified by:
      getLayer in interface LayerCollection
      Parameters:
      layerName - name of a layer of this collection
      Returns:
      a layer
      See Also:
    • getLayer

      public FLayer getLayer(org.gvsig.fmap.dal.DataStore store)
      Description copied from interface: LayerCollection
      Returns a first-level layer of this collection, using its name.
      Specified by:
      getLayer in interface LayerCollection
      Parameters:
      store - of a layer of this collection
      Returns:
      a layer
    • getLayersCount

      public int getLayersCount()
      Description copied from interface: LayerCollection

      Returns the number of layers that are at the first level inside this one.

      Doesn't counts the sublayers (of FLayers subnodes).

      Specified by:
      getLayersCount in interface LayerCollection
      Returns:
      number >= 0 with layers that are at the same first-level
      See Also:
    • draw

      public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, org.gvsig.tools.task.Cancellable cancel, double scale) throws org.gvsig.fmap.dal.exception.ReadException
      Description copied from interface: FLayer
      Draws the layer using a buffer.
      Specified by:
      draw in interface FLayer
      Parameters:
      image - an image used to accelerate the screen draw
      g - for rendering 2-dimensional shapes, text and images on the Java(tm) platform
      viewPort - information for drawing this layer
      cancel - an object thread that implements the Cancellable interface, and will allow to cancel the draw
      scale - value that represents the scale
      Throws:
      org.gvsig.fmap.dal.exception.ReadException - if fails the driver used in this method.
      See Also:
    • print

      public void print(Graphics2D g, ViewPort viewPort, org.gvsig.tools.task.Cancellable cancel, double scale, org.gvsig.compat.print.PrintAttributes properties) throws org.gvsig.fmap.dal.exception.ReadException
      Description copied from interface: FLayer
      Prints this layer according to some properties requested.
      Specified by:
      print in interface FLayer
      Parameters:
      g - for rendering 2-dimensional shapes, text and images on the Java(tm) platform
      viewPort - the information for drawing the layers
      cancel - an object thread that implements the Cancellable interface, and will allow to cancel the draw
      scale - the scale of the view. Must be between FLayer.getMinScale() and FLayer.getMaxScale().
      properties - a set with the settings to be applied to a whole print job and to all the docs in the print job
      Throws:
      org.gvsig.fmap.dal.exception.ReadException - if fails the driver used in this method.
      See Also:
    • getFullEnvelope

      public org.gvsig.fmap.geom.primitive.Envelope getFullEnvelope()
      Description copied from interface: FLayer
      Returns the full extension of the layer node.
      Specified by:
      getFullEnvelope in interface FLayer
      Returns:
      location and dimension of this layer node
    • callLayerAdding

      protected void callLayerAdding(LayerCollectionEvent event) throws CancelationException
      Notifies all listeners associated to this collection of layers, that another layer is going to be added or replaced in the internal list of layers.
      Parameters:
      event - a layer collection event with the new layer
      Throws:
      CancelationException
    • callLayerRemoving

      protected void callLayerRemoving(LayerCollectionEvent event) throws CancelationException
      Notifies all listeners associated to this collection of layers, that a layer is going to be removed from the internal list of layers.
      Parameters:
      event - a layer collection event with the layer being removed
      Throws:
      CancelationException - any exception produced during the cancellation of the driver.
    • callLayerMoving

      protected void callLayerMoving(LayerPositionEvent event) throws CancelationException
      Notifies all listeners associated to this collection of layers, that a layer is going to be moved in the internal list of layers.
      Parameters:
      event - a layer collection event with the layer being moved, and the initial and final positions
      Throws:
      CancelationException - any exception produced during the cancellation of the driver.
    • callLayerAdded

      protected void callLayerAdded(LayerCollectionEvent event)
      Notifies all listeners associated to this collection of layers, that another layer has been added or replaced in the internal list of layers.
      Parameters:
      event - a layer collection event with the new layer
    • callLayerRemoved

      protected void callLayerRemoved(LayerCollectionEvent event)
      Notifies all listeners associated to this collection of layers, that another layer has been removed from the internal list of layers.
      Parameters:
      event - a layer collection event with the layer removed
    • callLayerMoved

      protected void callLayerMoved(LayerPositionEvent event)
      Notifies all listeners associated to this collection of layers, that another layer has been moved in the internal list of layers.
      Parameters:
      event - a layer collection event with the layer moved, and the initial and final positions
    • saveToState

      public void saveToState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
      Specified by:
      saveToState in interface org.gvsig.tools.persistence.Persistent
      Overrides:
      saveToState in class FLyrDefault
      Throws:
      org.gvsig.tools.persistence.exception.PersistenceException
    • loadFromState

      public void loadFromState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
      Specified by:
      loadFromState in interface org.gvsig.tools.persistence.Persistent
      Overrides:
      loadFromState in class FLyrDefault
      Throws:
      org.gvsig.tools.persistence.exception.PersistenceException
    • getMapContext

      public MapContext getMapContext()
      Description copied from interface: FLayer

      Returns a reference to the model of this layer, or null if this layer has no model.

      Specified by:
      getMapContext in interface FLayer
      Overrides:
      getMapContext in class FLyrDefault
      Returns:
      the model of this layer
    • setAllActives

      public void setAllActives(boolean active)
      Description copied from interface: LayerCollection

      Changes the status of all layers to active or inactive.

      Specified by:
      setAllActives in interface LayerCollection
      Parameters:
      active - a boolean value
      See Also:
    • getLayers

      public List<FLayer> getLayers(Predicate<FLayer> filter)
      Specified by:
      getLayers in interface LayerCollection
    • getActives

      public FLayer[] getActives()
      Description copied from interface: LayerCollection

      Returns an array with all active layers in this collection.

      Specified by:
      getActives in interface LayerCollection
      Returns:
      array with first-level active layer nodes, or null if no there is no layer actived
      See Also:
    • getMinScale

      public double getMinScale()
      Description copied from interface: FLayer
      Returns the minimum scale visible. Lower scales won't be drawn.
      Specified by:
      getMinScale in interface FLayer
      Overrides:
      getMinScale in class FLyrDefault
      Returns:
      the minimum scale > 0, -1 if not defined
      See Also:
    • getMaxScale

      public double getMaxScale()
      Description copied from interface: FLayer
      Returns the maximum scale visible. Higher scales won't be drawn.
      Specified by:
      getMaxScale in interface FLayer
      Overrides:
      getMaxScale in class FLyrDefault
      Returns:
      the maximum scale > 0, -1 if not defined
      See Also:
    • setMinScale

      public void setMinScale(double minScale)
      Description copied from interface: FLayer
      Sets the minimum scale visible. Lower scales won't be drawn.
      Specified by:
      setMinScale in interface FLayer
      Overrides:
      setMinScale in class FLyrDefault
      Parameters:
      minScale - the scale > 0, -1 if not defined
      See Also:
    • setMaxScale

      public void setMaxScale(double maxScale)
      Description copied from interface: FLayer
      Sets the maximum scale visible. Higher scales won't be drawn.
      Specified by:
      setMaxScale in interface FLayer
      Overrides:
      setMaxScale in class FLyrDefault
      Parameters:
      maxScale - the scale > 0, -1 if not defined
      See Also:
    • setActive

      public void setActive(boolean b)
      Description copied from interface: FLayer

      Changes the status of this layer to active or inactive.

      One layer is active if is selected in TOC.

      Specified by:
      setActive in interface FLayer
      Overrides:
      setActive in class FLyrDefault
      Parameters:
      b - the boolean to be set
      See Also:
    • setActive

      public void setActive(boolean active, boolean applySublayers)
    • addLayerListener

      public boolean addLayerListener(LayerListener o)
      Description copied from interface: FLayer
      Adds a LayerListener to the listener list.
      Specified by:
      addLayerListener in interface FLayer
      Overrides:
      addLayerListener in class FLyrDefault
      Parameters:
      o - a layer listener
      Returns:
      true if hasn't been any problem during the insertion of the listener
      See Also:
    • getInfo

      public org.gvsig.tools.dynobject.DynObjectSet getInfo(Point p, double tolerance, org.gvsig.tools.task.Cancellable cancel) throws LoadLayerException, org.gvsig.fmap.dal.exception.DataException
      Description copied from interface: InfoByPoint

      Executes a consultation about information of a point on the layer.

      There is an area around the point where will got the information.

      Specified by:
      getInfo in interface InfoByPoint
      Parameters:
      p - point where is the consultation
      tolerance - permissible margin around the coordinates of the point where the method will got the information. Each singular implementation of this method would use it in a different way. The coordinates also depend on the implementation.
      cancel - shared object that determines if this layer can continue being drawn
      Returns:
      a DynObjectSet. If the InfoByPoint Object is a vector layer it should return a FeatureSet.
      Throws:
      LoadLayerException - any exception produced using the driver.
      org.gvsig.fmap.dal.exception.DataException - TODO
    • getInfo

      public org.gvsig.tools.dynobject.DynObjectSet getInfo(Point p, double tolerance, org.gvsig.tools.task.Cancellable cancel, boolean fast) throws LoadLayerException, org.gvsig.fmap.dal.exception.DataException
      Description copied from interface: InfoByPoint

      Executes a consultation about information of a point on the layer.

      There is an area around the point where will got the information.

      Specified by:
      getInfo in interface InfoByPoint
      Parameters:
      p - point where is the consultation
      tolerance - permissible margin around the coordinates of the point where the method will got the information. Each singular implementation of this method would use it in a different way. The coordinates also depend on the implementation.
      cancel - shared object that determines if this layer can continue being drawn
      fast - if true try to reuse objects as much as possible to make the object iteration faster. If true, DynObjects got through the returned set must not be stored unless cloned.
      Returns:
      a DynObjectSet. If the InfoByPoint Object is a vector layer it should return a FeatureSet.
      Throws:
      LoadLayerException - any exception produced using the driver.
      org.gvsig.fmap.dal.exception.DataException - TODO
    • getInfo

      public org.gvsig.tools.dynobject.DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p, double tolerance) throws LoadLayerException, org.gvsig.fmap.dal.exception.DataException
      Description copied from interface: InfoByPoint

      Executes a consultation about information of a point on the layer.

      There is an area around the point where will got the information.

      Specified by:
      getInfo in interface InfoByPoint
      Parameters:
      p - point in map coordinates where is the consultation
      tolerance - permissible margin around the coordinates of the point where the method will got the information. Each singular implementation of this method would use it in a different way. The unit are in map coordinates.
      Throws:
      LoadLayerException
      org.gvsig.fmap.dal.exception.DataException
    • getTocImageIcon

      public String getTocImageIcon()
      Description copied from interface: FLayer
      Returns the image icon that will be shown in the TOC next to this layer.
      Specified by:
      getTocImageIcon in interface FLayer
      Overrides:
      getTocImageIcon in class FLyrDefault
      Returns:
      a String reference to the image icon, or null if there isn't any
    • setMapContext

      public void setMapContext(MapContext mapContext)

      Sets the MapContext that contains this layer node.

      Parameters:
      mapContext - the MapContext that contains this layer node
    • accept

      public void accept(org.gvsig.tools.visitor.Visitor visitor) throws org.gvsig.tools.exception.BaseException
      Specified by:
      accept in interface org.gvsig.tools.visitor.Visitable
      Throws:
      org.gvsig.tools.exception.BaseException
    • accept

      public void accept(LayersVisitor visitor) throws org.gvsig.tools.exception.BaseException
      Specified by:
      accept in interface LayersVisitable
      Throws:
      org.gvsig.tools.exception.BaseException
    • getMetadataID

      public Object getMetadataID() throws org.gvsig.metadata.exceptions.MetadataException
      Specified by:
      getMetadataID in interface org.gvsig.metadata.Metadata
      Throws:
      org.gvsig.metadata.exceptions.MetadataException
    • getMetadataChildren

      public Set getMetadataChildren()
      Specified by:
      getMetadataChildren in interface org.gvsig.metadata.Metadata
    • getMetadataName

      public String getMetadataName() throws org.gvsig.metadata.exceptions.MetadataException
      Specified by:
      getMetadataName in interface org.gvsig.metadata.Metadata
      Overrides:
      getMetadataName in class FLyrDefault
      Throws:
      org.gvsig.metadata.exceptions.MetadataException
    • beginDraw

      public void beginDraw(Graphics2D g, ViewPort viewPort)
      Specified by:
      beginDraw in interface LayerCollection
    • endDraw

      public void endDraw(Graphics2D g, ViewPort viewPort)
      Specified by:
      endDraw in interface LayerCollection
    • doDispose

      protected void doDispose() throws org.gvsig.tools.exception.BaseException
      Specified by:
      doDispose in class org.gvsig.tools.dispose.impl.AbstractDisposable
      Throws:
      org.gvsig.tools.exception.BaseException
    • move

      public void move(FLayer layer, LayerCollection group, int where, FLayer adjoiningLayer) throws LayerNotFoundInCollectionException
      Description copied from interface: LayerCollection

      Moves a layer from this collection to another collection before or after an element if supplied, and if not at the beginning or end of the collection.

      Specified by:
      move in interface LayerCollection
      Parameters:
      layer - a FLayer to move
      group - a LayerCollection in which the layer has to be moved
      where - the position parameter. The valid values are:
      0 = BEGIN (first position)
      1 = END (last position)
      2 = BEFORE (before target layer)
      3 = AFTER (after target layer)
      adjoiningLayer - a FLayer a layer adjacent to where to insert the layer.
      Throws:
      LayerNotFoundInCollectionException
      See Also:
    • join

      public void join(FLayer layer, LayerCollection group)
    • move

      public void move(FLayer layer, LayerCollection group)
      Description copied from interface: LayerCollection

      Moves a layer from this collection to the end of another collection.

      Specified by:
      move in interface LayerCollection
      Parameters:
      layer - a FLayer to move
      group - a LayerCollection in which the layer has to be moved
    • addLayer

      public void addLayer(FLayer layer, int where, FLayer adjoiningLayer) throws LayerNotFoundInCollectionException
      Description copied from interface: LayerCollection

      Adds a new layer to this collection before or after an element if supplied, and if not at the beginning or end of the collection.

      .

      Specified by:
      addLayer in interface LayerCollection
      Parameters:
      layer - a FLayer to move
      where - the position parameter. The valid values are:
      0 = BEGIN (first position)
      1 = END (last position)
      2 = BEFORE (before target layer)
      3 = AFTER (after target layer)
      adjoiningLayer - a FLayer a layer adjacent to where to insert the layer.
      Throws:
      LayerNotFoundInCollectionException
      See Also:
      • invalid reference
        #moveTo(FLayer, LayerCollection, int, FLayer)
    • getFirstActiveLayer

      public FLayer getFirstActiveLayer()
    • getFirstActiveVectorLayer

      public FLyrVect getFirstActiveVectorLayer()
    • iterator

      public Iterator<FLayer> iterator()
      Specified by:
      iterator in interface Collection<FLayer>
      Specified by:
      iterator in interface Iterable<FLayer>
      Specified by:
      iterator in interface List<FLayer>
    • deepiterator

      public Iterator<FLayer> deepiterator()
    • deepiterable

      public Iterable<FLayer> deepiterable()
    • size

      public int size()
      Specified by:
      size in interface Collection<FLayer>
      Specified by:
      size in interface List<FLayer>
    • get

      public FLayer get(int index)
      Specified by:
      get in interface List<FLayer>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<FLayer>
      Specified by:
      isEmpty in interface List<FLayer>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<FLayer>
      Specified by:
      contains in interface List<FLayer>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<FLayer>
      Specified by:
      toArray in interface List<FLayer>
    • toArray

      public Object[] toArray(Object[] ts)
      Specified by:
      toArray in interface Collection<FLayer>
      Specified by:
      toArray in interface List<FLayer>
    • add

      public boolean add(FLayer e)
      Specified by:
      add in interface Collection<FLayer>
      Specified by:
      add in interface List<FLayer>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<FLayer>
      Specified by:
      remove in interface List<FLayer>
    • containsAll

      public boolean containsAll(Collection clctn)
      Specified by:
      containsAll in interface Collection<FLayer>
      Specified by:
      containsAll in interface List<FLayer>
    • add

      public void add(int i, FLayer e)
      Specified by:
      add in interface List<FLayer>
    • remove

      public FLayer remove(int i)
      Specified by:
      remove in interface List<FLayer>
    • indexOf

      public int indexOf(Object o)
      Specified by:
      indexOf in interface List<FLayer>
    • lastIndexOf

      public int lastIndexOf(Object o)
      Specified by:
      lastIndexOf in interface List<FLayer>
    • listIterator

      public ListIterator listIterator()
      Specified by:
      listIterator in interface List<FLayer>
    • listIterator

      public ListIterator listIterator(int i)
      Specified by:
      listIterator in interface List<FLayer>
    • subList

      public List subList(int i, int i1)
      Specified by:
      subList in interface List<FLayer>
    • addAll

      public boolean addAll(Collection clctn)
      Specified by:
      addAll in interface Collection<FLayer>
      Specified by:
      addAll in interface List<FLayer>
    • addAll

      public boolean addAll(int i, Collection clctn)
      Specified by:
      addAll in interface List<FLayer>
    • removeAll

      public boolean removeAll(Collection clctn)
      Specified by:
      removeAll in interface Collection<FLayer>
      Specified by:
      removeAll in interface List<FLayer>
    • retainAll

      public boolean retainAll(Collection clctn)
      Specified by:
      retainAll in interface Collection<FLayer>
      Specified by:
      retainAll in interface List<FLayer>
    • set

      public FLayer set(int i, FLayer e)
      Specified by:
      set in interface List<FLayer>
    • createFLayerGroup

      public FLayers createFLayerGroup(String name)
    • cloneLayer

      public FLayers cloneLayer() throws Exception
      Description copied from interface: FLayer

      This method can be used to have a fast cloned layer.

      The implementations should take care of not recreate this layer. Instead of this, is better to use the same source (driver) and deepclone the legend. Exception: the labels aren't deepcloned to avoid memory consumption.

      Note: Labels are memory consuming to speed up layers like PostGIS and so on.

      Specified by:
      cloneLayer in interface FLayer
      Overrides:
      cloneLayer in class FLyrDefault
      Returns:
      a layer that is a clonation of this layer
      Throws:
      Exception - any exception produced during the cloning of this layer.
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<FLayer>
      Specified by:
      clear in interface org.gvsig.tools.dynobject.DynObject
      Specified by:
      clear in interface List<FLayer>
      Overrides:
      clear in class FLyrDefault
    • clearMetadata

      public void clearMetadata()
    • clearLayers

      public void clearLayers()
      Remove all layers of this object.