JGraph X 1.2.0.8


com.mxgraph.canvas
Class mxGraphics2DCanvas

java.lang.Object
  extended by com.mxgraph.canvas.mxBasicCanvas
      extended by com.mxgraph.canvas.mxGraphics2DCanvas
All Implemented Interfaces:
mxICanvas
Direct Known Subclasses:
mxInteractiveCanvas

public class mxGraphics2DCanvas
extends mxBasicCanvas

An implementation of a canvas that uses Graphics2D for painting.


Field Summary
protected  Graphics2D g
          Global graphics handle to the image.
protected  Hashtable<String,Image> imageCache
          Cache for images.
protected  CellRendererPane rendererPane
          Optional renderer pane to be used for HTML label rendering.
 
Fields inherited from class com.mxgraph.canvas.mxBasicCanvas
DEFAULT_IMAGEBASEPATH, drawLabels, imageBasePath, scale, translate
 
Constructor Summary
mxGraphics2DCanvas()
          Constructs a new graphics canvas with an empty graphics object.
mxGraphics2DCanvas(Graphics2D g)
          Constructs a new graphics canvas for the given graphics object.
 
Method Summary
protected  Polygon createArrow(mxPoint p0, mxPoint pe)
          Creates a polygon that represents an arrow.
protected  void drawActor(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws an actor shape for the given parameters.
protected  void drawArrow(List<mxPoint> pts, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws the given arrow shape.
protected  void drawCloud(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws a cloud shape for the given parameters.
protected  void drawConnector(List<mxPoint> pts, float penWidth, Color penColor, Object startMarker, float startSize, Object endMarker, float endSize, boolean dashed, boolean rounded)
          Draws the given connector shape.
protected  void drawCylinder(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean isShadow)
          Draws a cylinder for the given parameters.
 Object drawEdge(List<mxPoint> pts, Map<String,Object> style)
          Draws the given edge.
protected  void drawHexagon(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow, String direction)
          Draws a hexagon shape for the given parameters.
protected  void drawHtmlText(String text, int x, int y, int w, int h, Map<String,Object> style)
          Draws the specified HTML markup.
protected  void drawImage(int x, int y, int w, int h, String image)
          Draws an image for the given parameters.
 Object drawLabel(String label, int x, int y, int w, int h, Map<String,Object> style, boolean isHtml)
          Draws the given label.
 void drawLine(int x0, int y0, int x1, int y1)
          Draws the given line if the line is inside the clipping area.
 void drawLine(List<mxPoint> pts, Map<String,Object> style)
          Draws the given lines as segments between all points of the given list of mxPoints.
 mxPoint drawMarker(Object type, mxPoint p0, mxPoint pe, float size, float strokeWidth)
          Draws the given type of marker.
protected  void drawOval(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws an oval for the given parameters.
protected  void drawPath(GeneralPath path, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws a path for the given parameters.
protected  void drawPlainText(String text, int x, int y, int w, int h, Map<String,Object> style)
          Draws the specified string as plain text.
protected  void drawPolygon(Polygon polygon, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws a a polygon for the given parameters.
protected  void drawRect(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow, boolean rounded)
          Draws a rectangle for the given parameters.
protected  void drawRhombus(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow)
          Draws a rhombus (aka.
 void drawShape(int x, int y, int w, int h, Map<String,Object> style)
          Draws the shape specified with the STYLE_SHAPE key in the given style.
protected  void drawTriangle(int x, int y, int w, int h, Color fillColor, Paint fillPaint, Color penColor, boolean shadow, String direction)
          Draws a triangle shape for the given parameters.
 Object drawVertex(int x, int y, int w, int h, Map<String,Object> style)
          Draws the given vertex.
static int getArcSize(int w, int h)
          Computes the arc size for the given dimension.
protected  Paint getFillPaint(Rectangle bounds, Color fillColor, Map<String,Object> style)
           
 Graphics2D getGraphics()
          Returns the graphics object for this canvas.
protected  Image loadImage(String image)
          Returns an image instance for the given URL.
 void setGraphics(Graphics2D g)
          Sets the graphics object for this canvas.
 
Methods inherited from class com.mxgraph.canvas.mxBasicCanvas
getImageBasePath, getImageForStyle, getScale, getTranslate, isDrawLabels, setDrawLabels, setImageBasePath, setScale, setTranslate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageCache

protected Hashtable<String,Image> imageCache
Cache for images.


rendererPane

protected CellRendererPane rendererPane
Optional renderer pane to be used for HTML label rendering.


g

protected Graphics2D g
Global graphics handle to the image.

Constructor Detail

mxGraphics2DCanvas

public mxGraphics2DCanvas()
Constructs a new graphics canvas with an empty graphics object.


mxGraphics2DCanvas

public mxGraphics2DCanvas(Graphics2D g)
Constructs a new graphics canvas for the given graphics object.

Method Detail

getGraphics

public Graphics2D getGraphics()
Returns the graphics object for this canvas.


setGraphics

public void setGraphics(Graphics2D g)
Sets the graphics object for this canvas.


loadImage

protected Image loadImage(String image)
Returns an image instance for the given URL. If the URL has been loaded before than an instance of the same instance is returned as in the previous call.


drawVertex

public Object drawVertex(int x,
                         int y,
                         int w,
                         int h,
                         Map<String,Object> style)
Description copied from interface: mxICanvas
Draws the given vertex.

Parameters:
x - X-coordinate of the vertex.
y - Y-coordinate of the vertex.
w - Width of the vertex.
h - Height of the vertex.
style - Style of the vertex.
Returns:
Optional object that represents the vertex.

drawEdge

public Object drawEdge(List<mxPoint> pts,
                       Map<String,Object> style)
Description copied from interface: mxICanvas
Draws the given edge.

Parameters:
pts - List of mxPoints that make up the edge.
style - Style of the edge.
Returns:
Optional object that represents the edge.

drawLabel

public Object drawLabel(String label,
                        int x,
                        int y,
                        int w,
                        int h,
                        Map<String,Object> style,
                        boolean isHtml)
Description copied from interface: mxICanvas
Draws the given label.

Parameters:
label - String that represents the label.
x - X-coordinate of the label.
y - Y-coordinate of the label.
w - Width of the label.
h - Height of the label.
style - Style of the label.
isHtml - Specifies if the label contains HTML markup.
Returns:
Optional object that represents the label.

drawShape

public void drawShape(int x,
                      int y,
                      int w,
                      int h,
                      Map<String,Object> style)
Draws the shape specified with the STYLE_SHAPE key in the given style.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
style - Style of the the shape.

drawPolygon

protected void drawPolygon(Polygon polygon,
                           Color fillColor,
                           Paint fillPaint,
                           Color penColor,
                           boolean shadow)
Draws a a polygon for the given parameters.

Parameters:
polygon - Points of the polygon.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawPath

protected void drawPath(GeneralPath path,
                        Color fillColor,
                        Paint fillPaint,
                        Color penColor,
                        boolean shadow)
Draws a path for the given parameters.

Parameters:
path - Path object to be drawn.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawRect

protected void drawRect(int x,
                        int y,
                        int w,
                        int h,
                        Color fillColor,
                        Paint fillPaint,
                        Color penColor,
                        boolean shadow,
                        boolean rounded)
Draws a rectangle for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.
rounded - Boolean indicating if the rectangle is rounded.

drawImage

protected void drawImage(int x,
                         int y,
                         int w,
                         int h,
                         String image)
Draws an image for the given parameters.

Parameters:
x - X-coordinate of the image.
y - Y-coordinate of the image.
w - Width of the image.
h - Height of the image.
image - URL of the image.

drawOval

protected void drawOval(int x,
                        int y,
                        int w,
                        int h,
                        Color fillColor,
                        Paint fillPaint,
                        Color penColor,
                        boolean shadow)
Draws an oval for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawRhombus

protected void drawRhombus(int x,
                           int y,
                           int w,
                           int h,
                           Color fillColor,
                           Paint fillPaint,
                           Color penColor,
                           boolean shadow)
Draws a rhombus (aka. diamond) for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawCylinder

protected void drawCylinder(int x,
                            int y,
                            int w,
                            int h,
                            Color fillColor,
                            Paint fillPaint,
                            Color penColor,
                            boolean isShadow)
Draws a cylinder for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
isShadow - Boolean indicating if a shadow should be painted.

drawActor

protected void drawActor(int x,
                         int y,
                         int w,
                         int h,
                         Color fillColor,
                         Paint fillPaint,
                         Color penColor,
                         boolean shadow)
Draws an actor shape for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawCloud

protected void drawCloud(int x,
                         int y,
                         int w,
                         int h,
                         Color fillColor,
                         Paint fillPaint,
                         Color penColor,
                         boolean shadow)
Draws a cloud shape for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawTriangle

protected void drawTriangle(int x,
                            int y,
                            int w,
                            int h,
                            Color fillColor,
                            Paint fillPaint,
                            Color penColor,
                            boolean shadow,
                            String direction)
Draws a triangle shape for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

drawHexagon

protected void drawHexagon(int x,
                           int y,
                           int w,
                           int h,
                           Color fillColor,
                           Paint fillPaint,
                           Color penColor,
                           boolean shadow,
                           String direction)
Draws a hexagon shape for the given parameters.

Parameters:
x - X-coordinate of the shape.
y - Y-coordinate of the shape.
w - Width of the shape.
h - Height of the shape.
fillColor - Optional fill color of the shape.
fillPaint - Optional paint of the shape.
penColor - Optional stroke color.
shadow - Boolean indicating if a shadow should be painted.

getArcSize

public static int getArcSize(int w,
                             int h)
Computes the arc size for the given dimension.

Parameters:
w - Width of the rectangle.
h - Height of the rectangle.
Returns:
Returns the arc size for the given dimension.

createArrow

protected Polygon createArrow(mxPoint p0,
                              mxPoint pe)
Creates a polygon that represents an arrow.

Parameters:
p0 - Start point of the arrow.
pe - End point of the arrow.
Returns:
Returns the polygon to be painted.

drawArrow

protected void drawArrow(List<mxPoint> pts,
                         Color fillColor,
                         Paint fillPaint,
                         Color penColor,
                         boolean shadow)
Draws the given arrow shape.

Parameters:
pts - List of points that define the line.

drawConnector

protected void drawConnector(List<mxPoint> pts,
                             float penWidth,
                             Color penColor,
                             Object startMarker,
                             float startSize,
                             Object endMarker,
                             float endSize,
                             boolean dashed,
                             boolean rounded)
Draws the given connector shape.

Parameters:
pts - List of points that define the line.

getFillPaint

protected Paint getFillPaint(Rectangle bounds,
                             Color fillColor,
                             Map<String,Object> style)
Parameters:
fillColor -
style -
Returns:
Returns the paint to be used for filling.

drawLine

public void drawLine(List<mxPoint> pts,
                     Map<String,Object> style)
Draws the given lines as segments between all points of the given list of mxPoints.

Parameters:
pts - List of points that define the line.
style - Style to be used for painting the line.

drawLine

public void drawLine(int x0,
                     int y0,
                     int x1,
                     int y1)
Draws the given line if the line is inside the clipping area. This method assumes that the stroke on the graphics object is already set.


drawMarker

public mxPoint drawMarker(Object type,
                          mxPoint p0,
                          mxPoint pe,
                          float size,
                          float strokeWidth)
Draws the given type of marker.

Parameters:
type -
p0 -
pe -
size -
strokeWidth -
Returns:
Return the mxPoint that defines the offset.

drawHtmlText

protected void drawHtmlText(String text,
                            int x,
                            int y,
                            int w,
                            int h,
                            Map<String,Object> style)
Draws the specified HTML markup.

Parameters:
text - HTML markup to be painted.
x - X-coordinate of the text.
y - Y-coordinate of the text.
w - Width of the text.
h - Height of the text.
style - Style to be used for painting the text.

drawPlainText

protected void drawPlainText(String text,
                             int x,
                             int y,
                             int w,
                             int h,
                             Map<String,Object> style)
Draws the specified string as plain text.

Parameters:
text - HTML markup to be painted.
x - X-coordinate of the text.
y - Y-coordinate of the text.
w - Width of the text.
h - Height of the text.
style - Style to be used for painting the text.

JGraph X 1.2.0.8


Copyright (c) 2008 Gaudenz Alder. All rights reserved.