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-2019 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.         super();
  25.     }

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

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

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

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

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

  76.     /**
  77.      * @return lineWidth
  78.      */
  79.     public final float getLineWidth()
  80.     {
  81.         return this.lineWidth;
  82.     }

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