public class StyleParser extends Object
This class is the basis for the inline style functionality:
Component.setInlineAllStyles(java.lang.String)
Component.getInlineAllStyles()
Component.setInlineSelectedStyles(java.lang.String)
Component.getInlineSelectedStyles()
Style strings are strings which describe a style, and are in a particular format that StyleParser
knows how to
parse. The general format of a style string is key1:value1; key2:value2; ... keyn:valuen;. I.e. a set of key-value pairs
with pairs separated by semi-colons, and keys and values separated by a colon. This is very similar to CSS, but it is NOT CSS.
Style string keys and values are closely related to the properties of the Style
class and their associated values.
The following keys are supported:
The padding and margin keys can take values the same format as is used for CSS margin and padding directives. That is the value can be expressed as a space-separated sequence of scalar values (i.e. float values with a unit suffix). Some examples:
All of the examples above use padding, but the same format is used for margin. They demonstrate the use of 1, 2, 3, and 4 value sequences, and their meaning. In general terms these formats can be described as:
Fonts strings can take any of the following formats:
The border property accepts several different formats for its value. This is due to the many different kinds of borders that can be created. The following are some of the formats.
Line Border
<thickness> solid <color> - E.g. 1mm solid ff0000. <thickness> should be expressed as a scalar value with unit. E.g. 1mm, or 2px. <color> should be an RGB hex string. E.g ff0000 for red.
Dashed Border
<thickness> dashed <color> - E.g. 1mm dashed ff0000. <thickness> should be expressed as a scalar value with unit. E.g. 1mm, or 2px. <color> should be an RGB hex string. E.g ff0000 for red.
Dotted Border
<thickness> dotted <color> - E.g. 1mm dotted ff0000. <thickness> should be expressed as a scalar value with unit. E.g. 1mm, or 2px. <color> should be an RGB hex string. E.g ff0000 for red.
Underline Border
<thickness> underline <color> - E.g. 1mm underline ff0000. <thickness> should be expressed as a scalar value with unit. E.g. 1mm, or 2px. <color> should be an RGB hex string. E.g ff0000 for red.
Image Border
image <image1> <image2> ... <image9> - A 9-piece image border. The <image1> .. <image9> values are strings which refer to images either on the classpath, or in the theme resource file.
If the image string starts with /, then it is assumed to be on the classpath. The order of the images corresponds to the parameters of Border.createImageBorder(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, com.codename1.ui.Image, com.codename1.ui.Image)
.
image <image1> <image2> <image3> - A 9-piece image border, but with the images corresponding to the parameters of Border.createImageBorder(com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image)
.
horizontalImage <leftImage> <rightImage> <centerImage> - A 3-piece horizontal image border. Image parameters correspond with Border.createHorizonalImageBorder(com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image)
parameters.
verticalImage <topImage> <bottomImage> <centerImage> - A 3-piece horizontal image border. Image parameters correspond with Border.createVerticalImageBorder(com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image)
parameters.
splicedImage <image> <topInset> <rightInset> <bottomInset> <leftInset> - A 9-piece image border that is generated from a single image, but with inset values specifying where the image should be sliced to create the 9 sub-images.
Parameters:
Modifier and Type | Class and Description |
---|---|
static class |
StyleParser.BorderInfo
Encapsulates information about the border property of a style string.
|
static class |
StyleParser.BoxInfo
Base class for style values that consist of 4 scalar values, such as padding and margin.
|
static class |
StyleParser.FontInfo
Encapsulates the value of the font property in a style string.
|
static class |
StyleParser.ImageInfo
Encapsulates an image that is referenced by a style string.
|
static class |
StyleParser.MarginInfo
Encapsulates information about the padding in a style string.
|
static class |
StyleParser.PaddingInfo
Encapsulates information about the padding in a style string.
|
static class |
StyleParser.ScalarValue
Encapsulates a scalar value with a unit.
|
static class |
StyleParser.StyleInfo
Encapculates a style string in structured format.
|
Modifier and Type | Field and Description |
---|---|
static byte |
UNIT_INHERIT |
Constructor and Description |
---|
StyleParser() |
Modifier and Type | Method and Description |
---|---|
static List<String> |
getBackgroundTypes()
Gets the available background type strings (which can be passed to
StyleParser.StyleInfo.setBgType(java.lang.String) |
static List<String> |
getSupportedBackgroundTypes()
Gets a list of the background types that are supported.
|
static StyleParser.ScalarValue |
parseScalarValue(String val)
Parses a string into a scalar value.
|
static boolean |
validateScalarValue(String val)
Checks if a string is a valid scalar value.
|
public static final byte UNIT_INHERIT
public static List<String> getBackgroundTypes()
StyleParser.StyleInfo.setBgType(java.lang.String)
public static boolean validateScalarValue(String val)
There is one special value: "inherit" which indicates that the scalar value just inherits from its parent.
val
- String value to validate.public static StyleParser.ScalarValue parseScalarValue(String val)
There is one special value: "inherit" which indicates that the scalar value just inherits from its parent.
val
- String that should be a valid scalar value.