public abstract class ALcdGXYAsynchronousPaintQueueManager extends Object
An abstract manager for automatically assigning ILcdGXYAsynchronousPaintQueue
instances to asynchronously painted layers which do not yet have a paint queue.
When assigning paint queues to layers, you can choose to share queues, which has the following advantages:
Sharing also has some limitations:
This manager offers some basic functionality and operations to find an acceptable compromise
between resources and requirements. To do this, it divides a view's layers into paint blocks
. A paint block is a contiguous set of layers with the same paint queue. This paint
queue is only null
for synchronously painted layers and asynchronous layers not
managed by this manager. The manager provides methods to split
, merge
and replace
paint blocks.
Furthermore, it automatically:
Implementing classes should implement the following methods:
createAsynchronousPaintQueue(java.util.List)
, a factory method for creating paint
queues for a given set of layersevaluateModifiedPaintBlocks(java.util.List<com.luciad.view.gxy.asynchronous.manager.ALcdGXYAsynchronousPaintQueueManager.PaintBlock>, com.luciad.view.gxy.ILcdGXYLayer)
, a method to further optimize the given paint blocks.
Typical behavior of this method will merge paint blocks to make use of advantages A1 and A2, and
split blocks to avoid limitation L2.This manager has some limitations:
ILcdGXYAsynchronousLayerWrapper
instances which are added to the view with a null
queue, and not affect any
ILcdGXYAsynchronousLayerWrapper
which is added with a non-null
queue.
Even when the queue of such a wrapper is replaced by a null
queue afterwards, it
will not be handled by this manager.ILcdGXYAsynchronousLayerWrapper
instances that are managed by an instance of this class.Warning: all methods of this class must only be called on the Event Dispatch Thread (EDT).
TLcdGXYAsynchronousPaintQueueManager
Modifier and Type | Class and Description |
---|---|
class |
ALcdGXYAsynchronousPaintQueueManager.PaintBlock
A contiguous set of layers sharing the same paint queue.
|
Modifier | Constructor and Description |
---|---|
protected |
ALcdGXYAsynchronousPaintQueueManager()
Creates a new
ALcdGXYAsynchronousPaintQueueManager which can manage the
ILcdGXYAsynchronousPaintQueue s of the ILcdGXYAsynchronousLayerWrapper
instances contained in a view. |
Modifier and Type | Method and Description |
---|---|
boolean |
canMergePaintBlocks(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlock,
ALcdGXYAsynchronousPaintQueueManager.PaintBlock aAdjacentPaintBlock)
Utility method to verify the prerequisites listed in the
mergePaintBlocks method. |
protected abstract ILcdGXYAsynchronousPaintQueue |
createAsynchronousPaintQueue(List<ILcdGXYAsynchronousLayerWrapper> aLayers)
Factory method to create a new
ILcdGXYAsynchronousPaintQueue that will be used
by aLayers . |
abstract void |
evaluateModifiedPaintBlocks(List<ALcdGXYAsynchronousPaintQueueManager.PaintBlock> aChangedPaintBlocks,
ILcdGXYLayer aLayer)
Method to inform the implementation that
aChangedPaintBlocks should be
re-evaluated. |
ILcdGXYView |
getGXYView()
Returns the view for which this
ALcdGXYAsynchronousPaintQueueManager is created. |
ALcdGXYAsynchronousPaintQueueManager.PaintBlock |
getPaintBlock(ILcdGXYLayer aLayer)
Returns the
PaintBlock containing aLayer . |
List<ALcdGXYAsynchronousPaintQueueManager.PaintBlock> |
getPaintBlocks()
Returns an ordered, unmodifiable
List of all PaintBlock instances. |
void |
mergePaintBlocksSFCT(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlockSFCT,
ALcdGXYAsynchronousPaintQueueManager.PaintBlock aAdjacentPaintBlock)
Merge the layers of
aPaintBlockSFCT and aAdjacentPaintBlock into
aPaintBlockSFCT . |
ALcdGXYAsynchronousPaintQueueManager.PaintBlock |
replacePaintBlockSFCT(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlock,
ILcdGXYAsynchronousPaintQueue aPaintQueue)
|
void |
setGXYView(ILcdGXYView aGXYView)
Set the view for which this
ALcdGXYAsynchronousPaintQueueManager should manage
the paint queues. |
ALcdGXYAsynchronousPaintQueueManager.PaintBlock |
splitPaintBlockSFCT(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlockToSplitSFCT,
int aFirstBlockSize)
Split
aPaintBlockToSplitSFCT in two separate PaintBlock instances:
the existing PaintBlock containing the first aFirstBlockSize original
ILcdGXYLayer s, and a new PaintBlock containing all remaining
ILcdGXYLayer s. |
protected ALcdGXYAsynchronousPaintQueueManager()
Creates a new ALcdGXYAsynchronousPaintQueueManager
which can manage the
ILcdGXYAsynchronousPaintQueue
s of the ILcdGXYAsynchronousLayerWrapper
instances contained in a view.
Call setGXYView
before using this
manager.
public void setGXYView(ILcdGXYView aGXYView)
Set the view for which this ALcdGXYAsynchronousPaintQueueManager
should manage
the paint queues.
For the initialization of this manager, it will create separate paint queues and
corresponding PaintBlock
s for every asynchronous layer with null
queue in the view followed by a call to the evaluateModifiedPaintBlocks
method allowing to merge / split
the created PaintBlock
s. Once this initialization is finished, it will react on
the events fired by the view and the layers.
When this manager is already managing a view, calling this method with a non-null view is
equivalent to calling this method successively with null
and
aGXYView
.
Calling this method with a null
view, will remove all attached listeners, and
clear the internal state of the manager. It will also reset all the paint queues of the layers
this manager is managing to null
. Therefore, if this method is called when the
layers are still contained in a view, it is necessary to set new paint queues to all
asynchronous layers (e.g. by creating a new ALcdGXYAsynchronousPaintQueueManager
for the view) before the layers are (re)painted.
Once this method is called on an ALcdGXYAsynchronousPaintQueueManager
that
particular manager can no longer be used until a new non-null view is set, since all internal
state is cleared. A possible use case of calling this method with a null view is if you want to
change the ALcdGXYAsynchronousPaintQueueManager
for a certain view.
aGXYView
- The view to manage, or null
to deactivate this manager.public List<ALcdGXYAsynchronousPaintQueueManager.PaintBlock> getPaintBlocks()
Returns an ordered, unmodifiable List
of all PaintBlock
instances.
The PaintBlock
at index 0 will contain the ILcdGXYLayer
which has
index 0 in the view.
List
of all PaintBlock
instancespublic ALcdGXYAsynchronousPaintQueueManager.PaintBlock getPaintBlock(ILcdGXYLayer aLayer)
Returns the PaintBlock
containing aLayer
.
aLayer
- the layer to search the PaintBlock for.PaintBlock
containing aLayer
.public abstract void evaluateModifiedPaintBlocks(List<ALcdGXYAsynchronousPaintQueueManager.PaintBlock> aChangedPaintBlocks, ILcdGXYLayer aLayer)
Method to inform the implementation that aChangedPaintBlocks
should be
re-evaluated. This method is called by the manager
aChangedPaintBlocks
.aChangedPaintBlocks
will
contain the PaintBlock
previously containing the layer. In case the paint block is
empty and removed, the adjacent PaintBlock
instances will be contained in
aChangedPaintBlocks
.aChangedPaintBlocks
will contain the adjacent
PaintBlock
s of the removed instance.x
to index y
,
aChangedPaintBlocks
will contain the same PaintBlock
s as when the
layer was removed from index x
and added to index y
, as described
above.ILcdLayerTreeNode
with child layers, this
method is only called once with the ILcdLayerTreeNode
as parameter. The List
of changed paint blocks will then include all relevant PaintBlock
s, based on the criteria
listed above.Typically, implementations of this method will call the split
and merge
methods of the manager to indicate which layers should share a paint queue.
An example implementation of this method is one which tries to minimize the number of paint
queues, by always merging adjacent paint blocks with a non-null
queue.
This method may be called from outside the manager as well, e.g. when the criteria to share a paint queue have been changed.
Note that this method will not be called when manual changes are applied to the paint blocks. For example, calling the merge, split and/or replace methods will not trigger this method.
aChangedPaintBlocks
- A List
containing all PaintBlock
s
remaining in this manager which must be re-evaluated. In case a
PaintBlock
is removed or inserted, this
List
will also include the neighbor
PaintBlock
instances. The paint queue of these PaintBlock
s will never be
null
. The PaintBlock
s in this
List
are ordered in the same way as in the getPaintBlocks()
List
aLayer
- The ILcdGXYLayer
in which the change, triggering the
call of this method, occurred, or null
when the change
was not triggered by a specific layer.protected abstract ILcdGXYAsynchronousPaintQueue createAsynchronousPaintQueue(List<ILcdGXYAsynchronousLayerWrapper> aLayers)
Factory method to create a new ILcdGXYAsynchronousPaintQueue
that will be used
by aLayers
. The returned ILcdGXYAsynchronousPaintQueue
must be a new
instance, and must not be in use by any existing PaintBlock
.
This method should always return a non-null
paint queue which may be used by
all layers in aLayers
. Either aLayers
will only contain one
ILcdGXYAsynchronousLayerWrapper
, or a set of ILcdGXYAsynchronousLayerWrapper
s
which were already part of one PaintBlock
with a non-null
paint
queue. Therefore this method should always be able to return a non-null
paint
queue.
The manager may wrap paint queues, so it may be that the returned
ILcdGXYAsynchronousPaintQueue
is not set directly as paint queue on the
layers.
The manager calls this method:
ILcdGXYAsynchronousPaintQueue
instances which only allocate resources (e.g. a
buffer and a separate Thread
) when needed, and not on creation.aLayers
- the ILcdGXYAsynchronousLayerWrapper
s that will use the returned
ILcdGXYAsynchronousPaintQueue
ILcdGXYAsynchronousPaintQueue
instance. Must not be
null
public final ALcdGXYAsynchronousPaintQueueManager.PaintBlock splitPaintBlockSFCT(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlockToSplitSFCT, int aFirstBlockSize)
Split aPaintBlockToSplitSFCT
in two separate PaintBlock
instances:
the existing PaintBlock
containing the first aFirstBlockSize
original
ILcdGXYLayer
s, and a new PaintBlock
containing all remaining
ILcdGXYLayer
s.
The newly created PaintBlock
will call the createAsynchronousPaintQueue
method to obtain
its paint queue..
aPaintBlockToSplitSFCT
- The PaintBlock
that will be split. Must have a
non-null
paint queue.aFirstBlockSize
- The size of the first block. Must be greater than 0 and smaller
then aPaintBlockToSplit.getLayers().size()
PaintBlock
instancepublic boolean canMergePaintBlocks(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlock, ALcdGXYAsynchronousPaintQueueManager.PaintBlock aAdjacentPaintBlock)
Utility method to verify the prerequisites listed in the mergePaintBlocks
method. Returns true
when the mergePaintBlocks method can be called with the same arguments, false
otherwise.
aPaintBlock
- a PaintBlock
aAdjacentPaintBlock
- an adjacent PaintBlock
true
when aPaintBlock
and aAdjacentPaintBlock
can be merged, false
otherwisemergePaintBlocksSFCT(com.luciad.view.gxy.asynchronous.manager.ALcdGXYAsynchronousPaintQueueManager.PaintBlock, com.luciad.view.gxy.asynchronous.manager.ALcdGXYAsynchronousPaintQueueManager.PaintBlock)
public final void mergePaintBlocksSFCT(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlockSFCT, ALcdGXYAsynchronousPaintQueueManager.PaintBlock aAdjacentPaintBlock)
Merge the layers of aPaintBlockSFCT
and aAdjacentPaintBlock
into
aPaintBlockSFCT
.
Merging two paint blocks is only possible if:
PaintBlock
instances are adjacentPaintBlock
instances have a non-null
paint queue.PaintBlock
s will not result in a paint queue which is used by
background and non-background layers (see ILcdGXYView#getNumberOfCachedBackgroundLayers()).The prerequisites of this method can be verified by using the canMergePaintBlocks
method. It is up to the user of this method to verify those prerequisites
before calling this method.
aPaintBlockSFCT
- The PaintBlock
to which all layers of
aAdjacentPaintBlock
will be added.aAdjacentPaintBlock
- an adjacent PaintBlock
canMergePaintBlocks(com.luciad.view.gxy.asynchronous.manager.ALcdGXYAsynchronousPaintQueueManager.PaintBlock,
com.luciad.view.gxy.asynchronous.manager.ALcdGXYAsynchronousPaintQueueManager.PaintBlock)
public final ALcdGXYAsynchronousPaintQueueManager.PaintBlock replacePaintBlockSFCT(ALcdGXYAsynchronousPaintQueueManager.PaintBlock aPaintBlock, ILcdGXYAsynchronousPaintQueue aPaintQueue)
Replace aPaintBlock
by a new PaintBlock
with
aPaintQueue
as paint queue.
It is not possible to replace a null
queue with a non-null
queue.
When the paint queue of aPaintBlock
is not null
and
aPaintQueue
is null
, the createAsynchronousPaintQueue
method will be used to create a new paint queue.
This method will have no effect when aPaintQueue
is the paint queue of
aPaintBlock
, and just return aPaintBlock
.
aPaintBlock
- The PaintBlock
to replace.aPaintQueue
- The ILcdGXYAsynchronousPaintQueue
for the new
PaintBlock
. Must not be used by any other
PaintBlock
, and can only be null
if the paint
queue of aPaintBlock
is null
.PaintBlock
, or aPaintBlock
in case
aPaintQueue
is already the paint queue of aPaintBlock
public ILcdGXYView getGXYView()
ALcdGXYAsynchronousPaintQueueManager
is created.ALcdGXYAsynchronousPaintQueueManager
is created.