Class GUIHelper


  • public final class GUIHelper
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.eclipse.swt.graphics.RGB blend​(org.eclipse.swt.graphics.RGB val1, org.eclipse.swt.graphics.RGB val2)
      Blend the two colour values returning a value that is halfway between them.
      static int convertHorizontalDpiToPixel​(int dpi)
      Converts the given DPI scaled value to a pixel value using the factor for the horizontal DPI.
      static int convertHorizontalDpiToPixel​(int dpi, boolean forDisplayDPI)
      Converts the given DPI scaled value to a pixel value using the factor for the horizontal DPI.
      static int convertHorizontalDpiToPixel​(int dpi, IConfigRegistry configRegistry)
      Default method to convert the given amount of horizontal dots per inch to a pixel value.
      static int convertHorizontalPixelToDpi​(int pixel)
      Converts the given amount of pixels to a DPI scaled value using the factor for the horizontal DPI value.
      static int convertHorizontalPixelToDpi​(int pixel, boolean forDisplayDPI)
      Converts the given amount of pixels to a DPI scaled value using the factor for the horizontal DPI value.
      static int convertHorizontalPixelToDpi​(int pixel, IConfigRegistry configRegistry)
      Default method to convert the given amount of pixels to a horizontal dots per inch value.
      static int convertVerticalDpiToPixel​(int dpi)
      Converts the given DPI scaled value to a pixel value using the factor for the vertical DPI.
      static int convertVerticalDpiToPixel​(int dpi, boolean forDisplayDPI)
      Converts the given DPI scaled value to a pixel value using the factor for the vertical DPI.
      static int convertVerticalDpiToPixel​(int dpi, IConfigRegistry configRegistry)
      Default method to convert the given amount of vertical dots per inch to pixel.
      static int convertVerticalPixelToDpi​(int pixel)
      Converts the given amount of pixels to a DPI scaled value using the factor for the vertical DPI.
      static int convertVerticalPixelToDpi​(int pixel, boolean forDisplayDPI)
      Converts the given amount of pixels to a DPI scaled value using the factor for the vertical DPI.
      static int convertVerticalPixelToDpi​(int pixel, IConfigRegistry configRegistry)
      Default method to convert the given amount of pixels to a vertical dots per inch value.
      static org.eclipse.swt.graphics.Color getColor​(int red, int green, int blue)  
      static org.eclipse.swt.graphics.Color getColor​(String key)  
      static org.eclipse.swt.graphics.Color getColor​(org.eclipse.swt.graphics.RGB rgb)  
      static org.eclipse.swt.graphics.Image getDisplayImage​(String imageName)
      Returns the Image representation of a NatTable internal image resource.
      static org.eclipse.swt.graphics.Image getDisplayImageByURL​(String key, URL url)
      This method returns the Image that is registered for the given key.
      static org.eclipse.swt.graphics.Image getDisplayImageByURL​(URL url)
      This method extracts the base filename out of the given URL and uses it as key to search for the Image in the ImageRegistry.
      static float getDpiFactor​(int dpi)
      Returns the factor for scaling calculations of pixels regarding the DPI.
      static int getDpiX()  
      static int getDpiX​(boolean displayDPI)
      Returns the horizontal dots per inch configured locally.
      static int getDpiY()  
      static int getDpiY​(boolean displayDPI)
      Returns the vertical dots per inch configured locally.
      static org.eclipse.swt.graphics.Font getFont​(String key)  
      static org.eclipse.swt.graphics.Font getFont​(org.eclipse.swt.graphics.FontData... fontDatas)  
      static org.eclipse.swt.graphics.Image getImage​(String imageName)
      Returns the Image representation of a NatTable internal image resource.
      static org.eclipse.swt.graphics.Image getImage​(String imageName, boolean considerScaling, boolean forDisplayDPI)
      Returns the Image representation of a NatTable internal image resource.
      static org.eclipse.swt.graphics.Image getImageByURL​(String key, URL url)
      This method returns the Image that is registered for the given key.
      static org.eclipse.swt.graphics.Image getImageByURL​(String key, URL url, boolean considerScaling, boolean forDisplayDPI)
      This method returns the Image that is registered for the given key.
      static org.eclipse.swt.graphics.Image getImageByURL​(URL url)
      This method extracts the base filename out of the given URL and uses it as key to search for the Image in the ImageRegistry.
      static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor​(String imageName)
      Returns the ImageDescriptor for a NatTable internal image resource.
      static URL getInternalImageUrl​(String imageName)
      Searches for the image with the given filename in the NatTable internal image resource folder with file extensions .png and .gif.
      static URL getInternalImageUrl​(String imageName, boolean needScaling)
      Searches for the image with the given filename in the NatTable internal image resource folder with file extensions .png and .gif.
      static URL getInternalImageUrl​(String imageName, boolean needScaling, boolean forDisplayDPI)
      Searches for the image with the given filename in the NatTable internal image resource folder with file extensions .png and .gif.
      static org.eclipse.swt.graphics.Font getScaledFont​(org.eclipse.swt.graphics.Font font, float fontScalingFactor)
      Return a scaled version of the configured font if font scaling is needed.
      static String getScalingImageSuffix()  
      static String getScalingImageSuffix​(boolean forDisplayDPI)  
      static String getSequenceNumber()  
      static boolean needScaling()  
      static boolean needScaling​(boolean forDisplay)  
      static void setDpi​(int x, int y)
      Set the dpi values that are used for image scaling.
    • Field Detail

      • COLOR_GRAY

        public static final org.eclipse.swt.graphics.Color COLOR_GRAY
      • COLOR_WHITE

        public static final org.eclipse.swt.graphics.Color COLOR_WHITE
      • COLOR_DARK_GRAY

        public static final org.eclipse.swt.graphics.Color COLOR_DARK_GRAY
      • COLOR_BLACK

        public static final org.eclipse.swt.graphics.Color COLOR_BLACK
      • COLOR_BLUE

        public static final org.eclipse.swt.graphics.Color COLOR_BLUE
      • COLOR_RED

        public static final org.eclipse.swt.graphics.Color COLOR_RED
      • COLOR_YELLOW

        public static final org.eclipse.swt.graphics.Color COLOR_YELLOW
      • COLOR_GREEN

        public static final org.eclipse.swt.graphics.Color COLOR_GREEN
      • COLOR_LIST_BACKGROUND

        public static final org.eclipse.swt.graphics.Color COLOR_LIST_BACKGROUND
      • COLOR_LIST_FOREGROUND

        public static final org.eclipse.swt.graphics.Color COLOR_LIST_FOREGROUND
      • COLOR_LIST_SELECTION

        public static final org.eclipse.swt.graphics.Color COLOR_LIST_SELECTION
      • COLOR_LIST_SELECTION_TEXT

        public static final org.eclipse.swt.graphics.Color COLOR_LIST_SELECTION_TEXT
      • COLOR_WIDGET_BACKGROUND

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_BACKGROUND
      • COLOR_WIDGET_FOREGROUND

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_FOREGROUND
      • COLOR_TITLE_INACTIVE_BACKGROUND

        public static final org.eclipse.swt.graphics.Color COLOR_TITLE_INACTIVE_BACKGROUND
      • COLOR_WIDGET_BORDER

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_BORDER
      • COLOR_WIDGET_DARK_SHADOW

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_DARK_SHADOW
      • COLOR_WIDGET_LIGHT_SHADOW

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_LIGHT_SHADOW
      • COLOR_WIDGET_NORMAL_SHADOW

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_NORMAL_SHADOW
      • COLOR_WIDGET_HIGHLIGHT_SHADOW

        public static final org.eclipse.swt.graphics.Color COLOR_WIDGET_HIGHLIGHT_SHADOW
      • DEFAULT_FONT

        public static final org.eclipse.swt.graphics.Font DEFAULT_FONT
      • DEFAULT_RESIZE_HANDLE_SIZE

        public static final int DEFAULT_RESIZE_HANDLE_SIZE
        See Also:
        Constant Field Values
      • DEFAULT_MIN_DISPLAY_SIZE

        public static final int DEFAULT_MIN_DISPLAY_SIZE
        See Also:
        Constant Field Values
    • Method Detail

      • getColor

        public static org.eclipse.swt.graphics.Color getColor​(org.eclipse.swt.graphics.RGB rgb)
      • getColor

        public static org.eclipse.swt.graphics.Color getColor​(int red,
                                                              int green,
                                                              int blue)
      • getColor

        public static org.eclipse.swt.graphics.Color getColor​(String key)
      • getFont

        public static org.eclipse.swt.graphics.Font getFont​(org.eclipse.swt.graphics.FontData... fontDatas)
      • getFont

        public static org.eclipse.swt.graphics.Font getFont​(String key)
      • getScaledFont

        public static org.eclipse.swt.graphics.Font getScaledFont​(org.eclipse.swt.graphics.Font font,
                                                                  float fontScalingFactor)
        Return a scaled version of the configured font if font scaling is needed. If no font scaling is needed, the given font is returned.
        Parameters:
        font - The font to scale.
        Returns:
        The font with the updated height if font scaling is needed, otherwise the given font.
        Since:
        2.0
      • getImageByURL

        public static org.eclipse.swt.graphics.Image getImageByURL​(URL url)
        This method extracts the base filename out of the given URL and uses it as key to search for the Image in the ImageRegistry. If the Image is not yet present it will create the Image instance and register it automatically. On creating and registering it will respect dpi scaling.
        Parameters:
        url - The URL of the image for initial loading.
        Returns:
        The Image representation of an image external to NatTable.
        See Also:
        getImageByURL(String, URL)
      • getImageByURL

        public static org.eclipse.swt.graphics.Image getImageByURL​(String key,
                                                                   URL url)
        This method returns the Image that is registered for the given key. If there is no Image registered for that key already, it will create and register the Image that can be loaded by the given URL.

        This method returns an Image that matches the dpi settings. If the dpi of an axis is bigger than 96 it will search for an image for the bigger dpi. For this the filenames need to carry the dpi information.

        For example if you request checkbox.png this method will search for a scaled version relative to the requested image. The following will give an example on the scaled files:

        • checkbox.png
        • checkbox_120_120.png
        • checkbox_128_128.png
        • checkbox_144_144.png
        • checkbox_192_192.png
        • checkbox_288_288.png

        If the matching scaled version is not found, it will automatically upscale the base image.

        Note: If you want to get the image later again you can directly use JFaceResources.getImage(key).

        Parameters:
        key - The key under which the resource is registered in the image registry.
        url - The URL of the image for initial loading.
        Returns:
        The Image representation of an image external to NatTable.
      • getDisplayImageByURL

        public static org.eclipse.swt.graphics.Image getDisplayImageByURL​(URL url)
        This method extracts the base filename out of the given URL and uses it as key to search for the Image in the ImageRegistry. If the Image is not yet present it will create the Image instance and register it automatically. On creating and registering it will respect display dpi scaling.
        Parameters:
        url - The URL of the image for initial loading.
        Returns:
        The Image representation of an image external to NatTable.
        Since:
        2.0
        See Also:
        getImageByURL(String, URL)
      • getDisplayImageByURL

        public static org.eclipse.swt.graphics.Image getDisplayImageByURL​(String key,
                                                                          URL url)
        This method returns the Image that is registered for the given key. If there is no Image registered for that key already, it will create and register the Image that can be loaded by the given URL.

        This method returns an Image that matches the display dpi settings. If the dpi of an axis is bigger than 96 it will search for an image for the bigger dpi. For this the filenames need to carry the dpi information.

        For example if you request checkbox.png this method will search for a scaled version relative to the requested image. The following will give an example on the scaled files:

        • checkbox.png
        • checkbox_120_120.png
        • checkbox_128_128.png
        • checkbox_144_144.png
        • checkbox_192_192.png
        • checkbox_288_288.png

        If the matching scaled version is not found, it will automatically upscale the base image.

        Note: If you want to get the image later again you can directly use JFaceResources.getImage(key).

        Parameters:
        key - The key under which the resource is registered in the image registry.
        url - The URL of the image for initial loading.
        Returns:
        The Image representation of an image external to NatTable.
        Since:
        2.0
      • getImageByURL

        public static org.eclipse.swt.graphics.Image getImageByURL​(String key,
                                                                   URL url,
                                                                   boolean considerScaling,
                                                                   boolean forDisplayDPI)
        This method returns the Image that is registered for the given key. If there is no Image registered for that key already, it will create and register the Image that can be loaded by the given URL.

        This method returns an Image that matches the dpi settings. If the dpi of an axis is bigger than 96 it will search for an image for the bigger dpi. For this the filenames need to carry the dpi information.

        For example if you request checkbox.png this method will search for a scaled version relative to the requested image. The following will give an example on the scaled files:

        • checkbox.png
        • checkbox_120_120.png
        • checkbox_128_128.png
        • checkbox_144_144.png
        • checkbox_192_192.png
        • checkbox_288_288.png

        If the matching scaled version is not found, it will automatically upscale the base image.

        Note: If you want to get the image later again you can directly use JFaceResources.getImage(key).

        Parameters:
        key - The key under which the resource is registered in the image registry.
        url - The URL of the image for initial loading.
        considerScaling - true if image scaling according to the scaling settings should be performed, false if only the existing file should be considered without scaling.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The Image representation of an image external to NatTable.
        Since:
        2.0
      • getImage

        public static org.eclipse.swt.graphics.Image getImage​(String imageName)
        Returns the Image representation of a NatTable internal image resource. Will handle scaling if needed.

        For upscaling this method checks whether there is a upscaled version of the image available, otherwise it will upscale the existing image and store that in the registry for further use.

        Parameters:
        imageName - The filename of the image (without extension).
        Returns:
        The Image representation of the internal NatTable image resource or null if there is no image found for the given name at the internal image resource location.
      • getDisplayImage

        public static org.eclipse.swt.graphics.Image getDisplayImage​(String imageName)
        Returns the Image representation of a NatTable internal image resource. Will apply scaling for the current display scaling factor if needed.

        For upscaling this method checks whether there is a upscaled version of the image available, otherwise it will upscale the existing image and store that in the registry for further use.

        Parameters:
        imageName - The filename of the image (without extension).
        Returns:
        The Image representation of the internal NatTable image resource or null if there is no image found for the given name at the internal image resource location.
        Since:
        2.0
      • getImage

        public static org.eclipse.swt.graphics.Image getImage​(String imageName,
                                                              boolean considerScaling,
                                                              boolean forDisplayDPI)
        Returns the Image representation of a NatTable internal image resource.

        For upscaling this method checks whether there is a upscaled version of the image available, otherwise it will upscale the existing image and store that in the registry for further use.

        Parameters:
        imageName - The filename of the image (without extension).
        considerScaling - true if image scaling according to the scaling settings should be performed, false if only the existing file should be considered without scaling.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The Image representation of the internal NatTable image resource or null if there is no image found for the given name at the internal image resource location.
        Since:
        2.0
      • getImageDescriptor

        public static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor​(String imageName)
        Returns the ImageDescriptor for a NatTable internal image resource.
        Parameters:
        imageName - The filename of the image (without extension).
        Returns:
        The ImageDescriptor of the internal NatTable image resource or null if there is no image found for the given name at the internal image resource location.
      • getInternalImageUrl

        public static URL getInternalImageUrl​(String imageName)
        Searches for the image with the given filename in the NatTable internal image resource folder with file extensions .png and .gif.
        Parameters:
        imageName - The filename of the image (without extension)
        Returns:
        The URL of the internal NatTable image or null if there is no image found for the given name at the internal image resource location.
        Since:
        1.5
      • getInternalImageUrl

        public static URL getInternalImageUrl​(String imageName,
                                              boolean needScaling)
        Searches for the image with the given filename in the NatTable internal image resource folder with file extensions .png and .gif.
        Parameters:
        imageName - The filename of the image (without extension).
        needScaling - true in case the scaled version is requested, false if the original version is requested.
        Returns:
        The URL of the internal NatTable image or null if there is no image found for the given name at the internal image resource location.
        Since:
        1.5
      • getInternalImageUrl

        public static URL getInternalImageUrl​(String imageName,
                                              boolean needScaling,
                                              boolean forDisplayDPI)
        Searches for the image with the given filename in the NatTable internal image resource folder with file extensions .png and .gif.
        Parameters:
        imageName - The filename of the image (without extension)
        needScaling - true in case the scaled version is requested, false if the original version is requested.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The URL of the internal NatTable image or null if there is no image found for the given name at the internal image resource location.
        Since:
        2.0
      • getSequenceNumber

        public static String getSequenceNumber()
      • blend

        public static org.eclipse.swt.graphics.RGB blend​(org.eclipse.swt.graphics.RGB val1,
                                                         org.eclipse.swt.graphics.RGB val2)
        Blend the two colour values returning a value that is halfway between them.
        Parameters:
        val1 - the first value
        val2 - the second value
        Returns:
        the blended colour
      • getDpiFactor

        public static float getDpiFactor​(int dpi)
        Returns the factor for scaling calculations of pixels regarding the DPI.
        Parameters:
        dpi - The DPI for which the factor is requested.
        Returns:
        The factor for dpi scaling calculations.
      • setDpi

        public static void setDpi​(int x,
                                  int y)
        Set the dpi values that are used for image scaling.
        Parameters:
        x - The horizontal dots per inch.
        y - The vertical dots per inch.
        Since:
        2.0
      • needScaling

        public static boolean needScaling()
        Returns:
        true if either the horizontal or the vertical DPI value is bigger than 96.
      • needScaling

        public static boolean needScaling​(boolean forDisplay)
        Parameters:
        forDisplay - if the check should be performed against the display scaling or the configured scaling.
        Returns:
        true if either the horizontal or the vertical DPI value is bigger than 96.
        Since:
        2.0
      • getDpiX

        public static int getDpiX()
        Returns:
        The horizontal dots per inch.
      • getDpiX

        public static int getDpiX​(boolean displayDPI)
        Returns the horizontal dots per inch configured locally. If no local dpi configuration is set, it falls back to the display dpi.
        Parameters:
        displayDPI - If the display dpi should be returned always.
        Returns:
        The horizontal dots per inch.
        Since:
        2.0
      • getDpiY

        public static int getDpiY()
        Returns:
        The vertical dots per inch.
      • getDpiY

        public static int getDpiY​(boolean displayDPI)
        Returns the vertical dots per inch configured locally. If no local dpi configuration is set, it falls back to the display dpi.
        Parameters:
        displayDPI - If the display dpi should be returned always.
        Returns:
        The vertical dots per inch.
        Since:
        2.0
      • getScalingImageSuffix

        public static String getScalingImageSuffix()
        Returns:
        The suffix that is used to mark an image as upscaled image.
      • getScalingImageSuffix

        public static String getScalingImageSuffix​(boolean forDisplayDPI)
        Parameters:
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The suffix that is used to mark an image as upscaled image.
        Since:
        2.0
      • convertHorizontalPixelToDpi

        public static int convertHorizontalPixelToDpi​(int pixel)
        Converts the given amount of pixels to a DPI scaled value using the factor for the horizontal DPI value.
        Parameters:
        pixel - the amount of pixels to convert.
        Returns:
        The converted pixels.
      • convertHorizontalPixelToDpi

        public static int convertHorizontalPixelToDpi​(int pixel,
                                                      boolean forDisplayDPI)
        Converts the given amount of pixels to a DPI scaled value using the factor for the horizontal DPI value.
        Parameters:
        pixel - the amount of pixels to convert.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The converted pixels.
        Since:
        2.0
      • convertHorizontalDpiToPixel

        public static int convertHorizontalDpiToPixel​(int dpi)
        Converts the given DPI scaled value to a pixel value using the factor for the horizontal DPI.
        Parameters:
        dpi - the DPI value to convert.
        Returns:
        The pixel value related to the given DPI
      • convertHorizontalDpiToPixel

        public static int convertHorizontalDpiToPixel​(int dpi,
                                                      boolean forDisplayDPI)
        Converts the given DPI scaled value to a pixel value using the factor for the horizontal DPI.
        Parameters:
        dpi - the DPI value to convert.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The pixel value related to the given DPI
        Since:
        2.0
      • convertVerticalPixelToDpi

        public static int convertVerticalPixelToDpi​(int pixel)
        Converts the given amount of pixels to a DPI scaled value using the factor for the vertical DPI.
        Parameters:
        pixel - the amount of pixels to convert.
        Returns:
        The converted pixels.
      • convertVerticalPixelToDpi

        public static int convertVerticalPixelToDpi​(int pixel,
                                                    boolean forDisplayDPI)
        Converts the given amount of pixels to a DPI scaled value using the factor for the vertical DPI.
        Parameters:
        pixel - the amount of pixels to convert.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The converted pixels.
        Since:
        2.0
      • convertVerticalDpiToPixel

        public static int convertVerticalDpiToPixel​(int dpi)
        Converts the given DPI scaled value to a pixel value using the factor for the vertical DPI.
        Parameters:
        dpi - the DPI value to convert.
        Returns:
        The pixel value related to the given DPI
      • convertVerticalDpiToPixel

        public static int convertVerticalDpiToPixel​(int dpi,
                                                    boolean forDisplayDPI)
        Converts the given DPI scaled value to a pixel value using the factor for the vertical DPI.
        Parameters:
        dpi - the DPI value to convert.
        forDisplayDPI - Whether the display DPI or the configured DPI should be considered.
        Returns:
        The pixel value related to the given DPI
        Since:
        2.0