1 package org.opentrafficsim.draw.road;
2
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.Graphics2D;
6 import java.awt.geom.Ellipse2D;
7 import java.awt.geom.Rectangle2D;
8 import java.awt.image.ImageObserver;
9 import java.io.Serializable;
10 import java.rmi.RemoteException;
11
12 import javax.naming.NamingException;
13
14 import org.djunits.unit.SpeedUnit;
15 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
16 import org.opentrafficsim.road.network.lane.object.SpeedSign;
17
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
19
20
21
22
23
24
25
26
27
28
29
30 public class SpeedSignAnimation extends Renderable2D<SpeedSign> implements Serializable
31 {
32
33
34 private static final long serialVersionUID = 20170420L;
35
36
37 private static final double RADIUS = 1.6;
38
39
40 private static final double EDGE = 1.3;
41
42
43
44
45
46
47
48 public SpeedSignAnimation(final SpeedSign source, final OtsSimulatorInterface simulator)
49 throws NamingException, RemoteException
50 {
51 super(source, simulator);
52 setRotate(false);
53 }
54
55
56 @Override
57 public final void paint(final Graphics2D g, final ImageObserver arg1)
58 {
59 Ellipse2D ellipse = new Ellipse2D.Double(-RADIUS, -RADIUS, 2 * RADIUS, 2 * RADIUS);
60 g.setColor(Color.RED);
61 g.fill(ellipse);
62 ellipse = new Ellipse2D.Double(-EDGE, -EDGE, 2 * EDGE, 2 * EDGE);
63 g.setColor(Color.WHITE);
64 g.fill(ellipse);
65 g.setColor(Color.BLACK);
66 int speed = (int) getSource().getSpeed().getInUnit(SpeedUnit.KM_PER_HOUR);
67 if (speed < 100)
68 {
69 g.setFont(new Font("Arial", 0, -1).deriveFont(2.0f));
70 }
71 else
72 {
73 g.setFont(new Font("Arial narrow", 0, -1).deriveFont(1.85f));
74 }
75 String str = Integer.toString(speed);
76 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(str, g);
77 g.drawString(str, (float) -stringBounds.getCenterX(), (float) -stringBounds.getCenterY());
78 }
79
80
81 @Override
82 public final String toString()
83 {
84 return "SpeedSignAnimation";
85 }
86
87 }