package org.opentrafficsim.draw.gtu; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; import java.awt.geom.RectangularShape; import java.awt.image.ImageObserver; import java.io.Serializable; import java.rmi.RemoteException; import javax.naming.NamingException; import org.opentrafficsim.core.animation.gtu.colorer.DefaultSwitchableGTUColorer; import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer; import org.opentrafficsim.core.animation.gtu.colorer.IDGTUColorer; import org.opentrafficsim.core.gtu.GTUType; import org.opentrafficsim.draw.core.ClonableRenderable2DInterface; import org.opentrafficsim.draw.core.TextAlignment; import org.opentrafficsim.draw.core.TextAnimation; import org.opentrafficsim.road.gtu.lane.LaneBasedGTU; import org.opentrafficsim.road.gtu.lane.LaneBasedIndividualGTU; import nl.tudelft.simulation.dsol.animation.Locatable; import nl.tudelft.simulation.dsol.animation.D2.Renderable2D; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import nl.tudelft.simulation.language.d2.Angle; import nl.tudelft.simulation.language.d3.DirectedPoint; /** * Draw a car. *
* Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
* initial version 29 dec. 2014
* Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
*/
public class DefaultCarAnimation extends Renderable2D
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public class Text extends TextAnimation
{
/** */
private static final long serialVersionUID = 20161211L;
/** is the animation destroyed? */
private boolean isTextDestroyed = false;
/**
* @param source Locatable; the object for which the text is displayed
* @param text String; the text to display
* @param dx float; the horizontal movement of the text, in meters
* @param dy float; the vertical movement of the text, in meters
* @param textAlignment TextAlignment; where to place the text
* @param color Color; the color of the text
* @param simulator SimulatorInterface.TimeDoubleUnit; the simulator
* @throws NamingException when animation context cannot be created or retrieved
* @throws RemoteException - when remote context cannot be found
*/
public Text(final Locatable source, final String text, final float dx, final float dy,
final TextAlignment textAlignment, final Color color, final SimulatorInterface.TimeDoubleUnit simulator)
throws RemoteException, NamingException
{
super(source, text, dx, dy, textAlignment, color, 1.0f, 12.0f, simulator);
}
/** {@inheritDoc} */
@Override
public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
{
final LaneBasedIndividualGTU car = (LaneBasedIndividualGTU) getSource();
if (car.isDestroyed())
{
if (!this.isTextDestroyed)
{
try
{
destroy();
}
catch (Exception e)
{
System.err.println("Error while destroying text animation of GTU " + car.getId());
}
this.isTextDestroyed = true;
}
return;
}
super.paint(graphics, observer);
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public DirectedPoint getLocation() throws RemoteException
{
// draw always on top, and not upside down.
DirectedPoint p = ((LaneBasedIndividualGTU) getSource()).getLocation();
double a = Angle.normalizePi(p.getRotZ());
if (a > Math.PI / 2.0 || a < -0.99 * Math.PI / 2.0)
{
a += Math.PI;
}
return new DirectedPoint(p.x, p.y, Double.MAX_VALUE, 0.0, 0.0, a);
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public TextAnimation clone(final Locatable newSource, final SimulatorInterface.TimeDoubleUnit newSimulator)
throws RemoteException, NamingException
{
return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "Text [isTextDestroyed=" + this.isTextDestroyed + "]";
}
}
}