javax.swing.text.html
Class StyleSheet
- AbstractDocument.AttributeContext, Serializable
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.
AttributeSet | addAttribute(AttributeSet old, Object key, Object value) - Adds an attribute to the given set and returns a new set.
|
AttributeSet | addAttributes(AttributeSet old, AttributeSet attr) - Adds a set of attributes to the element.
|
void | addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key, String value) - Adds a CSS attribute to the given set.
|
boolean | addCSSAttributeFromHTML(MutableAttributeSet attr, CSS.Attribute key, String value) - Adds a CSS attribute to the given set.
|
void | addRule(String rule) - Adds a set if rules to the sheet.
|
void | addStyleSheet(StyleSheet ss) - Adds the rules from ss to those of the receiver. ss's rules will
override the old rules.
|
protected MutableAttributeSet | createLargeAttributeSet(AttributeSet a) - Creates a large set of attributes.
|
protected StyleContext.SmallAttributeSet | createSmallAttributeSet(AttributeSet a) - Creates a compact set of attributes that might be shared.
|
Color | getBackground(AttributeSet a) - Takes a set of attributes and turns it into a background
color specification.
|
URL | getBase() - Gets the base url.
|
StyleSheet.BoxPainter | getBoxPainter(AttributeSet a) - Gets the box formatter to use for the given set of CSS attributes.
|
AttributeSet | getDeclaration(String decl) - Translates a CSS declaration into an AttributeSet.
|
Font | getFont(AttributeSet a) - Gets the font to use for the given set.
|
Color | getForeground(AttributeSet a) - Takes a set of attributes and turns it into a foreground
color specification.
|
static int | getIndexOfSize(float pt) - TODO
|
StyleSheet.ListPainter | getListPainter(AttributeSet a) - Gets the list formatter to use for the given set of CSS attributes.
|
float | getPointSize(int index) - Gets the point size, given a size index.
|
float | getPointSize(String size) - Given the string of the size, returns the point size value.
|
Style | getRule(String selector) - Gets the rule that best matches the selector. selector is a space
separated String of element names.
|
Style | getRule(HTML.Tag t, Element e) - Gets the style used to render the given tag.
|
StyleSheet[] | getStyleSheets() - Returns an array of the linked StyleSheets.
|
AttributeSet | getViewAttributes(View v) - Gets a set of attributes to use in the view.
|
void | importStyleSheet(URL url) - Imports a style sheet from the url.
|
void | loadRules(Reader in, URL ref) - Loads a set of rules that have been specified in terms of CSS grammar.
|
AttributeSet | removeAttribute(AttributeSet old, Object key) - Removes an attribute from the set.
|
AttributeSet | removeAttributes(AttributeSet old, Enumeration names) - Removes a set of attributes for the element.
|
AttributeSet | removeAttributes(AttributeSet old, AttributeSet attrs) - Removes an attribute from the set.
|
void | removeStyle(String nm) - Removes a style previously added.
|
void | removeStyleSheet(StyleSheet ss) - Removes ss from those of the receiver
|
void | setBase(URL base) - Sets the base url.
|
void | setBaseFontSize(int sz) - Sets the base font size between 1 and 7.
|
void | setBaseFontSize(String size) - Sets the base font size from the String.
|
Color | stringToColor(String colorName) - Convert the color string represenation into java.awt.Color.
|
AttributeSet | translateHTMLToCSS(AttributeSet htmlAttrSet) - Converts a set of HTML attributes to an equivalent set of CSS attributes.
|
addAttribute , addAttributes , addChangeListener , addStyle , createLargeAttributeSet , createSmallAttributeSet , getBackground , getChangeListeners , getCompressionThreshold , getDefaultStyleContext , getEmptySet , getFont , getFont , getFontMetrics , getForeground , getStaticAttribute , getStaticAttributeKey , getStyle , getStyleNames , readAttributeSet , readAttributes , reclaim , registerStaticAttributeKey , removeAttribute , removeAttributes , removeAttributes , removeChangeListener , removeStyle , writeAttributeSet , writeAttributes |
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
StyleSheet
public StyleSheet()
Constructs a StyleSheet.
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.
attr
- - the attribute setkey
- - the attribute to addvalue
- - the value of the key
- true if a valid value was found.
addRule
public void addRule(String rule)
Adds a set if rules to the sheet. The rules are expected to be in valid
CSS format. This is called as a result of parsing a
rule
- - the rule to add to the sheet
addStyleSheet
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.
ss
- - the new StyleSheet.
getBackground
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.
- getBackground in interface StyleContext
a
- - the set to get the background color for
- the background color for the set
getDeclaration
public AttributeSet getDeclaration(String decl)
Translates a CSS declaration into an AttributeSet. This is called
as a result of encountering an HTML style attribute.
decl
- - the declaration to get
- the AttributeSet representing the declaration
getForeground
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.
- getForeground in interface StyleContext
a
- - the set to get the foreground color for
- the foreground color for the set
getPointSize
public float getPointSize(int index)
Gets the point size, given a size index.
getPointSize
public float getPointSize(String size)
Given the string of the size, returns the point size value.
size
- - the string representation of the size.
getRule
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.
selector
- - the element names separated by spaces
- the set of CSS attributes to use to render
getRule
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.
t
- - the tag to translate to visual attributese
- - the element representing the tag
- the set of CSS attributes to use to render the tag.
getStyleSheets
public StyleSheet[] getStyleSheets()
Returns an array of the linked StyleSheets. May return null.
- - An array of the linked StyleSheets.
getViewAttributes
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
v
- - the view to get the set for
- the AttributeSet to use in the view.
importStyleSheet
public void importStyleSheet(URL url)
Imports a style sheet from the url. The rules are directly added to the
receiver.
url
- - the URL to import the StyleSheet from.
loadRules
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.
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.
removeStyleSheet
public void removeStyleSheet(StyleSheet ss)
Removes ss from those of the receiver
ss
- - the StyleSheet to remove.
setBase
public void setBase(URL base)
Sets the base url. All import statements that are relative, will be
relative to base.
setBaseFontSize
public void setBaseFontSize(int sz)
Sets the base font size between 1 and 7.
sz
- - the new font size for the base.
setBaseFontSize
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.
size
- - the new font size as a String.
stringToColor
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)".
colorName
- the color to convert.
- the matching java.awt.color
translateHTMLToCSS
public AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet)
Converts a set of HTML attributes to an equivalent set of CSS attributes.
htmlAttrSet
- - the set containing the HTML attributes.
- the set of CSS attributes
StyleSheet.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.