public final class RoundRectBorder
Customizable rounded rectangle border that breaks down the border into customizable pieces.
The background is inherited from the parent UIID but stroke and shadow can be customized via user settings.
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("RoundRect", 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(RoundRectBorder.create().
strokeColor(0).
strokeOpacity(120).
stroke(borderStroke));
loginStyle.setBgColor(0xffffff);
loginStyle.setBgTransparency(255);
loginStyle.setMarginUnit(Style.UNIT_TYPE_DIPS);
loginStyle.setMargin(Component.BOTTOM, 3);
Style passwordStyle = password.getAllStyles();
passwordStyle.setBorder(RoundRectBorder.create().
strokeColor(0).
strokeOpacity(120).
stroke(borderStroke));
passwordStyle.setBgColor(0xffffff);
passwordStyle.setBgTransparency(255);
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 RoundRectBorder create() | Creates a flat border with styles derived from the component UIID |
public RoundRectBorder arrowSize(float size) | Change the size of the arrow used for component tracking. |
public void setArrowSize(float size) | Change the size of the arrow used for component tracking. |
public RoundRectBorder strokeOpacity(int strokeOpacity) | Sets the opacity of the stroke line around the border |
public RoundRectBorder trackComponentSide(int side) | Explicitly positions the arrow used for component tracking to a particular side of the border. |
public int getTrackComponentSide() | Gets the side that the tracking component should be displayed on if using explicit placement. |
public RoundRectBorder trackComponentVerticalPosition(float pos) | Explicitly sets the vertical position of the tracking arrow. |
public float getTrackComponentVerticalPosition() | Gets the explicitly set vertical position of the tracking arrow. |
public RoundRectBorder trackComponentHorizontalPosition(float pos) | Explicitly sets the horizontal position of the tracking arrow. |
public float getTrackComponentHorizontalPosition() | Gets the explicitly set horizontal position of the tracking arrow. |
public RoundRectBorder useCache(boolean useCache) | Sets whether this RoundRectBorder instance should cache the border as a background image. |
public boolean isUseCache() | Checks whether this RoundRectBorder instance caches the border as a background image. |
public RoundRectBorder strokeColor(int strokeColor) | Sets the stroke color of the border |
public RoundRectBorder stroke(Stroke stroke) | Sets the stroke of the border |
public RoundRectBorder stroke(float stroke, boolean mm) | Sets the stroke of the border |
public RoundRectBorder shadowSpread(float shadowSpread) | Sets the spread of the shadow in millimeters i.e how much bigger is it than the actual border |
public RoundRectBorder shadowSpread(int shadowSpread) | Sets the spread in pixels of the shadow i.e how much bigger is it than the actual border |
public RoundRectBorder shadowOpacity(int shadowOpacity) | Sets the opacity of the shadow from 0 - 255 where 0 means no shadow and 255 means opaque black shadow |
public RoundRectBorder shadowColor(int shadowColor) | Sets the color of the shadow as an RRGGBB color |
public RoundRectBorder 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 RoundRectBorder 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 RoundRectBorder shadowBlur(float shadowBlur) | The blur on the shadow this is the standard Gaussian blur radius |
public RoundRectBorder cornerRadius(float cornerRadius) | The radius of the corners in millimeters |
public RoundRectBorder bezierCorners(boolean bezierCorners) | True if the corners are Bezier curves, otherwise the corners are drawn as a regular arc |
public RoundRectBorder cssBoxModel(boolean cssBoxModel) | Makes this border follow the CSS box model when the component is measured. |
public boolean isCssBoxModel() | True if this border is measured according to the CSS box model |
public RoundRectBorder topLeftMode(boolean topLeft) | True to draw the top left corner rounded, false to draw it as a corner |
public RoundRectBorder topRightMode(boolean topRight) | True to draw the top right corner rounded, false to draw it as a corner |
public RoundRectBorder bottomLeftMode(boolean bottomLeft) | True to draw the bottom left corner rounded, false to draw it as a corner |
public RoundRectBorder bottomRightMode(boolean bottomRight) | True to draw the bottom right corner rounded, false to draw it as a corner |
public RoundRectBorder topOnlyMode(boolean topOnlyMode) | Special mode where only the top of the round rectangle is rounded and the bottom is a regular rectangle |
public RoundRectBorder bottomOnlyMode(boolean bottomOnlyMode) | Special mode where only the bottom of the round rectangle is rounded and the top is a regular rectangle |
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 getStrokeColor() | The color of the edge of the border if applicable |
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 boolean isBezierCorners() | True if the corners are bezier curves, otherwise the corners are drawn as a regular arc |
public float getShadowSpread() | The spread of the shadow in pixels of millimeters |
public int getShadowOpacity() | The opacity of the shadow between 0 and 255 |
public int getShadowColor() | The color of the shadow as an RRGGBB color |
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 float getCornerRadius() | The radius of the corners in millimeters |
public boolean isTopOnlyMode() | Special mode where only the top of the round rectangle is rounded and the bottom is a regular rectangle |
public boolean isBottomOnlyMode() | Special mode where only the bottom of the round rectangle is rounded and the top is a regular rectangle |
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 boolean isTopLeft() | Returns true if this border corner is round and false if it’s square |
public boolean isTopRight() | Returns true if this border corner is round and false if it’s square |
public boolean isBottomLeft() | Returns true if this border corner is round and false if it’s square |
public boolean isBottomRight() | Returns true if this border corner is round and false if it’s square |
Inherited methods
From Border
getEmpty, createEmpty, createImageBorder, createImageSplicedBorder, createImageScaledBorder, createHorizonalImageBorder, createVerticalImageBorder, createImageBorder, createLineBorder, createLineBorder, createUndelineBorder, createUnderlineBorder, createUndelineBorder, createUnderlineBorder, createUnderlineBorder, createUnderlineBorder, createDottedBorder, createDashedBorder, createDoubleBorder, createDottedBorder, createDashedBorder, createDoubleBorder, createOutsetBorder, createOutsetBorder, createInsetBorder, createInsetBorder, createGrooveBorder, createGrooveBorder, createRidgeBorder, createRidgeBorder, createLineBorder, createLineBorder, createLineBorder, createLineBorder, createRoundBorder, createRoundBorder, createRoundBorder, createRoundBorder, createEtchedLowered, createEtchedLowered, createEtchedRaised, createEtchedRaised, createCompoundBorder, createBevelLowered, createBevelLowered, createBevelRaised, createBevelRaised, getDefaultBorder, setDefaultBorder, mirrorBorder, setImageBorderSpecialTile, getTrackComponent, setTrackComponent, setTrackComponent, setImageBorderSpecialTile, clearImageBorderSpecialTile, addOuterBorder, isEmptyBorder, isRectangleType, getFocusedInstance, setFocusedInstance, getPressedInstance, setPressedInstance, createPressedVersion, paint, getThickness, setThickness, isPaintOuterBorderFirst, setPaintOuterBorderFirst, getCompoundBorders, lock, unlock, getProperty
Method details
create
public static RoundRectBorder create()Returns
arrowSize
public RoundRectBorder arrowSize(float size)Parameters
sizefloat- Size of arrow in millimeters.
Returns
setArrowSize
public void setArrowSize(float size)Parameters
sizefloat- Size of arrow in millimeters.
strokeOpacity
public RoundRectBorder strokeOpacity(int strokeOpacity)Parameters
strokeOpacityint- the opacity from 0-255 where 255 is completely opaque
Returns
trackComponentSide
public RoundRectBorder trackComponentSide(int side)#setTrackComponent(com.codename1.ui.geom.Rectangle)).
Use in conjunction with #trackComponentHorizontalPosition(float), and #trackComponentHorizontalPosition.Parameters
sideint- The side to place the tracking arrow on. Values
Component#TOP,Component#BOTTOM,Component#LEFT, orComponent#BOTTOM. Set negative value for default behaviour, which is to just calculate the arrow position based on the tracking component bounds.
Returns
getTrackComponentSide
public int getTrackComponentSide()Returns
Component#TOP, Component#BOTTOM, Component#LEFT, or a negative number to indicate that the position will be calculated based on the position of the tracking component.
or Component#BOTTOM.trackComponentVerticalPosition
public RoundRectBorder trackComponentVerticalPosition(float pos)#setTrackComponent(com.codename1.ui.geom.Rectangle)).Parameters
posfloat- Vertical position of the arrow. Values between 0 and 1 will place the arrow in the range from top to bottom. Negative values result in default behaviour, which is to calculate the position based on the tracking component position.
Returns
getTrackComponentVerticalPosition
public float getTrackComponentVerticalPosition()#setTrackComponent(com.codename1.ui.geom.Rectangle)).Returns
trackComponentHorizontalPosition
public RoundRectBorder trackComponentHorizontalPosition(float pos)#setTrackComponent(com.codename1.ui.geom.Rectangle)).Parameters
posfloat- Vertical position of the arrow. Values between 0 and 1 will place the arrow in the range from left to right. Negative values result in default behaviour, which is to calculate the position based on the tracking component position.
Returns
getTrackComponentHorizontalPosition
public float getTrackComponentHorizontalPosition()#setTrackComponent(com.codename1.ui.geom.Rectangle)).Returns
useCache
public RoundRectBorder useCache(boolean useCache)Sets whether this RoundRectBorder instance should cache the border as a background image.
This setting is on by default, but can be turned off, as some older, low-memory devices may run into memory trouble if it is using a lot of RoundRectBorders. Turn the cache off for low-memory devices.
NOTE: Using the cache is required for gaussian blur to work. If cache is disabled, then gaussian blur settings will be ignored.
Parameters
useCacheboolean- True to cache the border as a mutable image on the Component.
Returns
isUseCache
public boolean isUseCache()strokeColor
public RoundRectBorder strokeColor(int strokeColor)Parameters
strokeColorint- the color
Returns
stroke
public RoundRectBorder stroke(Stroke stroke)Parameters
strokeStroke- the stroke object
Returns
stroke
public RoundRectBorder stroke(float stroke, boolean mm)Parameters
strokefloat- the thickness of the stroke object
mmboolean- set to true to indicate the value is in millimeters, false indicates pixels
Returns
shadowSpread
public RoundRectBorder shadowSpread(float shadowSpread)Parameters
shadowSpreadfloat- the amount in millimeters representing the size of the shadow
Returns
shadowSpread
public RoundRectBorder shadowSpread(int shadowSpread)Parameters
shadowSpreadint- the amount in pixels representing the size of the shadow
Returns
shadowOpacity
public RoundRectBorder shadowOpacity(int shadowOpacity)Parameters
shadowOpacityint- the opacity of the shadow
Returns
shadowColor
public RoundRectBorder shadowColor(int shadowColor)Parameters
shadowColorint- the color of the shadow
Returns
shadowX
public RoundRectBorder shadowX(float shadowX)Parameters
shadowXfloat- the position of the shadow between 0 - 1 where 0 equals left and 1 equals right
Returns
shadowY
public RoundRectBorder shadowY(float shadowY)Parameters
shadowYfloat- the position of the shadow between 0 - 1 where 0 equals top and 1 equals bottom
Returns
shadowBlur
public RoundRectBorder shadowBlur(float shadowBlur)Parameters
shadowBlurfloat- The blur on the shadow this is the standard Gaussian blur radius
Returns
cornerRadius
public RoundRectBorder cornerRadius(float cornerRadius)Parameters
cornerRadiusfloat- the radius value
Returns
bezierCorners
public RoundRectBorder bezierCorners(boolean bezierCorners)Parameters
bezierCornersboolean- true if the corners use a bezier curve for drawing
Returns
cssBoxModel
public RoundRectBorder cssBoxModel(boolean cssBoxModel)Makes this border follow the CSS box model when the component is measured.
By default a RoundRectBorder reports a minimum size of twice the corner
radius (see getMinimumHeight()), which grows the component so a fully
rounded “pill” always fits. That is the behavior hand written code and the
designer rely on, but it is not how CSS behaves: in CSS border-radius
never contributes to the size of the box, it is simply scaled down when the
box is too small to fit it. This flag only changes the reported minimum size;
scaling the radius down to fit the component it is actually given happens in
both modes.
Borders generated by the CSS compiler enable this mode so a rule such as
border-radius: 0 3mm 3mm 0 renders with the padding the stylesheet asked
for instead of a component inflated to 6mm tall.
Parameters
cssBoxModelboolean- true to measure like CSS, false for the legacy pill sizing
Returns
isCssBoxModel
public boolean isCssBoxModel()Returns
topLeftMode
public RoundRectBorder topLeftMode(boolean topLeft)Parameters
topLeftboolean- true for round false for sharp
Returns
topRightMode
public RoundRectBorder topRightMode(boolean topRight)Parameters
topRightboolean- true for round false for sharp
Returns
bottomLeftMode
public RoundRectBorder bottomLeftMode(boolean bottomLeft)Parameters
bottomLeftboolean- true for round false for sharp
Returns
bottomRightMode
public RoundRectBorder bottomRightMode(boolean bottomRight)Parameters
bottomRightboolean- true for round false for sharp
Returns
topOnlyMode
public RoundRectBorder topOnlyMode(boolean topOnlyMode)Parameters
topOnlyModeboolean- new value for top only mode
Returns
bottomOnlyMode
public RoundRectBorder bottomOnlyMode(boolean bottomOnlyMode)Parameters
bottomOnlyModeboolean- new value for bottom only mode
Returns
paintBorderBackground
public void paintBorderBackground(Graphics g, Component c)Parameters
gGraphics- graphics context to draw onto
cComponent- component whose border should be drawn
getMinimumHeight
public int getMinimumHeight()Returns
getMinimumWidth
public int getMinimumWidth()Returns
isBackgroundPainter
public boolean isBackgroundPainter()Returns
getStrokeColor
public int getStrokeColor()Returns
getStrokeOpacity
public int getStrokeOpacity()Returns
getStrokeThickness
public float getStrokeThickness()Returns
isStrokeMM
public boolean isStrokeMM()Returns
isBezierCorners
public boolean isBezierCorners()Returns
getShadowSpread
public float getShadowSpread()Returns
getShadowOpacity
public int getShadowOpacity()Returns
getShadowColor
public int getShadowColor()Returns
getShadowX
public float getShadowX()Returns
getShadowY
public float getShadowY()Returns
getShadowBlur
public float getShadowBlur()Returns
getCornerRadius
public float getCornerRadius()Returns
isTopOnlyMode
public boolean isTopOnlyMode()Returns
isBottomOnlyMode
public boolean isBottomOnlyMode()Returns
equals
public boolean equals(Object obj)hashCode
public int hashCode()isTopLeft
public boolean isTopLeft()Returns
isTopRight
public boolean isTopRight()Returns
isBottomLeft
public boolean isBottomLeft()Returns
isBottomRight
public boolean isBottomRight()