Class StyleConf

java.lang.Object
swingtree.style.StyleConf

@Immutable public final class StyleConf extends Object
An immutable config container with cloning based update methods designed for functional JComponent styling. The styling in SwingTree is completely functional, meaning that changing a property of a StyleConf instance will always return a new StyleConf instance with the updated property.

Consider the following example demonstrating how a JPanel is styled through the SwingTree style API, which consists of a functional Styler lambda that processes a ComponentStyleDelegate instance that internally assembles a StyleConf object:


  panel(FILL)
  .withStyle( it -> it
      .foundationColor(new Color(26,191,230))
      .backgroundColor(new Color(255,255,255))
      .paddingTop(30)
      .paddingLeft(35)
      .paddingRight(35)
      .paddingBottom(30)
      .borderRadius(25, 25)
      .borderWidth(3)
      .borderColor(new Color(0,102,255))
      .shadowColor(new Color(64,64,64))
      .shadowBlurRadius(6)
      .shadowSpreadRadius(5)
      .shadowInset(false)
  )
  
This design is inspired by the CSS styling language and the use of immutable objects is a key feature of the SwingTree API which makes it possible to safely compose Styler lambdas into a complex style pipeline without having to worry about side effects. See StyleSheet for more information about how this composition of styles is achieved in practice.
  • Method Details

    • none

      public static StyleConf none()
      Exposes the "null object" pattern for StyleConf instances. So the constant returned by this method is the default instance that represents the absence of a style.
      Returns:
      The default style instance, representing the absence of a style.
    • layoutConstraint

      public Optional<Object> layoutConstraint()
    • layout

      public swingtree.style.LayoutConf layout()
    • shadow

      public ShadowConf shadow()
      Exposes the default shadow style configuration object.
      Returns:
      The default shadow style.
    • shadow

      public ShadowConf shadow(UI.Layer layer, String shadowName)
      Internally, a style configuration consists of a set of layers defined by the UI.Layer enum. Using this method you can retrieve all shadow styles for a particular layer and with the provided name.
      Parameters:
      layer - The layer to retrieve the shadow style from.
      shadowName - The name of the shadow style to retrieve.
      Returns:
      The shadow style with the provided name.
    • font

      public FontConf font()
    • foundationColor

      public StyleConf foundationColor(Color color)
    • backgroundColor

      public StyleConf backgroundColor(Color color)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object