1 package org.opentrafficsim.road.gtu.lane.object.animation;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.geom.Rectangle2D;
6 import java.awt.image.ImageObserver;
7 import java.io.Serializable;
8 import java.rmi.RemoteException;
9
10 import javax.naming.NamingException;
11
12 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
13
14 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
15 import org.opentrafficsim.road.gtu.lane.object.LaneBlockOnOff;
16
17
18
19
20
21
22
23
24
25
26
27
28 public class DefaultBlockOnOffAnimation extends Renderable2D implements Serializable
29 {
30
31 private static final long serialVersionUID = 20160400L;
32
33
34 private final double halfWidth;
35
36
37
38
39
40
41
42
43 public DefaultBlockOnOffAnimation(final LaneBlockOnOff source, final OTSSimulatorInterface simulator)
44 throws NamingException, RemoteException
45 {
46 super(source, simulator);
47 this.halfWidth = 0.4 * source.getLane().getWidth(0.0).getSI();
48 }
49
50
51 @Override
52 public final void paint(final Graphics2D graphics, final ImageObserver observer)
53 {
54 if (((LaneBlockOnOff) this.source).isBlocked())
55 {
56 graphics.setColor(Color.RED);
57 }
58 else
59 {
60 graphics.setColor(Color.GREEN);
61 }
62 Rectangle2D rectangle = new Rectangle2D.Double(-0.4, -this.halfWidth, 0.8, 2 * this.halfWidth);
63 graphics.fill(rectangle);
64 }
65
66
67 @Override
68 public final String toString()
69 {
70 return "DefaultBlockOnOffAnimation [getSource()=" + this.getSource() + "]";
71 }
72
73 }