1
2
3
4
5
6
7
8
9
10
11 package nl.tudelft.simulation.traffic.animation;
12
13 import java.awt.BasicStroke;
14 import java.awt.Color;
15 import java.awt.Font;
16 import java.awt.Graphics2D;
17 import java.awt.geom.Line2D;
18 import java.awt.geom.Rectangle2D;
19 import java.awt.image.ImageObserver;
20 import java.rmi.RemoteException;
21
22 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
23 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
24 import nl.tudelft.simulation.traffic.controlpoint.real.SpeedSign;
25
26 /***
27 * This class is used for the animation of a speed sign.
28 * <p>
29 * (c) copyright 2004 <a href="http://www.simulation.tudelft.nl">Delft
30 * University of Technology </a>, the Netherlands.
31 * <p>
32 * See for project information <a href="http://www.simulation.tudelft.nl">
33 * www.simulation.tudelft.nl </a> <br>
34 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General
35 * Public License (GPL) </a>, no warranty <br>
36 *
37 * @version 1.0 June 1, 2004 <br>
38 * @author <a
39 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
40 * Verbraeck </a> <br>
41 */
42 public class SpeedSignAnimation extends Renderable2D
43 {
44 /*** the deltax of the place of the traffic light */
45 private double deltax;
46
47 /*** the deltay of the place of the traffic light */
48 private double deltay;
49
50 /*** the background color */
51 private Color backgroundColor;
52
53 /*** the text color */
54 private Color textColor;
55
56 /*** the line color */
57 private Color lineColor;
58
59 /***
60 * @param owner
61 * @param simulator
62 */
63 public SpeedSignAnimation(final SpeedSign owner,
64 final SimulatorInterface simulator)
65 {
66 this(owner, simulator, 0.0, 0.0, Color.BLACK, Color.YELLOW, Color.BLACK);
67 }
68
69 /***
70 * @param owner
71 * @param simulator
72 * @param deltax
73 * @param deltay
74 * @param backgroundColor
75 * @param textColor
76 * @param lineColor
77 */
78 public SpeedSignAnimation(final SpeedSign owner,
79 final SimulatorInterface simulator, final double deltax,
80 final double deltay, final Color backgroundColor,
81 final Color textColor, final Color lineColor)
82 {
83 super(owner, simulator);
84 this.deltax = deltax;
85 this.deltay = -deltay;
86 this.backgroundColor = backgroundColor;
87 this.textColor = textColor;
88 this.lineColor = lineColor;
89 }
90
91 /***
92 * @see nl.tudelft.simulation.dsol.animation.D2.Renderable2D#paint(java.awt.Graphics2D,
93 * java.awt.image.ImageObserver)
94 */
95 public void paint(Graphics2D graphics, ImageObserver imo)
96 throws RemoteException
97 {
98 SpeedSign sign = (SpeedSign) super.source;
99 graphics.setColor(this.lineColor);
100 graphics.setStroke(new BasicStroke(0.05f));
101 graphics.draw(new Line2D.Double(0, 0, this.deltax, this.deltay));
102 graphics.setColor(this.backgroundColor);
103 graphics.fill(new Rectangle2D.Double(this.deltax - 3, this.deltay - 6,
104 6, 6));
105 graphics.setColor(this.lineColor);
106 graphics.draw(new Rectangle2D.Double(this.deltax - 3, this.deltay - 6,
107 6, 6));
108 graphics.setColor(this.textColor);
109 Font font = new Font("SansSerif", Font.PLAIN, 5);
110 graphics.setFont(font);
111 graphics.drawString(sign.getText(), (float) (this.deltax - 3),
112 (float) (this.deltay - 1));
113 if (true)
114 {
115 graphics.setColor(Color.BLACK);
116 Font smallFont = new Font("SansSerif", Font.PLAIN, 2);
117 graphics.setFont(smallFont);
118 graphics.drawString(this.source.toString(),
119 (float) (this.deltax + 6), (float) (this.deltay));
120 }
121 }
122 }