NodeAnimation.java
package org.opentrafficsim.core.network.animation;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.image.ImageObserver;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.naming.NamingException;
import org.opentrafficsim.core.animation.ClonableRenderable2DInterface;
import org.opentrafficsim.core.animation.TextAlignment;
import org.opentrafficsim.core.animation.TextAnimation;
import org.opentrafficsim.core.network.Node;
import nl.tudelft.simulation.dsol.animation.Locatable;
import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
/**
* <p>
* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
* BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
* <p>
* $LastChangedDate: 2018-09-19 13:55:45 +0200 (Wed, 19 Sep 2018) $, @version $Revision: 4006 $, by $Author: averbraeck $,
* initial version Oct 17, 2014 <br>
* @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
*/
public class NodeAnimation extends Renderable2D implements ClonableRenderable2DInterface, Serializable
{
/** */
private static final long serialVersionUID = 20140000L;
/** the Text object to destroy when the animation is destroyed. */
private Text text;
/**
* @param node n
* @param simulator s
* @throws NamingException when animation context cannot be found.
* @throws RemoteException on communication failure
*/
public NodeAnimation(final Node node, final SimulatorInterface.TimeDoubleUnit simulator)
throws NamingException, RemoteException
{
super(node, simulator);
this.text = new Text(node, node.getId(), 0.0f, 3.0f, TextAlignment.CENTER, Color.BLACK, simulator);
}
/** {@inheritDoc} */
@Override
public final void paint(final Graphics2D graphics, final ImageObserver observer)
{
graphics.setColor(Color.BLACK);
graphics.draw(new Ellipse2D.Double(-1.0, -1.0, 2.0, 2.0));
}
/** {@inheritDoc} */
@Override
public final void destroy() throws NamingException
{
super.destroy();
this.text.destroy();
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public ClonableRenderable2DInterface clone(final Locatable newSource, final SimulatorInterface.TimeDoubleUnit newSimulator)
throws NamingException, RemoteException
{
// the constructor also constructs the corresponding Text object
return new NodeAnimation((Node) newSource, newSimulator);
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "NodeAnimation [node=" + super.getSource() + "]";
}
/**
* Text animation for the Node. Separate class to be able to turn it on and off...
* <p>
* Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* <br>
* BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
* </p>
* $LastChangedDate: 2018-09-19 13:55:45 +0200 (Wed, 19 Sep 2018) $, @version $Revision: 4006 $, by $Author: averbraeck $,
* initial version Dec 11, 2016 <br>
* @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
* @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
* @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
*/
public class Text extends TextAnimation
{
/** */
private static final long serialVersionUID = 20161211L;
/**
* @param source the object for which the text is displayed
* @param text the text to display
* @param dx the horizontal movement of the text, in meters
* @param dy the vertical movement of the text, in meters
* @param textPlacement where to place the text
* @param color the color of the text
* @param simulator 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 textPlacement, final Color color, final SimulatorInterface.TimeDoubleUnit simulator)
throws RemoteException, NamingException
{
super(source, text, dx, dy, textPlacement, color, simulator);
setFlip(false);
setRotate(false);
}
/** {@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 "NodeAnimation.Text []";
}
}
}