Package org.opentrafficsim.draw
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 typeT
- text animation type
- All Implemented Interfaces:
Serializable
,nl.tudelft.simulation.dsol.animation.Locatable
,org.opentrafficsim.base.geometry.OtsLocatable
- 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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface to obtain the color of the background.static interface
Determine if a Feature object should be rendered. -
Field Summary
Modifier and TypeFieldDescriptionstatic final TextAnimation.ScaleDependentRendering
Always render the Text.static final TextAnimation.ScaleDependentRendering
Don't render texts when smaller than 1.static final TextAnimation.ScaleDependentRendering
Don't render texts when smaller than 2.static final TextAnimation.ScaleDependentRendering
Don't render texts when smaller than 2. -
Constructor Summary
ConstructorDescriptionTextAnimation
(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.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.TextAnimation
(L source, Supplier<String> text, float dx, float dy, TextAlignment textAlignment, Color color, nl.tudelft.simulation.naming.context.Contextualized contextualized, TextAnimation.ScaleDependentRendering scaleDependentRendering) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
destroy
(nl.tudelft.simulation.naming.context.Contextualized contextProvider) Destroy the text animation.final org.opentrafficsim.base.geometry.OtsBounds2d
protected final Color
getColor()
Retrieve the current color.protected final float
getDx()
Retrieve dx.protected final float
getDy()
Retrieve dy.protected final Font
getFont()
Retrieve the font.protected final float
Retrieve the font size.org.djutils.draw.point.OrientedPoint2d
protected TextAnimation.ScaleDependentRendering
Retrieve the scale dependent rendering qualifier (used in cloning).protected final L
Retrieve the source.protected final String
getText()
Retrieve the current text.protected final TextAlignment
Retrieve the text alignment.double
getZ()
final boolean
isFlip()
Retrieve the current flip status.final boolean
isRotate()
Retrieve the current rotation status.final boolean
isScale()
Retrieve the current scale status.final boolean
Retrieve the current translate status.void
paint
(Graphics2D graphics, ImageObserver observer) paint() method so it can be overridden or extended.protected final void
Update the color.setDynamic
(boolean dynamic) Sets whether the location of this text is dynamic.final void
setFlip
(boolean flip) Update the flip status.final void
setRotate
(boolean rotate) Update the rotation status.final void
setScale
(boolean scale) Update the scale status.final void
Update the text.final void
setTranslate
(boolean translate) Update the translate status.protected final void
setXY
(float x, float y) Sets a new offset.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable
getDirZ
-
Field Details
-
RENDERALWAYS
Always render the Text. -
RENDERWHEN1
Don't render texts when smaller than 1. -
RENDERWHEN10
Don't render texts when smaller than 2. -
RENDERWHEN100
Don't render texts when smaller than 2.
-
-
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) throws RemoteException, NamingException Construct a new TextAnimation.- Parameters:
source
- L; the object for which the text is displayedtext
- Supplier<String>; the text to displaydx
- float; the horizontal movement of the text, in metersdy
- float; the vertical movement of the text, in meterstextAlignment
- TextAlignment; where to place the textcolor
- Color; the color of the textfontSize
- float; the size of the font; default = 2.0 (meters)minFontSize
- float; minimum font size resulting from scalingmaxFontSize
- float; maximum font size resulting from scalingcontextualized
- Contextualized; context provider.background
- ContrastToBackground; allows querying the background color and adaptation of the actual color of the text to ensure contrastscaleDependentRendering
- ScaleDependentRendering; suppress rendering when font scale is too small- Throws:
NamingException
- when animation context cannot be created or retrievedRemoteException
- when remote context cannot be found
-
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) throws RemoteException, NamingException Construct a new TextAnimation without contrast to background protection and no minimum font scale.- Parameters:
source
- L; the object for which the text is displayedtext
- Supplier<String>; the text to displaydx
- float; the horizontal movement of the text, in metersdy
- float; the vertical movement of the text, in meterstextAlignment
- TextAlignment; where to place the textcolor
- Color; the color of the textfontSize
- float; the size of the font; default = 2.0 (meters)minFontSize
- float; minimum font size resulting from scalingmaxFontSize
- float; maximum font size resulting from scalingcontextualized
- Contextualized; context providerscaleDependentRendering
- ScaleDependentRendering; render text only when bigger than minimum scale- Throws:
NamingException
- when animation context cannot be created or retrievedRemoteException
- when remote context cannot be found
-
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) throws RemoteException, NamingException - Parameters:
source
- L; the object for which the text is displayedtext
- Supplier<String>; the text to displaydx
- float; the horizontal movement of the text, in metersdy
- float; the vertical movement of the text, in meterstextAlignment
- TextAlignment; where to place the textcolor
- Color; the color of the textcontextualized
- Contextualized; context providerscaleDependentRendering
- ScaleDependentRendering; render text only when bigger than minimum scale- Throws:
NamingException
- when animation context cannot be created or retrievedRemoteException
- when remote context cannot be found
-
-
Method Details
-
setDynamic
Sets whether the location of this text is dynamic.- Parameters:
dynamic
- boolean; whether the location of this text is dynamic.- Returns:
- T; for method chaining.
-
getLocation
public org.djutils.draw.point.OrientedPoint2d getLocation()- Specified by:
getLocation
in interfacenl.tudelft.simulation.dsol.animation.Locatable
- Specified by:
getLocation
in interfaceorg.opentrafficsim.base.geometry.OtsLocatable
-
getBounds
public final org.opentrafficsim.base.geometry.OtsBounds2d getBounds()- Specified by:
getBounds
in interfacenl.tudelft.simulation.dsol.animation.Locatable
- Specified by:
getBounds
in interfaceorg.opentrafficsim.base.geometry.OtsLocatable
-
paint
paint() method so it can be overridden or extended.- Parameters:
graphics
- Graphics2D; the graphics objectobserver
- ImageObserver; the observer
-
destroy
public final void destroy(nl.tudelft.simulation.naming.context.Contextualized contextProvider) Destroy the text animation.- Parameters:
contextProvider
- Contextualized; the object with a Context
-
getSource
Retrieve the source.- Returns:
- L; the source
-
getDx
protected final float getDx()Retrieve dx.- Returns:
- float; the value of dx
-
getDy
protected final float getDy()Retrieve dy.- Returns:
- float; the value of dy
-
setXY
protected final void setXY(float x, float y) Sets a new offset.- Parameters:
x
- float; dxy
- float; dy
-
getZ
- Specified by:
getZ
in interfacenl.tudelft.simulation.dsol.animation.Locatable
- Throws:
RemoteException
-
getTextAlignment
Retrieve the text alignment.- Returns:
- TextAlignment; the text alignment
-
getFontSize
protected final float getFontSize()Retrieve the font size.- Returns:
- float; the font size
-
getFont
Retrieve the font.- Returns:
- Font; the font
-
getText
Retrieve the current text.- Returns:
- String; the current text
-
setText
Update the text.- Parameters:
text
- Supplier<String>; the new text
-
getColor
Retrieve the current color.- Returns:
- Color; the current color
-
setColor
Update the color.- Parameters:
color
- Color; the new color
-
isFlip
public final boolean isFlip()Retrieve the current flip status.- Returns:
- boolean; the current flip status
-
setFlip
public final void setFlip(boolean flip) Update the flip status.- Parameters:
flip
- boolean; the new flip status
-
isRotate
public final boolean isRotate()Retrieve the current rotation status.- Returns:
- boolean; the current rotation status
-
setRotate
public final void setRotate(boolean rotate) Update the rotation status.- Parameters:
rotate
- boolean; the new rotation status
-
isScale
public final boolean isScale()Retrieve the current scale status.- Returns:
- boolean; the current scale status
-
setScale
public final void setScale(boolean scale) Update the scale status.- Parameters:
scale
- boolean; the new scale status
-
isTranslate
public final boolean isTranslate()Retrieve the current translate status.- Returns:
- boolean; the current translate status
-
setTranslate
public final void setTranslate(boolean translate) Update the translate status.- Parameters:
translate
- boolean; the new translate status
-
getScaleDependentRendering
Retrieve the scale dependent rendering qualifier (used in cloning).- Returns:
- ScaleDependentRendering; the rendering qualifier of this TextAnimation
-