Class CSSBorder

java.lang.Object
com.codename1.ui.plaf.Border
com.codename1.ui.plaf.CSSBorder

public class CSSBorder extends Border

A border that can be configured using a limited subset of CSS directives. This class is designed as a stop-gap to deal with common CSS style patterns that aren't well-covered by existing borders. As time goes on this class will be enhanced to support more CSS styles. At present, it is used by the CSS compiler for compound borders. E.g. If one side has a different border style, color, or thickness than other sides.

The follow types of borders are well-supported with this class:

  • border-radius - can support different x and y radii for each corner.

  • border-width - can support different widths for each side.

  • border-color - can support different colors for each side

  • background-color

This class also supports background images and gradients, but these are not well-tested and are not currently used by the CSS compiler.

  • Field Details

    • REPEAT_NONE

      public static final byte REPEAT_NONE
      Constant indicating no-repeat for background images.
      See Also:
    • REPEAT_BOTH

      public static final byte REPEAT_BOTH
      Constant indicating repeating on both x and y for background images.
      See Also:
    • REPEAT_X

      public static final byte REPEAT_X
      Constant indicating repeat-x for background images.
      See Also:
    • REPEAT_Y

      public static final byte REPEAT_Y
      Constant indicating repeat-y for background images.
      See Also:
    • VPOSITION_TOP

      public static final byte VPOSITION_TOP
      Constant indicating background-position top.
      See Also:
    • VPOSITION_BOTTOM

      public static final byte VPOSITION_BOTTOM
      Constant indicating background-position bottom.
      See Also:
    • VPOSITION_CENTER

      public static final byte VPOSITION_CENTER
      Constant indicating background-position center.
      See Also:
    • VPOSITION_OTHER

      public static final byte VPOSITION_OTHER
      See Also:
    • HPOSITION_LEFT

      public static final byte HPOSITION_LEFT
      Constant indicating background-position left.
      See Also:
    • HPOSITION_RIGHT

      public static final byte HPOSITION_RIGHT
      Constant indicating background-position right.
      See Also:
    • HPOSITION_CENTER

      public static final byte HPOSITION_CENTER
      Constant indicating background-position center (horizontal).
      See Also:
    • HPOSITION_OTHER

      public static final byte HPOSITION_OTHER
      See Also:
    • SIZE_AUTO

      public static final byte SIZE_AUTO
      See Also:
    • SIZE_CONTAIN

      public static final byte SIZE_CONTAIN
      See Also:
    • SIZE_COVER

      public static final byte SIZE_COVER
      See Also:
    • SIZE_OTHER

      public static final byte SIZE_OTHER
      See Also:
    • STYLE_NONE

      public static final byte STYLE_NONE
      Constant for border-style none
      See Also:
    • STYLE_HIDDEN

      public static final byte STYLE_HIDDEN
      Constant for border-style hidden
      See Also:
    • STYLE_DOTTED

      public static final byte STYLE_DOTTED
      Constant for border-style dotted
      See Also:
    • STYLE_DASHED

      public static final byte STYLE_DASHED
      Constant for border-style dashed
      See Also:
    • STYLE_SOLID

      public static final byte STYLE_SOLID
      Constant for border-style solid
      See Also:
    • UNIT_PIXELS

      public static final byte UNIT_PIXELS
      Constant for unit px
      See Also:
    • UNIT_MM

      public static final byte UNIT_MM
      Constant for unit mm
      See Also:
    • UNIT_PERCENT

      public static final byte UNIT_PERCENT
      Constant for unit %
      See Also:
    • UNIT_EM

      public static final byte UNIT_EM
      Constant for unit em
      See Also:
  • Constructor Details

    • CSSBorder

      public CSSBorder()
      Creates a new empty CSS border.
    • CSSBorder

      public CSSBorder(Resources res)

      Creates an empty border.

      Parameters
      • res: Theme resource file from which images can be referenced.
    • CSSBorder

      public CSSBorder(String css)

      Creates a new CSS border with the provided CSS styles. This currenlty only supports a subset of CSS. The following properties are currently supported:

      • background-color

      • background-image

      • background-position

      • background-repeat

      • border-color

      • border-radius

      • border-stroke

      • border-style

      • border-width

      • border-image

      Parameters
      • css: CSS to parse.
      Throws
      • IllegalArgumentException: If it fails to parse the style.
    • CSSBorder

      public CSSBorder(Resources res, String css)

      Creates a new CSS border with the provided CSS styles. This currenlty only supports a subset of CSS. The following properties are currently supported:

      • background-color

      • background-image

      • background-position

      • background-repeat

      • border-color

      • border-radius

      • border-stroke

      • border-style

      • border-width

      • border-image

      Parameters
      • res: Theme resource file from which images can be loaded.

      • css: CSS to parse.

      Throws
      • IllegalArgumentException: If it fails to parse the style.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Description copied from class: Border
      {}
      Overrides:
      equals in class Border
    • hashCode

      public int hashCode()
      Description copied from class: Border
      Overrides:
      hashCode in class Border
    • toCSSString

      public String toCSSString()

      Converts this border to a CSS string.

      Returns

      CSS string for this border.

    • isBackgroundPainter

      public boolean isBackgroundPainter()

      Returns true if installing this border will override the painting of the component background

      Returns

      true if this border replaces the painter

      Overrides:
      isBackgroundPainter in class Border
    • paintBorderBackground

      public void paintBorderBackground(Graphics g, Component c)

      Has effect when the border demands responsibility for background painting normally the painter will perform this work but in this case the border might do it instead.

      Parameters
      • g: graphics context to draw onto

      • c: component whose border should be drawn

      Overrides:
      paintBorderBackground in class Border
    • getMinimumHeight

      public int getMinimumHeight()

      Returns the minimum size required to properly display this border, normally this is 0 but a border might deem itself undisplayable with too small a size e.g. for the case of an image border the minimum height would be top + bottom and the minimum width would be left+right

      Returns

      0 if not applicable or a dimension if it is.

      Overrides:
      getMinimumHeight in class Border
    • getMinimumWidth

      public int getMinimumWidth()

      Returns the minimum size required to properly display this border, normally this is 0 but a border might deem itself undisplayable with too small a size e.g. for the case of an image border the minimum height would be top + bottom and the minimum width would be left+right

      Returns

      0 if not applicable or a dimension if it is.

      Overrides:
      getMinimumWidth in class Border
    • borderImage

      public CSSBorder borderImage(Image borderImage, double... slicePoints)

      Creates a 9-piece image border.

      Insets are all given in a (u,v) coordinate space where (0,0) is the top-left corner of the image, and (1.0, 1.0) is the bottom-right corner of the image.

      If a border image is set for the CSS border, it will override all other border types, and will result in only the 9-piece border being rendered.

      Parameters
      • borderImage: The border image.

      • slicePoints: @param slicePoints The slice points. Accepts 1 - 4 values:

      • 1 value = all sides

      • 2 values = vertical horizontal

      • 3 values = top horizontal bottom

      • 4 values = top right bottom left

      Returns

      Self for chaining.

      Since

      7.0

      See also
      • #borderImageWithName(java.lang.String, double...)
    • borderImageWithName

      public CSSBorder borderImageWithName(String borderImageName, double... slicePoints)

      Adds a 9-piece image border using the provided image name, which should exist in the theme resource file.

      Insets are all given in a (u,v) coordinate space where (0,0) is the top-left corner of the image, and (1.0, 1.0) is the bottom-right corner of the image.

      If a border image is set for the CSS border, it will override all other border types, and will result in only the 9-piece border being rendered.

      Parameters
      • borderImageName: The image name.

      • slicePoints: @param slicePoints The slice points. Accepts 1 - 4 values:

      • 1 value = all sides

      • 2 values = vertical horizontal

      • 3 values = top horizontal bottom

      • 4 values = top right bottom left

      Returns

      Self for chaining.

      Since

      7.0

      See also
      • #borderImage(com.codename1.ui.Image, double...)
    • boxShadow

      public CSSBorder boxShadow(String value)
    • borderRadius

      public CSSBorder borderRadius(String radius)

      Sets the border radius for rounded corners.

      Parameters
      • radius
    • borderStroke

      public CSSBorder borderStroke(String... strokeStrs)

      Sets the border stroke.

      Parameters
      • strokeStrs
    • borderColor

      public CSSBorder borderColor(String... colors)

      Sets the border colors.

      Parameters
      • colors: The colors. 1 value sets all borders. 2 sets top/bottom, left/right. 3 sets top, left/right, bottom. 4 sets top, right, bottom, left.
      Returns

      Self for chaining.

    • borderWidth

      public CSSBorder borderWidth(String... widths)

      Sets the border widths.

      Parameters
      • widths: The widths. 1 value sets all borders. 2 sets top/bottom, left/right. 3 sets top, left/right, bottom. 4 sets top, right, bottom, left.
      Returns

      Self for chaining.

    • borderStyle

      public CSSBorder borderStyle(String... styles)

      Sets the border styles. Supported styles: none, hidden, dotted, dashed, solid.

      Parameters
      • styles: The border styles. 1 value sets all borders. 2 sets top/bottom, left/right. 3 sets top, left/right, bottom. 4 sets top, right, bottom, left.
      Returns

      Self for chaining.

    • backgroundColor

      public CSSBorder backgroundColor(String color)

      Sets the background color of the border.

      Parameters
      • color: A color string.
      Returns

      Self for chaining.

    • backgroundImage

      public CSSBorder backgroundImage(String cssDirective)

      Adds one or more background images from a CSS background-image property.

      Parameters
      • cssDirective: The value of the background-image property.
      Returns

      Self for chaining.

    • backgroundImage

      public CSSBorder backgroundImage(Image... images)

      Sets the background image of the border.

      Parameters
      • images: Images to use as background images.
      Returns

      Self for chaining.

    • backgroundRepeat

      public CSSBorder backgroundRepeat(String... repeat)

      Sets the background-repeat for the background images.

      Parameters
      • repeat: Repeat options for respective background images.
      Returns

      Self for chaining.

    • backgroundPosition

      public CSSBorder backgroundPosition(String... pos)

      Sets the background position.

      Parameters
      • pos: The background positions of background images.
      Returns

      Self for chaining.