Class FlatStylingSupport


  • public class FlatStylingSupport
    extends Object
    Support for styling components in CSS syntax.
    Since:
    2
    • Constructor Detail

      • FlatStylingSupport

        public FlatStylingSupport()
    • Method Detail

      • getStyleForClasses

        public static Object getStyleForClasses​(Object styleClass,
                                                String type)
        Returns the styles for the given style class(es) and the given type.

        The style rules must be defined in UI defaults either as strings (in CSS syntax) or as Map<String, Object> (with binary values). The key must be in syntax: [style]type.styleClass, where the type is optional. E.g. in FlatLaf properties file:

        
         [style]Button.primary = borderColor: #08f; background: #08f; foreground: #fff
         [style].secondary = borderColor: #0f8; background: #0f8
         
        or in Java code:
        
         UIManager.put( "[style]Button.primary", "borderColor: #08f; background: #08f; foreground: #fff" );
         UIManager.put( "[style].secondary", "borderColor: #0f8; background: #0f8" );
         
        The rule "Button.primary" can be applied to buttons only. The rule ".secondary" can be applied to any component.

        To have similar behavior as in CSS, this method first gets the rule without type, then the rule with type and concatenates both rules. E.g. invoking this method with parameters styleClass="foo" and type="Button" does following:

        
         return joinStyles(
             UIManager.get( "[style].foo" ),
             UIManager.get( "[style]Button.foo" ) );
         
        Parameters:
        styleClass - the style class(es) either as string (single class or multiple classes separated by space characters) or as String[] or List<String> (multiple classes)
        type - the type of the component
        Returns:
        the styles
      • joinStyles

        public static Object joinStyles​(Object style1,
                                        Object style2)
        Joins two styles. They can be either strings (in CSS syntax) or Map<String, Object> (with binary values).

        If both styles are strings, then a joined string is returned. If both styles are maps, then a joined map is returned. If one style is a map and the other style a string, then the string is parsed (using parse(String)) to a map and a joined map is returned.

        Parameters:
        style1 - first style as string or map, or null
        style2 - second style as string or map, or null
        Returns:
        new joined style
      • concatStyles

        public static String concatStyles​(String style1,
                                          String style2)
        Concatenates two styles in CSS syntax.
        Parameters:
        style1 - first style, or null
        style2 - second style, or null
        Returns:
        concatenation of the two styles separated by a semicolon
      • parse

        public static Map<String,​Object> parse​(String style)
                                              throws IllegalArgumentException
        Parses styles in CSS syntax ("key1: value1; key2: value2; ..."), converts the value strings into binary and returns all key/value pairs as map.
        Parameters:
        style - the style in CSS syntax, or null
        Returns:
        map of parsed styles, or null
        Throws:
        IllegalArgumentException - on syntax errors
      • getAnnotatedStyleableInfos

        public static Map<String,​Class<?>> getAnnotatedStyleableInfos​(Object obj)
        Returns a map of all fields annotated with FlatStylingSupport.Styleable. The key is the name of the field and the value the type of the field.
      • collectAnnotatedStyleableInfos

        public static void collectAnnotatedStyleableInfos​(Object obj,
                                                          Map<String,​Class<?>> infos)
        Search for all fields annotated with FlatStylingSupport.Styleable and add them to the given map. The key is the name of the field and the value the type of the field.
      • collectStyleableInfos

        public static void collectStyleableInfos​(Border border,
                                                 Map<String,​Class<?>> infos)
      • getAnnotatedStyleableValue

        public static Object getAnnotatedStyleableValue​(Object obj,
                                                        String key)
      • getAnnotatedStyleableValue

        public static Object getAnnotatedStyleableValue​(Object obj,
                                                        Border border,
                                                        String key)