org.eclipse.ecf.ui
Class SWTResourceManager

java.lang.Object
  extended by org.eclipse.ecf.ui.SWTResourceManager

public class SWTResourceManager
extends java.lang.Object

Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. !!! IMPORTANT !!! Application code must explicitly invoke the dispose() method to release the operating system resources managed by cached objects when those objects and OS resources are no longer needed (e.g. on application shutdown) This class may be freely distributed as part of any application or plugin.

Copyright (c) 2003 - 2005, Instantiations, Inc.
All Rights Reserved

Version:
$Revision$

Field Summary
static int BOTTOM_LEFT
          Style constant for placing decorator image in bottom left corner of base image.
static int BOTTOM_RIGHT
          Style constant for placing decorator image in bottom right corner of base image.
static int TOP_LEFT
          Style constant for placing decorator image in top left corner of base image.
static int TOP_RIGHT
          Style constant for placing decorator image in top right corner of base image.
 
Constructor Summary
SWTResourceManager()
           
 
Method Summary
static org.eclipse.swt.graphics.Image decorateImage(org.eclipse.swt.graphics.Image baseImage, org.eclipse.swt.graphics.Image decorator)
          Returns an image composed of a base image decorated by another image
static org.eclipse.swt.graphics.Image decorateImage(org.eclipse.swt.graphics.Image baseImage, org.eclipse.swt.graphics.Image decorator, int corner)
          Returns an image composed of a base image decorated by another image
static void dispose()
          Dispose of cached objects and their underlying OS resources.
static void disposeColors()
          Dispose of all the cached colors
static void disposeCursors()
          Dispose all of the cached cursors
static void disposeFonts()
          Dispose all of the cached fonts
static void disposeImages()
          Dispose all of the cached images
static void disposeImages(java.lang.String section)
          Dispose cached images in specified section
static void fixCoolBarSize(org.eclipse.swt.widgets.CoolBar bar)
          Fix the layout of the specified CoolBar
static org.eclipse.swt.graphics.Font getBoldFont(org.eclipse.swt.graphics.Font baseFont)
          Return a bold version of the give font
static org.eclipse.swt.graphics.Color getColor(int systemColorID)
          Returns the system color matching the specific ID
static org.eclipse.swt.graphics.Color getColor(int r, int g, int b)
          Returns a color given its red, green and blue component values
static org.eclipse.swt.graphics.Color getColor(org.eclipse.swt.graphics.RGB rgb)
          Returns a color given its RGB value
static org.eclipse.swt.graphics.Cursor getCursor(int id)
          Returns the system cursor matching the specific ID
static org.eclipse.swt.graphics.Font getFont(java.lang.String name, int height, int style)
          Returns a font based on its name, height and style
static org.eclipse.swt.graphics.Font getFont(java.lang.String name, int size, int style, boolean strikeout, boolean underline)
          Returns a font based on its name, height and style.
static org.eclipse.swt.graphics.Image getImage(java.lang.Class clazz, java.lang.String path)
          Returns an image stored in the file at the specified path relative to the specified class
protected static org.eclipse.swt.graphics.Image getImage(java.io.InputStream is)
          Returns an image encoded by the specified input stream
static org.eclipse.swt.graphics.Image getImage(java.lang.String path)
          Returns an image stored in the file at the specified path
static org.eclipse.swt.graphics.Image getImage(java.lang.String section, java.lang.String path)
          Returns an image stored in the file at the specified path
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_LEFT

public static final int TOP_LEFT
Style constant for placing decorator image in top left corner of base image.

See Also:
Constant Field Values

TOP_RIGHT

public static final int TOP_RIGHT
Style constant for placing decorator image in top right corner of base image.

See Also:
Constant Field Values

BOTTOM_LEFT

public static final int BOTTOM_LEFT
Style constant for placing decorator image in bottom left corner of base image.

See Also:
Constant Field Values

BOTTOM_RIGHT

public static final int BOTTOM_RIGHT
Style constant for placing decorator image in bottom right corner of base image.

See Also:
Constant Field Values
Constructor Detail

SWTResourceManager

public SWTResourceManager()
Method Detail

dispose

public static void dispose()
Dispose of cached objects and their underlying OS resources. This should only be called when the cached objects are no longer needed (e.g. on application shutdown)


getColor

public static org.eclipse.swt.graphics.Color getColor(int systemColorID)
Returns the system color matching the specific ID

Parameters:
systemColorID - int The ID value for the color
Returns:
Color The system color matching the specific ID

getColor

public static org.eclipse.swt.graphics.Color getColor(int r,
                                                      int g,
                                                      int b)
Returns a color given its red, green and blue component values

Parameters:
r - int The red component of the color
g - int The green component of the color
b - int The blue component of the color
Returns:
Color The color matching the given red, green and blue componet values

getColor

public static org.eclipse.swt.graphics.Color getColor(org.eclipse.swt.graphics.RGB rgb)
Returns a color given its RGB value

Parameters:
rgb - RGB The RGB value of the color
Returns:
Color The color matching the RGB value

disposeColors

public static void disposeColors()
Dispose of all the cached colors


getImage

protected static org.eclipse.swt.graphics.Image getImage(java.io.InputStream is)
Returns an image encoded by the specified input stream

Parameters:
is - InputStream The input stream encoding the image data
Returns:
Image The image encoded by the specified input stream

getImage

public static org.eclipse.swt.graphics.Image getImage(java.lang.String path)
Returns an image stored in the file at the specified path

Parameters:
path - String The path to the image file
Returns:
Image The image stored in the file at the specified path

getImage

public static org.eclipse.swt.graphics.Image getImage(java.lang.String section,
                                                      java.lang.String path)
Returns an image stored in the file at the specified path

Parameters:
section - The section to which belongs specified image
path - String The path to the image file
Returns:
Image The image stored in the file at the specified path

getImage

public static org.eclipse.swt.graphics.Image getImage(java.lang.Class clazz,
                                                      java.lang.String path)
Returns an image stored in the file at the specified path relative to the specified class

Parameters:
clazz - Class The class relative to which to find the image
path - String The path to the image file
Returns:
Image The image stored in the file at the specified path

decorateImage

public static org.eclipse.swt.graphics.Image decorateImage(org.eclipse.swt.graphics.Image baseImage,
                                                           org.eclipse.swt.graphics.Image decorator)
Returns an image composed of a base image decorated by another image

Parameters:
baseImage - Image The base image that should be decorated
decorator - Image The image to decorate the base image
Returns:
Image The resulting decorated image

decorateImage

public static org.eclipse.swt.graphics.Image decorateImage(org.eclipse.swt.graphics.Image baseImage,
                                                           org.eclipse.swt.graphics.Image decorator,
                                                           int corner)
Returns an image composed of a base image decorated by another image

Parameters:
baseImage - Image The base image that should be decorated
decorator - Image The image to decorate the base image
corner - The corner to place decorator image
Returns:
Image The resulting decorated image

disposeImages

public static void disposeImages()
Dispose all of the cached images


disposeImages

public static void disposeImages(java.lang.String section)
Dispose cached images in specified section

Parameters:
section - the section do dispose

getFont

public static org.eclipse.swt.graphics.Font getFont(java.lang.String name,
                                                    int height,
                                                    int style)
Returns a font based on its name, height and style

Parameters:
name - String The name of the font
height - int The height of the font
style - int The style of the font
Returns:
Font The font matching the name, height and style

getFont

public static org.eclipse.swt.graphics.Font getFont(java.lang.String name,
                                                    int size,
                                                    int style,
                                                    boolean strikeout,
                                                    boolean underline)
Returns a font based on its name, height and style. Windows-specific strikeout and underline flags are also supported.

Parameters:
name - String The name of the font
size - int The size of the font
style - int The style of the font
strikeout - boolean The strikeout flag (warning: Windows only)
underline - boolean The underline flag (warning: Windows only)
Returns:
Font The font matching the name, height, style, strikeout and underline

getBoldFont

public static org.eclipse.swt.graphics.Font getBoldFont(org.eclipse.swt.graphics.Font baseFont)
Return a bold version of the give font

Parameters:
baseFont - Font The font for whoch a bold version is desired
Returns:
Font The bold version of the give font

disposeFonts

public static void disposeFonts()
Dispose all of the cached fonts


fixCoolBarSize

public static void fixCoolBarSize(org.eclipse.swt.widgets.CoolBar bar)
Fix the layout of the specified CoolBar

Parameters:
bar - CoolBar The CoolBar that shgoud be fixed

getCursor

public static org.eclipse.swt.graphics.Cursor getCursor(int id)
Returns the system cursor matching the specific ID

Parameters:
id - int The ID value for the cursor
Returns:
Cursor The system cursor matching the specific ID

disposeCursors

public static void disposeCursors()
Dispose all of the cached cursors