public class IlvMutableStyleSheet extends Object
IlvMutableStyleSheet styleSheet = new IlvMutableStyleSheet(stylable); ... stylable.setStyleSheets(new String[] { styleSheet.toString() }); ... styleSheet.setDeclaration(selector, property, value); ... styleSheet.removeDeclaration(selector, property); ... styleSheet.removeRule(selector); ...In order to visit the entire contents of the style sheet, you need to iterate first over the rule selectors and then over the declared properties, for example:
IlvMutableStyleSheet styleSheet = ... ... Iterator iterator1 = styleSheet.getRuleSelectors(); while (iterator1.hasNext()) { String selector = (String)iterator1.next(); Iterator iterator2 = styleSheet.getDeclaredProperties(selector); while (iterator2.hasNext()) { String property = (String)iterator2.next(); String value = styleSheet.getDeclaration(selector, property); ... } }
IlvStylable.setStyleSheets(java.lang.String[])
Constructor and Description |
---|
IlvMutableStyleSheet(IlvStylable stylable)
Creates a new mutable style sheet.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsDeclaration(String selector,
String property)
Returns
true if the style sheet contains a rule with
the specified selector that contains a declaration for the specified
property. |
boolean |
containsRule(String selector)
Returns
true if the style sheet contains a rule with
the specified selector. |
String |
getDeclaration(String selector,
String property)
Returns the value of a declaration of a rule.
|
Iterator<String> |
getDeclaredProperties(String selector)
Returns all properties in declarations of the specified rule in the style
sheet.
|
Iterator<String> |
getRuleSelectors()
Returns all rule selectors stored in the style sheet.
|
IlvStylable |
getStylable()
Returns the stylable of this mutable style sheet.
|
protected String[] |
getUpdatedStyleSheets()
Return the updated set of style sheets.
|
boolean |
isAdjusting()
Returns
true if the adjusting mode is enabled. |
protected void |
propertyChanged()
Notifies the stylable that the style sheet has changed.
|
void |
readStyleSheet(InputStream stream)
Fills this style sheet with all declarations read from the input stream.
|
void |
readStyleSheet(Reader reader)
Fills this style sheet with all declarations read from the input reader.
|
void |
readStyleSheet(String styleSheet)
Fills this style sheet with all declarations of the input style sheet.
|
void |
readStyleSheet(URL url)
Fills this style sheet with all declarations read from a file.
|
void |
removeAllRules()
Removes all rules.
|
void |
removeDeclaration(String selector,
String property)
Removes a declaration in a rule.
|
void |
removeRule(String selector)
Removes a rule.
|
void |
setAdjusting(boolean adjusting)
Enables or disables the adjusting mode.
|
void |
setDeclaration(String selector,
String property,
String value)
Sets a declaration in a rule.
|
String |
toString()
Returns the string representation of the style sheet.
|
public IlvMutableStyleSheet(IlvStylable stylable)
stylable
- The stylable that should use this style sheet.public IlvStylable getStylable()
public void readStyleSheet(URL url) throws IlvStylingException
@charset "UTF-8";
then the stream encoding is assumed to be UTF-8. Otherwise, the
default encoding is used.url
- The URL of the file.IlvStylingException
- If the input contains CSS syntax errors
or if an IOException
occurs.public void readStyleSheet(InputStream stream) throws IlvStylingException
@charset "UTF-8";
then the stream encoding is assumed to be UTF-8. Otherwise, the
default encoding is used.stream
- The input stream. It is consumed by this method,
but has to be closed by the caller.IlvStylingException
- If the input contains CSS syntax errors
or if an IOException
occurs.public void readStyleSheet(String styleSheet)
styleSheet
- The text of the input style sheet.public void readStyleSheet(Reader reader) throws IlvStylingException
reader
- The input reader. It is consumed by this method,
but has to be closed by the caller.IlvStylingException
- If the input contains CSS syntax errors
or if an IOException
occurs.public void setDeclaration(String selector, String property, String value)
selector
- The selector of the rule.property
- The property name.value
- The property value.setAdjusting(boolean)
public String getDeclaration(String selector, String property)
null
if no rule matches the selector, or if
the property is not declared in the matching rule in the
mutable style sheet.
The returned string omits the optional leading and trailing quote
character.
selector
- The selector of the rule.property
- The property name.public boolean containsDeclaration(String selector, String property)
true
if the style sheet contains a rule with
the specified selector that contains a declaration for the specified
property.
selector
- The selector of the rule.property
- The property name.public void removeDeclaration(String selector, String property)
Note: don't remove a declaration while iterating over the declarations
via getDeclaredProperties(java.lang.String)
or over the rule selectors
via getRuleSelectors()
. This may mess up the iteration.
To remove all declarations of a rule, use removeRule(java.lang.String)
.
selector
- The selector of the rule.property
- The property name.setAdjusting(boolean)
,
removeRule(java.lang.String)
public boolean containsRule(String selector)
true
if the style sheet contains a rule with
the specified selector.
selector
- The selector of the rule.public void removeRule(String selector)
Note: don't remove a rule while iterating over the rule selectors
via getRuleSelectors()
. This may mess up the iteration.
To remove all rules of the style sheet, use removeAllRules()
.
selector
- The selector of the rule.setAdjusting(boolean)
,
removeAllRules()
public void removeAllRules()
Note: don't remove a rule while iterating over the rule selectors
via getRuleSelectors()
. This may mess up the iteration.
public Iterator<String> getRuleSelectors()
String
values.
Note that the rule selector strings are normalized according to
the CSS syntax.getDeclaredProperties(java.lang.String)
public Iterator<String> getDeclaredProperties(String selector)
String
values.
This method searches for a rule that matches the selector.
If such a rule does not exist, it returns an empty iteration.
If such a rule exists, it returns all properties that are set
by this rule.selector
- The selector of the rule.getDeclaration(java.lang.String, java.lang.String)
public void setAdjusting(boolean adjusting)
styleSheet.setAdjusting(true); try { // the following settings become not immediately effective styleSheet.setDeclaration(...); styleSheet.setDeclaration(...); styleSheet.setDeclaration(...); ... } finally { // now, the previous settings become effective styleSheet.setAdjusting(false); }
isAdjusting()
public boolean isAdjusting()
true
if the adjusting mode is enabled.
setAdjusting(boolean)
protected String[] getUpdatedStyleSheets()
protected void propertyChanged()
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.