public class TLcdTreeLayeredSupport extends Object implements ILcdTreeLayeredSupport
This is a utility class that can be used to make a class that implements
ILcdTreeLayered
.
The order of the layers in the flat list representation is derived from the order in which the
layers appear in the hierarchical layer structure. As a consequence, moving a layer to a certain
index is not always possible since the hierarchical structure must allow such a move (see also
moveLayerAt(int, ILcdLayer)
). This also means that adjusting the layer order in the
hierarchical structure will influence the layer order in the flat list.
TLcdIndependentOrderTreeLayeredSupport
,
Serialized FormConstructor and Description |
---|
TLcdTreeLayeredSupport(ILcdLayered aLayeredToSupport,
ILcdLayerTreeNode aRootNode)
Constructs a new
TLcdTreeLayeredSupport for a tree with root node aRootNode . |
TLcdTreeLayeredSupport(ILcdLayerTreeNode aRootNode)
Constructs a new
TLcdTreeLayeredSupport for a tree with root node
aRootNode . |
Modifier and Type | Method and Description |
---|---|
void |
addLayeredListener(ILcdLayeredListener aLayeredListener)
Registers the given
ILcdLayeredListener to be notified when layers are added,
removed or moved in the flat list. |
boolean |
containsLayer(ILcdLayer aLayer)
Returns whether the flat list representation of the hierarchical layer structure contains
the given layer.
|
ILcdLayer |
getLayer(int aIndex)
Returns the
ILcdLayer with index aIndex in the flat list
representation of the hierarchical layer structure. |
ILcdLayered |
getLayeredToSupport()
Returns the
ILcdLayered for which this support is created. |
ILcdLayerTreeNode |
getRootNode()
Returns the root node of the tree structure.
|
int |
indexOf(ILcdLayer aLayer)
Returns the index of the given layer
aLayer in the flat list representation of
the hierarchical structure. |
int |
layerCount()
Returns the number of layers in the flat list representation of the hierarchical layer
structure.
|
ILcdLayer |
layerOf(ILcdModel aModel)
Returns the
ILcdLayer of the flat list that contains the given
ILcdModel . |
Enumeration |
layers()
Returns an
Enumeration of all the ILcdLayer s currently in the flat
list representation of the hierarchical layer structure, starting from the bottom layer to the
top layer. |
Enumeration |
layersBackwards()
Returns an
Enumeration of all the ILcdLayer s currently in the flat
list representation of the hierarchical layer structure, starting from the top layer to the
bottom layer. |
void |
moveLayerAt(int aIndex,
ILcdLayer aLayer)
Tries to move the layer
aLayer to index aIndex , without affecting
the tree structure, in a best effort approach. |
void |
removeAllLayers()
Remove all the layers from the hierarchical layer structure and the flat list
representation.
|
void |
removeLayer(ILcdLayer aLayer)
Removes a layer from both the hierarchical layer structure and the flat list representation.
|
void |
removeLayeredListener(ILcdLayeredListener aLayeredListener)
Unregisters the given
ILcdLayeredListener from receiving layered events for the
flat list. |
void |
setLayeredToSupport(ILcdLayered aLayeredToSupport)
Sets the
ILcdLayered for which this support is created. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLayeredListener, getLayers, removeLayeredListener
public TLcdTreeLayeredSupport(ILcdLayered aLayeredToSupport, ILcdLayerTreeNode aRootNode)
Constructs a new TLcdTreeLayeredSupport
for a tree with root node aRootNode
.
aLayeredToSupport
- the ILcdLayered
that will delegate to this supportaRootNode
- the root node of the hierarchical layer structurepublic TLcdTreeLayeredSupport(ILcdLayerTreeNode aRootNode)
Constructs a new TLcdTreeLayeredSupport
for a tree with root node
aRootNode
.
Before using an instance of this class, setLayeredToSupport(ILcdLayered)
must be
called.
aRootNode
- the root node of the hierarchical layer structurepublic void setLayeredToSupport(ILcdLayered aLayeredToSupport)
Sets the ILcdLayered
for which this support is created. This method may only be
called once, and this call should happen before using this class. When using the constructor
which takes an ILcdLayered
as a parameter, calling this method is not necessary
since this is already done by the constructor.
setLayeredToSupport
in interface ILcdTreeLayeredSupport
aLayeredToSupport
- the ILcdLayered that will delegate to this supportpublic ILcdLayerTreeNode getRootNode()
ILcdTreeLayered
Returns the root node of the tree structure.
getRootNode
in interface ILcdTreeLayered
public void addLayeredListener(ILcdLayeredListener aLayeredListener)
ILcdTreeLayered
ILcdLayeredListener
to be notified when layers are added,
removed or moved in the flat list.addLayeredListener
in interface ILcdLayered
addLayeredListener
in interface ILcdTreeLayered
aLayeredListener
- the listener that from now on will be notified of all changes to the
flat list.ILcdTreeLayered.removeLayeredListener(com.luciad.view.ILcdLayeredListener)
public void removeLayeredListener(ILcdLayeredListener aLayeredListener)
ILcdTreeLayered
ILcdLayeredListener
from receiving layered events for the
flat list.removeLayeredListener
in interface ILcdLayered
removeLayeredListener
in interface ILcdTreeLayered
aLayeredListener
- the listener that will no longer be notified of changes in the flat
list.ILcdTreeLayered.addLayeredListener(com.luciad.view.ILcdLayeredListener)
public int layerCount()
ILcdTreeLayered
Returns the number of layers in the flat list representation of the hierarchical layer structure. This does not include the root node.
layerCount
in interface ILcdLayered
layerCount
in interface ILcdTreeLayered
public Enumeration layers()
ILcdTreeLayered
Returns an Enumeration
of all the ILcdLayer
s currently in the flat
list representation of the hierarchical layer structure, starting from the bottom layer to the
top layer. This does not include the root node.
layers
in interface ILcdLayered
layers
in interface ILcdTreeLayered
Enumeration
of all the ILcdLayer
s currently in the flat
list, starting from the bottom layer to the top layer. Does not include the root node.public Enumeration layersBackwards()
ILcdTreeLayered
Returns an Enumeration
of all the ILcdLayer
s currently in the flat
list representation of the hierarchical layer structure, starting from the top layer to the
bottom layer. This does not include the root node.
layersBackwards
in interface ILcdLayered
layersBackwards
in interface ILcdTreeLayered
Enumeration
of all the ILcdLayer
s currently in the flat
list, starting from the top layer to the bottom layer. Does not include the root node.public ILcdLayer getLayer(int aIndex) throws ArrayIndexOutOfBoundsException
ILcdTreeLayered
Returns the ILcdLayer
with index aIndex
in the flat list
representation of the hierarchical layer structure.
getLayer
in interface ILcdLayered
getLayer
in interface ILcdTreeLayered
aIndex
- the position of the layer to retrieve in the flat list representation.ILcdLayer
with index aIndex
in the flat list
representationArrayIndexOutOfBoundsException
- if the given index is invalidpublic ILcdLayer layerOf(ILcdModel aModel) throws NoSuchElementException
ILcdTreeLayered
ILcdLayer
of the flat list that contains the given
ILcdModel
.layerOf
in interface ILcdLayered
layerOf
in interface ILcdTreeLayered
aModel
- the model to check for in the flat listILcdLayer
of the flat list that contains the given
ILcdModel
.NoSuchElementException
- if there is no layer containing the given modelpublic int indexOf(ILcdLayer aLayer) throws NoSuchElementException
ILcdTreeLayered
Returns the index of the given layer aLayer
in the flat list representation of
the hierarchical structure.
indexOf
in interface ILcdLayered
indexOf
in interface ILcdTreeLayered
aLayer
- the layer whose index to returnaLayer
in the flat list representationNoSuchElementException
- if aLayer
is not in the flat listpublic void moveLayerAt(int aIndex, ILcdLayer aLayer) throws NoSuchElementException, ArrayIndexOutOfBoundsException
Tries to move the layer aLayer
to index aIndex
, without affecting
the tree structure, in a best effort approach. This best effort approach can be seen as
follows:
aIndex
is searched.aLayer
and the layer at index
aIndex
is searchedaLayer
is
moved to the position of the subtree containing the layer at index aIndex
in the
child list of the common ancestor This also means that after calling this method the index of the layer aLayer
can be different from the requested index aIndex
.
moveLayerAt
in interface ILcdLayered
aIndex
- the desired index for the layer aLayer
aLayer
- the layer to move.NoSuchElementException
- if aLayer
is not in this ILcdLayered
.ArrayIndexOutOfBoundsException
- if aIndex
is not an index of one of the
layers of this ILcdLayered
.public void removeLayer(ILcdLayer aLayer)
ILcdTreeLayered
Removes a layer from both the hierarchical layer structure and the flat list representation.
When removing an ILcdLayerTreeNode
all of its children will also be removed. An
event will then be generated for every layer that has been removed (one for the node and one
for each of its child layers).
It is not possible to remove the root node
removeLayer
in interface ILcdLayered
removeLayer
in interface ILcdTreeLayered
aLayer
- the layer to remove. If the layer is not in the flat list, this method has no effect.public void removeAllLayers()
ILcdTreeLayered
Remove all the layers from the hierarchical layer structure and the flat list representation. An event will be fired for every layer that has been removed. This will not remove the root node.
removeAllLayers
in interface ILcdLayered
removeAllLayers
in interface ILcdTreeLayered
public boolean containsLayer(ILcdLayer aLayer)
ILcdTreeLayered
Returns whether the flat list representation of the hierarchical layer structure contains
the given layer. More formally, returns true
if and only if the flat list
representation contains at least one layer l
such that (aLayer==null ? l==null : aLayer.equals(l)).
Calling this method with the root node will return false
, since the
root node is not a part of the flat list representation.
containsLayer
in interface ILcdLayered
containsLayer
in interface ILcdTreeLayered
aLayer
- the layer to check whether it is in the flat list representationtrue
when the flat list representation contains the given layer,
false
otherwisepublic ILcdLayered getLayeredToSupport()
ILcdTreeLayeredSupport
Returns the ILcdLayered
for which this support is created.
getLayeredToSupport
in interface ILcdTreeLayeredSupport
ILcdLayered
for which this support is created.