APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text.html

public Class CSS

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:serial
Imports
java.awt.Color, .Font, .Image, .Toolkit, java.io.IOException, .ObjectInputStream, .Serial, .Serializable, java.net.MalformedURLException, .URL, java.util.ArrayList, .Enumeration, .Hashtable, .Map, .Objects, javax.swing.ImageIcon, .SizeRequirements, javax.swing.text.AttributeSet, .Element, .MutableAttributeSet, .SimpleAttributeSet, .StyleConstants, .StyleContext, .View

Defines a set of CSS attributes as a typesafe enumeration. The HTML View implementations use CSS attributes to determine how they will render. This also defines methods to map between CSS/HTML/StyleConstants. Any shorthand properties, such as font, are mapped to the intrinsic properties.

The following describes the CSS properties that are supported by the rendering engine:

The following are modeled, but currently not rendered.

Note

for the time being we do not fully support relative units, unless noted, so that p { margin-top: 10% } will be treated as if no margin-top was specified.

Authors
Timothy Prinzing, Scott Violet
External Specification
https://www.w3.org/TR/REC-CSS1
See Also
StyleSheet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CSS.Attribute

Definitions to be used as a key on AttributeSet's that might hold CSS attributes.

pack-priv static class
CSS.BackgroundImage

Used for BackgroundImages.

pack-priv static class
CSS.BackgroundPosition

Used for background images, to represent the position.

pack-priv static class
pack-priv static class
CSS.BorderWidthValue

BorderWidthValue is used to model BORDER_XXX_WIDTH and adds support for the thin/medium/thick values.

pack-priv static class
pack-priv static class
CSS.CssValue

Base class to CSS values in the attribute sets.

pack-priv static class
CSS.CssValueMapper

Handles uniquing of CSS values, like lists, and background image repeating.

pack-priv static class
pack-priv class
CSS.FontSize

Represents a value for the CSS.FONT_SIZE attribute.

pack-priv static class
pack-priv static interface
CSS.LayoutIterator

An iterator to express the requirements to use when computing layout.

pack-priv static class
CSS.LengthUnit

Parses a length value, this is used internally, and never added to an AttributeSet or returned to the developer.

pack-priv static class
pack-priv static class
CSS.ShorthandBackgroundParser

Parses the background property into its intrinsic values.

pack-priv static class
pack-priv static class
CSS.ShorthandFontParser

Class used to parse font property.

pack-priv static class
CSS.ShorthandMarginParser

Used to parser margin and padding.

pack-priv static class
CSS.StringValue

By default CSS attributes are represented as simple strings.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final Hashtable<String, CSS.Attribute>
private int
baseFontSize

Size used for relative units.

pack-priv static int
private static final Hashtable<String, CSS.Value>
cssValueToInternalValueMap

Maps from CSS value (string) to internal value.

private static final Map<HTML.Attribute, CSS.Attribute[]>
htmlAttrToCssAttrMap

The hashtable and the static initialization block below, set up a mapping from well-known HTML attributes to CSS attributes.

private static final Hashtable<String, CSS.Value>
htmlValueToCssValueMap

Maps from HTML value to a CSS value.

private static final Map<Object, CSS.Attribute>
styleConstantToCssMap

The hashtable and static initialization that follows sets up a translation from StyleConstants (i.e. the well known attributes) to the associated CSS attributes.

private transient StyleSheet
private transient Hashtable<Object, Object>
valueConvertor

Maps from CSS key to CssValue.

private static final Hashtable<String, CSS.Value>

Constructor Summary

AccessConstructor and Description
public
CSS()

Constructs a CSS object.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addInternalCSSValue(MutableAttributeSet attr, CSS.Attribute key, String value)

Parses the CSS property key with value value placing the result in att.

pack-priv static void
calculateTiledLayout(CSS.LayoutIterator iter, int targetSpan)

Calculate a tiled layout for the given iterator.

pack-priv static SizeRequirements
calculateTiledRequirements(CSS.LayoutIterator iter, SizeRequirements r)

Calculate the requirements needed to tile the requirements given by the iterator that would be tiled.

pack-priv static String
colorToHex(Color color)

Converts a type Color to a hex string in the format "#RRGGBB"

pack-priv Object
cssValueToStyleConstantsValue(StyleConstants key, Object value)

Converts the passed in CSS value to a StyleConstants value.

public static CSS.Attribute[]

Returns:

the set of all possible CSS attribute keys
getAllAttributeKeys
()

Return the set of all possible CSS attribute keys.

public static final CSS.Attribute

Returns:

the CSS.Attribute object, or null if the string doesn't represent a valid attribute key
getAttribute
(String
the name of the CSS attribute to fetch the typesafe enumeration for
name
)

Translates a string to a CSS.Attribute object.

pack-priv int
getBaseFontSize()

Returns the base font size.

pack-priv Color

Returns:

the color
getColor
(AttributeSet
the set of attributes
a
,
CSS.Attribute
CSS.Attribute identifying where color is stored.
key
)

Takes a set of attributes and turn it into a color specification.

private static float
getColorComponent(String string, int[] index)

Returns the next integer value from string starting at index[0].

private CSS.Attribute

Returns:

CSS.Attribute mapping for HTML.Attribute.ALIGN.
getCssAlignAttribute
(HTML.Tag
the AttributeSet containing HTML attributes.
tag
,
AttributeSet htmlAttrSet)

Maps HTML.Attribute.ALIGN to either: CSS.Attribute.TEXT_ALIGN CSS.Attribute.FLOAT CSS.Attribute.VERTICAL_ALIGN based on the tag associated with the attribute and the value of the attribute.

private CSS.Attribute[]

Returns:

CSS.Attribute[]
getCssAttribute
(HTML.Attribute
HTML.Attribute
hAttr
)

Maps an HTML.Attribute object to its appropriate CSS.Attributes.

pack-priv Object
getCssValue(CSS.Attribute
the CSS.Attribute
cssAttr
,
String
a String containing the value associated HTML.Attribute.
htmlAttrValue
)

Given a CSS.Attribute object and its corresponding HTML.Attribute's value, this method returns a CssValue object to associate with the CSS attribute.

pack-priv Font
getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss)

Returns the font for the values in the passed in AttributeSet.

pack-priv static int
getFontSize(AttributeSet attr, int defaultSize, StyleSheet ss)

private HTML.Tag

Returns:

HTML.Tag
getHTMLTag
(AttributeSet
the AttributeSet containing the HTML attributes.
htmlAttrSet
)

Fetches the tag associated with the HTML AttributeSet.

pack-priv static int
getIndexOfSize(float pt, int[] sizeMap)

pack-priv static int
getIndexOfSize(float pt, StyleSheet ss)

pack-priv Object
getInternalCSSValue(CSS.Attribute key, String value)

Gets the internal CSS representation of value which is a CSS value of the CSS attribute named key.

pack-priv float
getLength(AttributeSet a, CSS.Attribute key, StyleSheet ss)

Returns the length of the attribute in a with key key.

pack-priv float
getPointSize(String
CSS string describing font size
size
,
StyleSheet ss)

Returns the size of a font from the passed in string.

pack-priv float
getPointSize(int index, StyleSheet ss)

Return the point size, given a size index.

private StyleSheet
private static int
pack-priv static URL
getURL(URL base, String cssString)

Returns a URL for the given CSS url string.

pack-priv static final CSS.Value

Returns:

the CSS.Value object, or null if the string doesn't represent a valid CSS value name; this does not mean that it doesn't represent a valid CSS value
getValue
(String
the name of the CSS value to fetch the typesafe enumeration for
name
)

Translates a string to a CSS.Value object.

pack-priv static final Color
hexToColor(String value)

Convert a "#FFFFFF" hex string to a Color.

private boolean
isFloater(String alignValue)

private boolean
pack-priv static Object
private static Color
parseRGB(String string)

Parses a String in the format rgb(r, g, b) where each of the Color components is either an integer, or a floating number with a % after indicating a percentage value of 255.

private static Color
parseRGBA(String string)

pack-priv static String[]
parseStrings(String value)

Returns: an array of all the strings in value that are separated by whitespace.

private void
pack-priv void
setBaseFontSize(int sz)

Sets the base font size.

pack-priv void
setBaseFontSize(String size)

Sets the base font size from the passed in string.

pack-priv static Color
stringToColor(String str)

Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)" or "rgba(r, g, b, a)" to a Color.

pack-priv CSS.Attribute
styleConstantsKeyToCSSKey(StyleConstants sc)

Maps from a StyleConstants to a CSS Attribute.

pack-priv Object
styleConstantsValueToCSSValue(StyleConstants sc, Object styleValue)

Maps from a StyleConstants value to a CSS value.

private void
private void
private void
pack-priv AttributeSet

Returns:

AttributeSet containing the corresponding CSS attributes. The AttributeSet will be empty if there are no mapping CSS attributes.
translateHTMLToCSS
(AttributeSet
AttributeSet containing the HTML attributes.
htmlAttrSet
)

Convert a set of HTML attributes to an equivalent set of CSS attributes.

private boolean
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait