1 package org.opentrafficsim.draw.gtu;
2
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.Graphics2D;
6 import java.awt.image.ImageObserver;
7 import java.rmi.RemoteException;
8 import java.util.Map;
9
10 import javax.naming.NamingException;
11
12 import org.djutils.draw.point.OrientedPoint3d;
13 import org.djutils.logger.CategoryLogger;
14 import org.opentrafficsim.core.geometry.DirectedPoint;
15 import org.opentrafficsim.draw.core.TextAlignment;
16 import org.opentrafficsim.draw.core.TextAnimation;
17 import org.opentrafficsim.road.gtu.generator.GtuGeneratorQueue;
18
19 import nl.tudelft.simulation.dsol.animation.Locatable;
20 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
21 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface.TimeDoubleUnit;
22
23
24
25
26
27
28
29
30
31
32
33
34 public class GtuGeneratorQueueAnimation extends TextAnimation
35 {
36
37
38 private static final long serialVersionUID = 20181018L;
39
40
41 private static final Font FONT = new Font("SansSerif", Font.PLAIN, 4);
42
43
44
45
46
47
48
49
50 public GtuGeneratorQueueAnimation(final GtuGeneratorQueue source, final SimulatorInterface.TimeDoubleUnit simulator)
51 throws NamingException, RemoteException
52 {
53 super(source, "", 0.0f, 0.0f, TextAlignment.CENTER, Color.BLACK, simulator, TextAnimation.RENDERWHEN1);
54 }
55
56
57 @Override
58 public void paint(final Graphics2D graphics, final ImageObserver observer)
59 {
60 try
61 {
62 graphics.setColor(Color.BLACK);
63 graphics.setFont(FONT);
64 OrientedPoint3d p = (OrientedPoint3d) getSource().getLocation();
65 Map<DirectedPoint, Integer> map = ((GtuGeneratorQueue) getSource()).getQueueLengths();
66 for (DirectedPoint lanePosition : map.keySet())
67 {
68 setText(map.get(lanePosition).toString());
69 setXY((float) (lanePosition.x - p.x), (float) (lanePosition.y - p.y));
70 super.paint(graphics, observer);
71 }
72 }
73 catch (RemoteException exception)
74 {
75 CategoryLogger.always().warn(exception);
76 }
77 }
78
79
80 @Override
81 public TextAnimation clone(final Locatable newSource, final TimeDoubleUnit newSimulator)
82 throws RemoteException, NamingException
83 {
84 return new GtuGeneratorQueueAnimation((GtuGeneratorQueue) newSource, newSimulator);
85 }
86
87 }