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