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>coordTypesstatic intDRAW_FASTstatic intDRAW_MAPstatic intDRAW_NORMALstatic intDRAW_SCREENAttributeListdrawing_attributesjava.awt.Graphics2Dg2d -
Constructor Summary
Constructors Constructor Description DrawingEngine()DrawingEngine(Map2D thisMap) -
Method Summary
Modifier and Type Method Description booleancallMethod(java.lang.String operation, java.lang.String method, java.util.ArrayList<?> params, ProgressUpdater progress)Calls the specified operation/method pair.booleancallMethod(java.lang.String operation, java.lang.String method, ProgressUpdater progress)Calls the specified operation/method pair.voiddrawCircle2D(java.awt.Graphics2D g, Circle2D thisCircle)Draws aCircle2DobjectvoiddrawEllipse2D(java.awt.Graphics2D g, Ellipse2D ellipse)Draws a 2D ellipse.voiddrawGrid2D(java.awt.Graphics2D g, Graphic2DGrid grid, boolean isMajor)Draw aGraphic2DGridobject.voiddrawImage2D(java.awt.Graphics2D graphics, Rect2D bounds, java.awt.image.BufferedImage image)Draws an image to fit a given rectangular bounds.voiddrawLabels2D(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.voiddrawLabels2D(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.voiddrawLine2D(java.awt.Graphics2D g, LineSegment2D thisLine)Draws a 2D line segment.voiddrawLine2D(java.awt.Graphics2D g, LineSegment2D thisLine, boolean setAttr)Draws a 2D line segment.voiddrawMesh2D(java.awt.Graphics2D g, java.util.ArrayList<org.jogamp.vecmath.Point2f[]> edges, float alpha)Draw a mesh intersection with the current line colourvoiddrawMesh2D(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 endpointsvoiddrawPoint2D(java.awt.Graphics2D g, Point2D pt, float size)Draws a Point2D object.voiddrawPointSet2D(java.awt.Graphics2D g, PointSet2D point_set, float size, NodeShape shape, java.util.ArrayList<Colour> colours, float alpha)Draws a PointSet3D with the specified parametersvoiddrawPointSet2D(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 parametersvoiddrawPolygon2D(java.awt.Graphics2D g, Polygon2D thisPoly)Draws a Polygon2D object.voiddrawPolygon2DLabels(java.awt.Graphics2D g, Polygon2D thisPoly, java.lang.String preStr)Draws labels on the vertices of a polygon object, offset to the right (East).voiddrawPolygon2DLine(java.awt.Graphics2D g, Polygon2D thisPoly)voiddrawPolygon2DNodes(java.awt.Graphics2D g, Polygon2D thisPoly)voiddrawRadius2D(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt)voiddrawRadius2D(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt, boolean showNodes)voiddrawRadius2DNode(java.awt.Graphics g, Radius2D thisRadius, org.jogamp.vecmath.Point2f centerPt, int nodeSize)voiddrawRect2D(java.awt.Graphics2D graphics, Rect2D rectangle)Draws and fills a rectangle.voiddrawSegmentData2D(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.voiddrawText2D(java.awt.Graphics2D g, Text2D text)Draws aText2Dobject.voiddrawVector2D(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.AttributeListgetAttributes()Returns the list of current attributes for this object.AttributeListgetAttributes(java.lang.String operation, java.lang.String method)Returns the attributes list corresponding to theoperationandmethod.java.lang.ObjectgetAttributeValue(java.lang.String name)Gets the value of attributename, ornullif it does not exist.static java.util.HashMap<java.lang.Integer,java.lang.String>getCoordTypes()Map2DgetMap()Returns the current Map2D for this drawing engine.floatgetMapDist(int screen_dist)java.util.ArrayList<java.lang.String>getMethods(java.lang.String operation)Returns a list of methods implementing a particularoperation.java.lang.StringgetName()Gets the name for this object.java.util.ArrayList<java.lang.String>getOperations()Returns a list of the operations available for thisEngine.java.awt.RectanglegetScreenBounds(Rect2D bounds)Returns the screen bounds ofbounds, a 2D rectangular boundary in model space.intgetScreenDist(double coordDist)java.awt.PointgetScreenPoint(org.jogamp.vecmath.Point2d thisPoint)Returns the screen coordinate ofpoint, a 2D location in model space.java.awt.PointgetScreenPoint(org.jogamp.vecmath.Point2f thisPoint)Returns the screen coordinate ofpoint, a 2D location in model space.booleanhasMap()protected java.awt.AlphaCompositemakeAlphaComposite(float alpha)voidreset(java.awt.Graphics2D g)voidsetAttribute(java.lang.String attrName, java.lang.Object newValue)Sets a value for a specific attribute.voidsetAttributes(AttributeList attr)Sets the list of attributes for this object.voidsetCoordSys(int newSys)voidsetDrawMode(int mode)voidsetGraphics2D(java.awt.Graphics2D g)voidsetMap(Map2D thisMap)voidsetName(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:NamedObjectGets the name for this object.- Specified by:
getNamein interfaceNamedObject- Returns:
-
setName
public void setName(java.lang.String name)Description copied from interface:NamedObjectSets the name for this object.- Specified by:
setNamein 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:EngineReturns the attributes list corresponding to theoperationandmethod.- Specified by:
getAttributesin interfaceEngine- Returns:
- The corresponding attributes, or
nullif no such combination ofoperation/methodexists.
-
getOperations
public java.util.ArrayList<java.lang.String> getOperations()Description copied from interface:EngineReturns a list of the operations available for thisEngine. Operations signify a general operation, which can be implemented through any number of "methods".- Specified by:
getOperationsin interfaceEngine- Returns:
-
getMethods
public java.util.ArrayList<java.lang.String> getMethods(java.lang.String operation)Description copied from interface:EngineReturns a list of methods implementing a particularoperation.- Specified by:
getMethodsin interfaceEngine- Returns:
-
callMethod
public boolean callMethod(java.lang.String operation, java.lang.String method, ProgressUpdater progress)Description copied from interface:EngineCalls the specified operation/method pair. Returnstrueif the operation was successful.- Specified by:
callMethodin interfaceEngine- Parameters:
operation- Operation to perform.method- Method with which to perform operation. Can benullif 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:EngineCalls the specified operation/method pair. Returnstrueif the operation was successful.- Specified by:
callMethodin interfaceEngine- Parameters:
operation- Operation to perform.method- Method with which to perform operation. Can benullif 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:AttributeObjectSets the list of attributes for this object.- Specified by:
setAttributesin 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 aGraphic2DGridobject.- 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_valueandmax_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 aText2Dobject.- Parameters:
g-text-
-
drawCircle2D
Draws aCircle2Dobject- 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:AttributeObjectReturns a specific attribute for this object.- Specified by:
getAttributein interfaceAttributeObject- Returns:
-
getAttributeValue
public java.lang.Object getAttributeValue(java.lang.String name)Description copied from interface:AttributeObjectGets the value of attributename, ornullif it does not exist.- Specified by:
getAttributeValuein interfaceAttributeObject- Parameters:
name- Name of the attribute- Returns:
- the value of attribute
name, ornullif it does not exist
-
getAttributes
Description copied from interface:AttributeObjectReturns the list of current attributes for this object.- Specified by:
getAttributesin interfaceAttributeObject- Returns:
-
setAttribute
public void setAttribute(java.lang.String attrName, java.lang.Object newValue)Description copied from interface:AttributeObjectSets a value for a specific attribute.- Specified by:
setAttributein interfaceAttributeObject
-