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