public class TLcdGXYDensityLayer extends Object implements ILcdGXYLayer
ILcdGXYLayer
is a layer wrapper that paints the wrapped
layer as color-coded densities. This means that elements are painted with
colors that vary depending on how many elements overlap. For instance,
regions where few elements overlap can be painted green, and regions
where many elements overlap can be painted red.
The colors are determined by an 8-bits or a 16-bits
IndexColorModel
, with color 0 representing no overlapping
elements, color 1 representing a single overlapping element, and so on,
up to the the last color representing the corresponding number of overlapping
elements (or more).
The class TLcdJetIndexColorModelFactory
provides a convenient way
to create color models, with colors that are interpolated between a few
given basic colors.
Sample code for creating a typical density layer:
ILcdGXYLayer layer = ...
// Set up a color model factory for creating a range of jet colors.
TLcdJetIndexColorModelFactory factory = new TLcdJetIndexColorModelFactory();
factory.setBasicColor( 0, new Color(0, 0, 0, 0));
factory.setBasicColor( 1, Color.blue);
factory.setBasicColor( 10, Color.cyan);
factory.setBasicColor( 20, Color.yellow);
factory.setBasicColor( 30, Color.orange);
factory.setBasicColor(255, Color.red);
// Create the color model.
IndexColorModel color_model = (IndexColorModel)factory.createColorModel();
// Create the density layer that wraps the original layer.
TLcdGXYDensityLayer density_layer =
new TLcdGXYDensityLayer(layer, color_model);
Note that, alternatively, the color model can be created as an equivalent
TLcdIndexColorModel
, whose TLcdColorMap
can conveniently be
edited with the corresponding TLcdColorMapCustomizer
.
TLcdColorMap color_map =
new TLcdColorMap(new TLcdInterval(1, 255),
new double[] {
1,
10,
20,
30,
255
},
new Color[] {
Color.blue,
Color.cyan,
Color.yellow,
Color.orange,
Color.red
});
IndexColorModel color_model = new TLcdIndexColorModel(8, color_map);
.....
Constructor and Description |
---|
TLcdGXYDensityLayer(ILcdGXYLayer aGXYLayer,
IndexColorModel aIndexColorModel)
Creates a new TLcdGXYDensityLayer for a given layer and with a given
color map.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Registers the given
PropertyChangeListener to be notified when this object's
properties change. |
void |
addSelectionListener(ILcdSelectionListener aSelectionListener)
Adds a listener to this selection.
|
int |
applyOnInteract(ILcdFunction aFunction,
Rectangle aBounds,
boolean aStrictInteract,
ILcdGXYView aGXYView)
Applies the function to (at the least) all objects that are contained (partially or completely) in the bounds of the view.
|
void |
clearSelection(int aDispatchEventMode)
Deselect all the Objects in this
ILcdLayer , i.e., the selection of
this ILcdLayer is empty afterward. |
void |
fireCollectedSelectionChanges()
Fires a
TLcdSelectionChangedEvent that contains all the
selection changes appended by successively calling
selectObject(Object, boolean, ILcdFireEventMode.FIRE_LATER) . |
ILcdBounds |
getBounds(int aMode,
ILcdGXYView aGXYView)
Returns the view bounds of this
ILcdGXYLayer content,
the bounds of all the drawings (for the supplied mode) that represent the Objects contained in
the ILcdModel of this ILcdGXYLayer . |
ILcdGXYEditor |
getGXYEditor(Object aObject)
Returns the editor to use to modify the object via a view.
|
ILcdGXYLabelPainter |
getGXYLabelPainter(Object aObject)
Returns the label painter to use to paint the objects label in a view.
|
ILcdGXYLayer |
getGXYLayer()
Returns the wrapped layer for which densities are painted.
|
ILcdGXYPainter |
getGXYPainter(Object aObject)
Returns the painter to use to render the object in a view.
|
ILcdGXYPen |
getGXYPen()
Returns the pen to use when performing basic painting operations for objects in this layers model.
|
ILcdIcon |
getIcon()
Returns a visual indication of the contents of this layer.
|
IndexColorModel |
getIndexColorModel()
Returns the color map for the element densities.
|
String |
getLabel()
A short textual representation of this
ILcdLayer . |
ILcdInterval |
getLabelScaleRange()
Returns the toolkit scale range for which to display labels for elements of the model.
|
ILcdModel |
getModel() |
Class |
getModelXYWorldTransfoClass()
Returns the transformation class that to use to transform points and bounds from model space to world space and
back.
|
ILcdInterval |
getScaleRange()
Returns the toolkit scale range for which to display elements of the model.
|
int |
getSelectionCount()
Returns the number of objects in this selection.
|
boolean |
isEditable()
Returns whether the layer allows editing the content that it visualizes.
|
boolean |
isEditableSupported()
Returns
true if the layer supports editing its objects. |
boolean |
isLabeled()
Returns whether objects should be represented as text.
|
boolean |
isLabeledSupported()
Returns whether this layer supports representing objects as text.
|
boolean |
isSelectable()
Returns whether the layer's objects can be selected, for example, by clicking on them.
|
boolean |
isSelectableSupported()
Returns
true if this layer supports selecting objects, false otherwise. |
boolean |
isSelected(Object aObject)
Checks whether the given
Object is currently in the set of
selected objects. |
boolean |
isVisible()
Returns whether or not the layer's content is painted.
|
void |
paint(Graphics aGraphics,
int aMode,
ILcdGXYView aGXYView)
Paints the combined representation of the layer's objects for a view, taking into account the mode.
|
void |
removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
De-registers the given
PropertyChangeListener from receiving property change events
for this object. |
void |
removeSelectionListener(ILcdSelectionListener aSelectionListener)
Removes an
ILcdSelectionListener from this ILcdSelection . |
Enumeration |
selectedObjects()
Returns the objects in this selection.
|
void |
selectObject(Object aObject,
boolean aSelection,
int aDispatchEventMode)
Changes the selection state of any element contained in the
ILcdModel this ILcdLayer refers to. |
void |
setEditable(boolean aEditable)
Sets whether the layer should allow editing the content that it visualizes.
|
void |
setIcon(ILcdIcon aIcon)
Sets a visual indication of the contents of this layer.
|
void |
setIndexColorModel(IndexColorModel aIndexColorModel)
Sets the color map for the element densities.
|
void |
setLabel(String aLabel)
Sets the textual representation of this
ILcdLayer . |
void |
setLabeled(boolean aLabeled)
Sets whether objects should be represented as text.
|
void |
setSelectable(boolean aSelectable)
Sets the Selectable property of this
ILcdLayer . |
void |
setVisible(boolean aVisible)
Sets whether or not the layer's content is painted.
|
void |
stopPainting()
Inform the layer that it should terminate the current paint operation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getLabelMapScaleRange, getMapScaleRange
getSelectedObjects
public TLcdGXYDensityLayer(ILcdGXYLayer aGXYLayer, IndexColorModel aIndexColorModel)
aGXYLayer
- the layer that is wrapped.aIndexColorModel
- the density colors to be used.public ILcdGXYLayer getGXYLayer()
public IndexColorModel getIndexColorModel()
public void setIndexColorModel(IndexColorModel aIndexColorModel)
public void paint(Graphics aGraphics, int aMode, ILcdGXYView aGXYView)
ILcdGXYLayer
The mode indicates what objects of the model should be taken into account and what representation should be provided. The objects to be taken into account shall be one of:
Note that the combined representation may contain less than the representation of all objects that were taken into account, as some objects may be disregarded for various reasons (filters, scale, ... ). When the views scale is outside the scale range (BODIES or HANDLES mode) or the label scale range (LABELS mode) nothing shall be painted.
The representations provided shall be one or more of:
The mode supplied shall be a bitwise or combination of a constant of the first group and one or more of the
second group. When painting in BODIES or HANDLES mode, painting of an object shall be delegated to the
painter
for that object, when the LABELS mode is passed, painting shall be delegated
to the labelpainter
for that object.
The view is passed to provide contextual information: some of the objects may have a different representation depending on the view, or depending on a property of the view, for example, the scale of the view.
The combined representation of the objects has to be painted on the Graphics supplied, as these may be different from the Graphics provided by the view (due to double buffering, for example).
When stopPainting
is called, the current painting operation should be aborted.
paint
in interface ILcdGXYLayer
aGraphics
- the Graphics to paint on.aMode
- indicates what should be painted and how it should be painted.aGXYView
- the view to paint for.ILcdGXYLayer.getGXYPainter(Object)
,
ILcdGXYLayer.getGXYLabelPainter(Object)
,
ILcdGXYLayer.getScaleRange()
,
ILcdGXYLayer.getLabelScaleRange()
,
ILcdGXYLayer.stopPainting()
public int applyOnInteract(ILcdFunction aFunction, Rectangle aBounds, boolean aStrictInteract, ILcdGXYView aGXYView)
ILcdGXYLayer
The function shall be applied successively to all objects in the bounds as long as the function returns
true
for an object. This allows developers to indicate a stop condition. Note that the order in
which the objects are passed to the function is not specified.
When strict interaction is required, only objects whose representation lies within the given bounds, completely or partially, are candidates to be passed to the function. An object whose representation does not interact with the bounds should not be passed to the function. Applying non strict interaction can be useful to avoid heavy computations to determine whether an objects representation lies within the bounds.
This method behaves similar to the paint method, and as such is allowed to omit small or invisible objects for performance reasons.
applyOnInteract
in interface ILcdGXYLayer
aFunction
- the function to apply. When the function returns false, no more objects should be passed to
the function.aBounds
- all objects who lie partially or completely in this area in the view are candidates to be passed to
the function.aStrictInteract
- if true
, the ILcdFunction
shall be applied only to the objects
interacting with the given bounds. When false is passed, other objects may be taken into account too.
When applying the function to an object consumes less time than checking whether an objects representation
interacts with the bounds, non-strict interaction is generally faster.aGXYView
- the view in whose bounds the objects representations should be in order to be passed to the
function.public ILcdBounds getBounds(int aMode, ILcdGXYView aGXYView) throws TLcdNoBoundsException
ILcdGXYLayer
ILcdGXYLayer
content,
the bounds of all the drawings (for the supplied mode) that represent the Objects contained in
the ILcdModel
of this ILcdGXYLayer
.
For this operation, this ILcdGXYLayer
is to be considered
as part of aGXYView
.
Outside of the layers bounds no interaction with any object of the layer via its representation is possible. Note that these bounds do not necessarily encompass the representation of all objects in the model, only the objects for which there is a representation in the view.
getBounds
in interface ILcdGXYLayer
aMode
- a bitwise combination of ALL or SELECTION and one or more of BODIES and HANDLES.
The ILcdGXYLayer.LABELS
mode is not supported.aGXYView
- the view in which the layer could be placed. This enables taking into account the views settings,
for example the scale.TLcdNoBoundsException
- if the layer doesn't have any valid bounds,
for example when none of the elements have a representation for the views current settings.public void stopPainting()
ILcdGXYLayer
Thread
and needs to be
stopped in a safe state from another Thread.stopPainting
in interface ILcdGXYLayer
paint
public ILcdInterval getScaleRange()
ILcdGXYLayer
view.getScale()
< getScaleRange().getMin()
or
view.getScale()
>= getScaleRange().getMax()
.
This does not imply that all objects in the model should be painted when the scale is inside this range as
other restrictions may apply. For example, a layer may have a filter which defines which objects should be painted.
For most use cases, we recommended using the unitless map scale range
instead.
This property is mutually exclusive with the map scale range:
only one of them has a non-null
value.getScaleRange
in interface ILcdGXYLayer
ILcdInterval
containing the minimum and maximum value of view scales for which objects
should be rendered, excluding the maximum. null
if the scale constraints are determined by ILcdGXYLayer.getMapScaleRange()
.
The scales are expressed in toolkit pixels/world unit.ILcdGXYLayer.getMapScaleRange()
public ILcdInterval getLabelScaleRange()
ILcdGXYLayer
view.getScale()
< getLabelScaleRange().getMin()
or
view.getScale()
>= getLabelScaleRange().getMax()
.
This does not imply that labels for all objects in the model should be painted when the scale is inside this range
as other restrictions may apply. For example, a layer may decide not to paint any labels for objects whose body is
not painted.
For most use cases, we recommended using the unitless map scale range
instead.
This property is mutually exclusive with the label map scale range:
only one of them has a non-null
value.getLabelScaleRange
in interface ILcdGXYLayer
ILcdInterval
containing the minimum and maximum value of view scales for which
labels should be rendered, excluding the maximum.
null
if the scale constraints are determined by ILcdGXYLayer.getLabelMapScaleRange()
The scales are expressed in toolkit pixels/world unit.ILcdGXYLayer.getLabelMapScaleRange()
public ILcdGXYPainter getGXYPainter(Object aObject)
ILcdGXYLayer
setObject
in ILcdGXYPainter.getGXYPainter
in interface ILcdGXYLayer
aObject
- the object to find a painter for.public ILcdGXYEditor getGXYEditor(Object aObject)
ILcdGXYLayer
setObject
in ILcdGXYEditor.getGXYEditor
in interface ILcdGXYLayer
aObject
- the object to find an editor for.public ILcdGXYLabelPainter getGXYLabelPainter(Object aObject)
ILcdGXYLayer
setObject
in ILcdGXYLabelPainter.getGXYLabelPainter
in interface ILcdGXYLayer
aObject
- the object to find a label painter for.public ILcdGXYPen getGXYPen()
ILcdGXYLayer
getGXYPen
in interface ILcdGXYLayer
public ILcdIcon getIcon()
ILcdLayer
public Class getModelXYWorldTransfoClass()
ILcdGXYLayer
getModelXYWorldTransfoClass
in interface ILcdGXYLayer
public boolean isLabeledSupported()
ILcdGXYLayer
isLabeledSupported
in interface ILcdGXYLayer
public boolean isLabeled()
ILcdGXYLayer
ILcdGXYLayer.isLabeledSupported()
returns false.isLabeled
in interface ILcdGXYLayer
ILcdGXYLayer.isLabeledSupported()
public void setLabeled(boolean aLabeled)
ILcdGXYLayer
ILcdGXYLayer.isLabeledSupported()
returns false.setLabeled
in interface ILcdGXYLayer
aLabeled
- true to have a textual representation of the objects in the model, false to have no such
representation.public void setIcon(ILcdIcon aIcon)
ILcdLayer
setIcon
in interface ILcdLayer
aIcon
- a visual indication of the contents of this layer.ILcdLayer.getIcon()
public ILcdModel getModel()
public String getLabel()
ILcdLayer
ILcdLayer
.public void setLabel(String aLabel)
ILcdLayer
ILcdLayer
.public boolean isVisible()
ILcdLayer
isVisible
in interface ILcdLayer
true
if the layer is visible, false
otherwise.ILcdLayer.setVisible(boolean)
public void setVisible(boolean aVisible)
ILcdLayer
setVisible
in interface ILcdLayer
aVisible
- true
if the layer should be visible, false
otherwise.ILcdLayer.isVisible()
public boolean isSelectableSupported()
ILcdLayer
true
if this layer supports selecting objects, false
otherwise.isSelectableSupported
in interface ILcdLayer
true
if this ILcdLayer
supports the
selectable property, false
otherwise. I.e. if this
ILcdLayer
can be put or not in a selectable mode.ILcdLayer.setSelectable(boolean)
,
ILcdLayer.selectObject(java.lang.Object, boolean, int)
public boolean isSelectable()
ILcdLayer
isSelectable
in interface ILcdLayer
true
if the layer allows selection, false
otherwise.ILcdSelection
,
ILcdLayer.setSelectable(boolean)
public void setSelectable(boolean aSelectable)
ILcdLayer
ILcdLayer
.
Check isSelectableSupported
to see if the layer supports selection.setSelectable
in interface ILcdLayer
aSelectable
- true
if the layer allows selection, false
otherwise.ILcdLayer.isSelectable()
,
ILcdLayer.isSelectableSupported()
public boolean isEditableSupported()
ILcdLayer
true
if the layer supports editing its objects.isEditableSupported
in interface ILcdLayer
true
if the layer supports editing, false
otherwise.ILcdLayer.setEditable(boolean)
public boolean isEditable()
ILcdLayer
isEditable
in interface ILcdLayer
true
if this ILcdLayer
is editable,
false
otherwiseILcdLayer.setEditable(boolean)
public void setEditable(boolean aEditable)
ILcdLayer
isEditableSupported
to see if the layer supports editing.setEditable
in interface ILcdLayer
aEditable
- true if the layer content can be editedILcdLayer.isEditableSupported()
,
ILcdLayer.isEditable()
public void selectObject(Object aObject, boolean aSelection, int aDispatchEventMode)
ILcdLayer
ILcdModel
this ILcdLayer
refers to. This method
shall have an effect only if isSelectableSupported and isSelectable return
true.selectObject
in interface ILcdLayer
aObject
- the Object
to select or deselect. The object should be in the model
of this layer. The implementation of this method is not responsible for checking this.aSelection
- the selection state, true
to select, false
to deselect.aDispatchEventMode
- shall be one among ILcdFireEventMode.FIRE_NOW
,
ILcdFireEventMode.FIRE_LATER
, ILcdFireEventMode.NO_EVENT
ILcdFireEventMode
public void fireCollectedSelectionChanges()
ILcdLayer
TLcdSelectionChangedEvent
that contains all the
selection changes appended by successively calling
selectObject(Object, boolean, ILcdFireEventMode.FIRE_LATER)
.fireCollectedSelectionChanges
in interface ILcdLayer
public void clearSelection(int aDispatchEventMode)
ILcdLayer
ILcdLayer
, i.e., the selection of
this ILcdLayer
is empty afterward.clearSelection
in interface ILcdLayer
aDispatchEventMode
- shall be one among ILcdFireEventMode.FIRE_NOW
,
ILcdFireEventMode.FIRE_LATER
, ILcdFireEventMode.NO_EVENT
ILcdFireEventMode
public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILcdPropertyChangeSource
Registers the given PropertyChangeListener
to be notified when this object's
properties change.
In case you need to register a listener which keeps a reference to an object with a shorter life-time than this change source,
you can use a ALcdWeakPropertyChangeListener
instance as property change listener.
addPropertyChangeListener
in interface ILcdPropertyChangeSource
aPropertyChangeListener
- The listener to be notifiedALcdWeakPropertyChangeListener
,
ILcdPropertyChangeSource.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILcdPropertyChangeSource
De-registers the given PropertyChangeListener
from receiving property change events
for this object.
If the listener was added more than once, it will be notified one less time after being
removed.
If the listener is null
, or was never added, no exception is thrown and no action is taken.
removePropertyChangeListener
in interface ILcdPropertyChangeSource
aPropertyChangeListener
- the listener that should no longer be notified of changes of
this object's propertiesILcdPropertyChangeSource.addPropertyChangeListener(java.beans.PropertyChangeListener)
public int getSelectionCount()
ILcdSelection
getSelectionCount
in interface ILcdSelection<Object>
ILcdSelection
.public Enumeration selectedObjects()
ILcdSelection
selectedObjects
in interface ILcdSelection<Object>
ILcdSelection
.public boolean isSelected(Object aObject)
ILcdSelection
Object
is currently in the set of
selected objects.isSelected
in interface ILcdSelection<Object>
aObject
- the Object
to be checked.true
if the Object
is in this ILcdSelection
,
false otherwise.public void addSelectionListener(ILcdSelectionListener aSelectionListener)
ILcdSelection
ILcdSelection
,
you can use a ALcdWeakSelectionListener
instance as selection listener.addSelectionListener
in interface ILcdSelection<Object>
aSelectionListener
- the ILcdSelectionListener
to be added.public void removeSelectionListener(ILcdSelectionListener aSelectionListener)
ILcdSelection
ILcdSelectionListener
from this ILcdSelection
.removeSelectionListener
in interface ILcdSelection<Object>
aSelectionListener
- the ILcdSelectionListener
to be removed.