Package com.luciad.view.swing
Class ALcdScaleIndicator
java.lang.Object
com.luciad.view.swing.ALcdScaleIndicator
- All Implemented Interfaces:
ILcdIcon
,ILcdCloneable
,Serializable
,Cloneable
- Direct Known Subclasses:
TLcdGXYScaleIndicator
,TLspFXScaleIndicator
,TLspScaleIndicator
An icon displaying the map scale.
The map scale representation is configurable by setting the scale representation:
-
BAR
representation: The map scale is represented by a bar of a certain length in pixels, along with its corresponding length in world distance in text on top of it.
The default behavior shows powers of ten multiplied by 1, 2, or 5, expressed in the currently configured distance unit, e.g. 0.5m, 1m, 2m, 5m, 10m, 20m, 50m ...
It also automatically switches between kilometers and meters, and mile and feet.
-
FRACTION
representation: The map scale is represented as a unit-less fraction of screen distance to world distance, for example "1 : 10,000".
The numerator of the fraction will always be 1, the denominator will differ according to the zoom level.
The precise formatting depends on thefractionFormat
property.
ALcdScaleIndicator
have to implement
retrieveScale()
, which returns the scale of a map as the number of
pixels per meter world distance.- Since:
- 2012.0
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration of possible map scale representations. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPropertyChangeListener
(PropertyChangeListener aPropertyChangeListener) Registers the givenPropertyChangeListener
to be notified when this scale indicator's properties change.protected TLcdISO19103DistanceMeasure
calculateScaleIndication
(double aScale) Calculates the value to display textually and graphically for the given scale.clone()
MakesObject.clone()
public.protected void
firePropertyChangeEvent
(String aPropertyName, Object aOldValue, Object aNewValue) Fires a newPropertyChangeEvent
to all the PropertyChangeListeners registered with thisALcdScaleIndicator
.Returns the alternate color of the bar used to indicate the scale.Returns the main color of the bar used to indicate the scale.int
Returns the height of the bar used to indicate the scale.int
Returns the amount of segments the scale indicator uses in its bar.int
Returns the maximum width of the bar used to indicate the scale.Gets the distance unit of this scale indicator.getFont()
Gets the font of the text displaying the scale of the view.Returns the format string that is used to display the fraction when usingALcdScaleIndicator.Representation.FRACTION
.Gets the halo color of the text displaying the scale of the view.int
Gets the height of the icon for displaying the scale of theILcdGXYView
.int
Gets the width of the icon for displaying the scale of theILcdGXYView
.Gets the color of the text displaying the scale of the view.Returns the current scale representation.boolean
Returns whether the scale is shown at the center of what the user is looking at, or the center of the entire projection.final void
Draw theALcdScaleIndicator
at the specified location.void
removePropertyChangeListener
(PropertyChangeListener aPropertyChangeListener) Unregisters the givenPropertyChangeListener
from receiving property change events for this scale indicator.protected Object
Returns the current world reference of the map, used to retrieve the world unit of measure.protected abstract double
Returns the current view scale according to theisScaleAtCenterOfMap()
value.void
setAlternateBarColor
(Color aColor) Sets the alternate color of the bar used to indicate the scale.void
setBarColor
(Color aColor) Sets the main color of the bar used to indicate the scale.void
setBarHeight
(int aBarHeight) Returns the height of the bar used to indicate the scale.void
setBarSegmentCount
(int aBarSegmentCount) Configures the amount of segments the scale indicator uses in its bar.void
setBarWidth
(int aWidth) Sets the maximum width of the bar used to indicate the scale.void
setDistanceUnit
(TLcdDistanceUnit aDistanceUnit) Sets the distance unit for the view.void
Sets the font of the text displaying the scale of the view.void
setFractionFormat
(TLcdScaleFormat aFractionFormat) Sets the format to be used to display the fraction when usingALcdScaleIndicator.Representation.FRACTION
.void
setHaloColor
(Color aHaloColor) Sets the halo color of the text displaying the scale of the view.void
setLabelColor
(Color aLabelColor) Sets the color of the text displaying the scale of the view.void
setScaleAtCenterOfMap
(boolean aScaleAtCenterOfMap) Sets whether to show the scale at the center of the map portion the user is looking at, or a global scale for the entire projection.void
setScaleRepresentation
(ALcdScaleIndicator.Representation aScaleRepresentation) Sets the scale representation.void
Toggles between all possible scale representation values, seesetScaleRepresentation(com.luciad.view.swing.ALcdScaleIndicator.Representation)
.
-
Constructor Details
-
ALcdScaleIndicator
public ALcdScaleIndicator()Constructs anALcdScaleIndicator
object.
-
-
Method Details
-
getIconWidth
public int getIconWidth()Gets the width of the icon for displaying the scale of theILcdGXYView
. Returns the fixed width of the icon.- Specified by:
getIconWidth
in interfaceILcdIcon
- Returns:
- the fixed width of the icon.
-
getIconHeight
public int getIconHeight()Gets the height of the icon for displaying the scale of theILcdGXYView
. If a font is set, the height is dependant of the font. Otherwise the height is set to 45. Returns the fixed height of the icon.- Specified by:
getIconHeight
in interfaceILcdIcon
- Returns:
- the fixed height of the icon.
-
getBarHeight
public int getBarHeight()Returns the height of the bar used to indicate the scale.- Returns:
- the bar height, in pixels
-
setBarHeight
public void setBarHeight(int aBarHeight) Returns the height of the bar used to indicate the scale.- Parameters:
aBarHeight
- the new bar height, in pixels
-
getBarWidth
public int getBarWidth()Returns the maximum width of the bar used to indicate the scale.- Returns:
- the bar width, in pixels
-
setBarWidth
public void setBarWidth(int aWidth) Sets the maximum width of the bar used to indicate the scale.- Parameters:
aWidth
- the new bar width, in pixels
-
setBarColor
Sets the main color of the bar used to indicate the scale. This bar is a sequence of boxes, filled with an alternating color.- Parameters:
aColor
- the new main color- See Also:
-
getBarColor
Returns the main color of the bar used to indicate the scale.- Returns:
- the main color
- See Also:
-
setAlternateBarColor
Sets the alternate color of the bar used to indicate the scale. This bar is a sequence of boxes, filled with an alternating color.- Parameters:
aColor
- the new alternate color- See Also:
-
getAlternateBarColor
Returns the alternate color of the bar used to indicate the scale.- Returns:
- the alternate color
- See Also:
-
setDistanceUnit
Sets the distance unit for the view. IfaDistanceUnit
differs from the current distance unit, aPropertyChangeEvent
is thrown.- Parameters:
aDistanceUnit
- the distance unit to set
-
getFractionFormat
Returns the format string that is used to display the fraction when usingALcdScaleIndicator.Representation.FRACTION
.- Returns:
- the format string
- Since:
- 2020.0
- See Also:
-
setFractionFormat
Sets the format to be used to display the fraction when usingALcdScaleIndicator.Representation.FRACTION
.The default value is
new TLcdScaleFormat()
.See also
setScaleRepresentation(com.luciad.view.swing.ALcdScaleIndicator.Representation)
.If
aFractionFormat
differs from the current fraction format, aPropertyChangeEvent
is fired.- Parameters:
aFractionFormat
- the fraction format string- Since:
- 2020.0
- See Also:
-
getScaleRepresentation
Returns the current scale representation.- Returns:
- the scale representation value.
- Since:
- 2020.0
-
setScaleRepresentation
Sets the scale representation.If
aScaleRepresentation
differs from the current scale representation value, aPropertyChangeEvent
is fired.- Parameters:
aScaleRepresentation
- the scale representation- Since:
- 2020.0
-
toggleScaleRepresentation
public void toggleScaleRepresentation()Toggles between all possible scale representation values, seesetScaleRepresentation(com.luciad.view.swing.ALcdScaleIndicator.Representation)
.The representations are iterated according to the order in which they are defined in the
ALcdScaleIndicator.Representation
enum. When the last item has been reached, this method will switch to the first item.A
PropertyChangeEvent
is fired.- Since:
- 2020.0
-
addPropertyChangeListener
Registers the givenPropertyChangeListener
to be notified when this scale indicator's properties change.- Parameters:
aPropertyChangeListener
- the listener to notify of changes of this indicator's properties
-
removePropertyChangeListener
Unregisters the givenPropertyChangeListener
from receiving property change events for this scale indicator.- Parameters:
aPropertyChangeListener
- the listener that should no longer be notified of changes of this indicator's properties
-
firePropertyChangeEvent
Fires a newPropertyChangeEvent
to all the PropertyChangeListeners registered with thisALcdScaleIndicator
.- Parameters:
aPropertyName
- The name of the changed propertyaOldValue
- The old value of the changed propertyaNewValue
- The new value of the changed property
-
setFont
Sets the font of the text displaying the scale of the view. IfaFont
differs from the current font, aPropertyChangeEvent
is thrown.- Parameters:
aFont
- the font of the display text
-
setHaloColor
Sets the halo color of the text displaying the scale of the view. IfaHaloColor
differs from the current halo color, aPropertyChangeEvent
is thrown.- Parameters:
aHaloColor
- The halo color of the display text
-
setLabelColor
Sets the color of the text displaying the scale of the view. IfaLabelColor
differs from the current halo color, aPropertyChangeEvent
is thrown.- Parameters:
aLabelColor
- the color of the display text
-
getFont
Gets the font of the text displaying the scale of the view.- Returns:
- the font of the display text
-
getHaloColor
Gets the halo color of the text displaying the scale of the view.- Returns:
- the halo color of the display text
-
getLabelColor
Gets the color of the text displaying the scale of the view.- Returns:
- the color of the display text
-
getDistanceUnit
Gets the distance unit of this scale indicator.- Returns:
- the distance unit of this scale indicator
-
getBarSegmentCount
public int getBarSegmentCount()Returns the amount of segments the scale indicator uses in its bar. The segments are filled with thegetBarColor()
andgetAlternateBarColor()
.- Returns:
- the amount of bar segments
- Since:
- 2018.0
-
setBarSegmentCount
public void setBarSegmentCount(int aBarSegmentCount) Configures the amount of segments the scale indicator uses in its bar. The segments are filled with thegetBarColor()
andgetAlternateBarColor()
. The default is 4.- Parameters:
aBarSegmentCount
- the new amount of bar segments. The amount should be more than zero and fit given the totalwidth
of the bar.- Since:
- 2018.0
-
paintIcon
Draw theALcdScaleIndicator
at the specified location. Draw theILcdIcon
at the specified location.ILcdIcon
implementations may use theComponent
argument to get properties useful for painting, e.g. the foreground or background color.- Specified by:
paintIcon
in interfaceILcdIcon
- Parameters:
c
- a Component to retrieve properties from.g
- the Graphics on which the icon will be painted.x
- the x position where the icon will be painted. x is the first coordinate of the top left corner point of the icon.y
- the y position where the icon will be painted. y is the second coordinate of the top left corner point of the icon.
-
isScaleAtCenterOfMap
public boolean isScaleAtCenterOfMap()Returns whether the scale is shown at the center of what the user is looking at, or the center of the entire projection.- Returns:
- true if the scale at the center of the view is shown, false otherwise
- Since:
- 2019.0
-
setScaleAtCenterOfMap
public void setScaleAtCenterOfMap(boolean aScaleAtCenterOfMap) Sets whether to show the scale at the center of the map portion the user is looking at, or a global scale for the entire projection. Displaying the scale of the center of the map part visible to the user shows a more relevant scale at places where distances are distorted by the projection. As a consequence, the scale will update whenever the user pans or zooms. Displaying the scale of the projection yields a constant scale for a given zoom level, regardless of pan operations.- Parameters:
aScaleAtCenterOfMap
- If true the scale at the center of the view will be shown, otherwise a global projection scale will be shown.- Since:
- 2019.0
-
retrieveScale
protected abstract double retrieveScale()Returns the current view scale according to theisScaleAtCenterOfMap()
value.- Returns:
- the current scale in toolkit pixels per meter.
-
retrieveMapReference
Returns the current world reference of the map, used to retrieve the world unit of measure. EitherILcdXYWorldReference
orILcdXYZWorldReference
. This method will returnnull
if the reference is unknown, in which case the world unit will be assumed to be 1 meter.- Returns:
- the current world reference of the map, or
null
if it is unknown - Since:
- 2020.0
-
calculateScaleIndication
Calculates the value to display textually and graphically for the given scale. The returned measure value will be displayed as text (expressed in the measure's unit), together with a bar of the returned distance. The default implementation snaps to powers of ten multiplied by 1, 2, or 5, expressed in the currently configureddistance unit
, e.g. 1km, 2km, 5km, 10km, 20km, 50km...
It also automatically switches between kilometers and meters, and mile and feet. When overriding this method, the implementation must ensure that the returned distance does not exceed the icon's width:
The measure must have a TLcdDistanceUnit configured as its unit of measure.valueInMeters * scale < getIconWidth()
- Parameters:
aScale
- the current scale, in pixels per meter- Returns:
- the measure determining the distance displayed in the indicator, both textually and as a bar whose width has the mentioned distance
-
clone
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
- Overrides:
clone
in classObject
- See Also:
-