Package com.bc.ceres.glayer
Class Layer
- java.lang.Object
-
- com.bc.ceres.core.ExtensibleObject
-
- com.bc.ceres.glayer.Layer
-
- All Implemented Interfaces:
Extensible
- Direct Known Subclasses:
BackgroundLayer
,CollectionLayer
,GraticuleLayer
,ImageLayer
,ShapeLayer
public abstract class Layer extends ExtensibleObject
A layer contributes graphical elements to a drawing represented by aRendering
.- Version:
- $revision$ $date$
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Layer(LayerType layerType)
protected
Layer(LayerType layerType, PropertySet configuration)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(LayerListener listener)
Adds a change listener to this layer.void
dispose()
Disposes all allocated resources.protected void
disposeChildren()
Disposes the child layers of this layer.protected void
disposeLayer()
Disposes the layer.protected void
fireLayerDataChanged(Rectangle2D modelRegion)
protected void
fireLayerPropertyChanged(PropertyChangeEvent event)
protected void
fireLayerPropertyChanged(String propertyName, Object oldValue, Object newValue)
protected void
fireLayersAdded(Layer[] layers)
protected void
fireLayersRemoved(Layer[] layers)
int
getChildIndex(String id)
Gets the index of the first child layer having the given identifier.List<Layer>
getChildren()
Gets the child layers of this layer.protected Rectangle2D
getChildrenModelBounds()
Gets the bounds (bounding box) of the child layers in model coordinates.Composite
getComposite()
Returns the composite of this layer.PropertySet
getConfiguration()
Returns the configuration which can be used by the layer type to recreate this layer.protected <T> T
getConfigurationProperty(String propertyName, T defaultValue)
String
getId()
protected Rectangle2D
getLayerModelBounds()
Gets the bounds (bounding box) of this layer in model coordinates.LayerType
getLayerType()
LayerListener[]
getListeners()
Rectangle2D
getModelBounds()
Gets the model bounds (bounding box) of the layer in model coordinates.String
getName()
Layer
getParent()
double
getSwipePercent()
Returns the swipe position of this layer.double
getTransparency()
Returns the transparency of this layer.boolean
isCollectionLayer()
boolean
isVisible()
void
regenerate()
Regenerates the layer.void
removeListener(LayerListener listener)
Removes a change listener from this layer.void
render(Rendering rendering)
Renders the layer.void
render(Rendering rendering, LayerFilter filter)
Renders the layer.protected void
renderChildren(Rendering rendering, LayerFilter filter)
Renders the child layers of this layer.protected void
renderLayer(Rendering rendering)
Renders the layer.void
setComposite(Composite composite)
Sets the composite of this layer.void
setId(String id)
void
setName(String name)
void
setSwipePercent(double swipePercent)
Sets the swipe position of this layer to a new value.void
setTransparency(double transparency)
Sets the transparency of this layer to a new value.void
setVisible(boolean visible)
String
toString()
-
Methods inherited from class com.bc.ceres.core.ExtensibleObject
getExtension
-
-
-
-
Constructor Detail
-
Layer
protected Layer(LayerType layerType)
-
Layer
protected Layer(LayerType layerType, PropertySet configuration)
Constructor. The following default properties are used:name = getClass().getName()
visible = true
transparency = 0.0
swipePercent = 1.0
- Parameters:
layerType
- the layer type.configuration
- the configuration used by the layer type to create this layer.
-
-
Method Detail
-
getLayerType
public LayerType getLayerType()
- Returns:
- The layer type.
-
getConfiguration
public PropertySet getConfiguration()
Returns the configuration which can be used by the layer type to recreate this layer.- Returns:
- the configuration.
-
getParent
public Layer getParent()
- Returns:
- The parent layer, or
null
if this layer is not a child of any other layer.
-
isCollectionLayer
public boolean isCollectionLayer()
- Returns:
- true, if this layer is a collection of other layers.
-
getChildren
public List<Layer> getChildren()
Gets the child layers of this layer. The returned list is "life", modifying the list's content will cause this layer to fire change events.- Returns:
- The child layers of this layer. May be empty.
-
getName
public String getName()
- Returns:
- The name.
-
setName
public void setName(String name)
- Parameters:
name
- The name.
-
getId
public String getId()
- Returns:
- An identifier which can be used to search for special layers.
- Since:
- Ceres 0.9
-
setId
public void setId(String id)
- Parameters:
id
- An identifier which can be used to search for special layers.- Since:
- Ceres 0.9
-
getChildIndex
public int getChildIndex(String id)
Gets the index of the first child layer having the given identifier.- Parameters:
id
- The identifier.- Returns:
- The child index, or
-1
if no such layer exists. - Since:
- Ceres 0.9
-
isVisible
public boolean isVisible()
- Returns:
true
, if this layer is visible.
-
setVisible
public void setVisible(boolean visible)
- Parameters:
visible
-true
, if this layer is visible.
-
getTransparency
public double getTransparency()
Returns the transparency of this layer.- Returns:
- the transparency of this layer.
-
setTransparency
public void setTransparency(double transparency)
Sets the transparency of this layer to a new value.- Parameters:
transparency
- the new transparency value of this layer.
-
getSwipePercent
public double getSwipePercent()
Returns the swipe position of this layer.- Returns:
- the swipe position of this layer.
-
setSwipePercent
public void setSwipePercent(double swipePercent)
Sets the swipe position of this layer to a new value.- Parameters:
swipePercent
- the new swipe position value of this layer.
-
getComposite
public Composite getComposite()
Returns the composite of this layer.- Returns:
- the composite of this layer.
-
setComposite
public void setComposite(Composite composite)
Sets the composite of this layer.- Parameters:
composite
- the new composite of this layer.
-
getConfigurationProperty
protected final <T> T getConfigurationProperty(String propertyName, T defaultValue)
-
getModelBounds
public final Rectangle2D getModelBounds()
Gets the model bounds (bounding box) of the layer in model coordinates. The default implementation returns the union of the model bounds (if any) returned bygetLayerModelBounds()
andgetChildrenModelBounds()
.- Returns:
- The bounds of the layer in model coordinates or
null
if this layer and all children have no specified boundary.
-
getLayerModelBounds
protected Rectangle2D getLayerModelBounds()
Gets the bounds (bounding box) of this layer in model coordinates. Called bygetModelBounds()
. The default implementation returnsnull
.- Returns:
- The bounds of the layer in model coordinates or
null
if this layer has no specified boundary.
-
getChildrenModelBounds
protected Rectangle2D getChildrenModelBounds()
Gets the bounds (bounding box) of the child layers in model coordinates. Called bygetModelBounds()
. The default implementation returns the union bounds (if any) of all child layers.- Returns:
- The bounds of the child layers in model coordinates or
null
none of the children have a specified boundary.
-
render
public final void render(Rendering rendering)
Renders the layer. Callsrender(rendering,null)
.- Parameters:
rendering
- The rendering to which the layer will be rendered.- See Also:
render(com.bc.ceres.grender.Rendering, LayerFilter)
-
render
public final void render(Rendering rendering, LayerFilter filter)
Renders the layer. The base class implementation configures the rendering with respect to the "transparency" and "composite" style properties. ThenrenderLayer(com.bc.ceres.grender.Rendering)
followed byrenderChildren(com.bc.ceres.grender.Rendering, LayerFilter)
are called.- Parameters:
rendering
- The rendering to which the layer will be rendered.filter
- An optional layer filter. May benull
.
-
renderLayer
protected void renderLayer(Rendering rendering)
Renders the layer. Called byrender(com.bc.ceres.grender.Rendering)
. The default implementation does nothing.- Parameters:
rendering
- The rendering to which the layer will be rendered.
-
renderChildren
protected void renderChildren(Rendering rendering, LayerFilter filter)
Renders the child layers of this layer. Called byrender(com.bc.ceres.grender.Rendering)
. The default implementation callsrender(com.bc.ceres.grender.Rendering)
on all child layers.- Parameters:
rendering
- The rendering to which the layer will be rendered.filter
- A layer filter. May benull
.
-
dispose
public final void dispose()
Disposes all allocated resources. Called if the layer will no longer be in use. The default implementation removes all registered listeners, callsdisposeChildren()
followed bydisposeLayer()
.
-
disposeLayer
protected void disposeLayer()
Disposes the layer. Called bydispose()
. The default implementation does nothing.
-
disposeChildren
protected void disposeChildren()
-
addListener
public void addListener(LayerListener listener)
Adds a change listener to this layer.- Parameters:
listener
- The listener.
-
removeListener
public void removeListener(LayerListener listener)
Removes a change listener from this layer.- Parameters:
listener
- The listener.
-
getListeners
public LayerListener[] getListeners()
- Returns:
- The listeners added to this layer..
-
fireLayerPropertyChanged
protected void fireLayerPropertyChanged(String propertyName, Object oldValue, Object newValue)
-
fireLayerPropertyChanged
protected void fireLayerPropertyChanged(PropertyChangeEvent event)
-
fireLayerDataChanged
protected void fireLayerDataChanged(Rectangle2D modelRegion)
-
fireLayersAdded
protected void fireLayersAdded(Layer[] layers)
-
fireLayersRemoved
protected void fireLayersRemoved(Layer[] layers)
-
regenerate
public void regenerate()
Regenerates the layer. May be called to update the layer data. The default implementation does nothing.
-
-