Class FormColors


  • public class FormColors
    extends java.lang.Object
    Manages colors that will be applied to forms and form widgets. The colors are chosen to make the widgets look correct in the editor area. If a different set of colors is needed, subclass this class and override 'initialize' and/or 'initializeColors'.
    Since:
    3.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Color background  
      protected Color border  
      static java.lang.String BORDER
      Deprecated.
      use IFormColors.BORDER
      protected java.util.Map<java.lang.String,​Color> colorRegistry  
      protected Display display  
      protected Color foreground  
      static java.lang.String SEPARATOR
      Deprecated.
      use IFormColors.SEPARATOR.
      static java.lang.String TB_BG
      Deprecated.
      use IFormColors.TB_BG
      static java.lang.String TB_BORDER
      Deprecated.
      use IFormColors.TB_BORDER.
      static java.lang.String TB_FG
      Deprecated.
      use IFormColors.TB_FG
      static java.lang.String TB_GBG
      Deprecated.
      use IFormColors.TB_GBG
      static java.lang.String TB_TOGGLE
      Deprecated.
      use IFormColors.TB_TOGGLE.
      static java.lang.String TB_TOGGLE_HOVER
      Deprecated.
      use IFormColors.TB_TOGGLE_HOVER.
      static java.lang.String TITLE
      Deprecated.
      use IFormColors.TITLE.
    • Constructor Summary

      Constructors 
      Constructor Description
      FormColors​(Display display)
      Creates form colors using the provided display.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static RGB blend​(RGB c1, RGB c2, int ratio)
      Blends c1 and c2 based in the provided ratio.
      Color createColor​(java.lang.String key, int r, int g, int b)
      Creates the color for the specified key using the provided RGB values.
      Color createColor​(java.lang.String key, RGB rgb)
      Creates the color for the specified key using the provided RGB object.
      void dispose()
      Disposes all the colors in the registry.
      Color getBackground()
      Returns the current background color.
      Color getBorderColor()
      Returns the computed border color.
      Color getColor​(java.lang.String key)
      Returns the color object for the provided key or null if not in the registry.
      Display getDisplay()
      Returns the display used to create colors.
      Color getForeground()
      Returns the current foreground color.
      Color getInactiveBackground()
      Creates a color that can be used for areas of the form that is inactive.
      RGB getSystemColor​(int code)
      Returns the RGB value of the system color represented by the code argument, as defined in SWT class.
      protected void initialize()
      Initializes the colors.
      protected void initializeColorTable()
      Allocates colors for the following keys: BORDER, SEPARATOR and TITLE.
      protected void initializeFormHeaderColors()
      Allocates additional colors for the form header, namely background gradients, bottom separator keylines and DND highlights.
      void initializeSectionToolBarColors()
      Allocates colors for the section tool bar (all the keys that start with TB).
      boolean isShared()
      Tests if the colors are shared.
      boolean isWhiteBackground()
      Tests if the background is white.
      void markShared()
      Marks the colors shared.
      void setBackground​(Color bg)
      Sets the background color.
      void setForeground​(Color fg)
      Sets the foreground color.
      static boolean testAnyPrimaryColor​(RGB rgb, int from, int to)
      Tests the source RGB for range.
      static boolean testTwoPrimaryColors​(RGB rgb, int from, int to)
      Tests the source RGB for range.
      protected void updateBorderColor()
      Computes the border color relative to the background.
      • Methods inherited from class java.lang.Object

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

      • TITLE

        @Deprecated
        public static final java.lang.String TITLE
        Deprecated.
        use IFormColors.TITLE.
        Key for the form title foreground color.
        See Also:
        Constant Field Values
      • BORDER

        @Deprecated
        public static final java.lang.String BORDER
        Deprecated.
        use IFormColors.BORDER
        Key for the tree/table border color.
        See Also:
        Constant Field Values
      • SEPARATOR

        @Deprecated
        public static final java.lang.String SEPARATOR
        Deprecated.
        use IFormColors.SEPARATOR.
        Key for the section separator color.
        See Also:
        Constant Field Values
      • TB_BG

        @Deprecated
        public static final java.lang.String TB_BG
        Deprecated.
        use IFormColors.TB_BG
        Key for the section title bar background.
        See Also:
        Constant Field Values
      • TB_FG

        @Deprecated
        public static final java.lang.String TB_FG
        Deprecated.
        use IFormColors.TB_FG
        Key for the section title bar foreground.
        See Also:
        Constant Field Values
      • TB_GBG

        @Deprecated
        public static final java.lang.String TB_GBG
        Deprecated.
        use IFormColors.TB_GBG
        Key for the section title bar gradient.
        See Also:
        Constant Field Values
      • TB_BORDER

        @Deprecated
        public static final java.lang.String TB_BORDER
        Deprecated.
        use IFormColors.TB_BORDER.
        Key for the section title bar border.
        See Also:
        Constant Field Values
      • TB_TOGGLE

        @Deprecated
        public static final java.lang.String TB_TOGGLE
        Deprecated.
        use IFormColors.TB_TOGGLE.
        Key for the section toggle color. Since 3.1, this color is used for all section styles.
        See Also:
        Constant Field Values
      • TB_TOGGLE_HOVER

        @Deprecated
        public static final java.lang.String TB_TOGGLE_HOVER
        Deprecated.
        use IFormColors.TB_TOGGLE_HOVER.
        Key for the section toggle hover color.
        Since:
        3.1
        See Also:
        Constant Field Values
      • colorRegistry

        protected java.util.Map<java.lang.String,​Color> colorRegistry
      • background

        protected Color background
      • foreground

        protected Color foreground
      • display

        protected Display display
      • border

        protected Color border
    • Constructor Detail

      • FormColors

        public FormColors​(Display display)
        Creates form colors using the provided display.
        Parameters:
        display - the display to use
    • Method Detail

      • getDisplay

        public Display getDisplay()
        Returns the display used to create colors.
        Returns:
        the display
      • initialize

        protected void initialize()
        Initializes the colors. Subclasses can override this method to change the way colors are created. Alternatively, only the color table can be modified by overriding initializeColorTable().
        See Also:
        initializeColorTable()
      • initializeColorTable

        protected void initializeColorTable()
        Allocates colors for the following keys: BORDER, SEPARATOR and TITLE. Subclasses can override to allocate these colors differently.
      • initializeSectionToolBarColors

        public void initializeSectionToolBarColors()
        Allocates colors for the section tool bar (all the keys that start with TB). Since these colors are only needed when TITLE_BAR style is used with the Section widget, they are not needed all the time and are allocated on demand. Consequently, this method will do nothing if the colors have been already initialized. Call this method prior to using colors with the TB keys to ensure they are available.
      • initializeFormHeaderColors

        protected void initializeFormHeaderColors()
        Allocates additional colors for the form header, namely background gradients, bottom separator keylines and DND highlights. Since these colors are only needed for clients that want to use these particular style of header rendering, they are not needed all the time and are allocated on demand. Consequently, this method will do nothing if the colors have been already initialized. Call this method prior to using color keys with the H_ prefix to ensure they are available.
        Since:
        3.3
      • getSystemColor

        public RGB getSystemColor​(int code)
        Returns the RGB value of the system color represented by the code argument, as defined in SWT class.
        Parameters:
        code - the system color constant as defined in SWT class.
        Returns:
        the RGB value of the system color
      • createColor

        public Color createColor​(java.lang.String key,
                                 RGB rgb)
        Creates the color for the specified key using the provided RGB object. The color object will be returned and also put into the registry. When the class is disposed, the color will be disposed with it.
        Parameters:
        key - the unique color key
        rgb - the RGB object
        Returns:
        the allocated color object
      • getInactiveBackground

        public Color getInactiveBackground()
        Creates a color that can be used for areas of the form that is inactive. These areas can contain images, links, controls and other content but are considered auxilliary to the main content area.

        The color should not be disposed because it is managed by this class.

        Returns:
        the inactive form color
        Since:
        3.1
      • createColor

        public Color createColor​(java.lang.String key,
                                 int r,
                                 int g,
                                 int b)
        Creates the color for the specified key using the provided RGB values. The color object will be returned and also put into the registry. If there is already another color object under the same key in the registry, the existing object will be disposed. When the class is disposed, the color will be disposed with it.
        Parameters:
        key - the unique color key
        r - red value
        g - green value
        b - blue value
        Returns:
        the allocated color object
      • updateBorderColor

        protected void updateBorderColor()
        Computes the border color relative to the background. Allocated border color is designed to work well with white. Otherwise, standard widget background color will be used.
      • setBackground

        public void setBackground​(Color bg)
        Sets the background color. All the toolkits that use this class will share the same background.
        Parameters:
        bg - background color
      • setForeground

        public void setForeground​(Color fg)
        Sets the foreground color. All the toolkits that use this class will share the same foreground.
        Parameters:
        fg - foreground color
      • getBackground

        public Color getBackground()
        Returns the current background color.
        Returns:
        the background color
      • getForeground

        public Color getForeground()
        Returns the current foreground color.
        Returns:
        the foreground color
      • getBorderColor

        public Color getBorderColor()
        Returns the computed border color. Border color depends on the background and is recomputed whenever the background changes.
        Returns:
        the current border color
      • isWhiteBackground

        public boolean isWhiteBackground()
        Tests if the background is white. White background has RGB value 255,255,255.
        Returns:
        true if background is white, false otherwise.
      • getColor

        public Color getColor​(java.lang.String key)
        Returns the color object for the provided key or null if not in the registry.
        Parameters:
        key - the color key
        Returns:
        color object if found, or null if not.
      • dispose

        public void dispose()
        Disposes all the colors in the registry.
      • markShared

        public void markShared()
        Marks the colors shared. This prevents toolkits that share this object from disposing it.
      • isShared

        public boolean isShared()
        Tests if the colors are shared.
        Returns:
        true if shared, false otherwise.
      • blend

        public static RGB blend​(RGB c1,
                                RGB c2,
                                int ratio)
        Blends c1 and c2 based in the provided ratio.
        Parameters:
        c1 - first color
        c2 - second color
        ratio - percentage of the first color in the blend (0-100)
        Returns:
        the RGB value of the blended color
        Since:
        3.1
      • testAnyPrimaryColor

        public static boolean testAnyPrimaryColor​(RGB rgb,
                                                  int from,
                                                  int to)
        Tests the source RGB for range.
        Parameters:
        rgb - the tested RGB
        from - range start (excluding the value itself)
        to - range end (excluding the value itself)
        Returns:
        true if at least one of the primary colors in the source RGB are within the provided range, false otherwise.
        Since:
        3.1
      • testTwoPrimaryColors

        public static boolean testTwoPrimaryColors​(RGB rgb,
                                                   int from,
                                                   int to)
        Tests the source RGB for range.
        Parameters:
        rgb - the tested RGB
        from - range start (excluding the value itself)
        to - range end (excluding the value itself)
        Returns:
        true if at least two of the primary colors in the source RGB are within the provided range, false otherwise.
        Since:
        3.1