Class Renderable2d<L extends Locatable>

java.lang.Object
nl.tudelft.simulation.dsol.animation.d2.Renderable2d<L>
Type Parameters:
L - the Locatable class of the source that can return the location of the Renderable on the screen
All Implemented Interfaces:
Serializable, Renderable2dInterface<L>
Direct Known Subclasses:
ImageRenderable

public abstract class Renderable2d<L extends Locatable> extends Object implements Renderable2dInterface<L>
The Renderable2d provides an easy accessible renderable object that can be drawn on an absolute or relative position, scaled, flipped, and rotated. For scaling, several options exist:
- scale: whether to scale the drawing at all; e.g. for a legend, absolute coordinates might be used (scale = false);
- scaleY: whether to scale differently in X and Y direction, e.g. for a map at higher latitudes (scaleY = true);
- scaleObject: whether to scale the drawing larger or smaller than the scale factor of the extent (e.g., to draw an object on a map where the units of the object are in meters, while the map is in lat / lon degrees).
The default values are: translate = true; scale = true; flip = false; rotate = true; scaleY = false; scaleObject = false.

Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Peter Jacobs
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Renderable2d(L source, Contextualized contextProvider)
    Constructs a new Renderable2d.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind2Context(Contextualized contextProvider)
    Bind a renderable2D to the context.
    boolean
    contains(Point2d pointWorldCoordinates, Bounds2d extent)
    does the shape contain the point?
    void
    destroy(Contextualized contextProvider)
    destroys this editable.
    long
    return the id of the renderable component.
    gets the source of this renderable.
    boolean
    Return whether to flip the renderable, if the direction is 'left' or not.
    boolean
    Return whether to rotate the renderable or not.
    boolean
    Return whether to scale the renderable or not.
    boolean
    Return whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.
    boolean
    Return whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.
    boolean
    Return whether to translate the renderable to its position or not (false means absolute position).
    abstract void
    paint(Graphics2D graphics, ImageObserver observer)
    Draws an animation on a world coordinate around [x,y] = [0,0].
    protected void
    paint(Graphics2D graphics, Bounds2d extent, Dimension screenSize, RenderableScale renderableScale, ImageObserver observer)
    The methods that actually paints the object at the right scale, rotation, and position on the screen using the user-implemented paint(graphics, observer) method to do the actual work.
    void
    paintComponent(Graphics2D graphics, Bounds2d extent, Dimension screenSize, RenderableScale renderableScale, ImageObserver observer)
    the overarching method that is called when painting, usually redirecting to paint(...) but possibly retrieving the drawing from a cache.
    void
    setFlip(boolean flip)
    Set whether to flip the renderable, if the direction is 'left' or not.
    void
    setRotate(boolean rotate)
    Set whether to rotate the renderable or not.
    void
    setScale(boolean scale)
    Set whether to scale the renderable or not.
    void
    setScaleObject(boolean scaleY)
    Set whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.
    void
    setScaleY(boolean scaleY)
    Set whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.
    void
    setTranslate(boolean translate)
    Set whether to translate the renderable to its position or not (false means absolute position).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Renderable2d

      public Renderable2d(L source, Contextualized contextProvider)
      Constructs a new Renderable2d.
      Parameters:
      source - T; the source
      contextProvider - Contextualized; the object that can provide the context to store the animation objects
  • Method Details

    • bind2Context

      public void bind2Context(Contextualized contextProvider)
      Bind a renderable2D to the context. The reason for specifying this in an independent method instead of adding the code in the constructor is related to the RFE submitted by van Houten that in specific distributed context, such binding must be overwritten.
      Parameters:
      contextProvider - Contextualized; the object that can provide the context to store the animation objects
    • isFlip

      public boolean isFlip()
      Return whether to flip the renderable, if the direction is 'left' or not.
      Returns:
      boolean; whether to flip the renderable, if the direction is 'left' or not
    • setFlip

      public void setFlip(boolean flip)
      Set whether to flip the renderable, if the direction is 'left' or not.
      Parameters:
      flip - boolean; whether to flip the renderable, if the direction is 'left' or not
    • isRotate

      public boolean isRotate()
      Return whether to rotate the renderable or not.
      Returns:
      boolean; whether to rotate the renderable or not
    • setRotate

      public void setRotate(boolean rotate)
      Set whether to rotate the renderable or not.
      Parameters:
      rotate - boolean; whether to rotate the renderable or not
    • isScale

      public boolean isScale()
      Return whether to scale the renderable or not.
      Returns:
      boolean; whether to scale the renderable or not
    • setScale

      public void setScale(boolean scale)
      Set whether to scale the renderable or not.
      Parameters:
      scale - boolean; whether to scale the renderable or not
    • isScaleY

      public boolean isScaleY()
      Return whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.
      Returns:
      boolean; whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not
    • setScaleObject

      public void setScaleObject(boolean scaleY)
      Set whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.
      Parameters:
      scaleY - boolean; whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not
    • isScaleObject

      public boolean isScaleObject()
      Return whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not.
      Returns:
      boolean; whether to scale the renderable in the X/Y-direction with the value of RenderableScale.objectScaleFactor or not
    • setScaleY

      public void setScaleY(boolean scaleY)
      Set whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not.
      Parameters:
      scaleY - boolean; whether to scale the renderable in the Y-direction when there is a compressed Y-axis or not
    • isTranslate

      public boolean isTranslate()
      Return whether to translate the renderable to its position or not (false means absolute position).
      Returns:
      boolean; whether to translate the renderable to its position or not (false means absolute position)
    • setTranslate

      public void setTranslate(boolean translate)
      Set whether to translate the renderable to its position or not (false means absolute position).
      Parameters:
      translate - boolean; whether to translate the renderable to its position or not (false means absolute position)
    • getSource

      public L getSource()
      gets the source of this renderable.
      Specified by:
      getSource in interface Renderable2dInterface<L extends Locatable>
      Returns:
      Locatable the source
    • paintComponent

      public void paintComponent(Graphics2D graphics, Bounds2d extent, Dimension screenSize, RenderableScale renderableScale, ImageObserver observer)
      the overarching method that is called when painting, usually redirecting to paint(...) but possibly retrieving the drawing from a cache.
      Specified by:
      paintComponent in interface Renderable2dInterface<L extends Locatable>
      Parameters:
      graphics - Graphics2D; the graphics object
      extent - Bounds2d; the extent of the panel
      screenSize - Dimension; the screen of the panel
      renderableScale - RenderableScale; the scale to use (usually RenderableScaleDefault where X/Y ratio is 1)
      observer - ImageObserver; the observer of the renderableInterface
    • paint

      protected void paint(Graphics2D graphics, Bounds2d extent, Dimension screenSize, RenderableScale renderableScale, ImageObserver observer)
      The methods that actually paints the object at the right scale, rotation, and position on the screen using the user-implemented paint(graphics, observer) method to do the actual work.
      Parameters:
      graphics - Graphics2D; the graphics object
      extent - Bounds2d; the extent of the panel
      screenSize - Dimension; the screen of the panel
      renderableScale - RenderableScale; the scale to use (usually RenderableScaleDefault where X/Y ratio is 1)
      observer - ImageObserver; the observer of the renderableInterface
    • contains

      public boolean contains(Point2d pointWorldCoordinates, Bounds2d extent)
      does the shape contain the point?
      Specified by:
      contains in interface Renderable2dInterface<L extends Locatable>
      Parameters:
      pointWorldCoordinates - Point2d; the point in world coordinates. Default implementation is to intersect the 3D bounds on location.z and to return the bounds2D of this intersect.
      extent - Bounds2d; the extent of the panel.
      Returns:
      whether the point is in the shape
    • destroy

      public void destroy(Contextualized contextProvider)
      destroys this editable. How to do this must be implemented by the modeler.
      Specified by:
      destroy in interface Renderable2dInterface<L extends Locatable>
      Parameters:
      contextProvider - Contextualized; the object that can provide the context to bind and unbind the animation objects
    • getId

      public long getId()
      return the id of the renderable component.
      Specified by:
      getId in interface Renderable2dInterface<L extends Locatable>
      Returns:
      long; the id of the renderable component
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • paint

      public abstract void paint(Graphics2D graphics, ImageObserver observer)
      Draws an animation on a world coordinate around [x,y] = [0,0].
      Parameters:
      graphics - Graphics2D; the graphics object
      observer - ImageObserver; the observer