Class DrawingEngine

java.lang.Object
mgui.interfaces.graphics.util.DrawingEngine
All Implemented Interfaces:
AttributeObject, NamedObject, Engine
Direct Known Subclasses:
MorphDrawEngine

public class DrawingEngine
extends java.lang.Object
implements Engine
Utility class to perform drawing of Shape2DInt shapes on a Graphics2D. Has specific functions for specific shapes. New subclasses of Shape2DInt should perform their drawing in a method contained in this class, or subclasses of it. TODO: Implement a renderer framework
Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected static java.util.HashMap<java.lang.Integer,​java.lang.String> coordTypes  
    static int DRAW_FAST  
    static int DRAW_MAP  
    static int DRAW_NORMAL  
    static int DRAW_SCREEN  
    AttributeList drawing_attributes  
    java.awt.Graphics2D g2d  
  • Constructor Summary

    Constructors
    Constructor Description
    DrawingEngine()  
    DrawingEngine​(Map2D thisMap)  
  • Method Summary

    Modifier and Type Method Description
    boolean callMethod​(java.lang.String operation, java.lang.String method, java.util.ArrayList<?> params, ProgressUpdater progress)
    Calls the specified operation/method pair.
    boolean callMethod​(java.lang.String operation, java.lang.String method, ProgressUpdater progress)
    Calls the specified operation/method pair.
    void drawCircle2D​(java.awt.Graphics2D g, Circle2D thisCircle)
    Draws a Circle2D object
    void drawEllipse2D​(java.awt.Graphics2D g, Ellipse2D ellipse)
    Draws a 2D ellipse.
    void drawGrid2D​(java.awt.Graphics2D g, Graphic2DGrid grid, boolean isMajor)
    Draw a Graphic2DGrid object.
    void drawImage2D​(java.awt.Graphics2D graphics, Rect2D bounds, java.awt.image.BufferedImage image)
    Draws an image to fit a given rectangular bounds.
    void drawLabels2D​(java.awt.Graphics2D g, java.awt.geom.Rectangle2D vertex_bounds, java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices, java.util.ArrayList<java.lang.String> labels)
    Draws labels at the specified vertices, given the current attributes.
    void drawLabels2D​(java.awt.Graphics2D g, java.awt.geom.Rectangle2D vertex_bounds, java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices, java.util.ArrayList<java.lang.String> labels, float alpha)
    Draws labels at the specified vertices, given the current attributes.
    void drawLine2D​(java.awt.Graphics2D g, LineSegment2D thisLine)
    Draws a 2D line segment.
    void drawLine2D​(java.awt.Graphics2D g, LineSegment2D thisLine, boolean setAttr)
    Draws a 2D line segment.
    void drawMesh2D​(java.awt.Graphics2D g, java.util.ArrayList<org.jogamp.vecmath.Point2f[]> edges, float alpha)
    Draw a mesh intersection with the current line colour
    void drawMesh2D​(java.awt.Graphics2D g, java.util.ArrayList<org.jogamp.vecmath.Point2f[]> edges, java.util.ArrayList<Colour> colours, float alpha)
    Draw a mesh intersection, by painting the line according to colours, where colours is an n * 2 array specifying the colours for each edge's endpoints
    void drawPoint2D​(java.awt.Graphics2D g, Point2D pt, float size)
    Draws a Point2D object.
    void drawPointSet2D​(java.awt.Graphics2D g, PointSet2D point_set, float size, NodeShape shape, java.util.ArrayList<Colour> colours, float alpha)
    Draws a PointSet3D with the specified parameters
    void drawPointSet2D​(java.awt.Graphics2D g, PointSet2D point_set, float size, NodeShape shape, java.util.ArrayList<Colour> colours, float alpha, java.util.ArrayList<java.lang.String> labels)
    Draws a PointSet3D with the specified parameters
    void drawPolygon2D​(java.awt.Graphics2D g, Polygon2D thisPoly)
    Draws a Polygon2D object.
    void drawPolygon2DLabels​(java.awt.Graphics2D g, Polygon2D thisPoly, java.lang.String preStr)
    Draws labels on the vertices of a polygon object, offset to the right (East).
    void drawPolygon2DLine​(java.awt.Graphics2D g, Polygon2D thisPoly)  
    void drawPolygon2DNodes​(java.awt.Graphics2D g, Polygon2D thisPoly)  
    void drawRadius2D​(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt)  
    void drawRadius2D​(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt, boolean showNodes)  
    void drawRadius2DNode​(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt, int nodeSize)  
    void drawRect2D​(java.awt.Graphics2D graphics, Rect2D rectangle)
    Draws and fills a rectangle.
    void drawSegmentData2D​(java.awt.Graphics2D g, LineSegment2D segment, java.util.ArrayList<MguiNumber> plotted_data, float min_value, float max_value, float offset, float height)
    Draws data as a line plot beside segment.
    void drawText2D​(java.awt.Graphics2D g, Text2D text)
    Draws a Text2D object.
    void drawVector2D​(java.awt.Graphics2D g, Vector2D v, Point2DShape start_point, Point2DShape arrow, float alpha)  
    Attribute<?> getAttribute​(java.lang.String attrName)
    Returns a specific attribute for this object.
    AttributeList getAttributes()
    Returns the list of current attributes for this object.
    AttributeList getAttributes​(java.lang.String operation, java.lang.String method)
    Returns the attributes list corresponding to the operation and method.
    java.lang.Object getAttributeValue​(java.lang.String name)
    Gets the value of attribute name, or null if it does not exist.
    static java.util.HashMap<java.lang.Integer,​java.lang.String> getCoordTypes()  
    Map2D getMap()
    Returns the current Map2D for this drawing engine.
    float getMapDist​(int screen_dist)  
    java.util.ArrayList<java.lang.String> getMethods​(java.lang.String operation)
    Returns a list of methods implementing a particular operation.
    java.lang.String getName()
    Gets the name for this object.
    java.util.ArrayList<java.lang.String> getOperations()
    Returns a list of the operations available for this Engine.
    java.awt.Rectangle getScreenBounds​(Rect2D bounds)
    Returns the screen bounds of bounds, a 2D rectangular boundary in model space.
    int getScreenDist​(double coordDist)  
    java.awt.Point getScreenPoint​(org.jogamp.vecmath.Point2d thisPoint)
    Returns the screen coordinate of point, a 2D location in model space.
    java.awt.Point getScreenPoint​(org.jogamp.vecmath.Point2f thisPoint)
    Returns the screen coordinate of point, a 2D location in model space.
    boolean hasMap()  
    protected java.awt.AlphaComposite makeAlphaComposite​(float alpha)  
    void reset​(java.awt.Graphics2D g)  
    void setAttribute​(java.lang.String attrName, java.lang.Object newValue)
    Sets a value for a specific attribute.
    void setAttributes​(AttributeList attr)
    Sets the list of attributes for this object.
    void setCoordSys​(int newSys)  
    void setDrawMode​(int mode)  
    void setGraphics2D​(java.awt.Graphics2D g)  
    void setMap​(Map2D thisMap)  
    void setName​(java.lang.String name)
    Sets the name for this object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • coordTypes

      protected static java.util.HashMap<java.lang.Integer,​java.lang.String> coordTypes
    • g2d

      public java.awt.Graphics2D g2d
    • drawing_attributes

      public AttributeList drawing_attributes
    • DRAW_MAP

      public static final int DRAW_MAP
      See Also:
      Constant Field Values
    • DRAW_SCREEN

      public static final int DRAW_SCREEN
      See Also:
      Constant Field Values
    • DRAW_NORMAL

      public static final int DRAW_NORMAL
      See Also:
      Constant Field Values
    • DRAW_FAST

      public static final int DRAW_FAST
      See Also:
      Constant Field Values
  • Constructor Details

    • DrawingEngine

      public DrawingEngine()
    • DrawingEngine

      public DrawingEngine​(Map2D thisMap)
  • Method Details

    • getName

      public java.lang.String getName()
      Description copied from interface: NamedObject
      Gets the name for this object.
      Specified by:
      getName in interface NamedObject
      Returns:
    • setName

      public void setName​(java.lang.String name)
      Description copied from interface: NamedObject
      Sets the name for this object.
      Specified by:
      setName in interface NamedObject
    • getCoordTypes

      public static java.util.HashMap<java.lang.Integer,​java.lang.String> getCoordTypes()
    • reset

      public void reset​(java.awt.Graphics2D g)
    • getAttributes

      public AttributeList getAttributes​(java.lang.String operation, java.lang.String method)
      Description copied from interface: Engine
      Returns the attributes list corresponding to the operation and method.
      Specified by:
      getAttributes in interface Engine
      Returns:
      The corresponding attributes, or null if no such combination of operation/ method exists.
    • getOperations

      public java.util.ArrayList<java.lang.String> getOperations()
      Description copied from interface: Engine
      Returns a list of the operations available for this Engine. Operations signify a general operation, which can be implemented through any number of "methods".
      Specified by:
      getOperations in interface Engine
      Returns:
    • getMethods

      public java.util.ArrayList<java.lang.String> getMethods​(java.lang.String operation)
      Description copied from interface: Engine
      Returns a list of methods implementing a particular operation.
      Specified by:
      getMethods in interface Engine
      Returns:
    • callMethod

      public boolean callMethod​(java.lang.String operation, java.lang.String method, ProgressUpdater progress)
      Description copied from interface: Engine
      Calls the specified operation/method pair. Returns true if the operation was successful.
      Specified by:
      callMethod in interface Engine
      Parameters:
      operation - Operation to perform.
      method - Method with which to perform operation. Can be null if this operation has no sub-methods
      progress - Optional progress updater (can be null)
      Returns:
    • callMethod

      public boolean callMethod​(java.lang.String operation, java.lang.String method, java.util.ArrayList<?> params, ProgressUpdater progress)
      Description copied from interface: Engine
      Calls the specified operation/method pair. Returns true if the operation was successful.
      Specified by:
      callMethod in interface Engine
      Parameters:
      operation - Operation to perform.
      method - Method with which to perform operation. Can be null if this operation has no sub-methods
      params - A list of additional parameters (not in the attributes) for this method
      progress - Optional progress updater (can be null)
      Returns:
    • setAttributes

      public void setAttributes​(AttributeList attr)
      Description copied from interface: AttributeObject
      Sets the list of attributes for this object.
      Specified by:
      setAttributes in interface AttributeObject
    • setDrawMode

      public void setDrawMode​(int mode)
    • setCoordSys

      public void setCoordSys​(int newSys)
    • setGraphics2D

      public void setGraphics2D​(java.awt.Graphics2D g)
    • setMap

      public void setMap​(Map2D thisMap)
    • getMap

      public Map2D getMap()
      Returns the current Map2D for this drawing engine.
      Returns:
    • hasMap

      public boolean hasMap()
    • getScreenPoint

      public java.awt.Point getScreenPoint​(org.jogamp.vecmath.Point2d thisPoint)
      Returns the screen coordinate of point, a 2D location in model space.
      Parameters:
      thisPoint -
      Returns:
    • getScreenPoint

      public java.awt.Point getScreenPoint​(org.jogamp.vecmath.Point2f thisPoint)
      Returns the screen coordinate of point, a 2D location in model space.
      Parameters:
      thisPoint -
      Returns:
    • getScreenBounds

      public java.awt.Rectangle getScreenBounds​(Rect2D bounds)
      Returns the screen bounds of bounds, a 2D rectangular boundary in model space.
      Parameters:
      thisPoint -
      Returns:
    • getScreenDist

      public int getScreenDist​(double coordDist)
    • getMapDist

      public float getMapDist​(int screen_dist)
    • drawGrid2D

      public void drawGrid2D​(java.awt.Graphics2D g, Graphic2DGrid grid, boolean isMajor)
      Draw a Graphic2DGrid object.
      Parameters:
      g -
      grid -
      isMajor -
    • drawPolygon2D

      public void drawPolygon2D​(java.awt.Graphics2D g, Polygon2D thisPoly)
      Draws a Polygon2D object.
      Parameters:
      g -
      thisPoly -
    • drawPolygon2DLine

      public void drawPolygon2DLine​(java.awt.Graphics2D g, Polygon2D thisPoly)
    • drawMesh2D

      public void drawMesh2D​(java.awt.Graphics2D g, java.util.ArrayList<org.jogamp.vecmath.Point2f[]> edges, float alpha)
      Draw a mesh intersection with the current line colour
      Parameters:
      g -
      edges -
    • drawMesh2D

      public void drawMesh2D​(java.awt.Graphics2D g, java.util.ArrayList<org.jogamp.vecmath.Point2f[]> edges, java.util.ArrayList<Colour> colours, float alpha)
      Draw a mesh intersection, by painting the line according to colours, where colours is an n * 2 array specifying the colours for each edge's endpoints
      Parameters:
      g -
      edges -
      colours -
    • drawPolygon2DNodes

      public void drawPolygon2DNodes​(java.awt.Graphics2D g, Polygon2D thisPoly)
    • drawPointSet2D

      public void drawPointSet2D​(java.awt.Graphics2D g, PointSet2D point_set, float size, NodeShape shape, java.util.ArrayList<Colour> colours, float alpha)
      Draws a PointSet3D with the specified parameters
      Parameters:
      g -
      point_set -
      size -
      shape -
      colours -
      alpha -
    • drawPointSet2D

      public void drawPointSet2D​(java.awt.Graphics2D g, PointSet2D point_set, float size, NodeShape shape, java.util.ArrayList<Colour> colours, float alpha, java.util.ArrayList<java.lang.String> labels)
      Draws a PointSet3D with the specified parameters
      Parameters:
      g -
      point_set -
      size -
      shape -
      colours -
      alpha -
    • drawLabels2D

      public void drawLabels2D​(java.awt.Graphics2D g, java.awt.geom.Rectangle2D vertex_bounds, java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices, java.util.ArrayList<java.lang.String> labels)
      Draws labels at the specified vertices, given the current attributes.
      Parameters:
      g - The Graphics context
      node_shape - The shape for vertex rendering
      size - The size of the vertex shape
      vertices - List of vertices to
      labels -
    • drawLabels2D

      public void drawLabels2D​(java.awt.Graphics2D g, java.awt.geom.Rectangle2D vertex_bounds, java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices, java.util.ArrayList<java.lang.String> labels, float alpha)
      Draws labels at the specified vertices, given the current attributes.
      Parameters:
      g - The Graphics context
      node_shape - The shape for vertex rendering
      size - The size of the vertex shape
      vertices - List of vertices to
      labels -
    • drawPoint2D

      public void drawPoint2D​(java.awt.Graphics2D g, Point2D pt, float size)
      Draws a Point2D object.
      Parameters:
      g -
      pt -
      size -
    • drawVector2D

      public void drawVector2D​(java.awt.Graphics2D g, Vector2D v, Point2DShape start_point, Point2DShape arrow, float alpha)
    • drawSegmentData2D

      public void drawSegmentData2D​(java.awt.Graphics2D g, LineSegment2D segment, java.util.ArrayList<MguiNumber> plotted_data, float min_value, float max_value, float offset, float height)
      Draws data as a line plot beside segment. Data will be plotted between min_value and max_value. TODO: label axes
      Parameters:
      g -
      segment -
      plotted_data - The data to plot
      min_value - Value at bottom of plot
      max_value - Value at top of plot
      offset - The offset from the segment to the plot
      height - The height of the plot
    • drawPolygon2DLabels

      public void drawPolygon2DLabels​(java.awt.Graphics2D g, Polygon2D thisPoly, java.lang.String preStr)
      Draws labels on the vertices of a polygon object, offset to the right (East). TODO: specify the label position
      Parameters:
      g -
      thisPoly -
      preStr -
    • drawText2D

      public void drawText2D​(java.awt.Graphics2D g, Text2D text)
      Draws a Text2D object.
      Parameters:
      g -
      text -
    • drawCircle2D

      public void drawCircle2D​(java.awt.Graphics2D g, Circle2D thisCircle)
      Draws a Circle2D object
      Parameters:
      g -
      thisCircle -
    • drawLine2D

      public void drawLine2D​(java.awt.Graphics2D g, LineSegment2D thisLine)
      Draws a 2D line segment.
      Parameters:
      g -
      thisLine -
    • drawLine2D

      public void drawLine2D​(java.awt.Graphics2D g, LineSegment2D thisLine, boolean setAttr)
      Draws a 2D line segment.
      Parameters:
      g -
      thisLine -
      setAttr -
    • drawRadius2D

      public void drawRadius2D​(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt)
    • drawRadius2D

      public void drawRadius2D​(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt, boolean showNodes)
    • drawRadius2DNode

      public void drawRadius2DNode​(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt, int nodeSize)
    • drawRect2D

      public void drawRect2D​(java.awt.Graphics2D graphics, Rect2D rectangle)
      Draws and fills a rectangle.
      Parameters:
      g -
      r -
    • drawEllipse2D

      public void drawEllipse2D​(java.awt.Graphics2D g, Ellipse2D ellipse)
      Draws a 2D ellipse.
      Parameters:
      g -
      ellipse -
    • drawImage2D

      public void drawImage2D​(java.awt.Graphics2D graphics, Rect2D bounds, java.awt.image.BufferedImage image)
      Draws an image to fit a given rectangular bounds.
      Parameters:
      graphics -
      bounds -
      image -
    • makeAlphaComposite

      protected java.awt.AlphaComposite makeAlphaComposite​(float alpha) throws java.lang.IllegalArgumentException
      Throws:
      java.lang.IllegalArgumentException
    • getAttribute

      public Attribute<?> getAttribute​(java.lang.String attrName)
      Description copied from interface: AttributeObject
      Returns a specific attribute for this object.
      Specified by:
      getAttribute in interface AttributeObject
      Returns:
    • getAttributeValue

      public java.lang.Object getAttributeValue​(java.lang.String name)
      Description copied from interface: AttributeObject
      Gets the value of attribute name, or null if it does not exist.
      Specified by:
      getAttributeValue in interface AttributeObject
      Parameters:
      name - Name of the attribute
      Returns:
      the value of attribute name, or null if it does not exist
    • getAttributes

      public AttributeList getAttributes()
      Description copied from interface: AttributeObject
      Returns the list of current attributes for this object.
      Specified by:
      getAttributes in interface AttributeObject
      Returns:
    • setAttribute

      public void setAttribute​(java.lang.String attrName, java.lang.Object newValue)
      Description copied from interface: AttributeObject
      Sets a value for a specific attribute.
      Specified by:
      setAttribute in interface AttributeObject