Eclipse Rich Ajax Platform
Release 1.3

org.eclipse.swt.graphics
Class GC

java.lang.Object
  extended byorg.eclipse.swt.graphics.Resource
      extended byorg.eclipse.swt.graphics.GC

public class GC
extends Resource

Class GC is provided to ease single-sourcing SWT and RWT code. Its text measurement methods directly delegate to the respective Graphics methods.

Styles:
LEFT_TO_RIGHT

Application code must explicitly invoke the GC.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.


Constructor Summary
GC(Drawable drawable)
          Constructs a new instance of this class which has been configured to draw on the specified drawable.
 
Method Summary
 Color getBackground()
          Returns the background color.
 int getCharWidth(char ch)
          Returns the width of the specified character in the font selected into the receiver.
 Font getFont()
          Returns the font currently being used by the receiver to draw and measure text.
 FontMetrics getFontMetrics()
          Returns a FontMetrics which contains information about the font currently being used by the receiver to draw and measure text.
 Color getForeground()
          Returns the receiver's foreground color.
 void setBackground(Color color)
          Sets the background color.
 void setFont(Font font)
          Sets the font which will be used by the receiver to draw and measure text to the argument.
 void setForeground(Color color)
          Sets the foreground color.
 Point stringExtent(String string)
          Returns the extent of the given string.
 Point textExtent(String string)
          Returns the extent of the given string.
 
Methods inherited from class org.eclipse.swt.graphics.Resource
dispose, getDevice, isDisposed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GC

public GC(Drawable drawable)
Constructs a new instance of this class which has been configured to draw on the specified drawable. Sets the foreground color, background color and font in the GC to match those in the drawable.

You must dispose the graphics context when it is no longer required.

Parameters:
drawable - the drawable to draw on
Throws:
IllegalArgumentException -
SWTError -
Method Detail

setFont

public void setFont(Font font)
Sets the font which will be used by the receiver to draw and measure text to the argument. If the argument is null, then a default font appropriate for the platform will be used instead.

Parameters:
font - the new font for the receiver, or null to indicate a default font
Throws:
IllegalArgumentException -
  • ERROR_INVALID_ARGUMENT - if the font has been disposed
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

getFont

public Font getFont()
Returns the font currently being used by the receiver to draw and measure text.

Returns:
the receiver's font
Throws:
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

getCharWidth

public int getCharWidth(char ch)
Returns the width of the specified character in the font selected into the receiver.

The width is defined as the space taken up by the actual character, not including the leading and tailing whitespace or overhang.

Parameters:
ch - the character to measure
Returns:
the width of the character
Throws:
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

stringExtent

public Point stringExtent(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 (in this case, the current font in the receiver).

Parameters:
string - the string to measure
Returns:
a point containing the extent of the string
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string is null
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

textExtent

public Point textExtent(String string)
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 (in this case, the current font in the receiver).

Parameters:
string - the string to measure
Returns:
a point containing the extent of the string
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string is null
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

getFontMetrics

public FontMetrics getFontMetrics()
Returns a FontMetrics which contains information about the font currently being used by the receiver to draw and measure text.

Returns:
font metrics for the receiver's font
Throws:
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

setBackground

public void setBackground(Color color)
Sets the background color. The background color is used for fill operations and as the background color when text is drawn.

Parameters:
color - the new background color for the receiver
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the color is null
  • ERROR_INVALID_ARGUMENT - if the color has been disposed
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

getBackground

public Color getBackground()
Returns the background color.

Returns:
the receiver's background color
Throws:
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

setForeground

public void setForeground(Color color)
Sets the foreground color. The foreground color is used for drawing operations including when text is drawn.

Parameters:
color - the new foreground color for the receiver
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the color is null
  • ERROR_INVALID_ARGUMENT - if the color has been disposed
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

getForeground

public Color getForeground()
Returns the receiver's foreground color.

Returns:
the color used for drawing foreground things
Throws:
SWTException -
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed

Eclipse Rich Ajax Platform
Release 1.3

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