Package org.opentrafficsim.draw
Class RenderableTextSource<L extends OtsShape,T extends RenderableTextSource<L,T>>
java.lang.Object
org.opentrafficsim.draw.RenderableTextSource<L,T>
- Type Parameters:
L- locatable typeT- text animation type
- All Implemented Interfaces:
nl.tudelft.simulation.dsol.animation.Locatable,OtsShape
- 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 RenderableTextSource<L extends OtsShape,T extends RenderableTextSource<L,T>>
extends Object
implements OtsShape
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface to obtain the color of the background.static interfaceDetermine if a Feature object should be rendered. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RenderableTextSource.ScaleDependentRenderingAlways render the Text.static final RenderableTextSource.ScaleDependentRenderingDon't render texts when smaller than 1.static final RenderableTextSource.ScaleDependentRenderingDon't render texts when smaller than 2.static final RenderableTextSource.ScaleDependentRenderingDon't render texts when smaller than 2.Fields inherited from interface org.opentrafficsim.base.geometry.OtsShape
DEFAULT_POLYGON_SEGMENTS, WORLD_MARGIN_LINE -
Constructor Summary
ConstructorsConstructorDescriptionRenderableTextSource(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, RenderableTextSource.ContrastToBackground background, RenderableTextSource.ScaleDependentRendering scaleDependentRendering) Construct a new TextAnimation.RenderableTextSource(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, RenderableTextSource.ScaleDependentRendering scaleDependentRendering) Construct a new TextAnimation without contrast to background protection and no minimum font scale.RenderableTextSource(L source, Supplier<String> text, float dx, float dy, TextAlignment textAlignment, Color color, nl.tudelft.simulation.naming.context.Contextualized contextualized, RenderableTextSource.ScaleDependentRendering scaleDependentRendering) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal voiddestroy(nl.tudelft.simulation.naming.context.Contextualized contextProvider) Destroy the text animation.protected ColorgetColor()Retrieve the current color.protected final floatgetDx()Retrieve dx.protected final floatgetDy()Retrieve dy.protected FontgetFont()Retrieve the font.protected floatRetrieve the font size.final Bounds2dRetrieve the scale dependent rendering qualifier (used in cloning).Returns the source.protected StringgetText()Retrieve the current text.protected TextAlignmentRetrieve the text alignment.doublegetZ()booleanisFlip()Retrieve the current flip status.booleanisRotate()Retrieve the current rotation status.booleanisScale()Retrieve the current scale status.booleanReturn whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.booleanisScaleY()Return whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.booleanRetrieve the current translate status.voidpaint(Graphics2D graphics, ImageObserver observer) paint() method so it can be overridden or extended.protected voidUpdate the color.setDynamic(boolean dynamic) Sets whether the location of this text is dynamic.voidsetFlip(boolean flip) Update the flip status.voidsetRotate(boolean rotate) Update the rotation status.voidsetScale(boolean scale) Update the scale status.voidsetScaleObject(boolean scaleObject) Set whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.voidsetScaleY(boolean scaleY) Set whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.voidUpdate the text.voidsetTranslate(boolean translate) Update the translate status.protected final voidsetXY(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, waitMethods inherited from interface org.opentrafficsim.base.geometry.OtsShape
contains, contains, getAbsoluteBounds, getAbsoluteContour, getDirZ, signedDistance, signedDistance
-
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
-
RenderableTextSource
public RenderableTextSource(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, RenderableTextSource.ContrastToBackground background, RenderableTextSource.ScaleDependentRendering scaleDependentRendering) Construct a new TextAnimation.- Parameters:
source- the object for which the text is displayedtext- the text to displaydx- the horizontal movement of the text, in metersdy- the vertical movement of the text, in meterstextAlignment- where to place the textcolor- the color of the textfontSize- the size of the font; default = 2.0 (meters)minFontSize- minimum font size resulting from scalingmaxFontSize- maximum font size resulting from scalingcontextualized- context provider.background- allows querying the background color and adaptation of the actual color of the text to ensure contrastscaleDependentRendering- suppress rendering when font scale is too small
-
RenderableTextSource
public RenderableTextSource(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, RenderableTextSource.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 displayedtext- the text to displaydx- the horizontal movement of the text, in metersdy- the vertical movement of the text, in meterstextAlignment- where to place the textcolor- the color of the textfontSize- the size of the font; default = 2.0 (meters)minFontSize- minimum font size resulting from scalingmaxFontSize- maximum font size resulting from scalingcontextualized- context providerscaleDependentRendering- render text only when bigger than minimum scale
-
RenderableTextSource
public RenderableTextSource(L source, Supplier<String> text, float dx, float dy, TextAlignment textAlignment, Color color, nl.tudelft.simulation.naming.context.Contextualized contextualized, RenderableTextSource.ScaleDependentRendering scaleDependentRendering) Constructor.- Parameters:
source- the object for which the text is displayedtext- the text to displaydx- the horizontal movement of the text, in metersdy- the vertical movement of the text, in meterstextAlignment- where to place the textcolor- the color of the textcontextualized- context providerscaleDependentRendering- render text only when bigger than minimum scale
-
-
Method Details
-
setDynamic
Sets whether the location of this text is dynamic.- Parameters:
dynamic- whether the location of this text is dynamic.- Returns:
- for method chaining.
-
getLocation
- Specified by:
getLocationin interfacenl.tudelft.simulation.dsol.animation.Locatable- Specified by:
getLocationin interfaceOtsShape
-
getSource
Returns the source.- Returns:
- the source
-
getRelativeBounds
- Specified by:
getRelativeBoundsin interfacenl.tudelft.simulation.dsol.animation.Locatable- Specified by:
getRelativeBoundsin interfaceOtsShape
-
getAbsoluteContour
- Specified by:
getAbsoluteContourin interfaceOtsShape
-
getRelativeContour
- Specified by:
getRelativeContourin interfaceOtsShape
-
paint
paint() method so it can be overridden or extended.- Parameters:
graphics- the graphics objectobserver- 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
-
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- dxy- dy
-
getZ
public double getZ()- Specified by:
getZin interfacenl.tudelft.simulation.dsol.animation.Locatable
-
getTextAlignment
Retrieve the text alignment.- Returns:
- the text alignment
-
getFontSize
protected float getFontSize()Retrieve the font size.- Returns:
- the font size
-
getFont
Retrieve the font.- Returns:
- the font
-
getText
Retrieve the current text.- Returns:
- the current text
-
setText
Update the text.- Parameters:
text- the new text
-
getColor
Retrieve the current color.- Returns:
- the current color
-
setColor
Update the color.- Parameters:
color- the new color
-
isFlip
public boolean isFlip()Retrieve the current flip status.- Returns:
- the current flip status
-
setFlip
public void setFlip(boolean flip) Update the flip status.- Parameters:
flip- the new flip status
-
isRotate
public boolean isRotate()Retrieve the current rotation status.- Returns:
- the current rotation status
-
setRotate
public void setRotate(boolean rotate) Update the rotation status.- Parameters:
rotate- the new rotation status
-
isScale
public boolean isScale()Retrieve the current scale status.- Returns:
- the current scale status
-
setScale
public void setScale(boolean scale) Update the scale status.- Parameters:
scale- the new scale status
-
isTranslate
public boolean isTranslate()Retrieve the current translate status.- Returns:
- the current translate status
-
setTranslate
public void setTranslate(boolean translate) Update the translate status.- Parameters:
translate- the new translate status
-
isScaleY
public boolean isScaleY()Return whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.- Returns:
- whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not
-
setScaleY
public void setScaleY(boolean scaleY) Set whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.- Parameters:
scaleY- whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not
-
isScaleObject
public boolean isScaleObject()Return whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.- Returns:
- whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not
-
setScaleObject
public void setScaleObject(boolean scaleObject) Set whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.- Parameters:
scaleObject- whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not
-
getScaleDependentRendering
Retrieve the scale dependent rendering qualifier (used in cloning).- Returns:
- the rendering qualifier of this TextAnimation
-