net.refractions.udig.ui.graphics
Interface ViewportGraphics

All Known Implementing Classes:
AWTGraphics, NonAdvancedSWTGraphics, SWTGraphics

public interface ViewportGraphics

An adapter that allows uDig and plugin writers to write to AWT components and images or SWT Drawable objects by using this common interface.

Author:
jeichar

Field Summary
static int ALIGN_BOTTOM
          ALIGN_BOTTOM field used to align text
static int ALIGN_LEFT
          ALIGN_LEFT field used to align text
static int ALIGN_MIDDLE
          ALIGN_MIDDLE field used to align text
static int ALIGN_RIGHT
          ALIGN_RIGHT field used to align text
static int ALIGN_TOP
          ALIGN_TOP field used to align text
static int LINE_DASH
          Line drawing style for dashed lines (value is 2).
static int LINE_DASHDOT
          Line drawing style for alternating dash-dot lines (value is 4).
static int LINE_DASHDOTDOT
          Line drawing style for dash-dot-dot lines (value is 5).
static int LINE_DOT
          Line drawing style for dotted lines (value is 3).
static int LINE_SOLID
          Line drawing style for solid lines (value is 1).
static int LINE_SOLID_ROUNDED
          Line drawing style for solid line with rounded ends lines (value is 6).
 
Method Summary
 void clearRect(int x, int y, int width, int height)
          Fills the specified rectangle with the background color.
 void dispose()
          Disposes of any resources the graphics might be hanging on to.
 void draw(java.awt.Shape s)
          Draws the outline of shape using the color, clip & transform.
 void drawImage(java.awt.Image awtImage, int x, int y)
          Draws an Image.
 void drawImage(java.awt.Image awtImage, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2)
          Draws a portion of the image to the target location on the viewport graphics.
 void drawImage(java.awt.image.RenderedImage renderedImage, int x, int y)
          Draws an image.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line from x1,y1 to x2,y2
 void drawOval(int x, int y, int width, int height)
          Draws an Oval - only the boundary
 void drawPath(Path path)
          Draws the outline of the path using the color, clip and transform.
 void drawRect(int x, int y, int width, int height)
          Draws a rectangle - only the boundary.
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a round cornered rectangle
 void drawString(java.lang.String string, int x, int y, int alignx, int aligny)
          Draws a string.
 void fill(java.awt.Shape s)
          Fills the interior of a Shape using the foreground color, clip & transform.
 void fillGradientRectangle(int x, int y, int width, int height, java.awt.Color startColor, java.awt.Color endColor, boolean isVertical)
          Fills a rectangle using a gradient paint
 void fillOval(int x, int y, int width, int height)
          Fills an Oval
 void fillPath(Path path)
          Fills the interior of the path with the forground color.
 void fillRect(int x, int y, int width, int height)
          Fills a rectangle.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Fills a round cornered rectangle using the foreground color
 java.awt.Color getBackgroundColor()
          Gets the current background color value
 java.awt.Shape getClip()
          Gets the area that can be drawn in.
 java.awt.Color getColor()
          Gets the current Color value
 int getDPI()
          Get the dots per inch, used to scale fonts, but you can scale anything you want based on this value (for example a scalebar).
 int getFontAscent()
          Gets the ascent of the current font, which is the distance the font rises above its baseline.
 int getFontHeight()
          Gets the height of the current font TODO at some point maybe this could be broken out to getFontMetrics(), and a create FontMetrics object that maps between SWT and AWT.
 GC getGC()
          Gets the SWT graphics if applicable.
 java.awt.geom.Rectangle2D getStringBounds(java.lang.String str)
          Returns the bounds of a String.
 java.awt.geom.AffineTransform getTransform()
           
 void setBackground(java.awt.Color c)
          Sets the background color to draw with.
 void setClip(java.awt.Rectangle r)
          Sets the clip.
 void setClipBounds(java.awt.Rectangle newBounds)
          Sets the clip area.
 void setColor(java.awt.Color c)
          Sets the foreground color to draw with.
 void setFont(java.awt.Font font)
          Sets the font; size is taken to be in DPI.
 void setLineDash(int[] dash)
          Sets the line dash pattern
 void setLineWidth(int width)
          Sets the line width of the graphics (in pixels).
 void setStroke(int strokeStyle, int strokeWidth)
          Sets the stroke color to draw with.
 void setTransform(java.awt.geom.AffineTransform transform)
          Modifies the graphics so that further draws us minX,minY as the origin and maxX and maxY as the width and height of the display area.
 int stringWidth(java.lang.String str)
          Returns the length in pixels of the given string, or -1 if this operation is not available.
 void translate(java.awt.Point offset)
          Sets the draw offset.
 

Field Detail

LINE_SOLID

static final int LINE_SOLID
Line drawing style for solid lines (value is 1).

See Also:
Constant Field Values

LINE_DASH

static final int LINE_DASH
Line drawing style for dashed lines (value is 2).

See Also:
Constant Field Values

LINE_DOT

static final int LINE_DOT
Line drawing style for dotted lines (value is 3).

See Also:
Constant Field Values

LINE_DASHDOT

static final int LINE_DASHDOT
Line drawing style for alternating dash-dot lines (value is 4).

See Also:
Constant Field Values

LINE_DASHDOTDOT

static final int LINE_DASHDOTDOT
Line drawing style for dash-dot-dot lines (value is 5).

See Also:
Constant Field Values

LINE_SOLID_ROUNDED

static final int LINE_SOLID_ROUNDED
Line drawing style for solid line with rounded ends lines (value is 6).

See Also:
Constant Field Values

ALIGN_TOP

static final int ALIGN_TOP
ALIGN_TOP field used to align text

See Also:
Constant Field Values

ALIGN_MIDDLE

static final int ALIGN_MIDDLE
ALIGN_MIDDLE field used to align text

See Also:
Constant Field Values

ALIGN_BOTTOM

static final int ALIGN_BOTTOM
ALIGN_BOTTOM field used to align text

See Also:
Constant Field Values

ALIGN_LEFT

static final int ALIGN_LEFT
ALIGN_LEFT field used to align text

See Also:
Constant Field Values

ALIGN_RIGHT

static final int ALIGN_RIGHT
ALIGN_RIGHT field used to align text

See Also:
Constant Field Values
Method Detail

fillPath

void fillPath(Path path)
Fills the interior of the path with the forground color.

Parameters:
path - the path to fill.

fill

void fill(java.awt.Shape s)
Fills the interior of a Shape using the foreground color, clip & transform.

Reference description from Graphics2d: Fills the interior of a Shape using the settings of the Graphics2D context. The rendering attributes applied include the Clip, Transform, Paint, and Composite.

Parameters:
s - the Shape to be filled

s - the Shape to be rendered
See Also:
fill

fillOval

void fillOval(int x,
              int y,
              int width,
              int height)
Fills an Oval

Parameters:
x - the starting x coordinate
y - the starting y coordinate
width - the width of the Oval.
height - the height of the Oval.

fillRect

void fillRect(int x,
              int y,
              int width,
              int height)
Fills a rectangle.

Parameters:
x - the starting x coordinate
y - the starting y coordinate
width - the width of the rectangle.
height - the height of the rectangle.

clearRect

void clearRect(int x,
               int y,
               int width,
               int height)
Fills the specified rectangle with the background color.

Parameters:
x - The starting corner's x-coordinate.
y - The starting corner's y-coordinate.
width - the width of the rectangle
height - the height of the rectangle

drawPath

void drawPath(Path path)
Draws the outline of the path using the color, clip and transform.


draw

void draw(java.awt.Shape s)
Draws the outline of shape using the color, clip & transform.

Reference description from Graphics2d: Strokes the outline of a Shape using the settings of the current Graphics2D context. The rendering attributes applied include the Clip, Transform, Paint, Composite and Stroke attributes.

Parameters:
s - the Shape to be rendered
See Also:
fill

drawRect

void drawRect(int x,
              int y,
              int width,
              int height)
Draws a rectangle - only the boundary.

Parameters:
x - the starting x coordinate
y - the starting y coordinate
width - the width of the rectangle.
height - the height of the rectangle.

drawLine

void drawLine(int x1,
              int y1,
              int x2,
              int y2)
Draws a line from x1,y1 to x2,y2

Parameters:
x1 -
y1 -
x2 -
y2 -

drawOval

void drawOval(int x,
              int y,
              int width,
              int height)
Draws an Oval - only the boundary

Parameters:
x - the starting x coordinate
y - the starting y coordinate
width - the width of the Oval.
height - the height of the Oval.

drawString

void drawString(java.lang.String string,
                int x,
                int y,
                int alignx,
                int aligny)
Draws a string. Alignment parameters specify where the string should be located relative to coordinate (x,y).

Parameters:
string - The string to draw.
x - the x coordinate of the location where the of the string will be placed.
y - the y coordinate of the location where the of the string will be placed.
alignx - horizontal alignment, ALIGN_LEFT, ALIGN_MIDDLE or ALIGN_RIGHT
aligny - vertical alignment, ALIGN_BOTTOM, ALIGN_MIDDLE or ALIGN_TOP

setColor

void setColor(java.awt.Color c)
Sets the foreground color to draw with.

Parameters:
c - The new color.

setBackground

void setBackground(java.awt.Color c)
Sets the background color to draw with.

Parameters:
c - The new color.

setStroke

void setStroke(int strokeStyle,
               int strokeWidth)
Sets the stroke color to draw with.

Parameters:
strokeStyle - The style of line to draw.
strokeWidth - the width, in pixels, to draw lines with.

setClip

void setClip(java.awt.Rectangle r)
Sets the clip.

Parameters:
r - the rectangle to clip to.

translate

void translate(java.awt.Point offset)
Sets the draw offset.

Parameters:
offset - The amount the draw is offset in the graphics.

drawImage

void drawImage(java.awt.image.RenderedImage renderedImage,
               int x,
               int y)
Draws an image.

Parameters:
image - The image to draw.
x - The x coordinate of the image top left corner of the image.
y - The y coordinate of the image top left corner of the image.

drawImage

void drawImage(java.awt.Image awtImage,
               int x,
               int y)
Draws an Image.

Parameters:
image - The Image to draw.
x - The x coordinate of the image top left corner of the image.
y - The y coordinate of the image top left corner of the image.

drawImage

void drawImage(java.awt.Image awtImage,
               int dx1,
               int dy1,
               int dx2,
               int dy2,
               int sx1,
               int sy1,
               int sx2,
               int sy2)
Draws a portion of the image to the target location on the viewport graphics.

Parameters:
image - Image to draw
dx1 - - the x coordinate of the first corner of the destination rectangle.
dy1 - - the y coordinate of the first corner of the destination rectangle.
dx2 - - the x coordinate of the second corner of the destination rectangle.
dy2 - - the y coordinate of the second corner of the destination rectangle.
sx1 - - the x coordinate of the first corner of the source rectangle.
sy1 - - the y coordinate of the first corner of the source rectangle.
sx2 - - the x coordinate of the second corner of the source rectangle.
sy2 - - the y coordinate of the second corner of the source rectangle.

setTransform

void setTransform(java.awt.geom.AffineTransform transform)
Modifies the graphics so that further draws us minX,minY as the origin and maxX and maxY as the width and height of the display area.

Parameters:
minX - The x-coord that will be used as the origin.
minY - The y-coord that will be used as the origin.
width - The width that will be used to draws.
height - The height that will be used to draws.

getFontHeight

int getFontHeight()
Gets the height of the current font TODO at some point maybe this could be broken out to getFontMetrics(), and a create FontMetrics object that maps between SWT and AWT.

Returns:
the height of the current font

stringWidth

int stringWidth(java.lang.String str)
Returns the length in pixels of the given string, or -1 if this operation is not available.

Parameters:
str -
Returns:

getFontAscent

int getFontAscent()
Gets the ascent of the current font, which is the distance the font rises above its baseline.

Returns:

getStringBounds

java.awt.geom.Rectangle2D getStringBounds(java.lang.String str)
Returns the bounds of a String. Does not expand tabs or newlines

Parameters:
str -
Returns:

getTransform

java.awt.geom.AffineTransform getTransform()

dispose

void dispose()
Disposes of any resources the graphics might be hanging on to.


getClip

java.awt.Shape getClip()
Gets the area that can be drawn in.

Returns:
the area that can be drawn in.

setClipBounds

void setClipBounds(java.awt.Rectangle newBounds)
Sets the clip area.

Parameters:
newBounds - new clip area

getColor

java.awt.Color getColor()
Gets the current Color value

Returns:
the current Color value

getBackgroundColor

java.awt.Color getBackgroundColor()
Gets the current background color value

Returns:
the current background color value

drawRoundRect

void drawRoundRect(int x,
                   int y,
                   int width,
                   int height,
                   int arcWidth,
                   int arcHeight)
Draws a round cornered rectangle

Parameters:
x - the x component of the upper left corner
y - the y component of the upper left corner
width - the width of the rectangle
height - the height of the rectangle
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners

fillRoundRect

void fillRoundRect(int x,
                   int y,
                   int width,
                   int height,
                   int arcWidth,
                   int arcHeight)
Fills a round cornered rectangle using the foreground color

Parameters:
x - the x component of the upper left corner
y - the y component of the upper left corner
width - the width of the rectangle
height - the height of the rectangle
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners

setLineWidth

void setLineWidth(int width)
Sets the line width of the graphics (in pixels).

If you need to make your drawing device independent please consider making use of the DPI setting.


 g.setLineWith( width ); // BEFORE
 g.setLineWith( (width * g.getDPI()) / 72 ); // AFTER 
 
Where 72 is chosen because that is what a Java image resolutions is assumed to be by default.

Parameters:
the - new line width

setLineDash

void setLineDash(int[] dash)
Sets the line dash pattern

Parameters:
dash - the pattern of dashes.

setFont

void setFont(java.awt.Font font)
Sets the font; size is taken to be in DPI.

Please note this is a change in behaviour over AWT (where size is documented to be in 72 dpi. They are changing their mind in later versions of java but we cannot wait for them to get there act together.

Parameters:
the - font new font

getDPI

int getDPI()
Get the dots per inch, used to scale fonts, but you can scale anything you want based on this value (for example a scalebar).

Parameters:
dpi -

fillGradientRectangle

void fillGradientRectangle(int x,
                           int y,
                           int width,
                           int height,
                           java.awt.Color startColor,
                           java.awt.Color endColor,
                           boolean isVertical)
Fills a rectangle using a gradient paint

Parameters:
x - the x component of the upper left corner
y - the y component of the upper left corner
width - the width of the rectangle
height - the height of the rectangle
startColor - the first color used in the gradient paint
endColor - the last color used in the gradient paint
isVertical - orientation of the gradient

getGC

GC getGC()
Gets the SWT graphics if applicable. May return null if no SWT graphics.

Returns:
SWT graphics or null