Class 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteConstant indicating background-position center (horizontal).static final byteConstant indicating background-position left.static final bytestatic final byteConstant indicating background-position right.static final byteConstant indicating repeating on both x and y for background images.static final byteConstant indicating no-repeat for background images.static final byteConstant indicating repeat-x for background images.static final byteConstant indicating repeat-y for background images.static final bytestatic final bytestatic final bytestatic final bytestatic final byteConstant for border-style dashedstatic final byteConstant for border-style dottedstatic final byteConstant for border-style hiddenstatic final byteConstant for border-style nonestatic final byteConstant for border-style solidstatic final byteConstant for unit emstatic final byteConstant for unit mmstatic final byteConstant for unit %static final byteConstant for unit pxstatic final byteConstant indicating background-position bottom.static final byteConstant indicating background-position center.static final bytestatic final byteConstant indicating background-position top. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbackgroundColor(String color) Sets the background color of the border.backgroundImage(Image... images) Sets the background image of the border.backgroundImage(String cssDirective) Adds one or more background images from a CSS background-image property.backgroundPosition(String... pos) Sets the background position.backgroundRepeat(String... repeat) Sets the background-repeat for the background images.borderColor(String... colors) Sets the border colors.borderImage(Image borderImage, double... slicePoints) Creates a 9-piece image border.borderImageWithName(String borderImageName, double... slicePoints) Adds a 9-piece image border using the provided image name, which should exist in the theme resource file.borderRadius(String radius) Sets the border radius for rounded corners.borderStroke(String... strokeStrs) Sets the border stroke.borderStyle(String... styles) Sets the border styles.borderWidth(String... widths) Sets the border widths.boolean{{Indicates whether some other object is "equal to" this one.intReturns 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.intReturns 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.inthashCode()Returns a hash code value for the object.booleanReturns true if installing this border will override the painting of the component backgroundvoidHas 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.Converts this border to a CSS string.Methods inherited from class Border
addOuterBorder, clearImageBorderSpecialTile, createBevelLowered, createBevelLowered, createBevelRaised, createBevelRaised, createCompoundBorder, createDashedBorder, createDashedBorder, createDottedBorder, createDottedBorder, createDoubleBorder, createDoubleBorder, createEmpty, createEtchedLowered, createEtchedLowered, createEtchedRaised, createEtchedRaised, createGrooveBorder, createGrooveBorder, createHorizonalImageBorder, createImageBorder, createImageBorder, createImageScaledBorder, createImageSplicedBorder, createInsetBorder, createInsetBorder, createLineBorder, createLineBorder, createLineBorder, createLineBorder, createLineBorder, createLineBorder, createOutsetBorder, createOutsetBorder, createPressedVersion, createRidgeBorder, createRidgeBorder, createRoundBorder, createRoundBorder, createRoundBorder, createRoundBorder, createUndelineBorder, createUndelineBorder, createUnderlineBorder, createUnderlineBorder, createUnderlineBorder, createUnderlineBorder, createVerticalImageBorder, getCompoundBorders, getDefaultBorder, getEmpty, getFocusedInstance, getPressedInstance, getProperty, getThickness, getTrackComponent, isEmptyBorder, isPaintOuterBorderFirst, isRectangleType, lock, mirrorBorder, paint, setDefaultBorder, setFocusedInstance, setImageBorderSpecialTile, setImageBorderSpecialTile, setPaintOuterBorderFirst, setPressedInstance, setThickness, setTrackComponent, setTrackComponent, unlockModifier and TypeMethodDescriptionvoidaddOuterBorder(Border outer) Ads a border that wraps this bordervoidCleans the tile tracking state allowing the garbage collector to pick up the component and the image datastatic BorderCreates a lowered bevel border with default colors, highlight is derived from the component and shadow is a plain dark colorstatic BordercreateBevelLowered(int highlightOuter, int highlightInner, int shadowOuter, int shadowInner) Creates a raised bevel border with the given colorsstatic BorderCreates a lowered bevel border with default colors, highlight is derived from the component and shadow is a plain dark colorstatic BordercreateBevelRaised(int highlightOuter, int highlightInner, int shadowOuter, int shadowInner) Creates a raised bevel border with the given colorsstatic BordercreateCompoundBorder(Border top, Border bottom, Border left, Border right) Creates a border that is comprised of multiple border types so one border type can be used on top while another one can be used at the bottom.static BordercreateDashedBorder(int thickness) Creates a dashed border with the specified thickness and the theme colorsstatic BordercreateDashedBorder(int thickness, int color) Creates a dashed border with the specified thickness and colorstatic BordercreateDottedBorder(int thickness) Creates a dotted border with the specified thickness and the theme colorsstatic BordercreateDottedBorder(int thickness, int color) Creates a dotted border with the specified thickness and colorstatic BordercreateDoubleBorder(int thickness) Creates a double border with the specified thickness and colorstatic BordercreateDoubleBorder(int thickness, int color) Creates a double border with the specified thickness and colorstatic BorderCreates an empty border, this is useful where we don't want a border for a component but want a focus border etc...static BorderCreates a lowered etched border with default colors, highlight is derived from the component and shadow is a plain dark colorstatic BordercreateEtchedLowered(int highlight, int shadow) Creates a raised etched border with the given colorsstatic BorderCreates a lowered etched border with default colors, highlight is derived from the component and shadow is a plain dark colorstatic BordercreateEtchedRaised(int highlight, int shadow) Creates a raised etched border with the given colorsstatic BordercreateGrooveBorder(int thickness) Creates a groove border with the specified thickness and theme colorsstatic BordercreateGrooveBorder(int thickness, int color) Creates a groove border with the specified thickness and colorstatic BordercreateHorizonalImageBorder(Image left, Image right, Image center) This is an image border that can only grow horizontallystatic BordercreateImageBorder(Image top, Image topLeft, Image background) The given images are tiled appropriately across the matching side of the border, rotated and placed as expected in the four corners.static BordercreateImageBorder(Image top, Image bottom, Image left, Image right, Image topLeft, Image topRight, Image bottomLeft, Image bottomRight, Image background) The given top/bottom/left/right images are tiled appropriately across the matching sides of the border and the corners are placed as expected in the four corners.static BordercreateImageScaledBorder(Image top, Image bottom, Image left, Image right, Image topLeft, Image topRight, Image bottomLeft, Image bottomRight, Image background) The given top/bottom/left/right images are scaled appropriately across the matching sides of the border and the corners are placed as expected in the four corners.static BordercreateImageSplicedBorder(Image img, double topInset, double rightInset, double bottomInset, double leftInset) The given image is spliced into 9 pieces based on the provided top, right, bottom, and left insets, and the resulting sub-images are used to form a 9-piece image border viacom.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image)static BordercreateInsetBorder(int thickness) Creates an inset border with the specified thickness and theme colorsstatic BordercreateInsetBorder(int thickness, int color) Creates an inset border with the specified thickness and colorstatic BordercreateLineBorder(float thickness) Creates a line border that uses the color of the component foreground for drawingstatic BordercreateLineBorder(float thickness, int color) Creates a line border that uses the given color for the componentstatic BordercreateLineBorder(int thickness) Creates a line border that uses the color of the component foreground for drawingstatic BordercreateLineBorder(int thickness, int color) Creates a line border that uses the given color for the componentstatic BordercreateLineBorder(int thickness, int color, String title) Creates a line border that uses the given color for the componentstatic BordercreateLineBorder(int thickness, String title) Creates a line border with the specified titlestatic BordercreateOutsetBorder(int thickness) Creates an outset border with the specified thickness and theme colorsstatic BordercreateOutsetBorder(int thickness, int color) Creates an outset border with the specified thickness and colorWhen applied to buttons borders produce a version that reverses the effects of the border providing a pressed feelstatic BordercreateRidgeBorder(int thickness) Creates a ridge border with the specified thickness and theme colorsstatic BordercreateRidgeBorder(int thickness, int color) Creates a ridge border with the specified thickness and colorstatic BordercreateRoundBorder(int arcWidth, int arcHeight) Creates a rounded corner border that uses the color of the component foreground for drawing.static BordercreateRoundBorder(int arcWidth, int arcHeight, boolean outline) Creates a rounded corner border that uses the color of the component foreground for drawing.static BordercreateRoundBorder(int arcWidth, int arcHeight, int color) Creates a rounded border that uses the given color for the component.static BordercreateRoundBorder(int arcWidth, int arcHeight, int color, boolean outline) Creates a rounded border that uses the given color for the component.static BordercreateUndelineBorder(float thickness) Creates an underline border that uses the color of the component foreground for drawingstatic BordercreateUndelineBorder(int thickness) Creates an underline border that uses the color of the component foreground for drawingstatic BordercreateUnderlineBorder(float thickness) Creates an underline border that uses the color of the component foreground for drawingstatic BordercreateUnderlineBorder(float thickness, int color) Creates an underline border that uses the given colorstatic BordercreateUnderlineBorder(int thickness) Creates an underline border that uses the color of the component foreground for drawingstatic BordercreateUnderlineBorder(int thickness, int color) Creates an underline border that uses the given colorstatic BordercreateVerticalImageBorder(Image top, Image bottom, Image center) This is an image border that can only grow verticallyBorder[]This method returns the Compound Borders array.static BorderGets the default border to the given valuestatic BordergetEmpty()Returns an empty border, this is mostly useful for overriding components that have a border by defaultReturns the focused version of the border if one is installedReturns the pressed version of the border if one is set by the userThis method is for internal usage only!intThis method returns how thick is the border in pixels, notice this doesn't apply to most border typesprotected RectangleThe track component is an area to which an arrow based border should point at.booleanIndicates whether this is an empty borderbooleanAllows toggling the order in which the outer and inner borders are painted for the Outer border typebooleanReturns true if this border type is a rectangle border.voidlock()This callback indicates that a component pointing at this border is initialized, this method is useful for image borders whose lock methods are implicitly invoked.If a border is a horizontal image border it can be mirrored which is useful for an RTL scenariovoidDraws the border for the given component, this method is called before a call to background painting is made.static voidsetDefaultBorder(Border border) Sets the default border to the given valuevoidsetFocusedInstance(Border focused) Allows us to define a border that will act as the focused version of this bordervoidsetImageBorderSpecialTile(Image tileTop, Image tileBottom, Image tileLeft, Image tileRight, Component trackComponent) This method is designed mainly for the purpose of creating an arrow that will track a specific component using the image border the tile given would be an arrow like image just like the ones used for the top/bottom/left/right images.voidsetImageBorderSpecialTile(Image tileTop, Image tileBottom, Image tileLeft, Image tileRight, Rectangle trackComponent) This method is designed mainly for the purpose of creating an arrow that will track a specific component using the image border the tile given would be an arrow like image just like the ones used for the top/bottom/left/right images.voidsetPaintOuterBorderFirst(boolean paintOuterBorderFirst) Allows toggling the order in which the outer and inner borders are painted for the Outer border typevoidsetPressedInstance(Border pressed) Allows us to define a border that will act as the pressed version of this bordervoidsetThickness(int thickness) This method returns sets the border thickness in pixels, notice this doesn't apply to most border typesvoidsetTrackComponent(Component trackComponent) In the case of an arrow border the track component lets us track the position to which the border is pointingvoidsetTrackComponent(Rectangle trackComponent) In the case of an arrow border the track component lets us track the position to which the border is pointingvoidunlock()This callback indicates that a component pointing at this border is now deinitilized This method may be invoked multiple times.Methods inherited from class Object
clone, getClass, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()final ClassgetClass()Returns the runtime class of an object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(long timeout) Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.final voidwait(long timeout, int nanos) Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
-
Field Details
-
REPEAT_NONE
public static final byte REPEAT_NONEConstant indicating no-repeat for background images.- See Also:
-
REPEAT_BOTH
public static final byte REPEAT_BOTHConstant indicating repeating on both x and y for background images.- See Also:
-
REPEAT_X
public static final byte REPEAT_XConstant indicating repeat-x for background images.- See Also:
-
REPEAT_Y
public static final byte REPEAT_YConstant indicating repeat-y for background images.- See Also:
-
VPOSITION_TOP
public static final byte VPOSITION_TOPConstant indicating background-position top.- See Also:
-
VPOSITION_BOTTOM
public static final byte VPOSITION_BOTTOMConstant indicating background-position bottom.- See Also:
-
VPOSITION_CENTER
public static final byte VPOSITION_CENTERConstant indicating background-position center.- See Also:
-
VPOSITION_OTHER
public static final byte VPOSITION_OTHER- See Also:
-
HPOSITION_LEFT
public static final byte HPOSITION_LEFTConstant indicating background-position left.- See Also:
-
HPOSITION_RIGHT
public static final byte HPOSITION_RIGHTConstant indicating background-position right.- See Also:
-
HPOSITION_CENTER
public static final byte HPOSITION_CENTERConstant 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_NONEConstant for border-style none- See Also:
-
STYLE_HIDDEN
public static final byte STYLE_HIDDENConstant for border-style hidden- See Also:
-
STYLE_DOTTED
public static final byte STYLE_DOTTEDConstant for border-style dotted- See Also:
-
STYLE_DASHED
public static final byte STYLE_DASHEDConstant for border-style dashed- See Also:
-
STYLE_SOLID
public static final byte STYLE_SOLIDConstant for border-style solid- See Also:
-
UNIT_PIXELS
public static final byte UNIT_PIXELSConstant for unit px- See Also:
-
UNIT_MM
public static final byte UNIT_MMConstant for unit mm- See Also:
-
UNIT_PERCENT
public static final byte UNIT_PERCENTConstant for unit %- See Also:
-
UNIT_EM
public static final byte UNIT_EMConstant for unit em- See Also:
-
-
Constructor Details
-
CSSBorder
public CSSBorder()Creates a new empty CSS border. -
CSSBorder
Creates an empty border.
Parameters
res: Theme resource file from which images can be referenced.
-
CSSBorder
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
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
Description copied from class:Border{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()Description copied from class:BorderReturns 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
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:
isBackgroundPainterin classBorder
-
paintBorderBackground
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:
paintBorderBackgroundin classBorder
-
-
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:
getMinimumHeightin classBorder
-
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:
getMinimumWidthin classBorder
-
borderImage
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
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
-
borderRadius
-
borderStroke
-
borderColor
-
borderWidth
-
borderStyle
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
-
backgroundImage
-
backgroundImage
-
backgroundRepeat
-
backgroundPosition
-