Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.text.StyleContext
javax.swing.text.html.StyleSheet
public class StyleSheet
extends StyleContext
Nested Class Summary | |
static class |
|
static class |
|
Nested classes/interfaces inherited from class javax.swing.text.StyleContext | |
StyleContext.NamedStyle , StyleContext.SmallAttributeSet |
Field Summary |
Fields inherited from class javax.swing.text.StyleContext | |
DEFAULT_STYLE |
Constructor Summary | |
|
Method Summary | |
AttributeSet |
|
AttributeSet |
|
void |
|
boolean |
|
void | |
void |
|
protected MutableAttributeSet |
|
protected StyleContext.SmallAttributeSet |
|
Color |
|
URL |
|
StyleSheet.BoxPainter |
|
AttributeSet |
|
Font |
|
Color |
|
static int |
|
StyleSheet.ListPainter |
|
float |
|
float |
|
Style | |
Style | |
StyleSheet[] |
|
AttributeSet |
|
void |
|
void | |
AttributeSet |
|
AttributeSet |
|
AttributeSet |
|
void |
|
void |
|
void | |
void |
|
void |
|
Color |
|
AttributeSet |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
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).
- Specified by:
- addAttribute in interface AbstractDocument.AttributeContext
- Overrides:
- addAttribute in interface StyleContext
- Parameters:
old
- - the old setkey
- - the non-null attribute keyvalue
- - the attribute value
- Returns:
- the updated set
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.
- Specified by:
- addAttributes in interface AbstractDocument.AttributeContext
- Overrides:
- addAttributes in interface StyleContext
- Parameters:
old
- - the old setattr
- - the attributes to add
- Returns:
- the updated attribute set
public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key, String value)
Adds a CSS attribute to the given set.
- Parameters:
attr
- - the attribute setkey
- - the attribute to addvalue
- - the value of the key
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 setkey
- - the attribute to addvalue
- - the value of the key
- Returns:
- true if a valid value was found.
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
- Parameters:
rule
- - the rule to add to the sheet
public void addStyleSheet(StyleSheet ss)
Adds the rules from ss to those of the receiver. ss's rules will override the old rules. An added StyleSheet will never override the rules of the receiving style sheet.
- Parameters:
ss
- - the new StyleSheet.
protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
Creates a large set of attributes. This set is not shared. This is a hook for subclasses that want to change the behaviour of the larger attribute storage format.
- Overrides:
- createLargeAttributeSet in interface StyleContext
- Parameters:
a
- - the set of attributes to be represented in the larger form.
- Returns:
- the large set of attributes.
protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
Creates a compact set of attributes that might be shared. This is a hook for subclasses that want to change the behaviour of SmallAttributeSet.
- Overrides:
- createSmallAttributeSet in interface StyleContext
- Parameters:
a
- - the set of attributes to be represented in the compact form.
- Returns:
- the set of attributes created
public Color getBackground(AttributeSet a)
Takes a set of attributes and turns it into a background color specification. This is used to specify things like, brigher, more hue etc.
- Overrides:
- getBackground in interface StyleContext
- Parameters:
a
- - the set to get the background color for
- Returns:
- the background color for the set
public StyleSheet.BoxPainter getBoxPainter(AttributeSet a)
Gets the box formatter to use for the given set of CSS attributes.
- Parameters:
a
- - the given set
- Returns:
- the box formatter
public AttributeSet getDeclaration(String decl)
Translates a CSS declaration into an AttributeSet. This is called as a result of encountering an HTML style attribute.
- Parameters:
decl
- - the declaration to get
- Returns:
- the AttributeSet representing the declaration
public Font getFont(AttributeSet a)
Gets the font to use for the given set.
- Overrides:
- getFont in interface StyleContext
- Parameters:
a
- - the set to get the font for.
- Returns:
- the font for the set
public Color getForeground(AttributeSet a)
Takes a set of attributes and turns it into a foreground color specification. This is used to specify things like, brigher, more hue etc.
- Overrides:
- getForeground in interface StyleContext
- Parameters:
a
- - the set to get the foreground color for
- Returns:
- the foreground color for the set
public StyleSheet.ListPainter getListPainter(AttributeSet a)
Gets the list formatter to use for the given set of CSS attributes.
- Parameters:
a
- - the given set
- Returns:
- the list formatter
public float getPointSize(int index)
Gets the point size, given a size index.
- Parameters:
index
- - the size index
- Returns:
- the point size.
public float getPointSize(String size)
Given the string of the size, returns the point size value.
- Parameters:
size
- - the string representation of the size.
- Returns:
- - the point size value.
public Style getRule(String selector)
Gets the rule that best matches the selector. selector is a space separated String of element names. The attributes of the returned Style will change as rules are added and removed.
- Parameters:
selector
- - the element names separated by spaces
- Returns:
- the set of CSS attributes to use to render
public Style getRule(HTML.Tag t, Element e)
Gets the style used to render the given tag. The element represents the tag and can be used to determine the nesting, where the attributes will differ if there is nesting inside of elements.
- Parameters:
t
- - the tag to translate to visual attributese
- - the element representing the tag
- Returns:
- the set of CSS attributes to use to render the tag.
public StyleSheet[] getStyleSheets()
Returns an array of the linked StyleSheets. May return null.
- Returns:
- - An array of the linked StyleSheets.
public AttributeSet getViewAttributes(View v)
Gets a set of attributes to use in the view. This is a set of attributes that can be used for View.getAttributes
- Parameters:
v
- - the view to get the set for
- Returns:
- the AttributeSet to use in the view.
public void importStyleSheet(URL url)
Imports a style sheet from the url. The rules are directly added to the receiver. This is usually called when a
- Parameters:
url
- the URL to import the StyleSheet from
public void loadRules(Reader in, URL ref) throws IOException
Loads a set of rules that have been specified in terms of CSS grammar. If there are any conflicts with existing rules, the new rule is added.
- Parameters:
in
- - the stream to read the CSS grammar from.ref
- - the reference URL. It is the location of the stream, it may be null. All relative URLs specified in the stream will be based upon this parameter.
- Throws:
IOException
- - For any IO error while reading
public AttributeSet removeAttribute(AttributeSet old, Object key)
Removes an attribute from the set. If the attribute is a StyleConstants, it will be converted to CSS before forwarding to the superclass.
- Specified by:
- removeAttribute in interface AbstractDocument.AttributeContext
- Overrides:
- removeAttribute in interface StyleContext
- Parameters:
old
- - the old setkey
- - the non-null attribute key
- Returns:
- the updated set
public AttributeSet removeAttributes(AttributeSet old, Enumeration names)
Removes a set of attributes for the element. If any of the attributes is a StyleConstants, they will be converted to CSS before forwarding to the superclass.
- Specified by:
- removeAttributes in interface AbstractDocument.AttributeContext
- Overrides:
- removeAttributes in interface StyleContext
- Parameters:
old
- - the old attribute setnames
- - the attribute names
- Returns:
- the update attribute set
public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
Removes an attribute from the set. If any of the attributes are StyleConstants, they will be converted to CSS before forwarding to the superclass.
- Specified by:
- removeAttributes in interface AbstractDocument.AttributeContext
- Overrides:
- removeAttributes in interface StyleContext
- Parameters:
old
- - the old setattrs
- - the attributes to remove
- Returns:
- the updated set
public void removeStyle(String nm)
Removes a style previously added.
- Overrides:
- removeStyle in interface StyleContext
- Parameters:
nm
- - the name of the style to remove
public void removeStyleSheet(StyleSheet ss)
Removes ss from those of the receiver
- Parameters:
ss
- - the StyleSheet to remove.
public void setBase(URL base)
Sets the base url. All import statements that are relative, will be relative to base.
- Parameters:
base
- - the base URL.
public void setBaseFontSize(int sz)
Sets the base font size between 1 and 7.
- Parameters:
sz
- - the new font size for the base.
public void setBaseFontSize(String size)
Sets the base font size from the String. It can either identify a specific font size (between 1 and 7) or identify a relative font size such as +1 or -2.
- Parameters:
size
- - the new font size as a String.
public Color stringToColor(String colorName)
Convert the color string represenation into java.awt.Color. The valid values are like "aqua" , "#00FFFF" or "rgb(1,6,44)".
- Parameters:
colorName
- the color to convert.
- Returns:
- the matching java.awt.color
public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
Converts a set of HTML attributes to an equivalent set of CSS attributes.
- Parameters:
htmlAttrSet
- - the set containing the HTML attributes.
- Returns:
- the set of CSS attributes