Class TLcdGXYDensityLayer
- All Implemented Interfaces:
ILcdPropertyChangeSource,ILcdSelection<Object>,ILcdGXYLayer,ILcdLayer,Serializable
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);
.....
- Since:
- 8.0
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTLcdGXYDensityLayer(ILcdGXYLayer aGXYLayer, IndexColorModel aIndexColorModel) Creates a new TLcdGXYDensityLayer for a given layer and with a given color map. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Registers the givenPropertyChangeListenerto be notified when this object's properties change.voidaddSelectionListener(ILcdSelectionListener aSelectionListener) Adds a listener to this selection.intapplyOnInteract(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.voidclearSelection(int aDispatchEventMode) Deselect all the Objects in thisILcdLayer, i.e., the selection of thisILcdLayeris empty afterward.voidFires aTLcdSelectionChangedEventthat contains all the selection changes appended by successively callingselectObject(Object, boolean, ILcdFireEventMode.FIRE_LATER).getBounds(int aMode, ILcdGXYView aGXYView) Returns the view bounds of thisILcdGXYLayercontent, the bounds of all the drawings (for the supplied mode) that represent the Objects contained in theILcdModelof thisILcdGXYLayer.getGXYEditor(Object aObject) Returns the editor to use to modify the object via a view.getGXYLabelPainter(Object aObject) Returns the label painter to use to paint the objects label in a view.Returns the wrapped layer for which densities are painted.getGXYPainter(Object aObject) Returns the painter to use to render the object in a view.Returns the pen to use when performing basic painting operations for objects in this layers model.getIcon()Returns a visual indication of the contents of this layer.Returns the color map for the element densities.getLabel()A short textual representation of thisILcdLayer.Returns the toolkit scale range for which to display labels for elements of the model.getModel()Returns the transformation class that to use to transform points and bounds from model space to world space and back.Returns the toolkit scale range for which to display elements of the model.intReturns the number of objects in this selection.booleanReturns whether the layer allows editing the content that it visualizes.booleanReturnstrueif the layer supports editing its objects.booleanReturns whether objects should be represented as text.booleanReturns whether this layer supports representing objects as text.booleanReturns whether the layer's objects can be selected, for example, by clicking on them.booleanReturnstrueif this layer supports selecting objects,falseotherwise.booleanisSelected(Object aObject) Checks whether the givenObjectis currently in the set of selected objects.booleanReturns whether or not the layer's content is painted.voidpaint(Graphics aGraphics, int aMode, ILcdGXYView aGXYView) Paints the combined representation of the layer's objects for a view, taking into account the mode.voidremovePropertyChangeListener(PropertyChangeListener aPropertyChangeListener) De-registers the givenPropertyChangeListenerfrom receiving property change events for this object.voidremoveSelectionListener(ILcdSelectionListener aSelectionListener) Removes anILcdSelectionListenerfrom thisILcdSelection.Returns the objects in this selection.voidselectObject(Object aObject, boolean aSelection, int aDispatchEventMode) Changes the selection state of any element contained in theILcdModelthisILcdLayerrefers to.voidsetEditable(boolean aEditable) Sets whether the layer should allow editing the content that it visualizes.voidSets a visual indication of the contents of this layer.voidsetIndexColorModel(IndexColorModel aIndexColorModel) Sets the color map for the element densities.voidSets the textual representation of thisILcdLayer.voidsetLabeled(boolean aLabeled) Sets whether objects should be represented as text.voidsetSelectable(boolean aSelectable) Sets the Selectable property of thisILcdLayer.voidsetVisible(boolean aVisible) Sets whether or not the layer's content is painted.voidInform the layer that it should terminate the current paint operation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.view.gxy.ILcdGXYLayer
getLabelMapScaleRange, getMapScaleRangeMethods inherited from interface com.luciad.util.ILcdSelection
getSelectedObjects
-
Constructor Details
-
TLcdGXYDensityLayer
Creates a new TLcdGXYDensityLayer for a given layer and with a given color map.- Parameters:
aGXYLayer- the layer that is wrapped.aIndexColorModel- the density colors to be used.
-
-
Method Details
-
getGXYLayer
Returns the wrapped layer for which densities are painted. -
getIndexColorModel
Returns the color map for the element densities. -
setIndexColorModel
Sets the color map for the element densities. -
paint
Description copied from interface:ILcdGXYLayerPaints the combined representation of the layer's objects for a view, taking into account the mode.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:
- ALL: all the objects in the layer's model, or
- SELECTION: all the objects in the layer's selection.
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:
- BODIES: the combination of geometric representations of the objects,
- HANDLES: the handles for the objects. These are the parts of the objects representation on which user interaction can be applied. For example, for a circle this can be the center point, allowing to move the circle.
- LABELS: the combination of the textual representations of the objects.
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
painterfor that object, when the LABELS mode is passed, painting shall be delegated to thelabelpainterfor 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
stopPaintingis called, the current painting operation should be aborted.- Specified by:
paintin interfaceILcdGXYLayer- Parameters:
aGraphics- the Graphics to paint on.aMode- indicates what should be painted and how it should be painted.aGXYView- the view to paint for.- See Also:
-
applyOnInteract
public int applyOnInteract(ILcdFunction aFunction, Rectangle aBounds, boolean aStrictInteract, ILcdGXYView aGXYView) Description copied from interface:ILcdGXYLayerApplies the function to (at the least) all objects that are contained (partially or completely) in the bounds of the view.The function shall be applied successively to all objects in the bounds as long as the function returns
truefor 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.
- Specified by:
applyOnInteractin interfaceILcdGXYLayer- Parameters:
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- iftrue, theILcdFunctionshall 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.- Returns:
- the number of objects the function was applied on.
-
getBounds
Description copied from interface:ILcdGXYLayerReturns the view bounds of thisILcdGXYLayercontent, the bounds of all the drawings (for the supplied mode) that represent the Objects contained in theILcdModelof thisILcdGXYLayer. For this operation, thisILcdGXYLayeris to be considered as part ofaGXYView.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.
- Specified by:
getBoundsin interfaceILcdGXYLayer- Parameters:
aMode- a bitwise combination of ALL or SELECTION and one or more of BODIES and HANDLES. TheILcdGXYLayer.LABELSmode 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.- Returns:
- a bounds (in view coordinates, pixels) that encompasses the representation of all objects that are rendered in a view.
- Throws:
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.
-
stopPainting
public void stopPainting()Description copied from interface:ILcdGXYLayerInform the layer that it should terminate the current paint operation. This method can be useful when the paint method is executed in a specificThreadand needs to be stopped in a safe state from another Thread.- Specified by:
stopPaintingin interfaceILcdGXYLayer- See Also:
-
getScaleRange
Description copied from interface:ILcdGXYLayerReturns the toolkit scale range for which to display elements of the model. In other words, the paint method will not render any objects in a view when:
view.getScale()<getScaleRange().getMin()orview.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 theunitless map scale rangeinstead. This property is mutually exclusive with the map scale range: only one of them has a non-nullvalue.- Specified by:
getScaleRangein interfaceILcdGXYLayer- Returns:
- an
ILcdIntervalcontaining the minimum and maximum value of view scales for which objects should be rendered, excluding the maximum.nullif the scale constraints are determined byILcdGXYLayer.getMapScaleRange(). The scales are expressed in toolkit pixels/world unit. - See Also:
-
getLabelScaleRange
Description copied from interface:ILcdGXYLayerReturns the toolkit scale range for which to display labels for elements of the model. In other words, the paint method will not render any labels for objects in a view when:
view.getScale()<getLabelScaleRange().getMin()orview.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 theunitless map scale rangeinstead. This property is mutually exclusive with the label map scale range: only one of them has a non-nullvalue.- Specified by:
getLabelScaleRangein interfaceILcdGXYLayer- Returns:
- an
ILcdIntervalcontaining the minimum and maximum value of view scales for which labels should be rendered, excluding the maximum.nullif the scale constraints are determined byILcdGXYLayer.getLabelMapScaleRange()The scales are expressed in toolkit pixels/world unit. - See Also:
-
getGXYPainter
Description copied from interface:ILcdGXYLayerReturns the painter to use to render the object in a view. If no painter is available, the object has no representation. When a painter is available, the object shall be assigned to the painter before using the painter, seesetObjectin ILcdGXYPainter.- Specified by:
getGXYPainterin interfaceILcdGXYLayer- Parameters:
aObject- the object to find a painter for.- Returns:
- the painter to use to render the object in a view. When null is returned, the object has no representation in the view, as part of this layer.
-
getGXYEditor
Description copied from interface:ILcdGXYLayerReturns the editor to use to modify the object via a view. If no editor is available, the object cannot be edited via interaction through a view. When an editor is available, the object shall be assigned to the editor before editing, usingsetObjectin ILcdGXYEditor.- Specified by:
getGXYEditorin interfaceILcdGXYLayer- Parameters:
aObject- the object to find an editor for.- Returns:
- the editor to use to modify the object via a view. When null is returned, the object cannot be edited via the view.
-
getGXYLabelPainter
Description copied from interface:ILcdGXYLayerReturns the label painter to use to paint the objects label in a view. If no label painter is available, the object does not have a label. When a label painter is available, the object shall be assigned to the label painter before using the label painter, seesetObjectin ILcdGXYLabelPainter.- Specified by:
getGXYLabelPainterin interfaceILcdGXYLayer- Parameters:
aObject- the object to find a label painter for.- Returns:
- the label painter to use to render the objects label in a view. When null is returned, the object does not have a label in the view, as part of this layer.
-
getGXYPen
Description copied from interface:ILcdGXYLayerReturns the pen to use when performing basic painting operations for objects in this layers model.- Specified by:
getGXYPenin interfaceILcdGXYLayer- Returns:
- the pen to use when performing basic painting operations for objects in this layers model.
-
getIcon
Description copied from interface:ILcdLayerReturns a visual indication of the contents of this layer. For example, for a grid layer, an icon containing a grid could be used. -
getModelXYWorldTransfoClass
Description copied from interface:ILcdGXYLayerReturns the transformation class that to use to transform points and bounds from model space to world space and back. This class has to be conform with the reference of the model of this layer and the reference of the view this layer is part of.- Specified by:
getModelXYWorldTransfoClassin interfaceILcdGXYLayer- Returns:
- the transformation class that to use to transform points and bounds from model space to world space and back.
-
isLabeledSupported
public boolean isLabeledSupported()Description copied from interface:ILcdGXYLayerReturns whether this layer supports representing objects as text. If not, no effort should be made trying to represent the objects with labels.- Specified by:
isLabeledSupportedin interfaceILcdGXYLayer- Returns:
- whether this layer supports representing objects as text.
-
isLabeled
public boolean isLabeled()Description copied from interface:ILcdGXYLayerReturns whether objects should be represented as text. Note that this property shall not be taken into account whenILcdGXYLayer.isLabeledSupported()returns false.- Specified by:
isLabeledin interfaceILcdGXYLayer- Returns:
- whether objects should be represented as text.
- See Also:
-
setLabeled
public void setLabeled(boolean aLabeled) Description copied from interface:ILcdGXYLayerSets whether objects should be represented as text. The value set for this property shall have no effect as long asILcdGXYLayer.isLabeledSupported()returns false.- Specified by:
setLabeledin interfaceILcdGXYLayer- Parameters:
aLabeled- true to have a textual representation of the objects in the model, false to have no such representation.
-
setIcon
Description copied from interface:ILcdLayerSets a visual indication of the contents of this layer. -
getModel
-
getLabel
Description copied from interface:ILcdLayerA short textual representation of thisILcdLayer. -
setLabel
Description copied from interface:ILcdLayerSets the textual representation of thisILcdLayer. -
isVisible
public boolean isVisible()Description copied from interface:ILcdLayerReturns whether or not the layer's content is painted. -
setVisible
public void setVisible(boolean aVisible) Description copied from interface:ILcdLayerSets whether or not the layer's content is painted.- Specified by:
setVisiblein interfaceILcdLayer- Parameters:
aVisible-trueif the layer should be visible,falseotherwise.- See Also:
-
isSelectableSupported
public boolean isSelectableSupported()Description copied from interface:ILcdLayerReturnstrueif this layer supports selecting objects,falseotherwise.- Specified by:
isSelectableSupportedin interfaceILcdLayer- Returns:
trueif thisILcdLayersupports the selectable property,falseotherwise. I.e. if thisILcdLayercan be put or not in a selectable mode.- See Also:
-
isSelectable
public boolean isSelectable()Description copied from interface:ILcdLayerReturns whether the layer's objects can be selected, for example, by clicking on them.- Specified by:
isSelectablein interfaceILcdLayer- Returns:
trueif the layer allows selection,falseotherwise.- See Also:
-
setSelectable
public void setSelectable(boolean aSelectable) Description copied from interface:ILcdLayerSets the Selectable property of thisILcdLayer. CheckisSelectableSupportedto see if the layer supports selection.- Specified by:
setSelectablein interfaceILcdLayer- Parameters:
aSelectable-trueif the layer allows selection,falseotherwise.- See Also:
-
isEditableSupported
public boolean isEditableSupported()Description copied from interface:ILcdLayerReturnstrueif the layer supports editing its objects.- Specified by:
isEditableSupportedin interfaceILcdLayer- Returns:
trueif the layer supports editing,falseotherwise.- See Also:
-
isEditable
public boolean isEditable()Description copied from interface:ILcdLayerReturns whether the layer allows editing the content that it visualizes.- Specified by:
isEditablein interfaceILcdLayer- Returns:
trueif thisILcdLayeris editable,falseotherwise- See Also:
-
setEditable
public void setEditable(boolean aEditable) Description copied from interface:ILcdLayerSets whether the layer should allow editing the content that it visualizes. CheckisEditableSupportedto see if the layer supports editing.- Specified by:
setEditablein interfaceILcdLayer- Parameters:
aEditable- true if the layer content can be edited- See Also:
-
selectObject
Description copied from interface:ILcdLayerChanges the selection state of any element contained in theILcdModelthisILcdLayerrefers to. This method shall have an effect only if isSelectableSupported and isSelectable return true.- Specified by:
selectObjectin interfaceILcdLayer- Parameters:
aObject- theObjectto 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,trueto select,falseto deselect.aDispatchEventMode- shall be one amongILcdFireEventMode.FIRE_NOW,ILcdFireEventMode.FIRE_LATER,ILcdFireEventMode.NO_EVENT- See Also:
-
fireCollectedSelectionChanges
public void fireCollectedSelectionChanges()Description copied from interface:ILcdLayerFires aTLcdSelectionChangedEventthat contains all the selection changes appended by successively callingselectObject(Object, boolean, ILcdFireEventMode.FIRE_LATER).- Specified by:
fireCollectedSelectionChangesin interfaceILcdLayer
-
clearSelection
public void clearSelection(int aDispatchEventMode) Description copied from interface:ILcdLayerDeselect all the Objects in thisILcdLayer, i.e., the selection of thisILcdLayeris empty afterward.- Specified by:
clearSelectionin interfaceILcdLayer- Parameters:
aDispatchEventMode- shall be one amongILcdFireEventMode.FIRE_NOW,ILcdFireEventMode.FIRE_LATER,ILcdFireEventMode.NO_EVENT- See Also:
-
addPropertyChangeListener
Description copied from interface:ILcdPropertyChangeSourceRegisters the given
PropertyChangeListenerto 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
ALcdWeakPropertyChangeListenerinstance as property change listener.- Specified by:
addPropertyChangeListenerin interfaceILcdPropertyChangeSource- Parameters:
aPropertyChangeListener- The listener to be notified- See Also:
-
removePropertyChangeListener
Description copied from interface:ILcdPropertyChangeSourceDe-registers the given
PropertyChangeListenerfrom 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.- Specified by:
removePropertyChangeListenerin interfaceILcdPropertyChangeSource- Parameters:
aPropertyChangeListener- the listener that should no longer be notified of changes of this object's properties- See Also:
-
getSelectionCount
public int getSelectionCount()Description copied from interface:ILcdSelectionReturns the number of objects in this selection.- Specified by:
getSelectionCountin interfaceILcdSelection<Object>- Returns:
- the number of objects in this
ILcdSelection.
-
selectedObjects
Description copied from interface:ILcdSelectionReturns the objects in this selection.- Specified by:
selectedObjectsin interfaceILcdSelection<Object>- Returns:
- the objects currently in this
ILcdSelection.
-
isSelected
Description copied from interface:ILcdSelectionChecks whether the givenObjectis currently in the set of selected objects.- Specified by:
isSelectedin interfaceILcdSelection<Object>- Parameters:
aObject- theObjectto be checked.- Returns:
trueif theObjectis in thisILcdSelection, false otherwise.
-
addSelectionListener
Description copied from interface:ILcdSelectionAdds a listener to this selection. In case you need to register a listener which keeps a reference to an object with a shorter life-time than thisILcdSelection, you can use aALcdWeakSelectionListenerinstance as selection listener.- Specified by:
addSelectionListenerin interfaceILcdSelection<Object>- Parameters:
aSelectionListener- theILcdSelectionListenerto be added.
-
removeSelectionListener
Description copied from interface:ILcdSelectionRemoves anILcdSelectionListenerfrom thisILcdSelection.- Specified by:
removeSelectionListenerin interfaceILcdSelection<Object>- Parameters:
aSelectionListener- theILcdSelectionListenerto be removed.
-