public final class RoundBorder

  1. Object
  2. Border
  3. RoundBorder

A border that can either be a circle or a circular rectangle which is a rectangle whose sides are circles. This border can optionally have a drop shadow associated with it.

IMPORTANT: RoundRectBorder instances can’t be reused you would need to create a separate instance for each style object! See this issue for further details.

Form hi = new Form("Round", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));

Button ok = new Button("OK");
Button cancel = new Button("Cancel");

Label loginLabel = new Label("Login", "Container");
loginLabel.getAllStyles().setAlignment(Component.CENTER);

Label passwordLabel = new Label("Password", "Container");
passwordLabel.getAllStyles().setAlignment(Component.CENTER);

TextField login = new TextField("", "Login", 20, TextArea.ANY);
TextField password = new TextField("", "Password", 20, TextArea.PASSWORD);
Style loginStyle = login.getAllStyles();
Stroke borderStroke = new Stroke(2, Stroke.CAP_SQUARE, Stroke.JOIN_MITER, 1);
loginStyle.setBorder(RoundBorder.create().
        rectangle(true).
        color(0xffffff).
        strokeColor(0).
        strokeOpacity(120).
        stroke(borderStroke));
loginStyle.setMarginUnit(Style.UNIT_TYPE_DIPS);
loginStyle.setMargin(Component.BOTTOM, 3);
Style passwordStyle = password.getAllStyles();
passwordStyle.setBorder(RoundBorder.create().
        rectangle(true).
        color(0xffffff).
        strokeColor(0).
        strokeOpacity(120).
        stroke(borderStroke));

Container box = BoxLayout.encloseY(
        loginLabel,
        login,
        passwordLabel,
        password,
            GridLayout.encloseIn(2, cancel, ok));

Button closeButton = new Button();
Style closeStyle = closeButton.getAllStyles();
closeStyle.setFgColor(0xffffff);
closeStyle.setBgTransparency(0);
closeStyle.setPaddingUnit(Style.UNIT_TYPE_DIPS);
closeStyle.setPadding(3, 3, 3, 3);
closeStyle.setBorder(RoundBorder.create().shadowOpacity(100));
FontImage.setMaterialIcon(closeButton, FontImage.MATERIAL_CLOSE);

Container layers = LayeredLayout.encloseIn(box, FlowLayout.encloseRight(closeButton));
Style boxStyle = box.getUnselectedStyle();
boxStyle.setBgTransparency(255);
boxStyle.setBgColor(0xeeeeee);
boxStyle.setMarginUnit(Style.UNIT_TYPE_DIPS);
boxStyle.setPaddingUnit(Style.UNIT_TYPE_DIPS);
boxStyle.setMargin(4, 3, 3, 3);
boxStyle.setPadding(2, 2, 2, 2);

hi.add(BorderLayout.CENTER, layers);

hi.show();

Methods

public static RoundBorder create()Creates a flat round border with no stroke and no shadow and the default color, this call can be chained with the other calls to mutate the color/opacity etc.
public RoundBorder uiid(boolean uiid)Uses the style of the components UIID to draw the background of the border, this effectively overrides all other style settings but allows the full power of UIID drawing including gradients, background images etc.
public boolean getUIID()True is we use the background of the component setting to draw
public RoundBorder color(int color)Sets the background color of the circle/rectangle
public RoundBorder opacity(int opacity)Sets the background opacity of the circle/rectangle
public RoundBorder strokeOpacity(int strokeOpacity)Sets the opacity of the stroke line around the circle/rectangle
public RoundBorder strokeColor(int strokeColor)Sets the stroke color of the circle/rectangle
public RoundBorder strokeColor2(int strokeColor2)Turns the stroke into a two-colour linear gradient running from strokeColor to the supplied end colour.
public RoundBorder strokeGradientAngle(float strokeGradientAngle)Sets the direction of the gradient stroke.
public RoundBorder strokeGradient(boolean strokeGradient)Explicitly enables/disables the gradient stroke without changing the colours.
public RoundBorder stroke(Stroke stroke)Sets the stroke of the circle/rectangle
public RoundBorder stroke(float stroke, boolean mm)Sets the stroke of the circle/rectangle
public RoundBorder strokeAngle(int strokeAngle)Sets the stroke angle of the circle, this only applies to circular versions
public RoundBorder shadowSpread(int shadowSpread, boolean mm)Sets the spread in pixels of the shadow i.e how much bigger is it than the actual circle/rectangle
public RoundBorder shadowSpread(int shadowSpread)Sets the spread in pixels of the shadow i.e how much bigger is it than the actual circle/rectangle
public RoundBorder shadowOpacity(int shadowOpacity)Sets the opacity of the shadow from 0 - 255 where 0 means no shadow and 255 means opaque black shadow
public RoundBorder shadowX(float shadowX)The position of the shadow on the X axis where 0.5f means the center and higher values draw it to the right side
public RoundBorder shadowY(float shadowY)The position of the shadow on the Y axis where 0.5f means the center and higher values draw it to the bottom
public RoundBorder shadowBlur(float shadowBlur)The blur on the shadow this is the standard Gaussian blur radius
public RoundBorder rectangle(boolean rectangle)When set to true this border grows into a rectangle when the space isn’t perfectly circular
public RoundBorder onlyLeftRounded(boolean onlyLeftRounded)Forces a special case of the rectangle mode that renders the right side as square.
public boolean isOnlyLeftRounded()Checks if only left side is rounded.
public RoundBorder onlyRightRounded(boolean onlyRightRounded)Forces a special case of the rectangle mode that renders the left side as square.
public boolean isOnlyRightRounded()Checks if only right side is rounded.
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 boolean isBackgroundPainter()Returns true if installing this border will override the painting of the component background
public int getColor()The color of the border background
public int getOpacity()The opacity (transparency) of the border background
public int getStrokeColor()The color of the edge of the border if applicable
public boolean isStrokeGradient()True if the stroke is painted as a two-colour gradient
public int getStrokeColor2()The end colour of the gradient stroke when #isStrokeGradient is true
public float getStrokeGradientAngle()The angle of the gradient stroke in degrees
public int getStrokeOpacity()The opacity of the edge of the border if applicable
public float getStrokeThickness()The thickness of the edge of the border if applicable, 0 if no stroke is needed
public boolean isStrokeMM()True if the thickness of the stroke is in millimeters
public int getShadowSpread()The spread of the shadow in pixels of millimeters
public int getShadowOpacity()The opacity of the shadow between 0 and 255
public float getShadowX()X axis bias of the shadow between 0 and 1 where 0 is to the top and 1 is to the bottom, defaults to 0.5
public float getShadowY()Y axis bias of the shadow between 0 and 1 where 0 is to the left and 1 is to the right, defaults to 0.5
public float getShadowBlur()The Gaussian blur size
public boolean isShadowMM()True if the shadow spread is in millimeters
public boolean isRectangle()True if this border grows into a rectangle horizontally or keeps growing as a circle
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.

Inherited methods

Method details

create

public static RoundBorder create()
Creates a flat round border with no stroke and no shadow and the default color, this call can be chained with the other calls to mutate the color/opacity etc.

Returns

a border instance

uiid

public RoundBorder uiid(boolean uiid)

Uses the style of the components UIID to draw the background of the border, this effectively overrides all other style settings but allows the full power of UIID drawing including gradients, background images etc.

**Notice: **this flag will only work when shaped clipping is supported. That feature isn’t available in all platforms…

Parameters

uiid boolean
true to use the background of the component setting

Returns

border instance so these calls can be chained

getUIID

public boolean getUIID()
True is we use the background of the component setting to draw

Returns

true if we draw based on the component UIID

color

public RoundBorder color(int color)
Sets the background color of the circle/rectangle

Parameters

color int
the color

Returns

border instance so these calls can be chained

opacity

public RoundBorder opacity(int opacity)
Sets the background opacity of the circle/rectangle

Parameters

opacity int
the background opacity from 0-255 where 255 is completely opaque

Returns

border instance so these calls can be chained

strokeOpacity

public RoundBorder strokeOpacity(int strokeOpacity)
Sets the opacity of the stroke line around the circle/rectangle

Parameters

strokeOpacity int
the opacity from 0-255 where 255 is completely opaque

Returns

border instance so these calls can be chained

strokeColor

public RoundBorder strokeColor(int strokeColor)
Sets the stroke color of the circle/rectangle

Parameters

strokeColor int
the color

Returns

border instance so these calls can be chained

strokeColor2

public RoundBorder strokeColor2(int strokeColor2)
Turns the stroke into a two-colour linear gradient running from strokeColor to the supplied end colour. The stroke thickness/opacity keep applying; only the colour along the rim changes. Requires shape-clip support (all modern ports); on ports without it the stroke falls back to the solid strokeColor.

Parameters

strokeColor2 int
the end colour of the gradient stroke

Returns

border instance so these calls can be chained

strokeGradientAngle

public RoundBorder strokeGradientAngle(float strokeGradientAngle)
Sets the direction of the gradient stroke.

Parameters

strokeGradientAngle float
the angle in degrees, 0 = top-to-bottom, increasing clockwise

Returns

border instance so these calls can be chained

strokeGradient

public RoundBorder strokeGradient(boolean strokeGradient)
Explicitly enables/disables the gradient stroke without changing the colours.

Parameters

strokeGradient boolean
true to paint the stroke as a gradient

Returns

border instance so these calls can be chained

stroke

public RoundBorder stroke(Stroke stroke)
Sets the stroke of the circle/rectangle

Parameters

stroke Stroke
the stroke object

Returns

border instance so these calls can be chained

stroke

public RoundBorder stroke(float stroke, boolean mm)
Sets the stroke of the circle/rectangle

Parameters

stroke float
the thickness of the stroke object
mm boolean
set to true to indicate the value is in millimeters, false indicates pixels

Returns

border instance so these calls can be chained

strokeAngle

public RoundBorder strokeAngle(int strokeAngle)
Sets the stroke angle of the circle, this only applies to circular versions

Parameters

strokeAngle int
the stroke angle in degrees

Returns

border instance so these calls can be chained

shadowSpread

public RoundBorder shadowSpread(int shadowSpread, boolean mm)
Sets the spread in pixels of the shadow i.e how much bigger is it than the actual circle/rectangle

Parameters

shadowSpread int
the amount in pixels representing the size of the shadow
mm boolean
set to true to indicate the value is in millimeters, false indicates pixels

Returns

border instance so these calls can be chained

shadowSpread

public RoundBorder shadowSpread(int shadowSpread)
Sets the spread in pixels of the shadow i.e how much bigger is it than the actual circle/rectangle

Parameters

shadowSpread int
the amount in pixels representing the size of the shadow

Returns

border instance so these calls can be chained

shadowOpacity

public RoundBorder shadowOpacity(int shadowOpacity)
Sets the opacity of the shadow from 0 - 255 where 0 means no shadow and 255 means opaque black shadow

Parameters

shadowOpacity int
the opacity of the shadow

Returns

border instance so these calls can be chained

shadowX

public RoundBorder shadowX(float shadowX)
The position of the shadow on the X axis where 0.5f means the center and higher values draw it to the right side

Parameters

shadowX float
the position of the shadow between 0 - 1 where 0 equals left and 1 equals right

Returns

border instance so these calls can be chained

shadowY

public RoundBorder shadowY(float shadowY)
The position of the shadow on the Y axis where 0.5f means the center and higher values draw it to the bottom

Parameters

shadowY float
the position of the shadow between 0 - 1 where 0 equals top and 1 equals bottom

Returns

border instance so these calls can be chained

shadowBlur

public RoundBorder shadowBlur(float shadowBlur)
The blur on the shadow this is the standard Gaussian blur radius

Parameters

shadowBlur float
The blur on the shadow this is the standard Gaussian blur radius

Returns

border instance so these calls can be chained

rectangle

public RoundBorder rectangle(boolean rectangle)
When set to true this border grows into a rectangle when the space isn’t perfectly circular

Parameters

rectangle boolean
When set to true this border grows into a rectangle when the space isn’t perfectly circular

Returns

border instance so these calls can be chained

onlyLeftRounded

public RoundBorder onlyLeftRounded(boolean onlyLeftRounded)
Forces a special case of the rectangle mode that renders the right side as square. This is ignored when the rectangle mode is false

Parameters

onlyLeftRounded boolean
the new state of this mode

Returns

border instance so these calls can be chained

isOnlyLeftRounded

public boolean isOnlyLeftRounded()
Checks if only left side is rounded.

Returns

True if only left side is rounded.

onlyRightRounded

public RoundBorder onlyRightRounded(boolean onlyRightRounded)
Forces a special case of the rectangle mode that renders the left side as square. This is ignored when the rectangle mode is false

Parameters

onlyRightRounded boolean
the new state of this mode

Returns

border instance so these calls can be chained

isOnlyRightRounded

public boolean isOnlyRightRounded()
Checks if only right side is rounded.

Returns

True if only right side is rounded.

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.

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

getColor

public int getColor()
The color of the border background

Returns

the color

getOpacity

public int getOpacity()
The opacity (transparency) of the border background

Returns

the opacity

getStrokeColor

public int getStrokeColor()
The color of the edge of the border if applicable

Returns

the strokeColor

isStrokeGradient

public boolean isStrokeGradient()
True if the stroke is painted as a two-colour gradient

Returns

the strokeGradient flag

getStrokeColor2

public int getStrokeColor2()
The end colour of the gradient stroke when #isStrokeGradient is true

Returns

the strokeColor2

getStrokeGradientAngle

public float getStrokeGradientAngle()
The angle of the gradient stroke in degrees

Returns

the strokeGradientAngle

getStrokeOpacity

public int getStrokeOpacity()
The opacity of the edge of the border if applicable

Returns

the strokeOpacity

getStrokeThickness

public float getStrokeThickness()
The thickness of the edge of the border if applicable, 0 if no stroke is needed

Returns

the strokeThickness

isStrokeMM

public boolean isStrokeMM()
True if the thickness of the stroke is in millimeters

Returns

the strokeMM

getShadowSpread

public int getShadowSpread()
The spread of the shadow in pixels of millimeters

Returns

the shadowSpread

getShadowOpacity

public int getShadowOpacity()
The opacity of the shadow between 0 and 255

Returns

the shadowOpacity

getShadowX

public float getShadowX()
X axis bias of the shadow between 0 and 1 where 0 is to the top and 1 is to the bottom, defaults to 0.5

Returns

the shadowX

getShadowY

public float getShadowY()
Y axis bias of the shadow between 0 and 1 where 0 is to the left and 1 is to the right, defaults to 0.5

Returns

the shadowY

getShadowBlur

public float getShadowBlur()
The Gaussian blur size

Returns

the shadowBlur

isShadowMM

public boolean isShadowMM()
True if the shadow spread is in millimeters

Returns

the shadowMM

isRectangle

public boolean isRectangle()
True if this border grows into a rectangle horizontally or keeps growing as a circle

Returns

the rectangle

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.)