org.eclipse.graphiti.export.batik
Class GraphicsToGraphics2DAdaptor

java.lang.Object
  extended by Graphics
      extended by org.eclipse.graphiti.export.batik.GraphicsToGraphics2DAdaptor

public class GraphicsToGraphics2DAdaptor
extends Graphics

Objects of this class can be used with draw2d to render to a Graphics2D object.

Author:
jschofie / sshaw This class is originally from GMF and was adapted for Graphiti needs.

Nested Class Summary
private static class GraphicsToGraphics2DAdaptor.State
           
 
Field Summary
(package private) static int ADVANCED_GRAPHICS_MASK
           
(package private) static int ADVANCED_SHIFT
           
private  float angle
          current rotation angle
private  GraphicsToGraphics2DAdaptor.State appliedState
           
private  GraphicsToGraphics2DAdaptor.State currentState
           
(package private) static int FILL_RULE_MASK
           
(package private) static int FILL_RULE_SHIFT
           
(package private) static int FILL_RULE_WHOLE_NUMBER
           
private  Graphics2D graphics2D
           
private  Image image
           
protected  boolean paintNotCompatibleStringsAsBitmaps
          Some strings, Asian string in particular, are painted differently between SWT and AWT.
private  Rectangle relativeClipRegion
           
private  int rotateX
          The x coordinate of the rotation point
private  int rotateY
          The y coordinate of the rotation point
private  Stack<GraphicsToGraphics2DAdaptor.State> states
           
private  BasicStroke stroke
           
private  SWTGraphics swtGraphics
           
private static TextUtilities TEXT_UTILITIES
           
private  int transX
          x coordinate for graphics translation
private  int transY
          y coordinate for graphics translation
private  org.eclipse.swt.graphics.Rectangle viewBox
           
 
Constructor Summary
GraphicsToGraphics2DAdaptor(Graphics2D graphics, Rectangle viewPort)
          Constructor
 
Method Summary
protected  void checkState()
          Verifies that the applied state is up to date with the current state and updates the applied state accordingly.
 void clipPath(Path path)
           
 void clipRect(Rectangle rect)
           
private  void cloneGC(GC gc)
           
private  GeneralPath createPathAWT(Path path)
           
private  Polygon createPolygon(PointList pointList)
           
private  Stroke createStroke()
          Sets and retirns AWT Stroke based on the value of LineAttributes within the current state object
private  void createSWTGraphics()
          This is a helper method used to create the SWT Graphics object
 void dispose()
           
 void drawArc(int x, int y, int width, int height, int startAngle, int endAngle)
           
 void drawFocus(int x, int y, int w, int h)
           
 void drawImage(Image srcImage, int xpos, int ypos)
           
 void drawImage(Image srcImage, int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
           
 void drawLine(int x1, int y1, int x2, int y2)
           
 void drawOval(int x, int y, int w, int h)
           
 void drawPath(Path path)
           
 void drawPolygon(PointList pointList)
           
 void drawPolyline(PointList pointList)
           
 void drawRectangle(int x, int y, int w, int h)
           
 void drawRoundRectangle(Rectangle rect, int arcWidth, int arcHeight)
           
 void drawString(String s, int x, int y)
           
 void drawText(String s, int x, int y)
           
 void drawTextLayout(TextLayout layout, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)
           
 void fillArc(int x, int y, int w, int h, int offset, int length)
           
 void fillGradient(int x, int y, int w, int h, boolean vertical)
           
 void fillOval(int x, int y, int w, int h)
           
 void fillPath(Path path)
           
 void fillPolygon(PointList pointList)
           
 void fillRectangle(int x, int y, int width, int height)
           
 void fillRoundRectangle(Rectangle rect, int arcWidth, int arcHeight)
           
 void fillString(String s, int x, int y)
           
 void fillText(String s, int x, int y)
           
 boolean getAdvanced()
           
 int getAlpha()
           
 int getAntialias()
           
 Color getBackgroundColor()
           
 Rectangle getClip(Rectangle rect)
           
protected  Color getColor(Color toConvert)
          This method is used to convert an SWT Color to an AWT Color.
 int getFillRule()
           
 Font getFont()
           
 FontMetrics getFontMetrics()
           
 Color getForegroundColor()
           
protected  Graphics2D getGraphics2D()
           
 int getInterpolation()
           
 LineAttributes getLineAttributes()
           
 int getLineStyle()
           
 int getLineWidth()
           
 float getLineWidthFloat()
           
 Dimension getMaximumRenderSize()
           
protected  BasicStroke getStroke()
           
private  SWTGraphics getSWTGraphics()
           
 int getTextAntialias()
           
protected  Point getTranslationOffset()
          Accessor method to return the translation offset for the graphics object
 boolean getXORMode()
           
private  void init()
          This method should only be called by the constructor.
private  void initSVGGraphics(Graphics2D graphics)
          Create the SVG graphics object and initializes it with the current line stlye and width
private  boolean isFontStrikeout(Font f)
           
private  boolean isFontUnderlined(Font f)
           
 void popState()
           
 void pushState()
           
 void restoreState()
           
private  void restoreState(GraphicsToGraphics2DAdaptor.State state)
           
 void rotate(float degrees)
           
 void scale(double amount)
           
 void setAdvanced(boolean value)
           
 void setAlpha(int alpha)
           
 void setAntialias(int value)
           
 void setBackgroundColor(Color rgb)
           
 void setClip(Rectangle rect)
           
private  void setClipAbsolute(int x, int y, int width, int height)
          Sets the current clip values
 void setFillRule(int rule)
           
 void setFont(Font f)
           
 void setForegroundColor(Color rgb)
           
 void setLineAttributes(LineAttributes lineAttributes)
           
 void setLineCap(int cap)
          ignored
 void setLineDash(float[] dash)
           
 void setLineDash(int[] dash)
          Sets the dash pattern when the custom line style is in use.
 void setLineJoin(int join)
          ignored
 void setLineMiterLimit(float miterLimit)
          ignored
 void setLineStyle(int style)
           
 void setLineWidth(int width)
           
 void setLineWidthFloat(float width)
           
protected  void setStroke(BasicStroke stroke)
           
private  void setTranslation(int x, int y)
          Sets the current translation values
 void setXORMode(boolean xorMode)
           
 boolean shouldAllowDelayRender()
           
 void translate(int dx, int dy)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADVANCED_GRAPHICS_MASK

static final int ADVANCED_GRAPHICS_MASK

ADVANCED_SHIFT

static final int ADVANCED_SHIFT

FILL_RULE_MASK

static final int FILL_RULE_MASK

FILL_RULE_SHIFT

static final int FILL_RULE_SHIFT

FILL_RULE_WHOLE_NUMBER

static final int FILL_RULE_WHOLE_NUMBER
See Also:
Constant Field Values

swtGraphics

private SWTGraphics swtGraphics

graphics2D

private Graphics2D graphics2D

stroke

private BasicStroke stroke

states

private Stack<GraphicsToGraphics2DAdaptor.State> states

currentState

private final GraphicsToGraphics2DAdaptor.State currentState

appliedState

private final GraphicsToGraphics2DAdaptor.State appliedState

paintNotCompatibleStringsAsBitmaps

protected boolean paintNotCompatibleStringsAsBitmaps
Some strings, Asian string in particular, are painted differently between SWT and AWT. SWT falls back to some default locale font if Asian string cannot be painted with the current font - this is done via the platform. AWT, unlike platform biased SWT, does not. Hence, Asian string widths are very different between SWT and AWT. To workaround the issue, if the flag below is set to true then once SWT and AWT string width are not equal, a bitmap of the SWT string will be painted. Otherwise the string is always painted with AWT Graphics 2D string rendering.


TEXT_UTILITIES

private static final TextUtilities TEXT_UTILITIES

relativeClipRegion

private Rectangle relativeClipRegion

viewBox

private org.eclipse.swt.graphics.Rectangle viewBox

image

private Image image

transX

private int transX
x coordinate for graphics translation


transY

private int transY
y coordinate for graphics translation


angle

private float angle
current rotation angle


rotateX

private int rotateX
The x coordinate of the rotation point


rotateY

private int rotateY
The y coordinate of the rotation point

Constructor Detail

GraphicsToGraphics2DAdaptor

public GraphicsToGraphics2DAdaptor(Graphics2D graphics,
                                   Rectangle viewPort)
Constructor

Parameters:
graphics - the Graphics2D object that this object is delegating calls to.
viewPort - the Rectangle that defines the logical area being rendered by the graphics object.
Method Detail

createSWTGraphics

private void createSWTGraphics()
This is a helper method used to create the SWT Graphics object


initSVGGraphics

private void initSVGGraphics(Graphics2D graphics)
Create the SVG graphics object and initializes it with the current line stlye and width


init

private void init()
This method should only be called by the constructor. Initializes state information for the currentState


checkState

protected void checkState()
Verifies that the applied state is up to date with the current state and updates the applied state accordingly.


clipRect

public void clipRect(Rectangle rect)

dispose

public void dispose()

getColor

protected Color getColor(Color toConvert)
This method is used to convert an SWT Color to an AWT Color.

Parameters:
toConvert - SWT Color to convert
Returns:
AWT Color

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int endAngle)

fillArc

public void fillArc(int x,
                    int y,
                    int w,
                    int h,
                    int offset,
                    int length)

drawFocus

public void drawFocus(int x,
                      int y,
                      int w,
                      int h)

drawTextLayout

public void drawTextLayout(TextLayout layout,
                           int x,
                           int y,
                           int selectionStart,
                           int selectionEnd,
                           Color selectionForeground,
                           Color selectionBackground)

cloneGC

private void cloneGC(GC gc)

getInterpolation

public int getInterpolation()

getLineAttributes

public LineAttributes getLineAttributes()

getTextAntialias

public int getTextAntialias()

drawImage

public void drawImage(Image srcImage,
                      int xpos,
                      int ypos)

drawImage

public void drawImage(Image srcImage,
                      int x1,
                      int y1,
                      int w1,
                      int h1,
                      int x2,
                      int y2,
                      int w2,
                      int h2)

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)

drawOval

public void drawOval(int x,
                     int y,
                     int w,
                     int h)

fillOval

public void fillOval(int x,
                     int y,
                     int w,
                     int h)

createPolygon

private Polygon createPolygon(PointList pointList)

drawPolygon

public void drawPolygon(PointList pointList)

fillPolygon

public void fillPolygon(PointList pointList)

drawPolyline

public void drawPolyline(PointList pointList)

drawRectangle

public void drawRectangle(int x,
                          int y,
                          int w,
                          int h)

fillRectangle

public void fillRectangle(int x,
                          int y,
                          int width,
                          int height)

drawRoundRectangle

public void drawRoundRectangle(Rectangle rect,
                               int arcWidth,
                               int arcHeight)

fillRoundRectangle

public void fillRoundRectangle(Rectangle rect,
                               int arcWidth,
                               int arcHeight)

drawText

public void drawText(String s,
                     int x,
                     int y)

drawString

public void drawString(String s,
                       int x,
                       int y)

fillString

public void fillString(String s,
                       int x,
                       int y)

fillText

public void fillText(String s,
                     int x,
                     int y)

getBackgroundColor

public Color getBackgroundColor()

getClip

public Rectangle getClip(Rectangle rect)

getFont

public Font getFont()

getFontMetrics

public FontMetrics getFontMetrics()

getForegroundColor

public Color getForegroundColor()

getLineStyle

public int getLineStyle()

getLineWidth

public int getLineWidth()

getLineWidthFloat

public float getLineWidthFloat()

getXORMode

public boolean getXORMode()

popState

public void popState()

pushState

public void pushState()

restoreState

public void restoreState()

restoreState

private void restoreState(GraphicsToGraphics2DAdaptor.State state)

scale

public void scale(double amount)

setBackgroundColor

public void setBackgroundColor(Color rgb)

setClip

public void setClip(Rectangle rect)

setClipAbsolute

private void setClipAbsolute(int x,
                             int y,
                             int width,
                             int height)
Sets the current clip values

Parameters:
x - the x value
y - the y value
width - the width value
height - the height value

isFontUnderlined

private boolean isFontUnderlined(Font f)

isFontStrikeout

private boolean isFontStrikeout(Font f)

setFont

public void setFont(Font f)

setForegroundColor

public void setForegroundColor(Color rgb)

setLineDash

public void setLineDash(int[] dash)
Sets the dash pattern when the custom line style is in use. Because this feature is rarely used, the dash pattern may not be preserved when calling pushState() and popState().

Parameters:
dash - the pixel pattern

setLineDash

public void setLineDash(float[] dash)

setLineStyle

public void setLineStyle(int style)

setLineMiterLimit

public void setLineMiterLimit(float miterLimit)
ignored


setLineCap

public void setLineCap(int cap)
ignored


setLineJoin

public void setLineJoin(int join)
ignored


setLineWidth

public void setLineWidth(int width)

setLineWidthFloat

public void setLineWidthFloat(float width)

setLineAttributes

public void setLineAttributes(LineAttributes lineAttributes)

setXORMode

public void setXORMode(boolean xorMode)

setTranslation

private void setTranslation(int x,
                            int y)
Sets the current translation values

Parameters:
x - the x translation value
y - the y translation value

translate

public void translate(int dx,
                      int dy)

getGraphics2D

protected Graphics2D getGraphics2D()
Returns:
the Graphics2D that this is delegating to.

getSWTGraphics

private SWTGraphics getSWTGraphics()
Returns:
Returns the swtGraphics.

fillGradient

public void fillGradient(int x,
                         int y,
                         int w,
                         int h,
                         boolean vertical)

drawPath

public void drawPath(Path path)

fillPath

public void fillPath(Path path)

getFillRule

public int getFillRule()

setFillRule

public void setFillRule(int rule)

createPathAWT

private GeneralPath createPathAWT(Path path)

shouldAllowDelayRender

public boolean shouldAllowDelayRender()

getMaximumRenderSize

public Dimension getMaximumRenderSize()

getTranslationOffset

protected Point getTranslationOffset()
Accessor method to return the translation offset for the graphics object

Returns:
Point x coordinate for graphics translation

getAntialias

public int getAntialias()

setAntialias

public void setAntialias(int value)

getAlpha

public int getAlpha()

setAlpha

public void setAlpha(int alpha)

getStroke

protected BasicStroke getStroke()

setStroke

protected void setStroke(BasicStroke stroke)

createStroke

private Stroke createStroke()
Sets and retirns AWT Stroke based on the value of LineAttributes within the current state object

Returns:
the new AWT stroke

getAdvanced

public boolean getAdvanced()

setAdvanced

public void setAdvanced(boolean value)

clipPath

public void clipPath(Path path)

rotate

public void rotate(float degrees)


Copyright (c) SAP AG 2005, 2012.