Class TLcdGXYDensityLayer

java.lang.Object
com.luciad.view.gxy.TLcdGXYDensityLayer
All Implemented Interfaces:
ILcdPropertyChangeSource, ILcdSelection<Object>, ILcdGXYLayer, ILcdLayer, Serializable

public class TLcdGXYDensityLayer extends Object implements ILcdGXYLayer
This 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:
  • Constructor Details

    • TLcdGXYDensityLayer

      public TLcdGXYDensityLayer(ILcdGXYLayer aGXYLayer, IndexColorModel aIndexColorModel)
      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

      public ILcdGXYLayer getGXYLayer()
      Returns the wrapped layer for which densities are painted.
    • getIndexColorModel

      public IndexColorModel getIndexColorModel()
      Returns the color map for the element densities.
    • setIndexColorModel

      public void setIndexColorModel(IndexColorModel aIndexColorModel)
      Sets the color map for the element densities.
    • paint

      public void paint(Graphics aGraphics, int aMode, ILcdGXYView aGXYView)
      Description copied from interface: ILcdGXYLayer
      Paints 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 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.

      Specified by:
      paint in interface ILcdGXYLayer
      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: ILcdGXYLayer
      Applies 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 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.

      Specified by:
      applyOnInteract in interface ILcdGXYLayer
      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 - 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.
      Returns:
      the number of objects the function was applied on.
    • getBounds

      public ILcdBounds getBounds(int aMode, ILcdGXYView aGXYView) throws TLcdNoBoundsException
      Description copied from interface: ILcdGXYLayer
      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. 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.

      Specified by:
      getBounds in interface ILcdGXYLayer
      Parameters:
      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.
      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: ILcdGXYLayer
      Inform the layer that it should terminate the current paint operation. This method can be useful when the paint method is executed in a specific Thread and needs to be stopped in a safe state from another Thread.
      Specified by:
      stopPainting in interface ILcdGXYLayer
      See Also:
    • getScaleRange

      public ILcdInterval getScaleRange()
      Description copied from interface: ILcdGXYLayer
      Returns 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() 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.

      Specified by:
      getScaleRange in interface ILcdGXYLayer
      Returns:
      an 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.
      See Also:
    • getLabelScaleRange

      public ILcdInterval getLabelScaleRange()
      Description copied from interface: ILcdGXYLayer
      Returns 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() 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.

      Specified by:
      getLabelScaleRange in interface ILcdGXYLayer
      Returns:
      an 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.
      See Also:
    • getGXYPainter

      public ILcdGXYPainter getGXYPainter(Object aObject)
      Description copied from interface: ILcdGXYLayer
      Returns 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, see setObject in ILcdGXYPainter.
      Specified by:
      getGXYPainter in interface ILcdGXYLayer
      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

      public ILcdGXYEditor getGXYEditor(Object aObject)
      Description copied from interface: ILcdGXYLayer
      Returns 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, using setObject in ILcdGXYEditor.
      Specified by:
      getGXYEditor in interface ILcdGXYLayer
      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

      public ILcdGXYLabelPainter getGXYLabelPainter(Object aObject)
      Description copied from interface: ILcdGXYLayer
      Returns 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, see setObject in ILcdGXYLabelPainter.
      Specified by:
      getGXYLabelPainter in interface ILcdGXYLayer
      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

      public ILcdGXYPen getGXYPen()
      Description copied from interface: ILcdGXYLayer
      Returns the pen to use when performing basic painting operations for objects in this layers model.
      Specified by:
      getGXYPen in interface ILcdGXYLayer
      Returns:
      the pen to use when performing basic painting operations for objects in this layers model.
    • getIcon

      public ILcdIcon getIcon()
      Description copied from interface: ILcdLayer
      Returns a visual indication of the contents of this layer. For example, for a grid layer, an icon containing a grid could be used.
      Specified by:
      getIcon in interface ILcdLayer
      Returns:
      a visual indication of the contents of this layer.
    • getModelXYWorldTransfoClass

      public Class getModelXYWorldTransfoClass()
      Description copied from interface: ILcdGXYLayer
      Returns 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:
      getModelXYWorldTransfoClass in interface ILcdGXYLayer
      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: ILcdGXYLayer
      Returns whether this layer supports representing objects as text. If not, no effort should be made trying to represent the objects with labels.
      Specified by:
      isLabeledSupported in interface ILcdGXYLayer
      Returns:
      whether this layer supports representing objects as text.
    • isLabeled

      public boolean isLabeled()
      Description copied from interface: ILcdGXYLayer
      Returns whether objects should be represented as text. Note that this property shall not be taken into account when ILcdGXYLayer.isLabeledSupported() returns false.
      Specified by:
      isLabeled in interface ILcdGXYLayer
      Returns:
      whether objects should be represented as text.
      See Also:
    • setLabeled

      public void setLabeled(boolean aLabeled)
      Description copied from interface: ILcdGXYLayer
      Sets whether objects should be represented as text. The value set for this property shall have no effect as long as ILcdGXYLayer.isLabeledSupported() returns false.
      Specified by:
      setLabeled in interface ILcdGXYLayer
      Parameters:
      aLabeled - true to have a textual representation of the objects in the model, false to have no such representation.
    • setIcon

      public void setIcon(ILcdIcon aIcon)
      Description copied from interface: ILcdLayer
      Sets a visual indication of the contents of this layer.
      Specified by:
      setIcon in interface ILcdLayer
      Parameters:
      aIcon - a visual indication of the contents of this layer.
      See Also:
    • getModel

      public ILcdModel getModel()
      Specified by:
      getModel in interface ILcdLayer
      Returns:
      the ILcdModel associated to this ILcdLayer
    • getLabel

      public String getLabel()
      Description copied from interface: ILcdLayer
      A short textual representation of this ILcdLayer.
      Specified by:
      getLabel in interface ILcdLayer
      Returns:
      a short textual representation of this ILcdLayer
    • setLabel

      public void setLabel(String aLabel)
      Description copied from interface: ILcdLayer
      Sets the textual representation of this ILcdLayer.
      Specified by:
      setLabel in interface ILcdLayer
      Parameters:
      aLabel - the the textual representation to use for this ILcdLayer.
    • isVisible

      public boolean isVisible()
      Description copied from interface: ILcdLayer
      Returns whether or not the layer's content is painted.
      Specified by:
      isVisible in interface ILcdLayer
      Returns:
      true if the layer is visible, false otherwise.
      See Also:
    • setVisible

      public void setVisible(boolean aVisible)
      Description copied from interface: ILcdLayer
      Sets whether or not the layer's content is painted.
      Specified by:
      setVisible in interface ILcdLayer
      Parameters:
      aVisible - true if the layer should be visible, false otherwise.
      See Also:
    • isSelectableSupported

      public boolean isSelectableSupported()
      Description copied from interface: ILcdLayer
      Returns true if this layer supports selecting objects, false otherwise.
      Specified by:
      isSelectableSupported in interface ILcdLayer
      Returns:
      true if this ILcdLayer supports the selectable property, false otherwise. I.e. if this ILcdLayer can be put or not in a selectable mode.
      See Also:
    • isSelectable

      public boolean isSelectable()
      Description copied from interface: ILcdLayer
      Returns whether the layer's objects can be selected, for example, by clicking on them.
      Specified by:
      isSelectable in interface ILcdLayer
      Returns:
      true if the layer allows selection, false otherwise.
      See Also:
    • setSelectable

      public void setSelectable(boolean aSelectable)
      Description copied from interface: ILcdLayer
      Sets the Selectable property of this ILcdLayer. Check isSelectableSupported to see if the layer supports selection.
      Specified by:
      setSelectable in interface ILcdLayer
      Parameters:
      aSelectable - true if the layer allows selection, false otherwise.
      See Also:
    • isEditableSupported

      public boolean isEditableSupported()
      Description copied from interface: ILcdLayer
      Returns true if the layer supports editing its objects.
      Specified by:
      isEditableSupported in interface ILcdLayer
      Returns:
      true if the layer supports editing, false otherwise.
      See Also:
    • isEditable

      public boolean isEditable()
      Description copied from interface: ILcdLayer
      Returns whether the layer allows editing the content that it visualizes.
      Specified by:
      isEditable in interface ILcdLayer
      Returns:
      true if this ILcdLayer is editable, false otherwise
      See Also:
    • setEditable

      public void setEditable(boolean aEditable)
      Description copied from interface: ILcdLayer
      Sets whether the layer should allow editing the content that it visualizes. Check isEditableSupported to see if the layer supports editing.
      Specified by:
      setEditable in interface ILcdLayer
      Parameters:
      aEditable - true if the layer content can be edited
      See Also:
    • selectObject

      public void selectObject(Object aObject, boolean aSelection, int aDispatchEventMode)
      Description copied from interface: ILcdLayer
      Changes the selection state of any element contained in the ILcdModel this ILcdLayer refers to. This method shall have an effect only if isSelectableSupported and isSelectable return true.
      Specified by:
      selectObject in interface ILcdLayer
      Parameters:
      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
      See Also:
    • fireCollectedSelectionChanges

      public void fireCollectedSelectionChanges()
      Description copied from interface: ILcdLayer
      Fires a TLcdSelectionChangedEvent that contains all the selection changes appended by successively calling selectObject(Object, boolean, ILcdFireEventMode.FIRE_LATER).
      Specified by:
      fireCollectedSelectionChanges in interface ILcdLayer
    • clearSelection

      public void clearSelection(int aDispatchEventMode)
      Description copied from interface: ILcdLayer
      Deselect all the Objects in this ILcdLayer, i.e., the selection of this ILcdLayer is empty afterward.
      Specified by:
      clearSelection in interface ILcdLayer
      Parameters:
      aDispatchEventMode - shall be one among ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER, ILcdFireEventMode.NO_EVENT
      See Also:
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Description copied from interface: 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.

      Specified by:
      addPropertyChangeListener in interface ILcdPropertyChangeSource
      Parameters:
      aPropertyChangeListener - The listener to be notified
      See Also:
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Description copied from interface: 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.

      Specified by:
      removePropertyChangeListener in interface ILcdPropertyChangeSource
      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: ILcdSelection
      Returns the number of objects in this selection.
      Specified by:
      getSelectionCount in interface ILcdSelection<Object>
      Returns:
      the number of objects in this ILcdSelection.
    • selectedObjects

      public Enumeration selectedObjects()
      Description copied from interface: ILcdSelection
      Returns the objects in this selection.
      Specified by:
      selectedObjects in interface ILcdSelection<Object>
      Returns:
      the objects currently in this ILcdSelection.
    • isSelected

      public boolean isSelected(Object aObject)
      Description copied from interface: ILcdSelection
      Checks whether the given Object is currently in the set of selected objects.
      Specified by:
      isSelected in interface ILcdSelection<Object>
      Parameters:
      aObject - the Object to be checked.
      Returns:
      true if the Object is in this ILcdSelection, false otherwise.
    • addSelectionListener

      public void addSelectionListener(ILcdSelectionListener aSelectionListener)
      Description copied from interface: ILcdSelection
      Adds 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 this ILcdSelection, you can use a ALcdWeakSelectionListener instance as selection listener.
      Specified by:
      addSelectionListener in interface ILcdSelection<Object>
      Parameters:
      aSelectionListener - the ILcdSelectionListener to be added.
    • removeSelectionListener

      public void removeSelectionListener(ILcdSelectionListener aSelectionListener)
      Description copied from interface: ILcdSelection
      Removes an ILcdSelectionListener from this ILcdSelection.
      Specified by:
      removeSelectionListener in interface ILcdSelection<Object>
      Parameters:
      aSelectionListener - the ILcdSelectionListener to be removed.