StaticObjectAnimation.java

  1. package org.opentrafficsim.core.object.animation;

  2. import java.awt.BasicStroke;
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.Stroke;
  6. import java.awt.image.ImageObserver;
  7. import java.io.Serializable;
  8. import java.rmi.RemoteException;

  9. import javax.naming.NamingException;

  10. import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
  11. import org.opentrafficsim.core.network.animation.PaintPolygons;
  12. import org.opentrafficsim.core.object.StaticObject;

  13. import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;

  14. /**
  15.  * <p>
  16.  * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  17.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  18.  * <p>
  19.  * $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $,
  20.  * initial version Sep 13, 2014 <br>
  21.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  22.  */
  23. public class StaticObjectAnimation extends Renderable2D implements Serializable
  24. {
  25.     /** */
  26.     private static final long serialVersionUID = 20160400L;

  27.     /** */
  28.     private float width;

  29.     /** */
  30.     private Color color;

  31.     /** */
  32.     private boolean fill;

  33.     /**
  34.      * @param source Static Object
  35.      * @param simulator simulator
  36.      * @param width width of the contour line to draw
  37.      * @param color color of the contour line / fill
  38.      * @param fill fill internal or not
  39.      * @throws NamingException for problems with registering in context
  40.      * @throws RemoteException on communication failure
  41.      */
  42.     public StaticObjectAnimation(final StaticObject source, final OTSSimulatorInterface simulator, final float width,
  43.         final Color color, final boolean fill) throws NamingException, RemoteException
  44.     {
  45.         super(source, simulator);
  46.         this.width = width;
  47.         this.color = color;
  48.         this.fill = fill;
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
  53.     {
  54.         if (this.width > 0.0f)
  55.         {
  56.             Stroke oldStroke = graphics.getStroke();
  57.             graphics.setStroke(new BasicStroke(this.width));
  58.             PaintPolygons.paintMultiPolygon(graphics, this.color, getSource().getLocation(),
  59.                 ((StaticObject) getSource()).getGeometry(), this.fill);
  60.             graphics.setStroke(oldStroke);
  61.         }
  62.     }

  63.     /**
  64.      * @return width
  65.      */
  66.     public final float getWidth()
  67.     {
  68.         return this.width;
  69.     }

  70.     /**
  71.      * @param width set width
  72.      */
  73.     public final void setWidth(final float width)
  74.     {
  75.         this.width = width;
  76.     }

  77.     /**
  78.      * @return color
  79.      */
  80.     public final Color getColor()
  81.     {
  82.         return this.color;
  83.     }

  84.     /**
  85.      * @param color set color
  86.      */
  87.     public final void setColor(final Color color)
  88.     {
  89.         this.color = color;
  90.     }

  91.     /**
  92.      * @return fill
  93.      */
  94.     public final boolean isFill()
  95.     {
  96.         return this.fill;
  97.     }

  98.     /**
  99.      * @param fill set fill
  100.      */
  101.     public final void setFill(final boolean fill)
  102.     {
  103.         this.fill = fill;
  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     public final String toString()
  108.     {
  109.         return "StaticObjectAnimation [width=" + this.width + ", color=" + this.color + ", fill=" + this.fill + "]";
  110.     }

  111. }