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