Class ColorToolsFX

java.lang.Object
qupath.lib.gui.tools.ColorToolsFX

public class ColorToolsFX extends Object
Helper class for converting between packed RGB colors and Java's AWT representation, as well as creating some ColorModels for BufferedImages.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Color
    Black with opacity at 50%.
    static final Color
    White with opacity at 50%.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getARGB(Color color)
    Get a packed int (ARGB) representation of a Color object.
    static Color
    getCachedColor(int r, int g, int b)
    Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).
    static Color
    getCachedColor(int r, int g, int b, int a)
    Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).
    static Color
    Get cached color.
    static Color
    getCachedColor(Integer rgb, boolean hasAlpha)
    Get cached color, explicitly stating whether alpha should be included or not.
    static Color
    getColorWithOpacity(Color color, double opacity)
    Derived a Color from an existing one, setting the alpha component to match the desired opacity.
    static Color
    getColorWithOpacityFX(Integer rgb, double opacity)
    Get a Color from a packed RGB value, setting the alpha component to match the desired opacity.
    static Color
    getDisplayedColor(qupath.lib.objects.PathObject pathObject)
    Get a Color appropriate for displaying an object.
    static Integer
    getDisplayedColorARGB(qupath.lib.objects.PathObject pathObject)
    Get the color with which an object should be displayed, as a packaged ARGB integer.
    static Color
    getPathClassColor(qupath.lib.objects.classes.PathClass pathClass)
    Get a Color appropriate for displaying a PathClass.
    static int
    getRGB(Color color)
    Get a packed int (ARGB) representation of a Color object, omitting the alpha component.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TRANSLUCENT_BLACK_FX

      public static final Color TRANSLUCENT_BLACK_FX
      Black with opacity at 50%.
    • TRANSLUCENT_WHITE_FX

      public static final Color TRANSLUCENT_WHITE_FX
      White with opacity at 50%.
  • Constructor Details

    • ColorToolsFX

      public ColorToolsFX()
  • Method Details

    • getCachedColor

      public static Color getCachedColor(int r, int g, int b, int a)
      Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).
      Parameters:
      r -
      g -
      b -
      a -
      Returns:
    • getCachedColor

      public static Color getCachedColor(int r, int g, int b)
      Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily).
      Parameters:
      r -
      g -
      b -
      Returns:
    • getCachedColor

      public static Color getCachedColor(Integer rgb)
      Get cached color. Assumed not to have alpha set, unless the relevant bits are non-zero.
      Parameters:
      rgb -
      Returns:
    • getCachedColor

      public static Color getCachedColor(Integer rgb, boolean hasAlpha)
      Get cached color, explicitly stating whether alpha should be included or not.
      Parameters:
      rgb -
      hasAlpha -
      Returns:
    • getRGB

      public static int getRGB(Color color)
      Get a packed int (ARGB) representation of a Color object, omitting the alpha component.
      Parameters:
      color -
      Returns:
    • getARGB

      public static int getARGB(Color color)
      Get a packed int (ARGB) representation of a Color object.
      Parameters:
      color -
      Returns:
    • getDisplayedColor

      public static Color getDisplayedColor(qupath.lib.objects.PathObject pathObject)
      Get a Color appropriate for displaying an object.
      Parameters:
      pathObject -
      Returns:
      See Also:
    • getPathClassColor

      public static Color getPathClassColor(qupath.lib.objects.classes.PathClass pathClass)
      Get a Color appropriate for displaying a PathClass.
      Parameters:
      pathClass -
      Returns:
    • getColorWithOpacityFX

      public static Color getColorWithOpacityFX(Integer rgb, double opacity)
      Get a Color from a packed RGB value, setting the alpha component to match the desired opacity.
      Parameters:
      rgb -
      opacity -
      Returns:
    • getColorWithOpacity

      public static Color getColorWithOpacity(Color color, double opacity)
      Derived a Color from an existing one, setting the alpha component to match the desired opacity.
      Parameters:
      color -
      opacity -
      Returns:
    • getDisplayedColorARGB

      public static Integer getDisplayedColorARGB(qupath.lib.objects.PathObject pathObject)
      Get the color with which an object should be displayed, as a packaged ARGB integer. This could be stored internally, or obtained from its PathClass. If neither of these produces a result, a default color will be returned based on PathPrefs for the specific (Java) class of the PathObject. Assuming PathPrefs does not contain any nulls, this will therefore not return nulls either.
      Parameters:
      pathObject -
      Returns: