ilog.views.util.styling
Class IlvMutableStyleSheet

java.lang.Object
  extended by ilog.views.util.styling.IlvMutableStyleSheet
Direct Known Subclasses:
IlpMutableStyleSheet, IlvSDMMutableStyleSheet

public class IlvMutableStyleSheet
extends Object

This is a mutable style sheet. It is designed to be used in memory. It is possible to add, change and remove rules of the style sheet. The stylable that uses this mutable style sheet is automatically notified of any change. In order to set the style sheet, use for example:

 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);
         ...
     }
 }
 

Since:
JViews 6.0
See Also:
IlvStylable.setStyleSheets(java.lang.String[])

Constructor Summary
IlvMutableStyleSheet(IlvStylable stylable)
          Creates a new mutable style sheet.
 
Method Summary
 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 getDeclaredProperties(String selector)
          Returns all properties in declarations of the specified rule in the style sheet.
 Iterator 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(String styleSheet)
          Fills this style sheet with all declarations of the input style sheet.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IlvMutableStyleSheet

public IlvMutableStyleSheet(IlvStylable stylable)
Creates a new mutable style sheet.

Parameters:
stylable - The stylable that should use this style sheet.
Method Detail

getStylable

public IlvStylable getStylable()
Returns the stylable of this mutable style sheet.


readStyleSheet

public void readStyleSheet(String styleSheet)
Fills this style sheet with all declarations of the input style sheet. This method can be used to create a mutable style sheet from an immutable style sheet.


setDeclaration

public void setDeclaration(String selector,
                           String property,
                           String value)
Sets a declaration in a rule. This method searches for a rule that matches the specified selector and has the specified property set to a value. If a rule that matches the selector is not found, this method adds the specified rule to the end of the style sheet. If a matching rule is found but the property is not found, this method adds the specified declaration to the rule. If a matching rule is found with the property, this method changes the value of the property to the specified value. Then this method notifies the stylable that the style sheet has changed.

Parameters:
selector - The selector of the rule.
property - The property name.
value - The property value.
See Also:
setAdjusting(boolean)

getDeclaration

public String getDeclaration(String selector,
                             String property)
Returns the value of a declaration of a rule. Returns 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.

Parameters:
selector - The selector of the rule.
property - The property name.
Returns:
The property value.

containsDeclaration

public 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.

Parameters:
selector - The selector of the rule.
property - The property name.
Returns:
Whether the declaration is contained in the style sheet.

removeDeclaration

public void removeDeclaration(String selector,
                              String property)
Removes a declaration in a rule. This method searches for a rule that matches the selector. If a matching rule contains a declaration for the property, this declaration is removed from the rule. The remaining declarations in the rule are not changed. Then this method notifies the stylable that the style sheet has changed.

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).

Parameters:
selector - The selector of the rule.
property - The property name.
See Also:
setAdjusting(boolean), removeRule(java.lang.String)

containsRule

public boolean containsRule(String selector)
Returns true if the style sheet contains a rule with the specified selector.

Parameters:
selector - The selector of the rule.
Returns:
Whether the rule is contained in the style sheet.

removeRule

public void removeRule(String selector)
Removes a rule. This method removes all declarations that depend on the same selector. It notifies the stylable that the style sheet has changed.

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().

Parameters:
selector - The selector of the rule.
See Also:
setAdjusting(boolean), removeAllRules()

removeAllRules

public void removeAllRules()
Removes all rules.

Note: don't remove a rule while iterating over the rule selectors via getRuleSelectors(). This may mess up the iteration.

Since:
JViews 8.1

getRuleSelectors

public Iterator getRuleSelectors()
Returns all rule selectors stored in the style sheet. This is an iterator over String values. Note that the rule selector strings are normalized according to the CSS syntax.

Returns:
An iterator over all rule selectors.
See Also:
getDeclaredProperties(java.lang.String)

getDeclaredProperties

public Iterator getDeclaredProperties(String selector)
Returns all properties in declarations of the specified rule in the style sheet. This is an iterator over 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.

Parameters:
selector - The selector of the rule.
Returns:
An iterator over the declared properties of this rule.
See Also:
getDeclaration(java.lang.String, java.lang.String)

setAdjusting

public void setAdjusting(boolean adjusting)
Enables or disables the adjusting mode. This method can be used when a series of declarations must be added, changed, or removed from the style sheet. If adjusting is enabled, the style sheet does not notify the stylable immediately about changes, but waits with the notification until the adjusting mode is disabled. The following example illustrates the usage:
 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);
 }
 

See Also:
isAdjusting()

isAdjusting

public boolean isAdjusting()
Returns true if the adjusting mode is enabled.

See Also:
setAdjusting(boolean)

getUpdatedStyleSheets

protected String[] getUpdatedStyleSheets()
Return the updated set of style sheets.


propertyChanged

protected void propertyChanged()
Notifies the stylable that the style sheet has changed.


toString

public String toString()
Returns the string representation of the style sheet.

Overrides:
toString in class Object


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.