public class CSSBorder

  1. Object
  2. Border
  3. CSSBorder

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.

Fields

public static final byte REPEAT_NONE = 0Constant indicating no-repeat for background images.
public static final byte REPEAT_BOTH = 1Constant indicating repeating on both x and y for background images.
public static final byte REPEAT_X = 2Constant indicating repeat-x for background images.
public static final byte REPEAT_Y = 3Constant indicating repeat-y for background images.
public static final byte VPOSITION_TOP = 0Constant indicating background-position top.
public static final byte VPOSITION_BOTTOM = 1Constant indicating background-position bottom.
public static final byte VPOSITION_CENTER = 2Constant indicating background-position center.
public static final byte VPOSITION_OTHER = 99
public static final byte HPOSITION_LEFT = 0Constant indicating background-position left.
public static final byte HPOSITION_RIGHT = 1Constant indicating background-position right.
public static final byte HPOSITION_CENTER = 2Constant indicating background-position center (horizontal).
public static final byte HPOSITION_OTHER = 99
public static final byte SIZE_AUTO = 0
public static final byte SIZE_CONTAIN = 1
public static final byte SIZE_COVER = 2
public static final byte SIZE_OTHER = 99
public static final byte STYLE_NONE = 0Constant for border-style none
public static final byte STYLE_HIDDEN = 1Constant for border-style hidden
public static final byte STYLE_DOTTED = 2Constant for border-style dotted
public static final byte STYLE_DASHED = 3Constant for border-style dashed
public static final byte STYLE_SOLID = 4Constant for border-style solid
public static final byte UNIT_PIXELS = 0Constant for unit px
public static final byte UNIT_MM = 2Constant for unit mm
public static final byte UNIT_PERCENT = 1Constant for unit %
public static final byte UNIT_EM = 4Constant for unit em

Constructors

public CSSBorder()Creates a new empty CSS border.
public CSSBorder(Resources res)Creates an empty border.
public CSSBorder(String css)Creates a new CSS border with the provided CSS styles.
public CSSBorder(Resources res, String css)Creates a new CSS border with the provided CSS styles.

Methods

public boolean equals(Object obj){Indicates whether some other object is “equal to” this one.
public int hashCode()Returns a hash code value for the object.
public String toCSSString()Converts this border to a CSS string.
public boolean isBackgroundPainter()Returns true if installing this border will override the painting of the component background
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.
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 m…
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 m…
public CSSBorder borderImage(Image borderImage, double... slicePoints)Creates a 9-piece image border.
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.
public CSSBorder boxShadow(String value)
public CSSBorder borderRadius(String radius)Sets the border radius for rounded corners.
public CSSBorder borderStroke(String... strokeStrs)Sets the border stroke.
public CSSBorder borderColor(String... colors)Sets the border colors.
public CSSBorder borderWidth(String... widths)Sets the border widths.
public CSSBorder borderStyle(String... styles)Sets the border styles.
public CSSBorder backgroundColor(String color)Sets the background color of the border.
public CSSBorder backgroundImage(String cssDirective)Adds one or more background images from a CSS background-image property.
public CSSBorder backgroundImage(Image... images)Sets the background image of the border.
public CSSBorder backgroundRepeat(String... repeat)Sets the background-repeat for the background images.
public CSSBorder backgroundPosition(String... pos)Sets the background position.

Inherited methods

Field details

REPEAT_NONE

public static final byte REPEAT_NONE = 0
Constant indicating no-repeat for background images.

REPEAT_BOTH

public static final byte REPEAT_BOTH = 1
Constant indicating repeating on both x and y for background images.

REPEAT_X

public static final byte REPEAT_X = 2
Constant indicating repeat-x for background images.

REPEAT_Y

public static final byte REPEAT_Y = 3
Constant indicating repeat-y for background images.

VPOSITION_TOP

public static final byte VPOSITION_TOP = 0
Constant indicating background-position top.

VPOSITION_BOTTOM

public static final byte VPOSITION_BOTTOM = 1
Constant indicating background-position bottom.

VPOSITION_CENTER

public static final byte VPOSITION_CENTER = 2
Constant indicating background-position center.

VPOSITION_OTHER

public static final byte VPOSITION_OTHER = 99

HPOSITION_LEFT

public static final byte HPOSITION_LEFT = 0
Constant indicating background-position left.

HPOSITION_RIGHT

public static final byte HPOSITION_RIGHT = 1
Constant indicating background-position right.

HPOSITION_CENTER

public static final byte HPOSITION_CENTER = 2
Constant indicating background-position center (horizontal).

HPOSITION_OTHER

public static final byte HPOSITION_OTHER = 99

SIZE_AUTO

public static final byte SIZE_AUTO = 0

SIZE_CONTAIN

public static final byte SIZE_CONTAIN = 1

SIZE_COVER

public static final byte SIZE_COVER = 2

SIZE_OTHER

public static final byte SIZE_OTHER = 99

STYLE_NONE

public static final byte STYLE_NONE = 0
Constant for border-style none

STYLE_HIDDEN

public static final byte STYLE_HIDDEN = 1
Constant for border-style hidden

STYLE_DOTTED

public static final byte STYLE_DOTTED = 2
Constant for border-style dotted

STYLE_DASHED

public static final byte STYLE_DASHED = 3
Constant for border-style dashed

STYLE_SOLID

public static final byte STYLE_SOLID = 4
Constant for border-style solid

UNIT_PIXELS

public static final byte UNIT_PIXELS = 0
Constant for unit px

UNIT_MM

public static final byte UNIT_MM = 2
Constant for unit mm

UNIT_PERCENT

public static final byte UNIT_PERCENT = 1
Constant for unit %

UNIT_EM

public static final byte UNIT_EM = 4
Constant for unit em

Constructor details

CSSBorder

public CSSBorder()
Creates a new empty CSS border.

CSSBorder

public CSSBorder(Resources res)
Creates an empty border.

Parameters

res Resources
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 String
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 Resources
Theme resource file from which images can be loaded.
css String
CSS to parse.

Throws

IllegalArgumentException
If it fails to parse the style.

Method details

equals

public boolean equals(Object obj)
{Indicates whether some other object is “equal to” this one. The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).}

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

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

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
graphics context to draw onto
c Component
component whose border should be drawn

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.

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.

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 Image
The border image.
slicePoints double...
The slice points. Accepts 1 - 4 values:

Returns

Self for chaining.

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 String
The image name.
slicePoints double...
The slice points. Accepts 1 - 4 values:

Returns

Self for chaining.

boxShadow

public CSSBorder boxShadow(String value)

borderRadius

public CSSBorder borderRadius(String radius)
Sets the border radius for rounded corners.

borderStroke

public CSSBorder borderStroke(String... strokeStrs)
Sets the border stroke.

borderColor

public CSSBorder borderColor(String... colors)
Sets the border colors.

Parameters

colors String...
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 String...
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 String...
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 String
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 String
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 Image...
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 String...
Repeat options for respective background images.

Returns

Self for chaining.

backgroundPosition

public CSSBorder backgroundPosition(String... pos)
Sets the background position.

Parameters

pos String...
The background positions of background images.

Returns

Self for chaining.