Class TextAnimation<L extends org.opentrafficsim.base.geometry.OtsLocatable,T extends TextAnimation<L,T>>

java.lang.Object
org.opentrafficsim.draw.TextAnimation<L,T>
Type Parameters:
L - locatable type
T - text animation type
All Implemented Interfaces:
Serializable, nl.tudelft.simulation.dsol.animation.Locatable, org.opentrafficsim.base.geometry.OtsLocatable, org.opentrafficsim.base.geometry.SpatialObject
Direct Known Subclasses:
BusStopAnimation.Text, DefaultCarAnimation.Text, GtuGeneratorPositionAnimation.Queue, LaneAnimation.Text, LaneDetectorAnimation.LoopDetectorData.LoopDetectorText, LaneDetectorAnimation.SinkData.SinkText, LaneDetectorAnimation.Text, LinkAnimation.Text, NodeAnimation.Text, TrafficLightAnimation.Text, TrafficLightDetectorAnimation.Text

public abstract class TextAnimation<L extends org.opentrafficsim.base.geometry.OtsLocatable,T extends TextAnimation<L,T>> extends Object implements org.opentrafficsim.base.geometry.OtsLocatable, Serializable
Display a text for another Locatable object.

Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
See Also:
  • Field Details

  • Constructor Details

    • TextAnimation

      public TextAnimation(L source, Supplier<String> text, float dx, float dy, TextAlignment textAlignment, Color color, float fontSize, float minFontSize, float maxFontSize, nl.tudelft.simulation.naming.context.Contextualized contextualized, TextAnimation.ContrastToBackground background, TextAnimation.ScaleDependentRendering scaleDependentRendering)
      Construct a new TextAnimation.
      Parameters:
      source - the object for which the text is displayed
      text - the text to display
      dx - the horizontal movement of the text, in meters
      dy - the vertical movement of the text, in meters
      textAlignment - where to place the text
      color - the color of the text
      fontSize - the size of the font; default = 2.0 (meters)
      minFontSize - minimum font size resulting from scaling
      maxFontSize - maximum font size resulting from scaling
      contextualized - context provider.
      background - allows querying the background color and adaptation of the actual color of the text to ensure contrast
      scaleDependentRendering - suppress rendering when font scale is too small
    • TextAnimation

      public TextAnimation(L source, Supplier<String> text, float dx, float dy, TextAlignment textAlignment, Color color, float fontSize, float minFontSize, float maxFontSize, nl.tudelft.simulation.naming.context.Contextualized contextualized, TextAnimation.ScaleDependentRendering scaleDependentRendering)
      Construct a new TextAnimation without contrast to background protection and no minimum font scale.
      Parameters:
      source - the object for which the text is displayed
      text - the text to display
      dx - the horizontal movement of the text, in meters
      dy - the vertical movement of the text, in meters
      textAlignment - where to place the text
      color - the color of the text
      fontSize - the size of the font; default = 2.0 (meters)
      minFontSize - minimum font size resulting from scaling
      maxFontSize - maximum font size resulting from scaling
      contextualized - context provider
      scaleDependentRendering - render text only when bigger than minimum scale
    • TextAnimation

      public TextAnimation(L source, Supplier<String> text, float dx, float dy, TextAlignment textAlignment, Color color, nl.tudelft.simulation.naming.context.Contextualized contextualized, TextAnimation.ScaleDependentRendering scaleDependentRendering)
      Parameters:
      source - the object for which the text is displayed
      text - the text to display
      dx - the horizontal movement of the text, in meters
      dy - the vertical movement of the text, in meters
      textAlignment - where to place the text
      color - the color of the text
      contextualized - context provider
      scaleDependentRendering - render text only when bigger than minimum scale
  • Method Details

    • setDynamic

      public T setDynamic(boolean dynamic)
      Sets whether the location of this text is dynamic.
      Parameters:
      dynamic - whether the location of this text is dynamic.
      Returns:
      for method chaining.
    • getLocation

      public org.djutils.draw.point.OrientedPoint2d getLocation()
      Specified by:
      getLocation in interface nl.tudelft.simulation.dsol.animation.Locatable
      Specified by:
      getLocation in interface org.opentrafficsim.base.geometry.OtsLocatable
    • getBounds

      public final org.djutils.draw.bounds.Bounds2d getBounds()
      Specified by:
      getBounds in interface nl.tudelft.simulation.dsol.animation.Locatable
      Specified by:
      getBounds in interface org.opentrafficsim.base.geometry.OtsLocatable
    • getContour

      public org.djutils.draw.line.Polygon2d getContour()
      Specified by:
      getContour in interface org.opentrafficsim.base.geometry.SpatialObject
    • paint

      public void paint(Graphics2D graphics, ImageObserver observer)
      paint() method so it can be overridden or extended.
      Parameters:
      graphics - the graphics object
      observer - the observer
    • destroy

      public final void destroy(nl.tudelft.simulation.naming.context.Contextualized contextProvider)
      Destroy the text animation.
      Parameters:
      contextProvider - the object with a Context
    • getSource

      protected final L getSource()
      Retrieve the source.
      Returns:
      the source
    • getDx

      protected final float getDx()
      Retrieve dx.
      Returns:
      the value of dx
    • getDy

      protected final float getDy()
      Retrieve dy.
      Returns:
      the value of dy
    • setXY

      protected final void setXY(float x, float y)
      Sets a new offset.
      Parameters:
      x - dx
      y - dy
    • getZ

      public double getZ() throws RemoteException
      Specified by:
      getZ in interface nl.tudelft.simulation.dsol.animation.Locatable
      Throws:
      RemoteException
    • getTextAlignment

      protected final TextAlignment getTextAlignment()
      Retrieve the text alignment.
      Returns:
      the text alignment
    • getFontSize

      protected final float getFontSize()
      Retrieve the font size.
      Returns:
      the font size
    • getFont

      protected final Font getFont()
      Retrieve the font.
      Returns:
      the font
    • getText

      protected final String getText()
      Retrieve the current text.
      Returns:
      the current text
    • setText

      public final void setText(Supplier<String> text)
      Update the text.
      Parameters:
      text - the new text
    • getColor

      protected final Color getColor()
      Retrieve the current color.
      Returns:
      the current color
    • setColor

      protected final void setColor(Color color)
      Update the color.
      Parameters:
      color - the new color
    • isFlip

      public final boolean isFlip()
      Retrieve the current flip status.
      Returns:
      the current flip status
    • setFlip

      public final void setFlip(boolean flip)
      Update the flip status.
      Parameters:
      flip - the new flip status
    • isRotate

      public final boolean isRotate()
      Retrieve the current rotation status.
      Returns:
      the current rotation status
    • setRotate

      public final void setRotate(boolean rotate)
      Update the rotation status.
      Parameters:
      rotate - the new rotation status
    • isScale

      public final boolean isScale()
      Retrieve the current scale status.
      Returns:
      the current scale status
    • setScale

      public final void setScale(boolean scale)
      Update the scale status.
      Parameters:
      scale - the new scale status
    • isTranslate

      public final boolean isTranslate()
      Retrieve the current translate status.
      Returns:
      the current translate status
    • setTranslate

      public final void setTranslate(boolean translate)
      Update the translate status.
      Parameters:
      translate - the new translate status
    • getScaleDependentRendering

      protected TextAnimation.ScaleDependentRendering getScaleDependentRendering()
      Retrieve the scale dependent rendering qualifier (used in cloning).
      Returns:
      the rendering qualifier of this TextAnimation