javax.swing.text.html

Class StyleSheet

public class StyleSheet extends StyleContext

This class adds support for defining the visual characteristics of HTML views being rendered. This enables views to be customized by a look-and-feel, mulitple views over the same model can be rendered differently. Each EditorPane has its own StyleSheet, but by default one sheet will be shared by all of the HTMLEditorKit instances. An HTMLDocument can also have a StyleSheet, which holds specific CSS specs. In order for Views to store less state and therefore be more lightweight, the StyleSheet can act as a factory for painters that handle some of the rendering tasks. Since the StyleSheet may be used by views over multiple documents the HTML attributes don't effect the selector being used. The rules are stored as named styles, and other information is stored to translate the context of an element to a rule.
Nested Class Summary
static classStyleSheet.BoxPainter
This class carries out some of the duties of CSS formatting.
static classStyleSheet.ListPainter
This class carries out some of the CSS list formatting duties.
Constructor Summary
StyleSheet()
Constructs a StyleSheet.
Method Summary
AttributeSetaddAttribute(AttributeSet old, Object key, Object value)
Adds an attribute to the given set and returns a new set.
AttributeSetaddAttributes(AttributeSet old, AttributeSet attr)
Adds a set of attributes to the element.
voidaddCSSAttribute(MutableAttributeSet attr, CSS.Attribute key, String value)
Adds a CSS attribute to the given set.
booleanaddCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key, String value)
Adds a CSS attribute to the given set.
voidaddRule(String rule)
Adds a set of rules to the sheet.
voidaddStyleSheet(StyleSheet ss)
Adds the rules from ss to those of the receiver. ss's rules will override the old rules.
protected MutableAttributeSetcreateLargeAttributeSet(AttributeSet a)
Creates a large set of attributes.
protected StyleContext.SmallAttributeSetcreateSmallAttributeSet(AttributeSet a)
Creates a compact set of attributes that might be shared.
ColorgetBackground(AttributeSet a)
Takes a set of attributes and turns it into a background color specification.
URLgetBase()
Gets the base url.
StyleSheet.BoxPaintergetBoxPainter(AttributeSet a)
Gets the box formatter to use for the given set of CSS attributes.
AttributeSetgetDeclaration(String decl)
Translates a CSS declaration into an AttributeSet.
FontgetFont(AttributeSet a)
Gets the font to use for the given set.
ColorgetForeground(AttributeSet a)
Takes a set of attributes and turns it into a foreground color specification.
static intgetIndexOfSize(float pt)
TODO
StyleSheet.ListPaintergetListPainter(AttributeSet a)
Gets the list formatter to use for the given set of CSS attributes.
floatgetPointSize(int index)
Gets the point size, given a size index.
floatgetPointSize(String size)
Given the string of the size, returns the point size value.
StylegetRule(HTML.Tag t, Element e)
Gets the style used to render the given tag.
StylegetRule(String selector)
Gets the rule that best matches the selector. selector is a space separated String of element names.
StyleSheet[]getStyleSheets()
Returns an array of the linked StyleSheets.
AttributeSetgetViewAttributes(View v)
Gets a set of attributes to use in the view.
voidimportStyleSheet(URL url)
Imports a style sheet from the url.
voidloadRules(Reader in, URL ref)
Loads a set of rules that have been specified in terms of CSS grammar.
AttributeSetremoveAttribute(AttributeSet old, Object key)
Removes an attribute from the set.
AttributeSetremoveAttributes(AttributeSet old, AttributeSet attrs)
Removes an attribute from the set.
AttributeSetremoveAttributes(AttributeSet old, Enumeration<?> names)
Removes a set of attributes for the element.
voidremoveStyle(String nm)
Removes a style previously added.
voidremoveStyleSheet(StyleSheet ss)
Removes ss from those of the receiver
voidsetBase(URL base)
Sets the base url.
voidsetBaseFontSize(int sz)
Sets the base font size between 1 and 7.
voidsetBaseFontSize(String size)
Sets the base font size from the String.
ColorstringToColor(String colorName)
Convert the color string represenation into java.awt.Color.
AttributeSettranslateHTMLToCSS(AttributeSet htmlAttrSet)
Converts a set of HTML attributes to an equivalent set of CSS attributes.

Constructor Detail

StyleSheet

public StyleSheet()
Constructs a StyleSheet.

Method Detail

addAttribute

public AttributeSet addAttribute(AttributeSet old, Object key, Object value)
Adds an attribute to the given set and returns a new set. This is implemented to convert StyleConstants attributes to CSS before forwarding them to the superclass. The StyleConstants attribute do not have corresponding CSS entry, the attribute is stored (but will likely not be used).

Parameters: old - the old set key - the non-null attribute key value - the attribute value

Returns: the updated set

addAttributes

public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
Adds a set of attributes to the element. If any of these attributes are StyleConstants, they will be converted to CSS before forwarding to the superclass.

Parameters: old - the old set attr - the attributes to add

Returns: the updated attribute set

addCSSAttribute

public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key, String value)
Adds a CSS attribute to the given set.

Parameters: attr - the attribute set key - the attribute to add value - the value of the key

addCSSAttributeFromHTML

public boolean addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key, String value)
Adds a CSS attribute to the given set. This method parses the value argument from HTML based on key. Returns true if it finds a valid value for the given key, and false otherwise.

Parameters: attr - the attribute set key - the attribute to add value - the value of the key

Returns: true if a valid value was found.

addRule

public void addRule(String rule)
Adds a set of rules to the sheet. The rules are expected to be in valid CSS format. This is called as a result of parsing a