Class TLcdRasterPainter
- All Implemented Interfaces:
ILcdRasterPainter
,ILcdCloneable
,ILcdPropertyChangeSource
,ILcdGXYPainter
,ILcdGXYPainterProvider
,Serializable
,Cloneable
com.luciad.imaging
presents a new API
for the modeling of raster data. For new projects, it is recommended to use
this API instead of ILcdRaster
et al. For visualization in a GXY view,
see TLcdGXYImagePainter
This ILcdGXYPainter
can paint ILcdRaster
instances.
It can warp them between different coordinate systems, if required, or just
paint their linearly scaled images, if possible.
It paints the visible portion of the raster if the scale of the
ILcdGXYView
on which to paint is such that the screen resolution
is inside the range defined by the properties startResolutionFactor and
stopResolutionFactor. Outside of this range, it paints only the outline of
the tiles of the raster The resolution factor defines ratio between the
resolution of the raster and the resolution of the screen. For example, a
resolution factor of 4 indicates that 4 raster pixels are used to color a
single screen pixel. A factor of 0.25 indicates that a single raster pixel
will be used to paint four screen pixels. Typical values for
startResolutionFactor and stopResolutionFactor are 2 and 0.5, respectively,
indicating that as we zoom in, the raster becomes visible at a point where 2
raster pixels are merged into a single screen pixel, and the raster becomes
invisible at a point where a single raster pixel is blurred into two screen
pixels.
The value of the startResolutionFactor, the dimensions of the tiles and the
dimension of the ILcdGXYView
on which to paint, determine the
maximum number of tiles that need to be loaded in memory, when painting the
visible portion of the raster. The minimum value of the maximum number of
tiles is always four because the visible portion can always be pointed at the
intersection of four tiles. Suppose we have tiles of 1024 by 1024 pixels, and
a maximum ILcdGXYView
size of 800 by 600. Suppose further that
we we choose a startResolutionFactor of 9. Then, there may be a maximum of 3
by 2 tiles needed to paint the 800 by 600 ILcdGXYView
, thus
requiring 6 tiles to be in memory. This calculation is a rough approximation
because of the non-linear transformation between the data reference of the
raster and the data reference of the ILcdGXYView
. For example,
at a small scale, an ILcdGXYView
with a data reference based on
an Orthographic projection may require more tiles than calculated with the
above procedure. Therefore, as a rule of thumb, allocate twice the amount of
memory to hold the maximum number of tiles calculated.
It is clear that, if the number of non-empty tiles in the raster is less than four, the value of the startResolutionFactor can be set at any value.
Often times, multiple instances of ILcdRaster
with different
resolutions are painted in different layers. In that case, the choice of the
startResolutionFactor and the stopResolutionFactor of the different
TLcdRasterPainters
is often chosen such that the
stopResolutionFactor of the painter in one layer corresponds to the
startResolutionFactor of the next layer holding a raster with a higher
resolution. For example, suppose we have two ILcdRaster
objects,
one that holds 1 degree by 1 degree tiles of 1024 by 1024 pixels and a second
raster 30' by 30' of 1024 by 1024 pixels. The resolution of the second raster
is four times the resolution of the first raster. Hence, in order to match
the stopResolutionFactor of the first raster with the startResolutionFactor
of the second raster, they have to be in the proportion of 1 to 4. The
symmetrical choice around a ResolutionFactor of 1 is 0.5 for the
stopResolutionFactor of the painter of the first raster and 2 for the
startResolutionFactor of the painter of the second raster.
- See Also:
-
Field Summary
Fields inherited from class com.luciad.format.raster.ALcdRasterPainter
DENSITY_OK, DENSITY_TOO_HIGH, DENSITY_TOO_LOW, fBrightness, fColorModel, fContrast, fFillOutlineArea, fForcePainting, fMaxNumberOfOutlineTiles, fPaintOutline, fRGBImageFilter, fStartResolutionFactor, fStopResolutionFactor, fTransparency
Fields inherited from class com.luciad.view.gxy.ALcdGXYPainter
defaultCreationFillStyle, defaultCreationLineStyle, defaultFillStyle, defaultLineStyle, fWorkBounds
Fields inherited from interface com.luciad.view.gxy.ILcdGXYPainter
BODY, CREATING, DEFAULT, HANDLES, RESHAPING, SELECTED, SNAPS, TRANSLATING
-
Constructor Summary
ConstructorDescriptionCreates a new TLcdRasterPainter, with a default name.TLcdRasterPainter
(String aDisplayName) Creates a new TLcdRasterPainter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boundsSFCT
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) Sets the supplied bounds (in view coordinates, pixels) so that it encompasses the representation of the object in the given mode taking into account the given context.clone()
MakesObject.clone()
public.int
Returns the additional border around all sides of the view.getGXYPainter
(Object aObject) Finds anILcdGXYPainter
that can be used to paint or locate the object passed.Returns the Object for which the representation is currently being handled by this painter.int
Returns the sampling rate used when transforming the raster.boolean
Returns whether this painter caches the warped raster images it has painted.int
Returns the width and height of the block in which the raster transformation is approximated using bilinear interpolation.boolean
boolean
Returns whether this painter caches a single warped raster image with this raster painter.boolean
isTouched
(Graphics aGraphics, int aState, ILcdGXYContext aGXYContext) Checks if the representation of the object in the given mode is touched at the location as defined in the supplied context.boolean
Returns whether this painter does not wait for tiles to be fully decoded before painting them.boolean
Returns whether this painter caches images that have been created from raster subtiles.void
paint
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Displays the representation of the object in the given mode on the Graphics passed, taking into account the supplied context.void
setAvoidOpaqueBorder
(boolean aAvoidOpaqueBorder) Specifies whether the painter should avoid drawing opaque borders around transformed rasters.void
setBorder
(int aBorder) Sets an additional border around all sides of the view, defining a region in which a painted raster is transformed and cached.void
setBrightness
(float aBrightness) Sets the brightness that is applied to painted rasters.void
setColorModel
(ColorModel aColorModel) Sets the ColorModel that determines how a raster pixel is transformed into color components for a screen pixel.void
setContrast
(float aContrast) Sets the contrast that is applied to painted rasters.void
setFillOutlineArea
(boolean aFillOutlineArea) Specifies whether the raster outlines and tile outlines should be filled when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.void
setForcePainting
(boolean aForcePainting) Specifies whether the visible portion of the raster should always be painted, irrespective of the startResolutionFactor and stopResolutionFactor.void
setMaxNoOfOutlineTiles
(int aMaxNumberOfOutlineTiles) void
setMaxNumberOfOutlineTiles
(int aMaxNumberOfOutlineTiles) Sets the maximum number of outlines of individual tiles to paint when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.void
Sets the Object for which the representation shall be handled by this painter.void
setOutlineAreaFillStyle
(ILcdGXYPainterStyle aFillStyle) Sets the style that is used when filling the outline area of raster and/or tiles.void
setOutlineColor
(Color aColor) Sets the line color used to paint the raster outlines and tile outlines when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.void
setOutlineStyle
(ILcdGXYPainterStyle aOutlineStyle) Sets the style that is used when drawing the outline of the area of raster and/or tiles.void
setOversamplingRate
(int aOverSamplingRate) Sets the number of samples used per pixel when transforming a raster.void
setPaintCache
(boolean aCache) Specifies whether this painter should cache the warped raster images it has painted.void
setPaintOutline
(boolean aPaintOutline) Specifies whether the raster outlines and tile outlines should be painted when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.void
setReuseInternalBuffer
(boolean aReuseInternalBuffer) Specifies whether this painter should cache a single warped raster image with this raster painter, or whether it should cache a warped raster image with each raster that is painted.void
setRGBImageFilter
(RGBImageFilter aRGBImageFilter) Sets the optional filter that is applied to painted rasters.void
setStartResolutionFactor
(double aFactor) Sets the highest pixel density (number of raster pixels per screen pixel) at which a raster is painted.void
setStartScale
(double aStartScale) As an alternative for the start resolution factor and stop resolution factor, this method andALcdRasterPainter.getStopScale()
can be used for more intuitive control on when to paint a raster and when to paint the outline.void
setStopResolutionFactor
(double aFactor) Sets the lowest pixel density (number of raster pixels per screen pixel) at which a raster is painted.void
setStopScale
(double aStopScale) As an alternative for the start resolution factor and stop resolution factor, this method andALcdRasterPainter.getStartScale()
can be used for more intuitive control on when to paint a raster.void
setTransparency
(float aTransparency) Sets the transparency factor that is applied to painted rasters.void
setUseDeferredSubTileDecoding
(boolean aDefer) Specifies whether this painter should not wait for tiles to be fully decoded before painting them.void
setUseSubTileImageCaching
(boolean aCaching) Specifies whether this painter should cache images that have been created from raster subtiles.void
setWarpBlockSize
(int aWarpBlockSize) Sets the width and height of the block in which the raster transformation is approximated using bilinear interpolation.Methods inherited from class com.luciad.format.raster.ALcdRasterPainter
densityCheck, densityCheck, getBrightness, getColorModel, getContrast, getMaxNoOfOutlineTiles, getMaxNumberOfOutlineTiles, getOutlineAreaFillStyle, getOutlineColor, getOutlineStyle, getRGBImageFilter, getSnapIcon, getStartResolutionFactor, getStartScale, getStopResolutionFactor, getStopScale, getTransparency, idealPixelDensity, idealPixelDensity, idealPixelDensity, isFillOutlineArea, isForcePainting, isPaintOutline, resolutionFactor, setSnapIcon, snapTarget, supportSnap
Methods inherited from class com.luciad.view.gxy.ALcdGXYPainter
addPropertyChangeListener, anchorPointSFCT, firePropertyChangeEvent, firePropertyChangeEvent, getCursor, getDisplayName, isTraceOn, removePropertyChangeListener, setClassTraceOn, setDisplayName, setTraceOn
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.view.gxy.ILcdGXYPainter
anchorPointSFCT, getCursor, getDisplayName, snapTarget, supportSnap
Methods inherited from interface com.luciad.util.ILcdPropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
Methods inherited from interface com.luciad.format.raster.ILcdRasterPainter
getBrightness, getColorModel, getMaxNoOfOutlineTiles, getMaxNumberOfOutlineTiles, getOutlineColor, getStartResolutionFactor, getStopResolutionFactor, getTransparency, isForcePainting, isPaintOutline
-
Constructor Details
-
TLcdRasterPainter
public TLcdRasterPainter()Creates a new TLcdRasterPainter, with a default name. -
TLcdRasterPainter
Creates a new TLcdRasterPainter.- Parameters:
aDisplayName
- the displayName of the painter.
-
-
Method Details
-
setStartResolutionFactor
public void setStartResolutionFactor(double aFactor) Description copied from interface:ILcdRasterPainter
Sets the highest pixel density (number of raster pixels per screen pixel) at which a raster is painted. If the pixel density is too high, only the raster outlines and tile outlines are painted (or a lower resolution level is chosen). This can avoid having to load a large raster to fill a relatively small view.- Specified by:
setStartResolutionFactor
in interfaceILcdRasterPainter
- Overrides:
setStartResolutionFactor
in classALcdRasterPainter
-
setStopResolutionFactor
public void setStopResolutionFactor(double aFactor) Description copied from interface:ILcdRasterPainter
Sets the lowest pixel density (number of raster pixels per screen pixel) at which a raster is painted. If the pixel density is too low, nothing is painted. This can avoid painting overly pixelated rasters.- Specified by:
setStopResolutionFactor
in interfaceILcdRasterPainter
- Overrides:
setStopResolutionFactor
in classALcdRasterPainter
-
setStartScale
public void setStartScale(double aStartScale) Description copied from class:ALcdRasterPainter
As an alternative for the start resolution factor and stop resolution factor, this method andALcdRasterPainter.getStopScale()
can be used for more intuitive control on when to paint a raster and when to paint the outline. When the internal scale of the view (ILcdGXYView.getScale()
is smaller than the start scale, the outline will be painted in stead of the raster. The default value is 0. Warning: when the view scale is in between the start and stop scale, the start resolution factor and the stop resolution factor are still used as a second check. If you don't want interference from these two settings, set the start resolution factor to Double.POSITIVE_INFINITY and the stop resolution factor to 0.- Overrides:
setStartScale
in classALcdRasterPainter
- Parameters:
aStartScale
- The view scale at which one starts painting the raster rather that the outline (when zooming in).- See Also:
-
setStopScale
public void setStopScale(double aStopScale) Description copied from class:ALcdRasterPainter
As an alternative for the start resolution factor and stop resolution factor, this method andALcdRasterPainter.getStartScale()
can be used for more intuitive control on when to paint a raster. When the internal scale of the view (ILcdGXYView.getScale()
is larger than the stop scale, the raster won't be painted. The default value is Double.POSITIVE_INFINITY.- Overrides:
setStopScale
in classALcdRasterPainter
- Parameters:
aStopScale
- The view scale at which one stops painting the raster (when zooming in).- See Also:
-
setForcePainting
public void setForcePainting(boolean aForcePainting) Description copied from interface:ILcdRasterPainter
Specifies whether the visible portion of the raster should always be painted, irrespective of the startResolutionFactor and stopResolutionFactor.- Specified by:
setForcePainting
in interfaceILcdRasterPainter
- Overrides:
setForcePainting
in classALcdRasterPainter
- See Also:
-
setPaintOutline
public void setPaintOutline(boolean aPaintOutline) Description copied from interface:ILcdRasterPainter
Specifies whether the raster outlines and tile outlines should be painted when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.- Specified by:
setPaintOutline
in interfaceILcdRasterPainter
- Overrides:
setPaintOutline
in classALcdRasterPainter
- See Also:
-
setOutlineStyle
Description copied from class:ALcdRasterPainter
Sets the style that is used when drawing the outline of the area of raster and/or tiles. If set to anon-null
value the configure style will take precedence over the configured outline color if the style modifies the Graphics current color.- Overrides:
setOutlineStyle
in classALcdRasterPainter
- Parameters:
aOutlineStyle
- the outline style to use- See Also:
-
setOutlineColor
Description copied from interface:ILcdRasterPainter
Sets the line color used to paint the raster outlines and tile outlines when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.- Specified by:
setOutlineColor
in interfaceILcdRasterPainter
- Overrides:
setOutlineColor
in classALcdRasterPainter
- See Also:
-
setFillOutlineArea
public void setFillOutlineArea(boolean aFillOutlineArea) Description copied from class:ALcdRasterPainter
Specifies whether the raster outlines and tile outlines should be filled when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor.- Overrides:
setFillOutlineArea
in classALcdRasterPainter
- See Also:
-
setOutlineAreaFillStyle
Description copied from class:ALcdRasterPainter
Sets the style that is used when filling the outline area of raster and/or tiles. If the fill style is set tonull
andfill outline area
is enabled the result visual result on screen is undefined.- Overrides:
setOutlineAreaFillStyle
in classALcdRasterPainter
- Parameters:
aFillStyle
- the fill style to use- See Also:
-
setMaxNumberOfOutlineTiles
public void setMaxNumberOfOutlineTiles(int aMaxNumberOfOutlineTiles) Description copied from interface:ILcdRasterPainter
Sets the maximum number of outlines of individual tiles to paint when the pixel density (number of raster pixels per screen pixel) of the raster to be painted is higher than the startResolutionFactor. If the number of tiles is larger than this maximum, only the global outline of the raster is painted.- Specified by:
setMaxNumberOfOutlineTiles
in interfaceILcdRasterPainter
- Overrides:
setMaxNumberOfOutlineTiles
in classALcdRasterPainter
- See Also:
-
setMaxNoOfOutlineTiles
public void setMaxNoOfOutlineTiles(int aMaxNumberOfOutlineTiles) - Specified by:
setMaxNoOfOutlineTiles
in interfaceILcdRasterPainter
- Overrides:
setMaxNoOfOutlineTiles
in classALcdRasterPainter
-
setColorModel
Description copied from interface:ILcdRasterPainter
Sets the ColorModel that determines how a raster pixel is transformed into color components for a screen pixel. If it is not set, the raster itself determines the ColorModel. If that is not set either, the contained raster tiles determine the ColorModel.- Specified by:
setColorModel
in interfaceILcdRasterPainter
- Overrides:
setColorModel
in classALcdRasterPainter
-
setRGBImageFilter
Description copied from class:ALcdRasterPainter
Sets the optional filter that is applied to painted rasters. The filter should be spatially invariant. Any brightness and transparency settings are applied on top of it.- Overrides:
setRGBImageFilter
in classALcdRasterPainter
-
setTransparency
public void setTransparency(float aTransparency) Description copied from interface:ILcdRasterPainter
Sets the transparency factor that is applied to painted rasters. It is an alpha value between 0 and 1, with 0 being perfectly transparent, and 1 (the default) being perfectly opaque.- Specified by:
setTransparency
in interfaceILcdRasterPainter
- Overrides:
setTransparency
in classALcdRasterPainter
-
setBrightness
public void setBrightness(float aBrightness) Description copied from interface:ILcdRasterPainter
Sets the brightness that is applied to painted rasters. It is a value in[0, 2]
. A value of 1 (the default) leaves the brightness unchanged. Values larger than 1 makes the colors brighter, while a value smaller than 1 makes the colors less bright.- Specified by:
setBrightness
in interfaceILcdRasterPainter
- Overrides:
setBrightness
in classALcdRasterPainter
- See Also:
-
setContrast
public void setContrast(float aContrast) Description copied from class:ALcdRasterPainter
Sets the contrast that is applied to painted rasters. It is a value in[0, 2]
. A value of 1 (the default) leaves the contrast unchanged. A value larger than 1 enhances the contrast of dark colors by making them brighter, while a value smaller than 1 enhances the contrast of bright colors by making them darker.- Overrides:
setContrast
in classALcdRasterPainter
-
setUseSubTileImageCaching
public void setUseSubTileImageCaching(boolean aCaching) Specifies whether this painter should cache images that have been created from raster subtiles. Setting this property totrue
helps to avoid disk access during painting (due to lazy loading of raster tiles). It may also speed up the painting of rasters with non-standard color models, like 16 bit indexed color images. The default isfalse
.This property is only relevant for rasters that don't have to be warped, that is, when the model reference of the raster is the same as the world reference of the view.
-
isUseSubTileImageCaching
public boolean isUseSubTileImageCaching()Returns whether this painter caches images that have been created from raster subtiles.- See Also:
-
setUseDeferredSubTileDecoding
public void setUseDeferredSubTileDecoding(boolean aDefer) Specifies whether this painter should not wait for tiles to be fully decoded before painting them. Setting this property totrue
means that parts of the view may remain blank, but the display will update sooner. A proper complete display update will be triggered when there are no more tiles waiting to be decoded. The default isfalse
.This property is only relevant if
isUseSubTileImageCaching()
istrue
.Note that this functionality is not needed for layers wrapped by ILcdGXYAsynchronousLayerWrapper. For best results, use the latter mechanism instead and set this property to false.
-
isUseDeferredSubTileDecoding
public boolean isUseDeferredSubTileDecoding()Returns whether this painter does not wait for tiles to be fully decoded before painting them.- See Also:
-
setPaintCache
public void setPaintCache(boolean aCache) Specifies whether this painter should cache the warped raster images it has painted. A warped raster image has the same size as the view for which it was created. Caching it may improve performance if it can be reused, and it can generally avoid repeated allocation of large image objects on the heap. The default istrue
.This property is only relevant for rasters that have to be warped, that is, when the model reference of the raster is different from the world reference of the view.
- See Also:
-
getPaintCache
public boolean getPaintCache()Returns whether this painter caches the warped raster images it has painted.- See Also:
-
setAvoidOpaqueBorder
public void setAvoidOpaqueBorder(boolean aAvoidOpaqueBorder) Specifies whether the painter should avoid drawing opaque borders around transformed rasters.The painter normally uses the default pixel of a raster when painting the border around a transformed raster. If the default pixel is transparent, the border is invisible. Otherwise, the border is opaque. This typically occurs if a raster has an IndexColorModel without a transparent color index.
Setting this property activates some additional processing to avoid the opaque border anyway. The processing overhead can run up to 50% when painting described rasters. Leaving the property unset is therefore preferable, for instance when the area around painted rasters is not relevant for the application. The default is
false
. -
isAvoidOpaqueBorder
public boolean isAvoidOpaqueBorder()- See Also:
-
setReuseInternalBuffer
public void setReuseInternalBuffer(boolean aReuseInternalBuffer) Specifies whether this painter should cache a single warped raster image with this raster painter, or whether it should cache a warped raster image with each raster that is painted. Caching a single image with this painter and reusing it is generally more memory-efficient. Caching images with the painted rasters can improve performance, but it may also waste a a lot of memory. The default isfalse
.This property is only relevant if
setPaintCache(boolean)
istrue
. -
isReuseInternalBuffer
public boolean isReuseInternalBuffer()Returns whether this painter caches a single warped raster image with this raster painter.- See Also:
-
setBorder
public void setBorder(int aBorder) Sets an additional border around all sides of the view, defining a region in which a painted raster is transformed and cached. A full repaint will be slower, but subsequent panning over the cached region will then be faster. For instance, a border of 200 pixels around a view of 800 by 600 pixels defines a cache region of 1200 by 1000 pixels. The default border is 0 pixels.This property is only relevant for rasters that have to be warped, that is, when the model reference of the raster is different from the world reference of the view.
- Parameters:
aBorder
- the border, expressed in pixels.
-
getBorder
public int getBorder()Returns the additional border around all sides of the view.- See Also:
-
setOversamplingRate
public void setOversamplingRate(int aOverSamplingRate) Sets the number of samples used per pixel when transforming a raster. The default is 1. The total number of samples used per pixel equals(aOverSamplingRate * aOverSamplingRate)
. For instance, if the oversampling rate is set to 2, the painter will take 4 samples per pixel and average their values. This increases the image quality, especially if the raster contains sharp edges, but it also increases the computational cost.This property is only relevant for rasters that have to be warped, that is, when the model reference of the raster is different from the world reference of the view.
- Parameters:
aOverSamplingRate
- the number of samples used per pixel in one direction.
-
getOversamplingRate
public int getOversamplingRate()Returns the sampling rate used when transforming the raster. The returned value equals the number of samples used per pixel in one direction.- See Also:
-
setWarpBlockSize
public void setWarpBlockSize(int aWarpBlockSize) Sets the width and height of the block in which the raster transformation is approximated using bilinear interpolation. Smaller values result in more accurate results, but also larger computation times. The default is 64. With a value of 1, every pixel is transformed without approximation.This property is only relevant for rasters that have to be warped, that is, when the model reference of the raster is different from the world reference of the view.
- Parameters:
aWarpBlockSize
- the width and height, expressed in pixels.
-
getWarpBlockSize
public int getWarpBlockSize()Returns the width and height of the block in which the raster transformation is approximated using bilinear interpolation.- See Also:
-
setObject
Description copied from interface:ILcdGXYPainter
Sets the Object for which the representation shall be handled by this painter.Setting the object on the painter may have an effect on the internal state of the painter, for example, the color to use.
When the object is set to a painter, the context parameter in subsequent calls to methods in this class must contain a layer that contains this object and for which the painter for this object is this painter.
- Specified by:
setObject
in interfaceILcdGXYPainter
- Parameters:
aObject
- the object for which the representation shall be handled by this painter.- See Also:
-
getObject
Description copied from interface:ILcdGXYPainter
Returns the Object for which the representation is currently being handled by this painter.- Specified by:
getObject
in interfaceILcdGXYPainter
- Returns:
- the Object for which the representation is currently being handled by this painter.
- See Also:
-
paint
Description copied from interface:ILcdGXYPainter
Displays the representation of the object in the given mode on the Graphics passed, taking into account the supplied context.The visual representation of an object depends on the context. Depending on the context (e.g. is the location covered by the view), an object may or may not have a representation. The context contains:
- transformations which allow to compute the location in view space of points and bounds given in model, space
- a pen which can connect points with a line or create arcs around a point,
- the view for which the object's representation must be painted. This can be useful when the painted object depends on the scale of the view, or the presence of other layers in the view.
- the current location(s) of the mouse or input device and the last location(s) the mouse or input device was pressed.
The mode passed in this method indicates what part of the object must be painted, whether it should be painted as selected or not, and whether user interaction (via mouse movements) must be taken into account.
When the mode passed contains either TRANSLATING, RESHAPING or CREATING, this method is also responsible for interpreting interaction on the representation of an object and modifying the representation of the object accordingly. The painter is not responsible for modifying the object itself, this is done by a corresponding
ILcdGXYEditor
. Implementations ofILcdGXYPainter
andILcdGXYEditor
interfaces must be consistent for an object: the painter must display the result of the user interaction on the object, while the editor is responsible for modifying the object as a result of the user interaction. A good practice to ensure a consistent implementation is to implement both theILcdGXYPainter
andILcdGXYEditor
interfaces in a single class.When the mode passed includes SNAPS, the part of the representation which corresponds to the object returned as snap target by the method
snapTarget
must be painted in order to provide the user with a visual indication of the snap target.The Graphics passed in this method can be different from the Graphics returned by a view due to techniques such as double buffering (as applied in Swing). Basic drawing operations must always be performed on the Graphics passed as an argument in this method.
- Specified by:
paint
in interfaceILcdGXYPainter
- Overrides:
paint
in classALcdRasterPainter
- Parameters:
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- the mode the object is represented in (see class documentation).aGXYContext
- theILcdGXYContext
the drawing depends on.
-
isTouched
Description copied from interface:ILcdGXYPainter
Checks if the representation of the object in the given mode is touched at the location as defined in the supplied context.The location that must be taken into account to check whether the representation is touched can be retrieved from the context passed with the methods
ILcdGXYContext.getX()
andILcdGXYContext.getY()
. If the check is part of an ongoing operation of user interaction, for example, when the mouse is being dragged, the location of the start of the operation can also be taken into account using the methodsILcdGXYContext.getDeltaX()
andILcdGXYContext.getDeltaY()
. The context contains the transformations required to convert this location into the equivalent location in model space. Implementations of this interface usually follow either of the following patterns:- transform the location of the interaction back to model space and compare the coordinates with the object in model space.
- transform the location to world space and compare with a world representation of the object. This forces the painter into caching a world representation of the object. Caching a view representation of an object is not very practical as it would have to change whenever the view's scale changes or when it is panned. A world representation of an object only changes when the view's XYWorldReference changes, which happens less frequently.
As the mode influences the way an object is represented, it must also be taken into account when checking whether that representation is being touched. When the mode contains CREATING, RESHAPING or TRANSLATING which indicate that the object must be represented in a state for an ongoing operation, the location of the start of the operation may be taken into account as mentioned above. The painting result can take into account multiple locations, to respond to, for example, multi-touch input. When the mode contains SELECTED, the painter should also check if the non-selected representation is touched, since these are always painted on top of each other.
The
boundsSFCT
is often used to speed up the performance of this method as a location outside these bounds can never touch the representation of the object.Note that this method does not give an indication of what part of the object is touched. It is up to the painter implementations to provide methods to make this distinction. The method does also not indicate what sensitivity must be applied when checking if an object is touched. It is up to the implementation to decide what should be the maximum distance between the location given in the context and the closest relevant point or area of the representation of the object.
- Specified by:
isTouched
in interfaceILcdGXYPainter
- Overrides:
isTouched
in classALcdRasterPainter
- Parameters:
aGraphics
- the Graphics on which the representation of the object is paintedaState
- the mode the object is represented inaGXYContext
- contains the location of the interaction and the transformations to convert this location into model coordinates- Returns:
- true if the representation of the object in the given mode is touched by the location as defined in the context passed, false otherwise
- See Also:
-
boundsSFCT
public void boundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException Description copied from interface:ILcdGXYPainter
Sets the supplied bounds (in view coordinates, pixels) so that it encompasses the representation of the object in the given mode taking into account the given context.If this method returns without exception the bounds argument must encompass the representation of the object. A point outside the bounds will not be contained within the painted object.
The bounds returned in this method can be seen as the equivalent in the view space of the bounds in the model space for
ILcdBounded
objects.- Specified by:
boundsSFCT
in interfaceILcdGXYPainter
- Parameters:
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- the mode the object is represented in (see class documentation). For example, an object may be represented differently in SELECTED mode compared to DEFAULT mode. The returned bounds of the representation must take this different representation into account.aGXYContext
- the context for which the representation of the object is painted. It contains amongst others the transformations from model to world and world to view.aBoundsSFCT
- the bounds that must be adapted to encompass the representation of the object in the given mode and context. These bounds must not be taken into account when the method has thrown an exception.- Throws:
TLcdNoBoundsException
- if no bounds can be determined for the representation of the object. This can happen when the object does not have a representation in the given context, for example when it is located in a part of the world which is not visible in the current view.- See Also:
-
getGXYPainter
Description copied from interface:ILcdGXYPainterProvider
Finds anILcdGXYPainter
that can be used to paint or locate the object passed.The painter provider is responsible for setting the object to the painter before returning the painter. An implementation should therefore have the following structure:
public ILcdGXYPainter getGXYPainter(Object aObject) { ILcdGXYPainter painter = ... // find the painter for the object if (painter != null) { painter.setObject(aObject); } return painter; }
- Specified by:
getGXYPainter
in interfaceILcdGXYPainterProvider
- Overrides:
getGXYPainter
in classALcdGXYPainter
- Parameters:
aObject
- the object to find a painter for- Returns:
- a painter that can be used to paint or locate the object; or null if no painter could be found for the given object, or the object could not be set on the retrieved painter.
-
clone
Description copied from interface:ILcdCloneable
Makes
When for example extending fromObject.clone()
public.java.lang.Object
, it can be implemented like this:public Object clone() { try { return super.clone(); } catch ( CloneNotSupportedException e ) { // Cannot happen: extends from Object and implements Cloneable (see also Object.clone) throw new RuntimeException( e ); } }
- Specified by:
clone
in interfaceILcdCloneable
- Specified by:
clone
in interfaceILcdGXYPainterProvider
- Overrides:
clone
in classALcdRasterPainter
- Returns:
- a clone of this painter provider.
- See Also:
-