Class ImageHelper


  • public class ImageHelper
    extends java.lang.Object
    Class to create a tooltip for images in the Assets directory.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      ImageHelper() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static voidaddImageTooltipBottomPart​(PropCnr prop, org.eclipse.swt.widgets.Composite composite, AssetReference ref, org.eclipse.core.resources.IFile file, java.lang.String id, org.eclipse.swt.graphics.Rectangle rect, SingleImageControl ic)
      Adds the bottom part to the tooltip composite.
      static SingleImageControladdImageTooltipImagePart​(org.eclipse.swt.widgets.Composite composite, AssetReference ref, org.eclipse.core.resources.IFile file, org.eclipse.swt.graphics.Rectangle rect)
      Creates the default image part for the tooltip, added to the top composite.
      static voidaddImageTooltipPreviews​(org.eclipse.swt.widgets.Composite composite, java.util.ArrayList<AssetReference> refs, java.util.ArrayList<Position> offsets, int cx, int cy, SingleImageControl ic)
      Creates a preview of the part images with a separator line below.
      static org.eclipse.swt.widgets.CompositecreateImageTooltip​(PropCnr prop, org.eclipse.swt.widgets.Composite parent, AssetReference ref, org.eclipse.swt.graphics.Image typeImage, java.lang.String type, java.lang.String id)
      Creates a composite for the specified file name.
      static org.eclipse.swt.widgets.CompositecreateImageTooltip​(PropCnr prop, org.eclipse.swt.widgets.Composite parent, AssetReference ref, org.eclipse.swt.graphics.Image typeImage, java.lang.String type, java.lang.String id, org.eclipse.swt.graphics.Rectangle rect)
      Creates a composite for the specified file name.
      static org.eclipse.swt.widgets.CompositecreateImageTooltip​(org.eclipse.swt.widgets.Composite parent, org.eclipse.core.resources.IFile file, org.eclipse.swt.graphics.Image typeImage, java.lang.String type, java.lang.String id)
      Creates a composite for the specified file name.
      static org.eclipse.swt.widgets.CompositecreateImageTooltipTopPart​(org.eclipse.swt.widgets.Composite parent, org.eclipse.swt.graphics.Image typeImage, java.lang.String type, java.lang.String id)
      Creates the top part of the image composite for tooltips.
      static voidflagVerification​(PropCnr pc)
      Flags changes when asset changed or asset file reference input changed.
      static java.lang.StringgetSize​(LastVerified last)
      Gets the size string.
      static java.lang.StringgetSizeString​(org.eclipse.core.resources.IFile file)
      Helper to get the size of a file.
      static java.lang.StringgetTypeString​(PropCnr stateCnr)
      Gets the type string.
      static intgetTypeValue​(java.lang.String s)
      Gets the mask value for types defined.
      static booleanisImageExtension​(FilePropCnr fpc, boolean includeSVG)
      Checks if it's an image resource, i.e.
      static booleanisImageExtension​(java.lang.String ext, boolean includeSVG)
      Checks if it's an image file, i.e.
      static booleanisImageExtension​(org.eclipse.core.resources.IResource resource, boolean includeSVG)
      Checks if it's an image resource, i.e.
      static org.eclipse.swt.graphics.ImageloadImage​(org.eclipse.core.resources.IFile file, java.lang.StringBuilder error)
      Loads an image from a file.
      static booleanverify​(PropCnr pc, PropVerification verification)
      Verifies an image against a size.
      • Methods inherited from class java.lang.Object

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

      • ImageHelper

        public ImageHelper()
    • Method Detail

      • isImageExtension

        public static boolean isImageExtension​(java.lang.String ext,
                                               boolean includeSVG)
        Checks if it's an image file, i.e. that the file extension is "gif", "png", "jpg", or "jpeg".
        Parameters:
        ext - The file extension without the "dot", can be null for none.
        includeSVG - Include "svg" as potential file extensions.
        Returns:
        If it's potentially an image or not.
      • isImageExtension

        public static boolean isImageExtension​(org.eclipse.core.resources.IResource resource,
                                               boolean includeSVG)
        Checks if it's an image resource, i.e. that the file extension is "gif", "png", "jpg" or "jpeg".
        Parameters:
        resource - The resource, or null for none.
        includeSVG - Include "svg" as potential file extensions.
        Returns:
        If it's potentially an image or not.
      • isImageExtension

        public static boolean isImageExtension​(FilePropCnr fpc,
                                               boolean includeSVG)
        Checks if it's an image resource, i.e. it's a file in Assets and that the file extension is "gif", "png", "jpg" or "jpeg".
        Parameters:
        fpc - The file property.
        includeSVG - Include "svg" as potential file extensions.
        Returns:
        If it's potentially an image or not.
      • loadImage

        public static org.eclipse.swt.graphics.Image loadImage​(org.eclipse.core.resources.IFile file,
                                                               java.lang.StringBuilder error)
        Loads an image from a file.
        Parameters:
        file - The file.
        error - Buffer where possible error message is stored when image can't be loaded, null for none.
        Returns:
        The image or null if it couldn't be loaded.
      • createImageTooltip

        public static org.eclipse.swt.widgets.Composite createImageTooltip​(org.eclipse.swt.widgets.Composite parent,
                                                                           org.eclipse.core.resources.IFile file,
                                                                           org.eclipse.swt.graphics.Image typeImage,
                                                                           java.lang.String type,
                                                                           java.lang.String id)
        Creates a composite for the specified file name.
        Parameters:
        parent - The parent composite.
        file - The file.
        Returns:
        The composite to use for tooltips, null if not possible. The composite uses a GridLayout with two columns in case additional information should be added, such as property errors or other properties.
      • createImageTooltip

        public static org.eclipse.swt.widgets.Composite createImageTooltip​(PropCnr prop,
                                                                           org.eclipse.swt.widgets.Composite parent,
                                                                           AssetReference ref,
                                                                           org.eclipse.swt.graphics.Image typeImage,
                                                                           java.lang.String type,
                                                                           java.lang.String id)
        Creates a composite for the specified file name.
        Parameters:
        parent - The parent composite.
        Returns:
        The composite to use for tooltips, null if not possible. The composite uses a GridLayout with two columns in case additional information should be added, such as property errors or other properties.
      • createImageTooltip

        public static org.eclipse.swt.widgets.Composite createImageTooltip​(PropCnr prop,
                                                                           org.eclipse.swt.widgets.Composite parent,
                                                                           AssetReference ref,
                                                                           org.eclipse.swt.graphics.Image typeImage,
                                                                           java.lang.String type,
                                                                           java.lang.String id,
                                                                           org.eclipse.swt.graphics.Rectangle rect)
        Creates a composite for the specified file name.
        Parameters:
        parent - The parent composite.
        Returns:
        The composite to use for tooltips, null if not possible. The composite uses a GridLayout with two columns in case additional information should be added, such as property errors or other properties.
      • createImageTooltipTopPart

        public static org.eclipse.swt.widgets.Composite createImageTooltipTopPart​(org.eclipse.swt.widgets.Composite parent,
                                                                                  org.eclipse.swt.graphics.Image typeImage,
                                                                                  java.lang.String type,
                                                                                  java.lang.String id)
        Creates the top part of the image composite for tooltips.
      • addImageTooltipImagePart

        public static SingleImageControl addImageTooltipImagePart​(org.eclipse.swt.widgets.Composite composite,
                                                                  AssetReference ref,
                                                                  org.eclipse.core.resources.IFile file,
                                                                  org.eclipse.swt.graphics.Rectangle rect)
        Creates the default image part for the tooltip, added to the top composite.
      • addImageTooltipBottomPart

        public static void addImageTooltipBottomPart​(PropCnr prop,
                                                     org.eclipse.swt.widgets.Composite composite,
                                                     AssetReference ref,
                                                     org.eclipse.core.resources.IFile file,
                                                     java.lang.String id,
                                                     org.eclipse.swt.graphics.Rectangle rect,
                                                     SingleImageControl ic)
        Adds the bottom part to the tooltip composite.
      • addImageTooltipPreviews

        public static void addImageTooltipPreviews​(org.eclipse.swt.widgets.Composite composite,
                                                   java.util.ArrayList<AssetReference> refs,
                                                   java.util.ArrayList<Position> offsets,
                                                   int cx,
                                                   int cy,
                                                   SingleImageControl ic)
        Creates a preview of the part images with a separator line below. If offsets is null, offsets are not used.
      • getSizeString

        public static java.lang.String getSizeString​(org.eclipse.core.resources.IFile file)
        Helper to get the size of a file.
      • verify

        public static boolean verify​(PropCnr pc,
                                     PropVerification verification)
        Verifies an image against a size.
        Parameters:
        pc - Property container to verify that also must implement ILastVerified
        verification - Verification instance.
      • flagVerification

        public static void flagVerification​(PropCnr pc)
        Flags changes when asset changed or asset file reference input changed.
      • getTypeValue

        public static int getTypeValue​(java.lang.String s)
        Gets the mask value for types defined. Several values can be combined with '+'.
      • getTypeString

        public static java.lang.String getTypeString​(PropCnr stateCnr)
        Gets the type string.
      • getSize

        public static java.lang.String getSize​(LastVerified last)
        Gets the size string.