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:
-
BARrepresentation: 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.
The BAR representation of the scale indicator. -
FRACTIONrepresentation: 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 thefractionFormatproperty.
The FRACTION representation of the scale indicator.
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
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of possible map scale representations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Registers the givenPropertyChangeListenerto be notified when this scale indicator's properties change.protected TLcdISO19103DistanceMeasurecalculateScaleIndication(double aScale) Calculates the value to display textually and graphically for the given scale.clone()MakesObject.clone()public.protected voidfirePropertyChangeEvent(String aPropertyName, Object aOldValue, Object aNewValue) Fires a newPropertyChangeEventto 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.intReturns the height of the bar used to indicate the scale.intReturns the amount of segments the scale indicator uses in its bar.intReturns 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.intGets the height of the icon for displaying the scale of theILcdGXYView.intGets 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.booleanReturns whether the scale is shown at the center of what the user is looking at, or the center of the entire projection.final voidDraw theALcdScaleIndicatorat the specified location.voidremovePropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Unregisters the givenPropertyChangeListenerfrom receiving property change events for this scale indicator.protected ObjectReturns the current world reference of the map, used to retrieve the world unit of measure.protected abstract doubleReturns the current view scale according to theisScaleAtCenterOfMap()value.voidsetAlternateBarColor(Color aColor) Sets the alternate color of the bar used to indicate the scale.voidsetBarColor(Color aColor) Sets the main color of the bar used to indicate the scale.voidsetBarHeight(int aBarHeight) Returns the height of the bar used to indicate the scale.voidsetBarSegmentCount(int aBarSegmentCount) Configures the amount of segments the scale indicator uses in its bar.voidsetBarWidth(int aWidth) Sets the maximum width of the bar used to indicate the scale.voidsetDistanceUnit(TLcdDistanceUnit aDistanceUnit) Sets the distance unit for the view.voidSets the font of the text displaying the scale of the view.voidsetFractionFormat(TLcdScaleFormat aFractionFormat) Sets the format to be used to display the fraction when usingALcdScaleIndicator.Representation.FRACTION.voidsetHaloColor(Color aHaloColor) Sets the halo color of the text displaying the scale of the view.voidsetLabelColor(Color aLabelColor) Sets the color of the text displaying the scale of the view.voidsetScaleAtCenterOfMap(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.voidsetScaleRepresentation(ALcdScaleIndicator.Representation aScaleRepresentation) Sets the scale representation.voidToggles between all possible scale representation values, seesetScaleRepresentation(com.luciad.view.swing.ALcdScaleIndicator.Representation).
-
Constructor Details
-
ALcdScaleIndicator
public ALcdScaleIndicator()Constructs anALcdScaleIndicatorobject.
-
-
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:
getIconWidthin 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:
getIconHeightin 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. IfaDistanceUnitdiffers from the current distance unit, aPropertyChangeEventis 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
aFractionFormatdiffers from the current fraction format, aPropertyChangeEventis 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
aScaleRepresentationdiffers from the current scale representation value, aPropertyChangeEventis 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.Representationenum. When the last item has been reached, this method will switch to the first item.A
PropertyChangeEventis fired.- Since:
- 2020.0
-
addPropertyChangeListener
Registers the givenPropertyChangeListenerto 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 givenPropertyChangeListenerfrom 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 newPropertyChangeEventto 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. IfaFontdiffers from the current font, aPropertyChangeEventis thrown.- Parameters:
aFont- the font of the display text
-
setHaloColor
Sets the halo color of the text displaying the scale of the view. IfaHaloColordiffers from the current halo color, aPropertyChangeEventis thrown.- Parameters:
aHaloColor- The halo color of the display text
-
setLabelColor
Sets the color of the text displaying the scale of the view. IfaLabelColordiffers from the current halo color, aPropertyChangeEventis 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 totalwidthof the bar.- Since:
- 2018.0
-
paintIcon
Draw theALcdScaleIndicatorat the specified location. Draw theILcdIconat the specified location.ILcdIconimplementations may use theComponentargument to get properties useful for painting, e.g. the foreground or background color.- Specified by:
paintIconin 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. EitherILcdXYWorldReferenceorILcdXYZWorldReference. This method will returnnullif 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
nullif 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:
clonein interfaceILcdCloneable- Overrides:
clonein classObject- See Also:
-