Eclipse Rich Ajax Platform

org.eclipse.rwt.graphics
Class Graphics

java.lang.Object
  extended by org.eclipse.rwt.graphics.Graphics

public final class Graphics
extends java.lang.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 Font getFont(FontData data)
          Returns a new font given a font data which describes the desired font's appearance.
static Font getFont(java.lang.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(java.lang.String path)
          Deprecated. Use getImage(String, ClassLoader) or getImage(String, InputStream) instead.
static Image getImage(java.lang.String path, java.lang.ClassLoader imageLoader)
          Returns an instance of Image based on the specified image path.
static Image getImage(java.lang.String path, java.io.InputStream inputStream)
          Returns an instance of Image based on the specified image path.
static Point stringExtent(Font font, java.lang.String string)
          Returns the extent of the given string.
static Point textExtent(Font font, java.lang.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
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the rgb argument is null
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread
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
Throws:
java.lang.IllegalArgumentException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

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:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the data argument is null
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

getFont

public static Font getFont(java.lang.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:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the name argument is null
  • ERROR_INVALID_ARGUMENT - if the height is negative
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

getImage

@Deprecated
public static Image getImage(java.lang.String path)
Deprecated. Use getImage(String, ClassLoader) or getImage(String, InputStream) instead.

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:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the path is null
  • ERROR_ILLEGAL_ARGUMENT - if the path is invalid
java.lang.IllegalArgumentException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread
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(java.lang.String path,
                             java.lang.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:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the path is null
  • ERROR_ILLEGAL_ARGUMENT - if the path is invalid
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread
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(java.lang.String path,
                             java.io.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:
java.lang.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
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread
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

textExtent

public static Point textExtent(Font font,
                               java.lang.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:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the font or string argument is null
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

stringExtent

public static Point stringExtent(Font font,
                                 java.lang.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:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the font or string arguemnt is null
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

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
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the font argument is null
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

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
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the font argument is null
  • ERROR_THREAD_INVALID_ACCESS - if not called from the current display's UI thread

Eclipse Rich Ajax Platform

Copyright (c) EclipseSource and others 2002, 2012. All rights reserved.