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.core.dsol.OTSSimulatorInterface;
12 import org.opentrafficsim.road.network.lane.object.LaneBasedObject;
13
14 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class AbstractLineAnimation<T extends LaneBasedObject> extends Renderable2D<T>
29 {
30
31
32 private final Rectangle2D rectangle;
33
34
35 private final double halfLength;
36
37
38
39
40
41
42
43
44
45
46 public AbstractLineAnimation(final T source, final OTSSimulatorInterface 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
56
57
58 public final double getHalfLength()
59 {
60 return this.halfLength;
61 }
62
63
64 @Override
65 public void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
66 {
67 graphics.fill(this.rectangle);
68 }
69
70 }