View Javadoc
1   package org.opentrafficsim.draw.object;
2   
3   import java.awt.BasicStroke;
4   import java.awt.Color;
5   import java.awt.Graphics2D;
6   import java.awt.Stroke;
7   import java.awt.image.ImageObserver;
8   import java.io.Serializable;
9   import java.rmi.RemoteException;
10  
11  import javax.naming.NamingException;
12  
13  import org.opentrafficsim.core.object.StaticObject;
14  import org.opentrafficsim.draw.core.PaintPolygons;
15  
16  import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
17  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
18  
19  /**
20   * <p>
21   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
23   * <p>
24   * $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $,
25   * initial version Sep 13, 2014 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   */
28  public class StaticObjectAnimation extends Renderable2D implements Serializable
29  {
30      /** */
31      private static final long serialVersionUID = 20160400L;
32  
33      /** */
34      private float width;
35  
36      /** */
37      private Color color;
38  
39      /** */
40      private boolean fill;
41  
42      /**
43       * @param source StaticObject; Static Object
44       * @param simulator SimulatorInterface.TimeDoubleUnit; simulator
45       * @param width float; width of the contour line to draw
46       * @param color Color; color of the contour line / fill
47       * @param fill boolean; fill internal or not
48       * @throws NamingException for problems with registering in context
49       * @throws RemoteException on communication failure
50       */
51      public StaticObjectAnimation(final StaticObject source, final SimulatorInterface.TimeDoubleUnit simulator,
52              final float width, final Color color, final boolean fill) throws NamingException, RemoteException
53      {
54          super(source, simulator);
55          this.width = width;
56          this.color = color;
57          this.fill = fill;
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
63      {
64          if (this.width > 0.0f)
65          {
66              Stroke oldStroke = graphics.getStroke();
67              graphics.setStroke(new BasicStroke(this.width));
68              PaintPolygons.paintMultiPolygon(graphics, this.color, getSource().getLocation(),
69                      ((StaticObject) getSource()).getGeometry(), this.fill);
70              graphics.setStroke(oldStroke);
71          }
72      }
73  
74      /**
75       * @return width
76       */
77      public final float getWidth()
78      {
79          return this.width;
80      }
81  
82      /**
83       * @param width float; set width
84       */
85      public final void setWidth(final float width)
86      {
87          this.width = width;
88      }
89  
90      /**
91       * @return color
92       */
93      public final Color getColor()
94      {
95          return this.color;
96      }
97  
98      /**
99       * @param color Color; set color
100      */
101     public final void setColor(final Color color)
102     {
103         this.color = color;
104     }
105 
106     /**
107      * @return fill
108      */
109     public final boolean isFill()
110     {
111         return this.fill;
112     }
113 
114     /**
115      * @param fill boolean; set fill
116      */
117     public final void setFill(final boolean fill)
118     {
119         this.fill = fill;
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public final String toString()
125     {
126         return "StaticObjectAnimation [width=" + this.width + ", color=" + this.color + ", fill=" + this.fill + "]";
127     }
128 
129 }