Class ALcdScaleIndicator

java.lang.Object
com.luciad.view.swing.ALcdScaleIndicator
All Implemented Interfaces:
ILcdIcon, ILcdCloneable, Serializable, Cloneable
Direct Known Subclasses:
TLcdGXYScaleIndicator, TLspFXScaleIndicator, TLspScaleIndicator

public abstract class ALcdScaleIndicator extends Object implements ILcdIcon, Cloneable
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.
    The BAR representation of the scale indicator.
    The BAR representation of the scale indicator.
  • 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 the fractionFormat property.
    The FRACTION representation of the scale indicator.
    The FRACTION representation of the scale indicator.

By default, the bar representation is chosen.

Concrete implementations of 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:
  • Constructor Details

    • ALcdScaleIndicator

      public ALcdScaleIndicator()
      Constructs an ALcdScaleIndicator object.
  • Method Details

    • getIconWidth

      public int getIconWidth()
      Gets the width of the icon for displaying the scale of the ILcdGXYView. Returns the fixed width of the icon.
      Specified by:
      getIconWidth in interface ILcdIcon
      Returns:
      the fixed width of the icon.
    • getIconHeight

      public int getIconHeight()
      Gets the height of the icon for displaying the scale of the ILcdGXYView. 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 interface ILcdIcon
      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

      public void setBarColor(Color aColor)
      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

      public Color getBarColor()
      Returns the main color of the bar used to indicate the scale.
      Returns:
      the main color
      See Also:
    • setAlternateBarColor

      public void setAlternateBarColor(Color aColor)
      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

      public Color getAlternateBarColor()
      Returns the alternate color of the bar used to indicate the scale.
      Returns:
      the alternate color
      See Also:
    • setDistanceUnit

      public void setDistanceUnit(TLcdDistanceUnit aDistanceUnit)
      Sets the distance unit for the view. If aDistanceUnit differs from the current distance unit, a PropertyChangeEvent is thrown.
      Parameters:
      aDistanceUnit - the distance unit to set
    • getFractionFormat

      public TLcdScaleFormat getFractionFormat()
      Returns the format string that is used to display the fraction when using ALcdScaleIndicator.Representation.FRACTION.
      Returns:
      the format string
      Since:
      2020.0
      See Also:
    • setFractionFormat

      public void setFractionFormat(TLcdScaleFormat aFractionFormat)
      Sets the format to be used to display the fraction when using ALcdScaleIndicator.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, a PropertyChangeEvent is fired.

      Parameters:
      aFractionFormat - the fraction format string
      Since:
      2020.0
      See Also:
    • getScaleRepresentation

      public ALcdScaleIndicator.Representation getScaleRepresentation()
      Returns the current scale representation.
      Returns:
      the scale representation value.
      Since:
      2020.0
    • setScaleRepresentation

      public void setScaleRepresentation(ALcdScaleIndicator.Representation aScaleRepresentation)
      Sets the scale representation.

      If aScaleRepresentation differs from the current scale representation value, a PropertyChangeEvent is fired.

      Parameters:
      aScaleRepresentation - the scale representation
      Since:
      2020.0
    • toggleScaleRepresentation

      public void toggleScaleRepresentation()
      Toggles between all possible scale representation values, see setScaleRepresentation(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

      public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Registers the given PropertyChangeListener to be notified when this scale indicator's properties change.
      Parameters:
      aPropertyChangeListener - the listener to notify of changes of this indicator's properties
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Unregisters the given PropertyChangeListener 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

      protected void firePropertyChangeEvent(String aPropertyName, Object aOldValue, Object aNewValue)
      Fires a new PropertyChangeEvent to all the PropertyChangeListeners registered with this ALcdScaleIndicator.
      Parameters:
      aPropertyName - The name of the changed property
      aOldValue - The old value of the changed property
      aNewValue - The new value of the changed property
    • setFont

      public void setFont(Font aFont)
      Sets the font of the text displaying the scale of the view. If aFont differs from the current font, a PropertyChangeEvent is thrown.
      Parameters:
      aFont - the font of the display text
    • setHaloColor

      public void setHaloColor(Color aHaloColor)
      Sets the halo color of the text displaying the scale of the view. If aHaloColor differs from the current halo color, a PropertyChangeEvent is thrown.
      Parameters:
      aHaloColor - The halo color of the display text
    • setLabelColor

      public void setLabelColor(Color aLabelColor)
      Sets the color of the text displaying the scale of the view. If aLabelColor differs from the current halo color, a PropertyChangeEvent is thrown.
      Parameters:
      aLabelColor - the color of the display text
    • getFont

      public Font getFont()
      Gets the font of the text displaying the scale of the view.
      Returns:
      the font of the display text
    • getHaloColor

      public Color getHaloColor()
      Gets the halo color of the text displaying the scale of the view.
      Returns:
      the halo color of the display text
    • getLabelColor

      public Color getLabelColor()
      Gets the color of the text displaying the scale of the view.
      Returns:
      the color of the display text
    • getDistanceUnit

      public TLcdDistanceUnit 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 the getBarColor() and getAlternateBarColor().
      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 the getBarColor() and getAlternateBarColor(). The default is 4.
      Parameters:
      aBarSegmentCount - the new amount of bar segments. The amount should be more than zero and fit given the total width of the bar.
      Since:
      2018.0
    • paintIcon

      public final void paintIcon(Component c, Graphics g, int x, int y)
      Draw the ALcdScaleIndicator at the specified location. Draw the ILcdIcon at the specified location. ILcdIcon implementations may use the Component argument to get properties useful for painting, e.g. the foreground or background color.
      Specified by:
      paintIcon in interface ILcdIcon
      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 the isScaleAtCenterOfMap() value.
      Returns:
      the current scale in toolkit pixels per meter.
    • retrieveMapReference

      protected Object retrieveMapReference()
      Returns the current world reference of the map, used to retrieve the world unit of measure. Either ILcdXYWorldReference or ILcdXYZWorldReference.

      This method will return null 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

      protected TLcdISO19103DistanceMeasure calculateScaleIndication(double aScale)
      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 configured distance 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:

      
       valueInMeters * scale < getIconWidth()
       
      The measure must have a TLcdDistanceUnit configured as its unit of measure.
      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

      public Object clone()

      Makes Object.clone() public.

      When for example extending from 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 interface ILcdCloneable
      Overrides:
      clone in class Object
      See Also: