View Javadoc
1   package org.opentrafficsim.road.gtu.generator;
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 nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
13  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
14  import nl.tudelft.simulation.language.d3.DirectedPoint;
15  
16  /**
17   * Animator that displays generation queues as numbers.
18   * <p>
19   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
21   * <p>
22   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 28 dec. 2017 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
26   */
27  public class GTUGeneratorAnimation extends Renderable2D<GTUGenerator>
28  {
29      
30      /** Default font. */
31      private static final Font FONT = new Font("SansSerif", Font.PLAIN, 4);
32  
33      /**
34       * Constructor.
35       * @param source GTUGenerator; generator
36       * @param simulator SimulatorInterface&lt;?, ?, ?&gt;; simulator
37       * @throws NamingException when animation context cannot be created or retrieved
38       * @throws RemoteException when remote context cannot be found
39       */
40      public GTUGeneratorAnimation(final GTUGenerator source, final SimulatorInterface<?, ?, ?> simulator)
41              throws NamingException, RemoteException
42      {
43          super(source, simulator);
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
49      {
50          graphics.setColor(Color.BLACK);
51          graphics.setFont(FONT);
52          DirectedPoint p = getSource().getLocation();
53          Map<DirectedPoint, Integer> map = getSource().getQueueLengths();
54          for (DirectedPoint lanePosition : map.keySet())
55          {
56              graphics.drawString(map.get(lanePosition) + "", (int) (lanePosition.x - p.x), (int) (-lanePosition.y + p.y));
57          }
58      }
59  
60  }