1 package org.opentrafficsim.road.network.animation;
2
3 import java.awt.Graphics2D;
4 import java.awt.geom.Rectangle2D;
5 import java.awt.image.ImageObserver;
6 import java.rmi.RemoteException;
7
8 import javax.naming.NamingException;
9
10 import org.djunits.value.vdouble.scalar.Length;
11 import org.opentrafficsim.road.network.lane.object.LaneBasedObject;
12
13 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
14 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
15
16 /**
17 * Abstract class for objects that draw a line perpendicular on the lane.
18 * <p>
19 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
21 * <p>
22 * @version $Revision$, $LastChangedDate$, by $Author$, initial version 25 jan. 2017 <br>
23 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
26 * @param <T> the LaneBasedObject class of the source that indicates the location of the Renderable on the screen
27 */
28 public abstract class AbstractLineAnimation<T extends LaneBasedObject> extends Renderable2D<T>
29 {
30
31 /** Rectangle to color. */
32 private final Rectangle2D rectangle;
33
34 /** Half length, for placement of coupled text labels. */
35 private final double halfLength;
36
37 /**
38 * Construct the line animation.
39 * @param source source
40 * @param simulator the simulator to schedule on
41 * @param length length of the line, as fraction of the lane width
42 * @param width line width
43 * @throws NamingException in case of registration failure of the animation
44 * @throws RemoteException in case of remote registration failure of the animation
45 */
46 public AbstractLineAnimation(final T source, final SimulatorInterface.TimeDoubleUnit simulator, final double length, final Length width)
47 throws NamingException, RemoteException
48 {
49 super(source, simulator);
50 this.halfLength = .5 * length * source.getLane().getWidth(0.0).getSI();
51 this.rectangle = new Rectangle2D.Double(-.5 * width.si, -this.halfLength, width.si, 2 * this.halfLength);
52 }
53
54 /**
55 * Returns half the length.
56 * @return half the length
57 */
58 public final double getHalfLength()
59 {
60 return this.halfLength;
61 }
62
63 /** {@inheritDoc} */
64 @Override
65 @SuppressWarnings("checkstyle:designforextension")
66 public void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
67 {
68 graphics.fill(this.rectangle);
69 }
70
71 }