Package org.opentrafficsim.draw.core
Class TextAnimation
- java.lang.Object
-
- org.opentrafficsim.draw.core.TextAnimation
-
- All Implemented Interfaces:
java.io.Serializable
,Locatable
- Direct Known Subclasses:
BusStopAnimation.Text
,DefaultCarAnimation.Text
,GtuGeneratorQueueAnimation
,LaneAnimation.Text
,LinkAnimation.Text
,NodeAnimation.Text
,SensorAnimation.Text
,TrafficLightAnimation.Text
public abstract class TextAnimation extends java.lang.Object implements Locatable, java.io.Serializable
Display a text for another Locatable object.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Dec 11, 2016
BSD-style license. See OpenTrafficSim License.- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TextAnimation.ContrastToBackground
Interface to obtain the color of the background.static interface
TextAnimation.ScaleDependentRendering
Determine if a Feature object should be rendered.
-
Field Summary
Fields Modifier and Type Field Description static TextAnimation.ScaleDependentRendering
RENDERALWAYS
Always render the Text.static TextAnimation.ScaleDependentRendering
RENDERWHEN1
Don't render texts when smaller than 1.static TextAnimation.ScaleDependentRendering
RENDERWHEN10
Don't render texts when smaller than 2.static TextAnimation.ScaleDependentRendering
RENDERWHEN100
Don't render texts when smaller than 2.
-
Constructor Summary
Constructors Constructor Description TextAnimation(Locatable source, java.lang.String text, float dx, float dy, TextAlignment textAlignment, java.awt.Color color, float fontSize, float minFontSize, float maxFontSize, SimulatorInterface.TimeDoubleUnit simulator, TextAnimation.ContrastToBackground background, TextAnimation.ScaleDependentRendering scaleDependentRendering)
Construct a new TextAnimation.TextAnimation(Locatable source, java.lang.String text, float dx, float dy, TextAlignment textAlignment, java.awt.Color color, float fontSize, float minFontSize, float maxFontSize, SimulatorInterface.TimeDoubleUnit simulator, TextAnimation.ScaleDependentRendering scaleDependentRendering)
Construct a new TextAnimation without contrast to background protection and no minimum font scale.TextAnimation(Locatable source, java.lang.String text, float dx, float dy, TextAlignment textAlignment, java.awt.Color color, SimulatorInterface.TimeDoubleUnit simulator, TextAnimation.ScaleDependentRendering scaleDependentRendering)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract TextAnimation
clone(Locatable newSource, SimulatorInterface.TimeDoubleUnit newSimulator)
Clone the TextAnimation and return a copy for the new source on the new simulator.void
destroy()
Destroy the text animation.javax.media.j3d.Bounds
getBounds()
protected java.awt.Color
getColor()
Retrieve the current color.protected float
getDx()
Retrieve dx.protected float
getDy()
Retrieve dy.protected java.awt.Font
getFont()
Retrieve the font.protected float
getFontSize()
Retrieve the font size.DirectedPoint
getLocation()
protected TextAnimation.ScaleDependentRendering
getScaleDependentRendering()
Retrieve the scale dependent rendering qualifier (used in cloning).protected Locatable
getSource()
Retrieve the source.protected java.lang.String
getText()
Retrieve the current text.protected TextAlignment
getTextAlignment()
Retrieve the text alignment.boolean
isFlip()
Retrieve the current flip status.boolean
isRotate()
Retrieve the current rotation status.boolean
isScale()
Retrieve the current scale status.boolean
isTranslate()
Retrieve the current translate status.void
paint(java.awt.Graphics2D graphics, java.awt.image.ImageObserver observer)
paint() method so it can be overridden or extended.protected void
setColor(java.awt.Color color)
Update the color.void
setFlip(boolean flip)
Update the flip status.void
setRotate(boolean rotate)
Update the rotation status.void
setScale(boolean scale)
Update the scale status.protected void
setText(java.lang.String text)
Update the text.void
setTranslate(boolean translate)
Update the translate status.protected void
setXY(float x, float y)
Sets a new offset.
-
-
-
Field Detail
-
RENDERALWAYS
public static final TextAnimation.ScaleDependentRendering RENDERALWAYS
Always render the Text.
-
RENDERWHEN1
public static final TextAnimation.ScaleDependentRendering RENDERWHEN1
Don't render texts when smaller than 1.
-
RENDERWHEN10
public static final TextAnimation.ScaleDependentRendering RENDERWHEN10
Don't render texts when smaller than 2.
-
RENDERWHEN100
public static final TextAnimation.ScaleDependentRendering RENDERWHEN100
Don't render texts when smaller than 2.
-
-
Constructor Detail
-
TextAnimation
public TextAnimation(Locatable source, java.lang.String text, float dx, float dy, TextAlignment textAlignment, java.awt.Color color, float fontSize, float minFontSize, float maxFontSize, SimulatorInterface.TimeDoubleUnit simulator, TextAnimation.ContrastToBackground background, TextAnimation.ScaleDependentRendering scaleDependentRendering) throws java.rmi.RemoteException, javax.naming.NamingException
Construct a new TextAnimation.- Parameters:
source
- Locatable; the object for which the text is displayedtext
- 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 scalingsimulator
- SimulatorInterface.TimeDoubleUnit; the simulatorbackground
- 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:
javax.naming.NamingException
- when animation context cannot be created or retrievedjava.rmi.RemoteException
- when remote context cannot be found
-
TextAnimation
public TextAnimation(Locatable source, java.lang.String text, float dx, float dy, TextAlignment textAlignment, java.awt.Color color, float fontSize, float minFontSize, float maxFontSize, SimulatorInterface.TimeDoubleUnit simulator, TextAnimation.ScaleDependentRendering scaleDependentRendering) throws java.rmi.RemoteException, javax.naming.NamingException
Construct a new TextAnimation without contrast to background protection and no minimum font scale.- Parameters:
source
- Locatable; the object for which the text is displayedtext
- 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 scalingsimulator
- SimulatorInterface.TimeDoubleUnit; the simulatorscaleDependentRendering
- ScaleDependentRendering; render text only when bigger than minimum scale- Throws:
javax.naming.NamingException
- when animation context cannot be created or retrievedjava.rmi.RemoteException
- when remote context cannot be found
-
TextAnimation
public TextAnimation(Locatable source, java.lang.String text, float dx, float dy, TextAlignment textAlignment, java.awt.Color color, SimulatorInterface.TimeDoubleUnit simulator, TextAnimation.ScaleDependentRendering scaleDependentRendering) throws java.rmi.RemoteException, javax.naming.NamingException
- Parameters:
source
- Locatable; the object for which the text is displayedtext
- 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 textsimulator
- SimulatorInterface.TimeDoubleUnit; the simulatorscaleDependentRendering
- ScaleDependentRendering; render text only when bigger than minimum scale- Throws:
javax.naming.NamingException
- when animation context cannot be created or retrievedjava.rmi.RemoteException
- when remote context cannot be found
-
-
Method Detail
-
getLocation
public DirectedPoint getLocation() throws java.rmi.RemoteException
- Specified by:
getLocation
in interfaceLocatable
- Throws:
java.rmi.RemoteException
-
getBounds
public final javax.media.j3d.Bounds getBounds() throws java.rmi.RemoteException
-
paint
public void paint(java.awt.Graphics2D graphics, java.awt.image.ImageObserver observer) throws java.rmi.RemoteException
paint() method so it can be overridden or extended.- Parameters:
graphics
- Graphics2D; the graphics objectobserver
- ImageObserver; the observer- Throws:
java.rmi.RemoteException
- on network exception
-
destroy
public final void destroy()
Destroy the text animation.
-
clone
public abstract TextAnimation clone(Locatable newSource, SimulatorInterface.TimeDoubleUnit newSimulator) throws java.rmi.RemoteException, javax.naming.NamingException
Clone the TextAnimation and return a copy for the new source on the new simulator.- Parameters:
newSource
- Locatable; the new source to link to the text animationnewSimulator
- SimulatorInterface.TimeDoubleUnit; the new simulator to register the animation on- Returns:
- TextAnimation; a copy of this TextAnimation
- Throws:
java.rmi.RemoteException
- when remote animation cannot be reachedjavax.naming.NamingException
- when animation name cannot be found or bound in the Context
-
getSource
protected final Locatable getSource()
Retrieve the source.- Returns:
- Locatable; 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
-
getTextAlignment
protected final TextAlignment 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
protected final java.awt.Font getFont()
Retrieve the font.- Returns:
- Font; the font
-
getText
protected final java.lang.String getText()
Retrieve the current text.- Returns:
- String; the current text
-
setText
protected final void setText(java.lang.String text)
Update the text.- Parameters:
text
- String; the new text
-
getColor
protected final java.awt.Color getColor()
Retrieve the current color.- Returns:
- Color; the current color
-
setColor
protected final void setColor(java.awt.Color color)
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
protected TextAnimation.ScaleDependentRendering getScaleDependentRendering()
Retrieve the scale dependent rendering qualifier (used in cloning).- Returns:
- ScaleDependentRendering; the rendering qualifier of this TextAnimation
-
-