Class 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 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
    • Constructor Detail

      • SWTResourceManager

        public SWTResourceManager()
    • Method Detail

      • getColor

        public static Color getColor​(int systemColorID)
        Returns the system Color matching the specific ID.
        Parameters:
        systemColorID - the ID value for the color
        Returns:
        the system Color matching the specific ID
      • getColor

        public static Color getColor​(int r,
                                     int g,
                                     int b)
        Returns a Color given its red, green and blue component values.
        Parameters:
        r - the red component of the color
        g - the green component of the color
        b - the blue component of the color
        Returns:
        the Color matching the given red, green and blue component values
      • getColor

        public static Color getColor​(RGB rgb)
        Returns a Color given its RGB value.
        Parameters:
        rgb - the RGB value of the color
        Returns:
        the Color matching the RGB value
      • disposeColors

        public static void disposeColors()
        Dispose of all the cached Color's.
      • getImage

        public static Image getImage​(String path)
        Returns an Image stored in the file at the specified path.
        Parameters:
        path - the path to the image file
        Returns:
        the Image stored in the file at the specified path
      • getImage

        public static Image getImage​(Class<?> clazz,
                                     String path)
        Returns an Image stored in the file at the specified path relative to the specified class.
        Parameters:
        clazz - the Class relative to which to find the image
        path - the path to the image file, if starts with '/'
        Returns:
        the Image stored in the file at the specified path
      • decorateImage

        public static Image decorateImage​(Image baseImage,
                                          Image decorator)
        Returns an Image composed of a base image decorated by another image.
        Parameters:
        baseImage - the base Image that should be decorated
        decorator - the Image to decorate the base image
        Returns:
        Image The resulting decorated image
      • decorateImage

        public static Image decorateImage​(Image baseImage,
                                          Image decorator,
                                          int corner)
        Returns an Image composed of a base image decorated by another image.
        Parameters:
        baseImage - the base Image that should be decorated
        decorator - the Image to decorate the base image
        corner - the corner to place decorator image
        Returns:
        the resulting decorated Image
      • disposeImages

        public static void disposeImages()
        Dispose all of the cached Image's.
      • getFont

        public static Font getFont​(String name,
                                   int height,
                                   int style)
        Returns a Font based on its name, height and style.
        Parameters:
        name - the name of the font
        height - the height of the font
        style - the style of the font
        Returns:
        Font The font matching the name, height and style
      • getFont

        public static Font getFont​(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 - the name of the font
        size - the size of the font
        style - the style of the font
        strikeout - the strikeout flag (warning: Windows only)
        underline - the underline flag (warning: Windows only)
        Returns:
        Font The font matching the name, height, style, strikeout and underline
      • getBoldFont

        public static Font getBoldFont​(Font baseFont)
        Returns a bold version of the given Font.
        Parameters:
        baseFont - the Font for which a bold version is desired
        Returns:
        the bold version of the given Font
      • disposeFonts

        public static void disposeFonts()
        Dispose all of the cached Font'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).