Package org.eclipse.wb.swt
Class SWTResourceManager
- java.lang.Object
-
- org.eclipse.wb.swt.SWTResourceManager
-
- Direct Known Subclasses:
ResourceManager
public class SWTResourceManager extends 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.
-
-
Field Summary
Fields Modifier and Type Field Description static intBOTTOM_LEFTStyle constant for placing decorator image in bottom left corner of base image.static intBOTTOM_RIGHTStyle constant for placing decorator image in bottom right corner of base image.protected static intLAST_CORNER_KEYInternal value.static intTOP_LEFTStyle constant for placing decorator image in top left corner of base image.static intTOP_RIGHTStyle constant for placing decorator image in top right corner of base image.
-
Constructor Summary
Constructors Constructor Description SWTResourceManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ImagedecorateImage(Image baseImage, Image decorator)Returns anImagecomposed of a base image decorated by another image.static ImagedecorateImage(Image baseImage, Image decorator, int corner)Returns anImagecomposed of a base image decorated by another image.static voiddispose()Dispose of cached objects and their underlying OS resources.static voiddisposeColors()Dispose of all the cachedColor's.static voiddisposeCursors()Dispose all of the cached cursors.static voiddisposeFonts()Dispose all of the cachedFont's.static voiddisposeImages()Dispose all of the cachedImage's.static FontgetBoldFont(Font baseFont)Returns a bold version of the givenFont.static ColorgetColor(int systemColorID)Returns the systemColormatching the specific ID.static ColorgetColor(int r, int g, int b)Returns aColorgiven its red, green and blue component values.static ColorgetColor(RGB rgb)Returns aColorgiven its RGB value.static CursorgetCursor(int id)Returns the system cursor matching the specific ID.static FontgetFont(String name, int height, int style)Returns aFontbased on its name, height and style.static FontgetFont(String name, int size, int style, boolean strikeout, boolean underline)Returns aFontbased on its name, height and style.protected static ImagegetImage(InputStream stream)Returns anImageencoded by the specifiedInputStream.static ImagegetImage(Class<?> clazz, String path)Returns anImagestored in the file at the specified path relative to the specified class.static ImagegetImage(String path)Returns anImagestored in the file at the specified path.
-
-
-
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
-
LAST_CORNER_KEY
protected static final int LAST_CORNER_KEY
Internal value.- See Also:
- Constant Field Values
-
-
Method Detail
-
getColor
public static Color getColor(int systemColorID)
Returns the systemColormatching the specific ID.- Parameters:
systemColorID- the ID value for the color- Returns:
- the system
Colormatching the specific ID
-
getColor
public static Color getColor(int r, int g, int b)
Returns aColorgiven its red, green and blue component values.- Parameters:
r- the red component of the colorg- the green component of the colorb- the blue component of the color- Returns:
- the
Colormatching the given red, green and blue component values
-
disposeColors
public static void disposeColors()
Dispose of all the cachedColor's.
-
getImage
protected static Image getImage(InputStream stream) throws IOException
Returns anImageencoded by the specifiedInputStream.- Parameters:
stream- theInputStreamencoding the image data- Returns:
- the
Imageencoded by the specified input stream - Throws:
IOException
-
getImage
public static Image getImage(String path)
Returns anImagestored in the file at the specified path.- Parameters:
path- the path to the image file- Returns:
- the
Imagestored in the file at the specified path
-
getImage
public static Image getImage(Class<?> clazz, String path)
Returns anImagestored in the file at the specified path relative to the specified class.
-
decorateImage
public static Image decorateImage(Image baseImage, Image decorator)
Returns anImagecomposed of a base image decorated by another image.
-
decorateImage
public static Image decorateImage(Image baseImage, Image decorator, int corner)
Returns anImagecomposed of a base image decorated by another image.
-
disposeImages
public static void disposeImages()
Dispose all of the cachedImage's.
-
getFont
public static Font getFont(String name, int height, int style)
Returns aFontbased on its name, height and style.- Parameters:
name- the name of the fontheight- the height of the fontstyle- the style of the font- Returns:
FontThe font matching the name, height and style
-
getFont
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline)
Returns aFontbased on its name, height and style. Windows-specific strikeout and underline flags are also supported.- Parameters:
name- the name of the fontsize- the size of the fontstyle- the style of the fontstrikeout- the strikeout flag (warning: Windows only)underline- the underline flag (warning: Windows only)- Returns:
FontThe font matching the name, height, style, strikeout and underline
-
getBoldFont
public static Font getBoldFont(Font baseFont)
Returns a bold version of the givenFont.
-
disposeFonts
public static void disposeFonts()
Dispose all of the cachedFont's.
-
getCursor
public static 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.
-
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).
-
-