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.Ellipse2D;
18 import java.awt.geom.Line2D;
19 import java.awt.geom.Rectangle2D;
20 import java.awt.image.ImageObserver;
21 import java.rmi.RemoteException;
22
23 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
24 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
25 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
26 import nl.tudelft.simulation.traffic.controlpoint.blocks.BlockTrafficLight;
27 import nl.tudelft.simulation.traffic.controlpoint.blocks.SwitchBlockTrafficLight;
28
29 /***
30 * This class is used for the animation of a green / red / yellow + green block
31 * traffic light.
32 * <p>
33 * (c) copyright 2004 <a href="http://www.simulation.tudelft.nl">Delft
34 * University of Technology </a>, the Netherlands.
35 * <p>
36 * See for project information <a href="http://www.simulation.tudelft.nl">
37 * www.simulation.tudelft.nl </a> <br>
38 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General
39 * Public License (GPL) </a>, no warranty <br>
40 *
41 * @version 1.0 June 1, 2004 <br>
42 * @author <a
43 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
44 * Verbraeck </a> <br>
45 * <b>Original version: </b> H.W.G. Phaff & J.H. Kwakkel
46 * @see nl.tudelft.simulation.traffic.track.TrackInterface
47 */
48 public class SwitchBlockTrafficLightAnimation extends Renderable2D
49 {
50 /*** the deltax of the place of the traffic light */
51 private double deltax;
52
53 /*** the deltay of the place of the traffic light */
54 private double deltay;
55
56 /***
57 * @param owner
58 * @param simulator
59 */
60 public SwitchBlockTrafficLightAnimation(final LocatableInterface owner,
61 final SimulatorInterface simulator)
62 {
63 this(owner, simulator, 0.0, 0.0);
64 }
65
66 /***
67 * @param owner
68 * @param simulator
69 * @param deltax
70 * @param deltay
71 */
72 public SwitchBlockTrafficLightAnimation(final LocatableInterface owner,
73 final SimulatorInterface simulator, final double deltax,
74 final double deltay)
75 {
76 super(owner, simulator);
77 this.deltax = deltax;
78 this.deltay = -deltay;
79 }
80
81 /***
82 * @see nl.tudelft.simulation.dsol.animation.D2.Renderable2D#paint(java.awt.Graphics2D,
83 * java.awt.image.ImageObserver)
84 */
85 public void paint(Graphics2D graphics, ImageObserver imo)
86 throws RemoteException
87 {
88 SwitchBlockTrafficLight trafficLight = (SwitchBlockTrafficLight) super.source;
89 graphics.setColor(Color.BLACK);
90 graphics.setStroke(new BasicStroke(0.05f));
91 graphics.draw(new Line2D.Double(0, 0, this.deltax, this.deltay));
92 graphics.fill(new Rectangle2D.Double(this.deltax - 2, this.deltay - 12,
93 4, 12));
94 String state = trafficLight.getCurrentState();
95 if (state == BlockTrafficLight.STATE_GREEN)
96 {
97 graphics.setColor(Color.GREEN);
98 graphics.fill(new Ellipse2D.Double(this.deltax - 1.5,
99 this.deltay - 3.5, 3, 3));
100 } else if (state == BlockTrafficLight.STATE_RED)
101 {
102 graphics.setColor(Color.RED);
103 graphics.fill(new Ellipse2D.Double(this.deltax - 1.5,
104 this.deltay - 7.5, 3, 3));
105 } else if (state == BlockTrafficLight.STATE_YELLOW)
106 {
107 graphics.setColor(Color.GREEN);
108 graphics.fill(new Ellipse2D.Double(this.deltax - 1.5,
109 this.deltay - 3.5, 3, 3));
110 graphics.setColor(Color.YELLOW);
111 graphics.fill(new Ellipse2D.Double(this.deltax - 1.5,
112 this.deltay - 11.5, 3, 3));
113 }
114 if (true)
115 {
116 graphics.setColor(Color.BLACK);
117 Font smallFont = new Font("SansSerif", Font.PLAIN, 2);
118 graphics.setFont(smallFont);
119 graphics.drawString(this.source.toString(),
120 (float) (this.deltax + 4), (float) (this.deltay));
121 }
122 }
123 }