Module ij
Package ij.plugin

Class Colors

java.lang.Object
ij.plugin.Colors
All Implemented Interfaces:
PlugIn, ItemListener, EventListener

public class Colors extends Object implements PlugIn, ItemListener
This plugin implements most of the Edit/Options/Colors command.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Converts a Color into a lowercase string ("red", "green", "#aa55ff", etc.).
    static String
    Converts a Color into a string ("Red", "Green", #aa55ff, etc.).
    static Color
    decode(String hexColor)
    Converts a String with the color name or the hexadecimal representation of a color with 6 or 8 hex digits to a Color.
    static Color
    decode(String hexColor, Color defaultColor)
    Converts a String with the color name or the hexadecimal representation of a color with 6 or 8 hex digits to a Color.
    static int
    getBlue(String hexColor)
     
    static Color
    getColor(String name, Color defaultColor)
    For named colors, converts the name String to the corresponding color.
    static String
    getColorName(Color c, String defaultName)
    For named colors, returns the name, or 'defaultName' if not a named color.
    static String[]
    getColors(String... moreColors)
    Returns an array of the color Strings in the argument(s) and the 13 predefined color names "Red", "Green", ...
    static int
    getGreen(String hexColor)
     
    static int
    getRed(String hexColor)
     
    static String
    Converts a hex color (e.g., "ffff00") into "red", "green", "yellow", etc.
    static String
    Converts a hex color (e.g., "ffff00" or "#ffff00") into a color name "Red", "Green", "Yellow", etc.
    void
    Callback listener for Choice modifications in the dialog
    void
    run(String arg)
    This method is called when the plugin is loaded.
    static Color
    toColor(int red, int green, int blue)
    Returns an opaque color with the specified red, green, and blue values.
    static Color
    wavelengthToColor(double wl)
    Converts a wavelength (380-750 nm) to color.

    Methods inherited from class java.lang.Object

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

    • colors

      public static final String[] colors
  • Constructor Details

    • Colors

      public Colors()
  • Method Details

    • run

      public void run(String arg)
      Description copied from interface: PlugIn
      This method is called when the plugin is loaded. 'arg', which may be blank, is the argument specified for this plugin in IJ_Props.txt.
      Specified by:
      run in interface PlugIn
    • getColorName

      public static String getColorName(Color c, String defaultName)
      For named colors, returns the name, or 'defaultName' if not a named color. If 'defaultName' is non-null and starts with an uppercase character, the returned name is capitalized (first character uppercase). Use colorToString or colorToString2 to get a String representation (hexadecimal) also for unnamed colors.
    • getColor

      public static Color getColor(String name, Color defaultColor)
      For named colors, converts the name String to the corresponding color. Returns 'defaultColor' if the color has no name. Use 'decode' to also decode hex color names like "#ffff00"
    • decode

      public static Color decode(String hexColor)
      Converts a String with the color name or the hexadecimal representation of a color with 6 or 8 hex digits to a Color. With 8 hex digits, the first two digits are the alpha. With 6 hex digits, the color is opaque (alpha = hex ff). A hex String may be preceded by '#' such as "#80ff00". When the string does not include a valid color name or hex code, returns Color.GRAY.
    • decode

      public static Color decode(String hexColor, Color defaultColor)
      Converts a String with the color name or the hexadecimal representation of a color with 6 or 8 hex digits to a Color. With 8 hex digits, the first two digits are the alpha. With 6 hex digits, the color is opaque (alpha = hex ff). A hex String may be preceded by "#" such as "#80ff00" or "0x". When the string does not include a valid color name or hex code, returns 'defaultColor'.
    • getRed

      public static int getRed(String hexColor)
    • getGreen

      public static int getGreen(String hexColor)
    • getBlue

      public static int getBlue(String hexColor)
    • hexToColor

      public static String hexToColor(String hex)
      Converts a hex color (e.g., "ffff00") into "red", "green", "yellow", etc. Returns null if the hex color does not have a name. Unused in ImageJ, for compatibility only.
    • hexToColor2

      public static String hexToColor2(String hex)
      Converts a hex color (e.g., "ffff00" or "#ffff00") into a color name "Red", "Green", "Yellow", etc. Returns null if the hex color does not have a name. Unused in ImageJ, for compatibility only.
    • colorToString

      public static String colorToString(Color color)
      Converts a Color into a lowercase string ("red", "green", "#aa55ff", etc.). If color is null, returns the String "none".
    • colorToString2

      public static String colorToString2(Color color)
      Converts a Color into a string ("Red", "Green", #aa55ff, etc.). If color is null, returns the String "None".
    • toColor

      public static Color toColor(int red, int green, int blue)
      Returns an opaque color with the specified red, green, and blue values. Values is outside the 0-255 range are replaced by the nearest valid number (0 or 255)
    • itemStateChanged

      public void itemStateChanged(ItemEvent e)
      Callback listener for Choice modifications in the dialog
      Specified by:
      itemStateChanged in interface ItemListener
    • getColors

      public static String[] getColors(String... moreColors)
      Returns an array of the color Strings in the argument(s) and the 13 predefined color names "Red", "Green", ... "Pink". The Strings arguments must be either "None" or hex codes starting with "#". Any null arguments are ignored.
    • wavelengthToColor

      public static Color wavelengthToColor(double wl)
      Converts a wavelength (380-750 nm) to color. Based on the wavelength_to_rgb.R program at https://gist.github.com/friendly/67a7df339aa999e2bcfcfec88311abfc, which in turn is based on a FORTRAN program at http://www.physics.sfasu.edu/astro/color.html.