DrawingInfoLine.java

  1. package org.opentrafficsim.core.animation;

  2. import java.awt.Color;

  3. /**
  4.  * DrawingInfoLine stores the drawing information about a line. This can be interpreted by a visualization or animation class.
  5.  * <br>
  6.  * <br>
  7.  * Copyright (c) 2003-2020 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
  8.  * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
  9.  * source code and binary code of this software is proprietary information of Delft University of Technology.
  10.  * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
  11.  * @param <D> The drawable type for which this is the DrawingInfo
  12.  */
  13. public class DrawingInfoLine<D extends Drawable> implements DrawingInfo
  14. {
  15.     /** lineColorer. */
  16.     private Colorer<D> lineColorer = FixedColorer.black();

  17.     /** lineWidth, to be interpreted by the animation package; could be relative. */
  18.     private float lineWidth = 1.0f;

  19.     /**
  20.      * Create an empty DrawingInfo object for a line.
  21.      */
  22.     public DrawingInfoLine()
  23.     {
  24.     }

  25.     /**
  26.      * Create a DrawingInfo object for a line.
  27.      * @param lineColor Color; the line color
  28.      * @param lineWidth float; the line width, which could be relative and is open for interpretation by the visualization or
  29.      *            animation class
  30.      */
  31.     public DrawingInfoLine(final Color lineColor, final float lineWidth)
  32.     {
  33.         setLineColor(lineColor);
  34.         this.lineWidth = lineWidth;
  35.     }

  36.     /**
  37.      * Create a DrawingInfo object for a line.
  38.      * @param lineColorer Colorer&lt;D&gt;; the line colorer
  39.      * @param lineWidth float; the line width, which could be relative and is open for interpretation by the visualization or
  40.      *            animation class
  41.      */
  42.     public DrawingInfoLine(final Colorer<D> lineColorer, final float lineWidth)
  43.     {
  44.         setLineColorer(lineColorer);
  45.         this.lineWidth = lineWidth;
  46.     }

  47.     /**
  48.      * The returned color could be dependent on the state of the object representing the line. E.g., it turns red under certain
  49.      * circumstances.
  50.      * @param drawable D; the object that could influence the color of the line
  51.      * @return the color of the line
  52.      */
  53.     public final Color getLineColor(final D drawable)
  54.     {
  55.         return this.lineColorer.getColor(drawable);
  56.     }

  57.     /**
  58.      * Set the line color using a FixedColorer.
  59.      * @param lineColor Color; lineColor to set
  60.      */
  61.     public final void setLineColor(final Color lineColor)
  62.     {
  63.         this.lineColorer = FixedColorer.create(lineColor);
  64.     }

  65.     /**
  66.      * Set the line colorer.
  67.      * @param lineColorer Colorer&lt;D&gt;; lineColorer to set
  68.      */
  69.     public final void setLineColorer(final Colorer<D> lineColorer)
  70.     {
  71.         this.lineColorer = lineColorer;
  72.     }

  73.     /**
  74.      * @return lineWidth
  75.      */
  76.     public final float getLineWidth()
  77.     {
  78.         return this.lineWidth;
  79.     }

  80.     /**
  81.      * @param lineWidth float; lineWidth to set
  82.      */
  83.     public final void setLineWidth(final float lineWidth)
  84.     {
  85.         this.lineWidth = lineWidth;
  86.     }
  87. }