Eclipse Rich Ajax Platform
Release 1.3

org.eclipse.rwt.graphics
Class Graphics

java.lang.Object
  extended byorg.eclipse.rwt.graphics.Graphics

public final class Graphics
extends Object

This is a helper class for operations with text, fonts, colors and images. As RAP needs to handle with multiple clients simultaneously there are no constructors for these objects to share them between different sessions in order to have a much smaller memory footprint.

Since:
1.0

Method Summary
static float getAvgCharWidth(Font font)
          Returns the average character width of the specified font, measured in pixels.
static int getCharHeight(Font font)
          Returns the height of the specified font, measured in pixels.
static Color getColor(int red, int green, int blue)
          Returns a Color given the desired red, green and blue values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness).
static Color getColor(RGB rgb)
          Returns an instance of Color given an RGB describing the desired red, green and blue values.
static Cursor getCursor(int style)
          Deprecated. use Display#getSystemCursor(int)
static Font getFont(FontData data)
          Returns a new font given a font data which describes the desired font's appearance.
static Font getFont(String name, int height, int style)
          Returns a Font object given a font name, the height of the desired font in points, and a font style.
static Image getImage(String path)
          Returns an instance of Image based on the specified image path.
static Image getImage(String path, ClassLoader imageLoader)
          Returns an instance of Image based on the specified image path.
static Image getImage(String path, InputStream inputStream)
          Returns an instance of Image based on the specified image path.
static Point stringExtent(Font font, String string)
          Returns the extent of the given string.
static Point textExtent(Font font, String string, int wrapWidth)
          Returns the extent of the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getColor

public static Color getColor(RGB rgb)
Returns an instance of Color given an RGB describing the desired red, green and blue values.

Note: it is considered an error to attempt to dispose of colors that were created by this method. An IllegalStateException is thrown in this case.

Parameters:
rgb - the RGB values of the desired color - must not be null
Returns:
the color
See Also:
RGB, Device.getSystemColor(int)

getColor

public static Color getColor(int red,
                             int green,
                             int blue)
Returns a Color given the desired red, green and blue values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness).

Note: it is considered an error to attempt to dispose of colors that were created by this method. An IllegalStateException is thrown in this case.

Parameters:
red - the amount of red in the color
green - the amount of green in the color
blue - the amount of blue in the color
Returns:
the color

getFont

public static Font getFont(FontData data)
Returns a new font given a font data which describes the desired font's appearance.

Note: it is considered an error to attempt to dispose of fonts that were created by this method. An IllegalStateException is thrown in this case.

Parameters:
data - the FontData to use - must not be null
Returns:
the font
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the data argument is null

getFont

public static Font getFont(String name,
                           int height,
                           int style)
Returns a Font object given a font name, the height of the desired font in points, and a font style.

Note: it is considered an error to attempt to dispose of fonts that were created by this method. An IllegalStateException is thrown in this case.

Parameters:
name - the name of the font (must not be null)
height - the font height in points
style - a bit or combination of NORMAL, BOLD, ITALIC
Returns:
the font
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the name argument is null
  • ERROR_INVALID_ARGUMENT - if the height is negative

getImage

public static Image getImage(String path)
Returns an instance of Image based on the specified image path. The image has to be on the applications class-path.

Parameters:
path - the path to the image
Returns:
the image
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the path is null
  • ERROR_ILLEGAL_ARGUMENT - if the path is invalid
SWTException -
  • ERROR_IO - if an IO error occurs while reading from the stream
  • ERROR_INVALID_IMAGE - if the image stream contains invalid data
  • ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format

getImage

public static Image getImage(String path,
                             ClassLoader imageLoader)
Returns an instance of Image based on the specified image path. The image has to be on the applications class-path. Uses the specified classloader to load the image.

Parameters:
path - the path to the image
imageLoader - the classloader to use
Returns:
the image
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the path is null
  • ERROR_ILLEGAL_ARGUMENT - if the path is invalid
SWTException -
  • ERROR_IO - if an IO error occurs while reading from the stream
  • ERROR_INVALID_IMAGE - if the image stream contains invalid data
  • ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format

getImage

public static Image getImage(String path,
                             InputStream inputStream)
Returns an instance of Image based on the specified image path. The image will be read from the provided InputStream.

Parameters:
path - the path the image resource is registered at
inputStream - the input stream for the image
Returns:
the image
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the path is null
  • ERROR_NULL_ARGUMENT - if the inputStream is null
  • ERROR_INVALID_ARGUMENT - if the path is invalid
SWTException -
  • ERROR_IO - if an IO error occurs while reading from the stream
  • ERROR_INVALID_IMAGE - if the image stream contains invalid data
  • ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format

getCursor

public static Cursor getCursor(int style)
Deprecated. use Display#getSystemCursor(int)

Returns an instance of Cursor based on a style constant describing the desired cursor appearance.

Note: it is considered an error to attempt to dispose of cursors that were created by this method. An IllegalStateException is thrown in this case.

Parameters:
style - the style of the cursor to create
Returns:
the cursor
Since:
1.2
See Also:
SWT.CURSOR_ARROW, SWT.CURSOR_WAIT, SWT.CURSOR_CROSS, SWT.CURSOR_HELP, SWT.CURSOR_SIZEALL, SWT.CURSOR_SIZENS, SWT.CURSOR_SIZEWE, SWT.CURSOR_SIZEN, SWT.CURSOR_SIZES, SWT.CURSOR_SIZEE, SWT.CURSOR_SIZEW, SWT.CURSOR_SIZENE, SWT.CURSOR_SIZESE, SWT.CURSOR_SIZESW, SWT.CURSOR_SIZENW, SWT.CURSOR_IBEAM, SWT.CURSOR_HAND

textExtent

public static Point textExtent(Font font,
                               String string,
                               int wrapWidth)
Returns the extent of the given string. Tab expansion and carriage return processing are performed.

The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font.

Parameters:
font - the font for which the result is valid
string - the string to measure
wrapWidth - the maximum width of the text. The text will be wrapped to match this width. If set to 0, no wrapping will be performed.
Returns:
a point containing the extent of the string
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string is null

stringExtent

public static Point stringExtent(Font font,
                                 String string)
Returns the extent of the given string. No tab expansion or carriage return processing will be performed.

The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font.

Parameters:
font - the font for which the result is valid
string - the string to measure
Returns:
a point containing the extent of the string
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string is null

getCharHeight

public static int getCharHeight(Font font)
Returns the height of the specified font, measured in pixels.

Parameters:
font - the font for which the result is valid
Returns:
the height of the font

getAvgCharWidth

public static float getAvgCharWidth(Font font)
Returns the average character width of the specified font, measured in pixels.

Parameters:
font - the font for which the result is valid
Returns:
the average character width of the font

Eclipse Rich Ajax Platform
Release 1.3

Copyright (c) Innoopract Informationssysteme GmbH and others 2002, 2011. All rights reserved.