Class SWTGraphicUtil


  • public class SWTGraphicUtil
    extends java.lang.Object
    This class is a singleton that provides useful methods
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SWTGraphicUtil()
      Constructor
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addDisposer​(org.eclipse.swt.widgets.Widget widget, org.eclipse.swt.graphics.Resource resource)
      Dispose safely any SWT resource when a widget is disposed
      static void applyHTMLFormating​(org.eclipse.swt.custom.StyledText styledText)
      Apply a very basic pseudo-HTML formating to a text stored in a StyledText widget.
      static org.eclipse.swt.graphics.ImageData blur​(org.eclipse.swt.graphics.ImageData originalImageData, int radius)  
      private static org.eclipse.swt.graphics.RGB[] blurRow​(org.eclipse.swt.graphics.ImageData originalImageData, int row, int radius)
      Average blurs a given row of image data.
      static org.eclipse.swt.graphics.Font buildFontFrom​(org.eclipse.swt.widgets.Control control, int style)
      Build a font from a given control.
      static org.eclipse.swt.graphics.Font buildFontFrom​(org.eclipse.swt.widgets.Control control, int style, int size)
      Build a font from a given control.
      static void centerShell​(org.eclipse.swt.widgets.Shell shell)
      Center a shell on the primary monitor
      static int computeWidth​(java.lang.String text)  
      static org.eclipse.swt.graphics.Image createImageFromFile​(java.lang.String fileName)
      Loads an image and create a SWT Image corresponding to this file
      static org.eclipse.swt.graphics.Image createReflectedImage​(org.eclipse.swt.graphics.Image source)
      Create a reflected image of a source Inspired by Daniel Spiewak work (http://www.eclipsezone.com/eclipse/forums/t91013.html)
      static org.eclipse.swt.graphics.Image createReflectedResizedImage​(org.eclipse.swt.graphics.Image source, int newWidth, int newHeight)
      Create a reflected and resized version of an image
      static void disableAllChildrenWidgets​(org.eclipse.swt.widgets.Control control)
      Disable all widgets of a control
      static void enableAllChildrenWidgets​(org.eclipse.swt.widgets.Control control)
      Enable all widgets of a control
      static org.eclipse.swt.graphics.Rectangle getBoundsOfMonitorOnWhichShellIsDisplayed​(org.eclipse.swt.widgets.Shell shell)  
      static org.eclipse.swt.graphics.Color getColorSafely​(int r, int g, int b)
      Create a color that is disposed automatically
      static org.eclipse.swt.graphics.Color getDefaultColor​(org.eclipse.swt.widgets.Control control, int red, int green, int blue)  
      static boolean isMacOS()  
      static org.eclipse.swt.graphics.Image resize​(org.eclipse.swt.graphics.Image source, int newWidth, int newHeight)
      Returns a new scaled image.
      static void safeDispose​(org.eclipse.swt.graphics.Resource resource)
      Dispose safely any SWT resource
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SWTGraphicUtil

        private SWTGraphicUtil()
        Constructor
    • Method Detail

      • addDisposer

        public static void addDisposer​(org.eclipse.swt.widgets.Widget widget,
                                       org.eclipse.swt.graphics.Resource resource)
        Dispose safely any SWT resource when a widget is disposed
        Parameters:
        widget - widget attached to the resource
        resource - the resource to dispose
      • safeDispose

        public static void safeDispose​(org.eclipse.swt.graphics.Resource resource)
        Dispose safely any SWT resource
        Parameters:
        resource - the resource to dispose
      • getColorSafely

        public static org.eclipse.swt.graphics.Color getColorSafely​(int r,
                                                                    int g,
                                                                    int b)
        Create a color that is disposed automatically
        Parameters:
        r - red component
        g - green component
        b - blue component
        Returns:
        the color
      • createImageFromFile

        public static org.eclipse.swt.graphics.Image createImageFromFile​(java.lang.String fileName)
        Loads an image and create a SWT Image corresponding to this file
        Parameters:
        fileName - file name of the image
        Returns:
        an image
        See Also:
        Image
      • createReflectedImage

        public static org.eclipse.swt.graphics.Image createReflectedImage​(org.eclipse.swt.graphics.Image source)
        Create a reflected image of a source Inspired by Daniel Spiewak work (http://www.eclipsezone.com/eclipse/forums/t91013.html)
        Parameters:
        source - source to be reflected
        Returns:
        the source image with a reflection
      • resize

        public static org.eclipse.swt.graphics.Image resize​(org.eclipse.swt.graphics.Image source,
                                                            int newWidth,
                                                            int newHeight)
        Returns a new scaled image.
        Parameters:
        source - the image to be scaled
        newWidth - new width of the image
        newHeight - new height of the image
        Returns:
        a scaled image of the source
      • createReflectedResizedImage

        public static org.eclipse.swt.graphics.Image createReflectedResizedImage​(org.eclipse.swt.graphics.Image source,
                                                                                 int newWidth,
                                                                                 int newHeight)
        Create a reflected and resized version of an image
        Parameters:
        source - source image to be scaled and reflected
        newWidth - new width of the scaled image
        newHeight - new height of the scaled image
        Returns:
        the resized and reflected image
      • centerShell

        public static void centerShell​(org.eclipse.swt.widgets.Shell shell)
        Center a shell on the primary monitor
        Parameters:
        shell - shell to center
      • getBoundsOfMonitorOnWhichShellIsDisplayed

        public static org.eclipse.swt.graphics.Rectangle getBoundsOfMonitorOnWhichShellIsDisplayed​(org.eclipse.swt.widgets.Shell shell)
        Parameters:
        shell -
        Returns:
        the bounds of the monitor on which the shell is running
      • applyHTMLFormating

        public static void applyHTMLFormating​(org.eclipse.swt.custom.StyledText styledText)
        Apply a very basic pseudo-HTML formating to a text stored in a StyledText widget. Supported tags are , , , , , and
        Parameters:
        styledText - styled text that contains an HTML text
      • blur

        public static org.eclipse.swt.graphics.ImageData blur​(org.eclipse.swt.graphics.ImageData originalImageData,
                                                              int radius)
        Parameters:
        originalImageData - The ImageData to be average blurred. Transparency information will be ignored.
        radius - the number of radius pixels to consider when blurring image.
        Returns:
        A blurred copy of the image data, or null if an error occured.
      • blurRow

        private static org.eclipse.swt.graphics.RGB[] blurRow​(org.eclipse.swt.graphics.ImageData originalImageData,
                                                              int row,
                                                              int radius)
        Average blurs a given row of image data. Returns the blurred row as a matrix of separated RGB values.
      • enableAllChildrenWidgets

        public static void enableAllChildrenWidgets​(org.eclipse.swt.widgets.Control control)
        Enable all widgets of a control
        Parameters:
        control - control to enable/disable
        enable - true to enable, false to disable
      • disableAllChildrenWidgets

        public static void disableAllChildrenWidgets​(org.eclipse.swt.widgets.Control control)
        Disable all widgets of a control
        Parameters:
        control - control to enable/disable
        enable - true to enable, false to disable
      • buildFontFrom

        public static org.eclipse.swt.graphics.Font buildFontFrom​(org.eclipse.swt.widgets.Control control,
                                                                  int style)
        Build a font from a given control. Useful if we just want a bold label for example
        Parameters:
        control - control that handle the default font
        style - new style
        Returns:
        a font with the given style
      • buildFontFrom

        public static org.eclipse.swt.graphics.Font buildFontFrom​(org.eclipse.swt.widgets.Control control,
                                                                  int style,
                                                                  int size)
        Build a font from a given control. Useful if we just want a bold label for example
        Parameters:
        control - control that handle the default font
        style - new style
        Returns:
        a font with the given style
      • isMacOS

        public static boolean isMacOS()
        Returns:
        true if the operating system is MacOS, false otherwise
      • getDefaultColor

        public static org.eclipse.swt.graphics.Color getDefaultColor​(org.eclipse.swt.widgets.Control control,
                                                                     int red,
                                                                     int green,
                                                                     int blue)
        Parameters:
        control -
        red -
        green -
        blue -
        Returns:
        a color that will be disposed when control is disposed
      • computeWidth

        public static int computeWidth​(java.lang.String text)
        Parameters:
        text -
        Returns:
        the width of text