Package mgui.interfaces.graphics.util
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 aCircle2D
objectvoid
drawEllipse2D(java.awt.Graphics2D g, Ellipse2D ellipse)
Draws a 2D ellipse.void
drawGrid2D(java.awt.Graphics2D g, Graphic2DGrid grid, boolean isMajor)
Draw aGraphic2DGrid
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 colourvoid
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 endpointsvoid
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 parametersvoid
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 parametersvoid
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 besidesegment
.void
drawText2D(java.awt.Graphics2D g, Text2D text)
Draws aText2D
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 theoperation
andmethod
.java.lang.Object
getAttributeValue(java.lang.String name)
Gets the value of attributename
, ornull
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 particularoperation
.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 thisEngine
.java.awt.Rectangle
getScreenBounds(Rect2D bounds)
Returns the screen bounds ofbounds
, a 2D rectangular boundary in model space.int
getScreenDist(double coordDist)
java.awt.Point
getScreenPoint(org.jogamp.vecmath.Point2d thisPoint)
Returns the screen coordinate ofpoint
, a 2D location in model space.java.awt.Point
getScreenPoint(org.jogamp.vecmath.Point2f thisPoint)
Returns the screen coordinate ofpoint
, 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
-
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
-
-
Method Details
-
getName
public java.lang.String getName()Description copied from interface:NamedObject
Gets the name for this object.- Specified by:
getName
in interfaceNamedObject
- Returns:
-
setName
public void setName(java.lang.String name)Description copied from interface:NamedObject
Sets the name for this object.- Specified by:
setName
in interfaceNamedObject
-
getCoordTypes
public static java.util.HashMap<java.lang.Integer,java.lang.String> getCoordTypes() -
reset
public void reset(java.awt.Graphics2D g) -
getAttributes
Description copied from interface:Engine
Returns the attributes list corresponding to theoperation
andmethod
.- Specified by:
getAttributes
in interfaceEngine
- Returns:
- The corresponding attributes, or
null
if no such combination ofoperation
/method
exists.
-
getOperations
public java.util.ArrayList<java.lang.String> getOperations()Description copied from interface:Engine
Returns a list of the operations available for thisEngine
. Operations signify a general operation, which can be implemented through any number of "methods".- Specified by:
getOperations
in interfaceEngine
- 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 particularoperation
.- Specified by:
getMethods
in interfaceEngine
- 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. Returnstrue
if the operation was successful.- Specified by:
callMethod
in interfaceEngine
- Parameters:
operation
- Operation to perform.method
- Method with which to perform operation. Can benull
if this operation has no sub-methodsprogress
- Optional progress updater (can benull
)- 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. Returnstrue
if the operation was successful.- Specified by:
callMethod
in interfaceEngine
- Parameters:
operation
- Operation to perform.method
- Method with which to perform operation. Can benull
if this operation has no sub-methodsparams
- A list of additional parameters (not in the attributes) for this methodprogress
- Optional progress updater (can benull
)- Returns:
-
setAttributes
Description copied from interface:AttributeObject
Sets the list of attributes for this object.- Specified by:
setAttributes
in interfaceAttributeObject
-
setDrawMode
public void setDrawMode(int mode) -
setCoordSys
public void setCoordSys(int newSys) -
setGraphics2D
public void setGraphics2D(java.awt.Graphics2D g) -
setMap
-
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 ofpoint
, a 2D location in model space.- Parameters:
thisPoint
-- Returns:
-
getScreenPoint
public java.awt.Point getScreenPoint(org.jogamp.vecmath.Point2f thisPoint)Returns the screen coordinate ofpoint
, a 2D location in model space.- Parameters:
thisPoint
-- Returns:
-
getScreenBounds
Returns the screen bounds ofbounds
, a 2D rectangular boundary in model space.- Parameters:
thisPoint
-- Returns:
-
getScreenDist
public int getScreenDist(double coordDist) -
getMapDist
public float getMapDist(int screen_dist) -
drawGrid2D
Draw aGraphic2DGrid
object.- Parameters:
g
-grid
-isMajor
-
-
drawPolygon2D
Draws a Polygon2D object.- Parameters:
g
-thisPoly
-
-
drawPolygon2DLine
-
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
-
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 contextnode_shape
- The shape for vertex renderingsize
- The size of the vertex shapevertices
- List of vertices tolabels
-
-
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 contextnode_shape
- The shape for vertex renderingsize
- The size of the vertex shapevertices
- List of vertices tolabels
-
-
drawPoint2D
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 besidesegment
. Data will be plotted betweenmin_value
andmax_value
. TODO: label axes- Parameters:
g
-segment
-plotted_data
- The data to plotmin_value
- Value at bottom of plotmax_value
- Value at top of plotoffset
- The offset from the segment to the plotheight
- 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
Draws aText2D
object.- Parameters:
g
-text
-
-
drawCircle2D
Draws aCircle2D
object- Parameters:
g
-thisCircle
-
-
drawLine2D
Draws a 2D line segment.- Parameters:
g
-thisLine
-
-
drawLine2D
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
Draws and fills a rectangle.- Parameters:
g
-r
-
-
drawEllipse2D
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
Description copied from interface:AttributeObject
Returns a specific attribute for this object.- Specified by:
getAttribute
in interfaceAttributeObject
- Returns:
-
getAttributeValue
public java.lang.Object getAttributeValue(java.lang.String name)Description copied from interface:AttributeObject
Gets the value of attributename
, ornull
if it does not exist.- Specified by:
getAttributeValue
in interfaceAttributeObject
- Parameters:
name
- Name of the attribute- Returns:
- the value of attribute
name
, ornull
if it does not exist
-
getAttributes
Description copied from interface:AttributeObject
Returns the list of current attributes for this object.- Specified by:
getAttributes
in interfaceAttributeObject
- 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 interfaceAttributeObject
-